@gravito/cosmos 1.0.0 → 3.0.0
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/CHANGELOG.md +15 -0
- package/dist/core/src/Application.d.ts +185 -0
- package/dist/core/src/ConfigManager.d.ts +21 -0
- package/dist/core/src/Container.d.ts +38 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +31 -0
- package/dist/core/src/GravitoServer.d.ts +20 -0
- package/dist/core/src/HookManager.d.ts +70 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +207 -0
- package/dist/core/src/Route.d.ts +25 -0
- package/dist/core/src/Router.d.ts +232 -0
- package/dist/core/src/ServiceProvider.d.ts +150 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +142 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +36 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +21 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +27 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +15 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/types.d.ts +186 -0
- package/dist/core/src/engine/AOTRouter.d.ts +117 -0
- package/dist/core/src/engine/FastContext.d.ts +34 -0
- package/dist/core/src/engine/Gravito.d.ts +191 -0
- package/dist/core/src/engine/MinimalContext.d.ts +36 -0
- package/dist/core/src/engine/analyzer.d.ts +21 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +107 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +4 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +4 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +15 -0
- package/dist/core/src/exceptions/HttpException.d.ts +5 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +6 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +14 -0
- package/dist/core/src/exceptions/index.d.ts +6 -0
- package/dist/core/src/helpers/Arr.d.ts +14 -0
- package/dist/core/src/helpers/Str.d.ts +18 -0
- package/dist/core/src/helpers/data.d.ts +5 -0
- package/dist/core/src/helpers/errors.d.ts +12 -0
- package/dist/core/src/helpers/response.d.ts +17 -0
- package/dist/core/src/helpers.d.ts +38 -0
- package/dist/core/src/http/CookieJar.d.ts +37 -0
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +6 -0
- package/dist/core/src/http/middleware/Cors.d.ts +12 -0
- package/dist/core/src/http/middleware/Csrf.d.ts +11 -0
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +11 -0
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +17 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +12 -0
- package/dist/core/src/http/types.d.ts +312 -0
- package/dist/core/src/index.d.ts +60 -0
- package/dist/core/src/runtime.d.ts +63 -0
- package/dist/core/src/security/Encrypter.d.ts +24 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +38 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/cosmos/src/I18nService.d.ts +144 -0
- package/dist/cosmos/src/index.d.ts +21 -0
- package/dist/cosmos/src/loader.d.ts +11 -0
- package/dist/index.js +1 -1
- package/dist/photon/src/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/I18nService.ts +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TestResponse wraps a standard Fetch Response and provides fluent assertion methods
|
|
3
|
+
* inspired by Laravel's TestResponse.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TestResponse {
|
|
6
|
+
readonly response: Response;
|
|
7
|
+
private _jsonData;
|
|
8
|
+
private _textData;
|
|
9
|
+
constructor(response: Response);
|
|
10
|
+
/**
|
|
11
|
+
* Assert the response status code
|
|
12
|
+
*/
|
|
13
|
+
assertStatus(status: number): this;
|
|
14
|
+
/**
|
|
15
|
+
* Assert that the response has a 200 status code
|
|
16
|
+
*/
|
|
17
|
+
assertOk(): this;
|
|
18
|
+
/**
|
|
19
|
+
* Assert that the response has a 201 status code
|
|
20
|
+
*/
|
|
21
|
+
assertCreated(): this;
|
|
22
|
+
/**
|
|
23
|
+
* Assert that the response has a 404 status code
|
|
24
|
+
*/
|
|
25
|
+
assertNotFound(): this;
|
|
26
|
+
/**
|
|
27
|
+
* Assert that the response has a 403 status code
|
|
28
|
+
*/
|
|
29
|
+
assertForbidden(): this;
|
|
30
|
+
/**
|
|
31
|
+
* Assert that the response has a 401 status code
|
|
32
|
+
*/
|
|
33
|
+
assertUnauthorized(): this;
|
|
34
|
+
/**
|
|
35
|
+
* Assert the response is a redirect
|
|
36
|
+
*/
|
|
37
|
+
assertRedirect(uri?: string): this;
|
|
38
|
+
/**
|
|
39
|
+
* Assert that the response contains the given JSON data.
|
|
40
|
+
*/
|
|
41
|
+
assertJson(data: any): Promise<this>;
|
|
42
|
+
/**
|
|
43
|
+
* Assert that the response contains exactly the given JSON data.
|
|
44
|
+
*/
|
|
45
|
+
assertExactJson(data: any): Promise<this>;
|
|
46
|
+
/**
|
|
47
|
+
* Assert the structure of the JSON response.
|
|
48
|
+
*/
|
|
49
|
+
assertJsonStructure(structure: any): Promise<this>;
|
|
50
|
+
/**
|
|
51
|
+
* Assert that the response contains the given string.
|
|
52
|
+
*/
|
|
53
|
+
assertSee(value: string): Promise<this>;
|
|
54
|
+
/**
|
|
55
|
+
* Assert that the response does not contain the given string.
|
|
56
|
+
*/
|
|
57
|
+
assertDontSee(value: string): Promise<this>;
|
|
58
|
+
/**
|
|
59
|
+
* Assert a header exists and matches value
|
|
60
|
+
*/
|
|
61
|
+
assertHeader(header: string, value: string): this;
|
|
62
|
+
/**
|
|
63
|
+
* Assert a header does not exist
|
|
64
|
+
*/
|
|
65
|
+
assertHeaderMissing(header: string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Get the JSON content
|
|
68
|
+
*/
|
|
69
|
+
getJson(): Promise<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the text content
|
|
72
|
+
*/
|
|
73
|
+
getText(): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Alias for getText for standard expectations if needed
|
|
76
|
+
*/
|
|
77
|
+
get body(): Promise<string>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system type definitions.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Listener interface.
|
|
6
|
+
*
|
|
7
|
+
* All event listeners must implement this interface.
|
|
8
|
+
*/
|
|
9
|
+
export interface Listener<TEvent extends Event = Event> {
|
|
10
|
+
/**
|
|
11
|
+
* Handle an event.
|
|
12
|
+
* @param event - Event instance
|
|
13
|
+
*/
|
|
14
|
+
handle(event: TEvent): Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Marker interface for listeners that should be queued.
|
|
18
|
+
*
|
|
19
|
+
* Listeners implementing this interface can be dispatched asynchronously via a queue.
|
|
20
|
+
*/
|
|
21
|
+
export interface ShouldQueue {
|
|
22
|
+
/**
|
|
23
|
+
* Queue name (optional).
|
|
24
|
+
*/
|
|
25
|
+
queue?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Connection name (optional).
|
|
28
|
+
*/
|
|
29
|
+
connection?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Delay before execution (seconds).
|
|
32
|
+
*/
|
|
33
|
+
delay?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Marker interface for events that should be broadcast.
|
|
37
|
+
*
|
|
38
|
+
* Events implementing this interface can be automatically broadcast to clients.
|
|
39
|
+
*/
|
|
40
|
+
export interface ShouldBroadcast {
|
|
41
|
+
/**
|
|
42
|
+
* Define the broadcast channel.
|
|
43
|
+
* @returns Channel name or channel object
|
|
44
|
+
*/
|
|
45
|
+
broadcastOn(): string | Channel;
|
|
46
|
+
/**
|
|
47
|
+
* Define broadcast payload (optional).
|
|
48
|
+
* If omitted, public event properties will be used.
|
|
49
|
+
* @returns Broadcast payload
|
|
50
|
+
*/
|
|
51
|
+
broadcastWith?(): Record<string, unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Define the broadcast event name (optional).
|
|
54
|
+
* If omitted, the event class name will be used.
|
|
55
|
+
* @returns Event name
|
|
56
|
+
*/
|
|
57
|
+
broadcastAs?(): string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Channel interface.
|
|
61
|
+
*/
|
|
62
|
+
export interface Channel {
|
|
63
|
+
/**
|
|
64
|
+
* Channel name.
|
|
65
|
+
*/
|
|
66
|
+
name: string;
|
|
67
|
+
/**
|
|
68
|
+
* Channel type.
|
|
69
|
+
*/
|
|
70
|
+
type: 'public' | 'private' | 'presence';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Base event class.
|
|
74
|
+
*
|
|
75
|
+
* All events should extend this class.
|
|
76
|
+
*/
|
|
77
|
+
export declare abstract class Event {
|
|
78
|
+
/**
|
|
79
|
+
* Whether this event should be broadcast.
|
|
80
|
+
*/
|
|
81
|
+
shouldBroadcast(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Get broadcast channel.
|
|
84
|
+
*/
|
|
85
|
+
getBroadcastChannel(): string | Channel | null;
|
|
86
|
+
/**
|
|
87
|
+
* Get broadcast payload.
|
|
88
|
+
*/
|
|
89
|
+
getBroadcastData(): Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Get broadcast event name.
|
|
92
|
+
*/
|
|
93
|
+
getBroadcastEventName(): string;
|
|
94
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from '@gravito/photon';
|
|
2
|
+
export type TranslationMap = {
|
|
3
|
+
[key: string]: string | TranslationMap;
|
|
4
|
+
};
|
|
5
|
+
export interface I18nConfig {
|
|
6
|
+
defaultLocale: string;
|
|
7
|
+
supportedLocales: string[];
|
|
8
|
+
translations?: Record<string, TranslationMap>;
|
|
9
|
+
}
|
|
10
|
+
export interface I18nService {
|
|
11
|
+
locale: string;
|
|
12
|
+
setLocale(locale: string): void;
|
|
13
|
+
getLocale(): string;
|
|
14
|
+
t(key: string, replacements?: Record<string, string | number>): string;
|
|
15
|
+
has(key: string): boolean;
|
|
16
|
+
clone(locale?: string): I18nService;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Request-scoped I18n Instance
|
|
20
|
+
* Holds the state (locale) for a single request, but shares the heavy resources (translations)
|
|
21
|
+
*/
|
|
22
|
+
export declare class I18nInstance implements I18nService {
|
|
23
|
+
private manager;
|
|
24
|
+
private _locale;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new I18nInstance.
|
|
27
|
+
*
|
|
28
|
+
* @param manager - The I18nManager instance.
|
|
29
|
+
* @param initialLocale - The initial locale for this instance.
|
|
30
|
+
*/
|
|
31
|
+
constructor(manager: I18nManager, initialLocale: string);
|
|
32
|
+
get locale(): string;
|
|
33
|
+
set locale(value: string);
|
|
34
|
+
/**
|
|
35
|
+
* Set the current locale.
|
|
36
|
+
*
|
|
37
|
+
* @param locale - The locale to set.
|
|
38
|
+
*/
|
|
39
|
+
setLocale(locale: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get the current locale.
|
|
42
|
+
*
|
|
43
|
+
* @returns The current locale string.
|
|
44
|
+
*/
|
|
45
|
+
getLocale(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Translate a key.
|
|
48
|
+
*
|
|
49
|
+
* @param key - The translation key (e.g., 'messages.welcome').
|
|
50
|
+
* @param replacements - Optional replacements for parameters in the translation string.
|
|
51
|
+
* @returns The translated string, or the key if not found.
|
|
52
|
+
*/
|
|
53
|
+
t(key: string, replacements?: Record<string, string | number>): string;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a translation key exists.
|
|
56
|
+
*
|
|
57
|
+
* @param key - The translation key to check.
|
|
58
|
+
* @returns True if the key exists, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
has(key: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Clone the current instance with a potentially new locale.
|
|
63
|
+
*
|
|
64
|
+
* @param locale - Optional new locale for the cloned instance.
|
|
65
|
+
* @returns A new I18nInstance.
|
|
66
|
+
*/
|
|
67
|
+
clone(locale?: string): I18nService;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Global I18n Manager
|
|
71
|
+
* Holds shared configuration and translation resources
|
|
72
|
+
*/
|
|
73
|
+
export declare class I18nManager implements I18nService {
|
|
74
|
+
private config;
|
|
75
|
+
private translations;
|
|
76
|
+
private globalInstance;
|
|
77
|
+
/**
|
|
78
|
+
* Create a new I18nManager.
|
|
79
|
+
*
|
|
80
|
+
* @param config - The I18n configuration.
|
|
81
|
+
*/
|
|
82
|
+
constructor(config: I18nConfig);
|
|
83
|
+
get locale(): string;
|
|
84
|
+
set locale(value: string);
|
|
85
|
+
/**
|
|
86
|
+
* Set the global locale.
|
|
87
|
+
*
|
|
88
|
+
* @param locale - The locale to set.
|
|
89
|
+
*/
|
|
90
|
+
setLocale(locale: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get the global locale.
|
|
93
|
+
*
|
|
94
|
+
* @returns The global locale string.
|
|
95
|
+
*/
|
|
96
|
+
getLocale(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Translate a key using the global locale.
|
|
99
|
+
*
|
|
100
|
+
* @param key - The translation key.
|
|
101
|
+
* @param replacements - Optional replacements.
|
|
102
|
+
* @returns The translated string.
|
|
103
|
+
*/
|
|
104
|
+
t(key: string, replacements?: Record<string, string | number>): string;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a translation key exists in the global locale.
|
|
107
|
+
*
|
|
108
|
+
* @param key - The translation key.
|
|
109
|
+
* @returns True if found.
|
|
110
|
+
*/
|
|
111
|
+
has(key: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Clone the global instance.
|
|
114
|
+
*
|
|
115
|
+
* @param locale - Optional locale for the clone.
|
|
116
|
+
* @returns A new I18nInstance.
|
|
117
|
+
*/
|
|
118
|
+
clone(locale?: string): I18nService;
|
|
119
|
+
/**
|
|
120
|
+
* Get the I18n configuration.
|
|
121
|
+
*
|
|
122
|
+
* @returns The configuration object.
|
|
123
|
+
*/
|
|
124
|
+
getConfig(): I18nConfig;
|
|
125
|
+
/**
|
|
126
|
+
* Add a resource bundle for a specific locale.
|
|
127
|
+
*
|
|
128
|
+
* @param locale - The locale string.
|
|
129
|
+
* @param translations - The translations object.
|
|
130
|
+
*/
|
|
131
|
+
addResource(locale: string, translations: TranslationMap): void;
|
|
132
|
+
/**
|
|
133
|
+
* Internal translation logic used by instances
|
|
134
|
+
*/
|
|
135
|
+
translate(locale: string, key: string, replacements?: Record<string, string | number>): string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Locale Middleware
|
|
139
|
+
*
|
|
140
|
+
* Detects locale from:
|
|
141
|
+
* 1. Route Parameter (e.g. /:locale/foo) - Recommended for SEO
|
|
142
|
+
* 2. Header (Accept-Language) - Recommended for APIs
|
|
143
|
+
*/
|
|
144
|
+
export declare const localeMiddleware: (i18nManager: I18nService) => MiddlewareHandler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
2
|
+
import { type I18nConfig, type I18nService } from './I18nService';
|
|
3
|
+
declare module '@gravito/core' {
|
|
4
|
+
interface Variables {
|
|
5
|
+
i18n: I18nService;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* OrbitCosmos - Internationalization Orbit
|
|
10
|
+
*
|
|
11
|
+
* Provides i18n functionality for Gravito applications.
|
|
12
|
+
*/
|
|
13
|
+
export declare class OrbitCosmos implements GravitoOrbit {
|
|
14
|
+
private config;
|
|
15
|
+
constructor(config: I18nConfig);
|
|
16
|
+
install(core: PlanetCore): void;
|
|
17
|
+
}
|
|
18
|
+
/** @deprecated Use OrbitCosmos instead */
|
|
19
|
+
export declare const I18nOrbit: typeof OrbitCosmos;
|
|
20
|
+
export * from './I18nService';
|
|
21
|
+
export * from './loader';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load translations from a directory
|
|
3
|
+
* Structure:
|
|
4
|
+
* /lang
|
|
5
|
+
* /en.json -> { "welcome": "Hello" }
|
|
6
|
+
* /zh.json -> { "welcome": "Hello" }
|
|
7
|
+
* /en/auth.json -> { "failed": "Login failed" } (Optional deep structure, maybe later)
|
|
8
|
+
*
|
|
9
|
+
* For now, we support flat JSON files per locale: en.json, zh.json
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadTranslations(directory: string): Promise<Record<string, Record<string, string>>>;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED