@gravito/cosmos 3.0.0 → 3.1.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +105 -45
  3. package/README.zh-TW.md +102 -22
  4. package/build.ts +35 -0
  5. package/docs/plans/01-performance.md +187 -0
  6. package/docs/plans/02-architecture.md +309 -0
  7. package/docs/plans/03-api-enhancement.md +345 -0
  8. package/docs/plans/04-testing.md +431 -0
  9. package/docs/plans/README.md +47 -0
  10. package/ion/src/index.js +1179 -1138
  11. package/package.json +18 -5
  12. package/src/I18nService.ts +657 -94
  13. package/src/index.ts +51 -6
  14. package/src/loader.ts +45 -12
  15. package/tests/helpers/factory.ts +41 -0
  16. package/tests/performance/translate.bench.ts +27 -0
  17. package/tests/unit/api.test.ts +37 -0
  18. package/tests/unit/detector.test.ts +70 -0
  19. package/tests/unit/edge.test.ts +100 -0
  20. package/tests/unit/fallback.test.ts +66 -0
  21. package/tests/unit/lazy.test.ts +35 -0
  22. package/tests/{loader.test.ts → unit/loader.test.ts} +1 -1
  23. package/tests/{manager.test.ts → unit/manager.test.ts} +1 -2
  24. package/tests/unit/plural.test.ts +58 -0
  25. package/tests/{service.test.ts → unit/service.test.ts} +7 -2
  26. package/tsconfig.json +12 -24
  27. package/dist/core/src/Application.d.ts +0 -185
  28. package/dist/core/src/ConfigManager.d.ts +0 -21
  29. package/dist/core/src/Container.d.ts +0 -38
  30. package/dist/core/src/Event.d.ts +0 -5
  31. package/dist/core/src/EventManager.d.ts +0 -123
  32. package/dist/core/src/GlobalErrorHandlers.d.ts +0 -31
  33. package/dist/core/src/GravitoServer.d.ts +0 -20
  34. package/dist/core/src/HookManager.d.ts +0 -70
  35. package/dist/core/src/Listener.d.ts +0 -4
  36. package/dist/core/src/Logger.d.ts +0 -20
  37. package/dist/core/src/PlanetCore.d.ts +0 -207
  38. package/dist/core/src/Route.d.ts +0 -25
  39. package/dist/core/src/Router.d.ts +0 -232
  40. package/dist/core/src/ServiceProvider.d.ts +0 -150
  41. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -142
  42. package/dist/core/src/adapters/bun/BunContext.d.ts +0 -36
  43. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +0 -21
  44. package/dist/core/src/adapters/bun/BunRequest.d.ts +0 -27
  45. package/dist/core/src/adapters/bun/RadixNode.d.ts +0 -15
  46. package/dist/core/src/adapters/bun/RadixRouter.d.ts +0 -31
  47. package/dist/core/src/adapters/bun/types.d.ts +0 -20
  48. package/dist/core/src/adapters/types.d.ts +0 -186
  49. package/dist/core/src/engine/AOTRouter.d.ts +0 -117
  50. package/dist/core/src/engine/FastContext.d.ts +0 -34
  51. package/dist/core/src/engine/Gravito.d.ts +0 -191
  52. package/dist/core/src/engine/MinimalContext.d.ts +0 -36
  53. package/dist/core/src/engine/analyzer.d.ts +0 -21
  54. package/dist/core/src/engine/index.d.ts +0 -26
  55. package/dist/core/src/engine/path.d.ts +0 -26
  56. package/dist/core/src/engine/pool.d.ts +0 -83
  57. package/dist/core/src/engine/types.d.ts +0 -107
  58. package/dist/core/src/exceptions/AuthenticationException.d.ts +0 -4
  59. package/dist/core/src/exceptions/AuthorizationException.d.ts +0 -4
  60. package/dist/core/src/exceptions/GravitoException.d.ts +0 -15
  61. package/dist/core/src/exceptions/HttpException.d.ts +0 -5
  62. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +0 -6
  63. package/dist/core/src/exceptions/ValidationException.d.ts +0 -14
  64. package/dist/core/src/exceptions/index.d.ts +0 -6
  65. package/dist/core/src/helpers/Arr.d.ts +0 -14
  66. package/dist/core/src/helpers/Str.d.ts +0 -18
  67. package/dist/core/src/helpers/data.d.ts +0 -5
  68. package/dist/core/src/helpers/errors.d.ts +0 -12
  69. package/dist/core/src/helpers/response.d.ts +0 -17
  70. package/dist/core/src/helpers.d.ts +0 -38
  71. package/dist/core/src/http/CookieJar.d.ts +0 -37
  72. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -6
  73. package/dist/core/src/http/middleware/Cors.d.ts +0 -12
  74. package/dist/core/src/http/middleware/Csrf.d.ts +0 -11
  75. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -11
  76. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -17
  77. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -12
  78. package/dist/core/src/http/types.d.ts +0 -312
  79. package/dist/core/src/index.d.ts +0 -60
  80. package/dist/core/src/runtime.d.ts +0 -63
  81. package/dist/core/src/security/Encrypter.d.ts +0 -24
  82. package/dist/core/src/security/Hasher.d.ts +0 -29
  83. package/dist/core/src/testing/HttpTester.d.ts +0 -38
  84. package/dist/core/src/testing/TestResponse.d.ts +0 -78
  85. package/dist/core/src/testing/index.d.ts +0 -2
  86. package/dist/core/src/types/events.d.ts +0 -94
  87. package/dist/cosmos/src/I18nService.d.ts +0 -144
  88. package/dist/cosmos/src/index.d.ts +0 -21
  89. package/dist/cosmos/src/loader.d.ts +0 -11
  90. package/dist/index.js +0 -168
  91. package/dist/photon/src/index.d.ts +0 -2
  92. package/dist/src/index.js +0 -173
@@ -1,37 +0,0 @@
1
- import type { Encrypter } from '../security/Encrypter';
2
- import type { GravitoContext } from './types';
3
- export interface CookieOptions {
4
- path?: string;
5
- domain?: string;
6
- secure?: boolean;
7
- httpOnly?: boolean;
8
- sameSite?: 'Strict' | 'Lax' | 'None';
9
- maxAge?: number;
10
- expires?: Date;
11
- encrypt?: boolean;
12
- }
13
- export declare class CookieJar {
14
- private encrypter?;
15
- private queued;
16
- constructor(encrypter?: Encrypter | undefined);
17
- /**
18
- * Queue a cookie to be sent with the response
19
- */
20
- queue(name: string, value: string, minutes?: number, options?: CookieOptions): void;
21
- /**
22
- * Make a cookie that lasts "forever" (5 years)
23
- */
24
- forever(name: string, value: string, options?: CookieOptions): void;
25
- /**
26
- * Expire a cookie
27
- */
28
- forget(name: string, options?: CookieOptions): void;
29
- /**
30
- * Serialize a cookie to a Set-Cookie header value
31
- */
32
- private serializeCookie;
33
- /**
34
- * Attach queued cookies to the context
35
- */
36
- attach(c: GravitoContext): void;
37
- }
@@ -1,6 +0,0 @@
1
- import type { GravitoMiddleware } from '../types';
2
- export type BodySizeLimitOptions = {
3
- methods?: string[];
4
- requireContentLength?: boolean;
5
- };
6
- export declare function bodySizeLimit(maxBytes: number, options?: BodySizeLimitOptions): GravitoMiddleware;
@@ -1,12 +0,0 @@
1
- import type { GravitoMiddleware } from '../types';
2
- export type CorsOrigin = string | string[] | ((origin: string | undefined) => string | false);
3
- export type CorsOptions = {
4
- origin?: CorsOrigin;
5
- methods?: string[];
6
- allowedHeaders?: string[];
7
- exposedHeaders?: string[];
8
- credentials?: boolean;
9
- maxAge?: number;
10
- optionsSuccessStatus?: number;
11
- };
12
- export declare function cors(options?: CorsOptions): GravitoMiddleware;
@@ -1,11 +0,0 @@
1
- import type { CookieOptions } from '../CookieJar';
2
- import type { GravitoContext, GravitoMiddleware } from '../types';
3
- export type CsrfOptions = {
4
- cookieName?: string;
5
- headerName?: string;
6
- formFieldName?: string;
7
- cookie?: CookieOptions;
8
- safeMethods?: string[];
9
- };
10
- export declare function getCsrfToken(c: GravitoContext, options?: CsrfOptions): string;
11
- export declare function csrfProtection(options?: CsrfOptions): GravitoMiddleware;
@@ -1,11 +0,0 @@
1
- import type { GravitoContext, GravitoMiddleware } from '../types';
2
- export type HeaderTokenGateOptions = {
3
- headerName?: string;
4
- token?: string | ((c: GravitoContext) => string | undefined);
5
- };
6
- export type RequireHeaderTokenOptions = HeaderTokenGateOptions & {
7
- status?: number;
8
- message?: string;
9
- };
10
- export declare function createHeaderGate(options?: HeaderTokenGateOptions): (c: GravitoContext) => Promise<boolean>;
11
- export declare function requireHeaderToken(options?: RequireHeaderTokenOptions): GravitoMiddleware;
@@ -1,17 +0,0 @@
1
- import type { GravitoContext, GravitoMiddleware } from '../types';
2
- export type HstsOptions = {
3
- maxAge: number;
4
- includeSubDomains?: boolean;
5
- preload?: boolean;
6
- };
7
- export type SecurityHeadersOptions = {
8
- contentSecurityPolicy?: string | false | ((c: GravitoContext) => string | false);
9
- frameOptions?: string | false;
10
- referrerPolicy?: string | false;
11
- noSniff?: boolean;
12
- hsts?: HstsOptions | false;
13
- permissionsPolicy?: string | false;
14
- crossOriginOpenerPolicy?: string | false;
15
- crossOriginResourcePolicy?: string | false;
16
- };
17
- export declare function securityHeaders(options?: SecurityHeadersOptions): GravitoMiddleware;
@@ -1,12 +0,0 @@
1
- import type { GravitoMiddleware } from '../../http/types';
2
- import type { PlanetCore } from '../../PlanetCore';
3
- export declare class ThrottleRequests {
4
- private core;
5
- constructor(core: PlanetCore);
6
- /**
7
- * Create the middleware
8
- * @param maxAttempts - Max requests allowed
9
- * @param decaySeconds - Time window in seconds
10
- */
11
- handle(maxAttempts?: number, decaySeconds?: number): GravitoMiddleware;
12
- }
@@ -1,312 +0,0 @@
1
- /**
2
- * @fileoverview Core HTTP Types for Gravito Framework
3
- *
4
- * These types provide a unified abstraction layer that decouples the framework
5
- * from any specific HTTP engine (Photon, Express, custom, etc.).
6
- *
7
- * @module @gravito/core/http
8
- * @since 2.0.0
9
- */
10
- declare global {
11
- interface ExecutionContext {
12
- waitUntil(promise: Promise<unknown>): void;
13
- passThroughOnException(): void;
14
- }
15
- }
16
- /**
17
- * Standard HTTP methods supported by Gravito
18
- */
19
- export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
20
- /**
21
- * HTTP status codes
22
- */
23
- export type StatusCode = number;
24
- /**
25
- * Content-bearing HTTP status codes (excludes 1xx, 204, 304)
26
- */
27
- export type ContentfulStatusCode = Exclude<StatusCode, 100 | 101 | 102 | 103 | 204 | 304>;
28
- /**
29
- * Base context variables available in every request
30
- * Orbits can extend this interface via module augmentation
31
- *
32
- * @example
33
- * ```typescript
34
- * // Extending variables in your orbit:
35
- * declare module '@gravito/core' {
36
- * interface GravitoVariables {
37
- * myService: MyService
38
- * }
39
- * }
40
- * ```
41
- */
42
- export interface GravitoVariables {
43
- /**
44
- * The PlanetCore instance
45
- * @remarks Always available in PlanetCore-managed contexts
46
- */
47
- core?: unknown;
48
- /**
49
- * Logger instance
50
- */
51
- logger?: unknown;
52
- /**
53
- * Configuration manager
54
- */
55
- config?: unknown;
56
- /**
57
- * Cookie jar for managing response cookies
58
- */
59
- cookieJar?: unknown;
60
- /**
61
- * URL generator helper
62
- */
63
- route?: (name: string, params?: Record<string, unknown>, query?: Record<string, unknown>) => string;
64
- [key: string]: unknown;
65
- }
66
- /**
67
- * Validated request data targets
68
- */
69
- export type ValidationTarget = 'json' | 'query' | 'param' | 'header' | 'form' | 'cookie';
70
- /**
71
- * GravitoRequest - Unified request interface
72
- *
73
- * Provides a consistent API for accessing request data regardless of
74
- * the underlying HTTP engine.
75
- *
76
- * @example
77
- * ```typescript
78
- * const userId = ctx.req.param('id')
79
- * const search = ctx.req.query('q')
80
- * const body = await ctx.req.json<CreateUserDto>()
81
- * ```
82
- */
83
- export interface GravitoRequest {
84
- /** Full request URL */
85
- readonly url: string;
86
- /** HTTP method (uppercase) */
87
- readonly method: string;
88
- /** Request path without query string */
89
- readonly path: string;
90
- /**
91
- * Get a route parameter value
92
- * @param name - Parameter name (e.g., 'id' for route '/users/:id')
93
- */
94
- param(name: string): string | undefined;
95
- /**
96
- * Get all route parameters
97
- */
98
- params(): Record<string, string>;
99
- /**
100
- * Get a query string parameter
101
- * @param name - Query parameter name
102
- */
103
- query(name: string): string | undefined;
104
- /**
105
- * Get all query parameters
106
- */
107
- queries(): Record<string, string | string[]>;
108
- /**
109
- * Get a request header value
110
- * @param name - Header name (case-insensitive)
111
- */
112
- header(name: string): string | undefined;
113
- /**
114
- * Get all request headers
115
- */
116
- header(): Record<string, string>;
117
- /**
118
- * Parse request body as JSON
119
- * @throws {Error} If body is not valid JSON
120
- */
121
- json<T = unknown>(): Promise<T>;
122
- /**
123
- * Parse request body as text
124
- */
125
- text(): Promise<string>;
126
- /**
127
- * Parse request body as FormData
128
- */
129
- formData(): Promise<FormData>;
130
- /**
131
- * Parse request body as ArrayBuffer
132
- */
133
- arrayBuffer(): Promise<ArrayBuffer>;
134
- /**
135
- * Parse form data (urlencoded or multipart)
136
- */
137
- parseBody<T = unknown>(): Promise<T>;
138
- /**
139
- * Get the raw Request object
140
- */
141
- readonly raw: Request;
142
- /**
143
- * Get validated data from a specific source
144
- * @param target - The validation target
145
- * @throws {Error} If validation was not performed for this target
146
- */
147
- valid<T = unknown>(target: ValidationTarget): T;
148
- }
149
- /**
150
- * GravitoContext - Unified request context
151
- *
152
- * This interface encapsulates all HTTP request/response operations,
153
- * enabling seamless replacement of the underlying HTTP engine.
154
- *
155
- * @typeParam V - Context variables type
156
- *
157
- * @example
158
- * ```typescript
159
- * // In a controller
160
- * async show(ctx: GravitoContext) {
161
- * const id = ctx.req.param('id')
162
- * const user = await User.find(id)
163
- * return ctx.json({ user })
164
- * }
165
- * ```
166
- */
167
- export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
168
- /** The incoming request */
169
- readonly req: GravitoRequest;
170
- /**
171
- * Send a JSON response
172
- * @param data - Data to serialize as JSON
173
- * @param status - HTTP status code (default: 200)
174
- */
175
- json<T>(data: T, status?: ContentfulStatusCode): Response;
176
- /**
177
- * Send a plain text response
178
- * @param text - Text content
179
- * @param status - HTTP status code (default: 200)
180
- */
181
- text(text: string, status?: ContentfulStatusCode): Response;
182
- /**
183
- * Send an HTML response
184
- * @param html - HTML content
185
- * @param status - HTTP status code (default: 200)
186
- */
187
- html(html: string, status?: ContentfulStatusCode): Response;
188
- /**
189
- * Send a redirect response
190
- * @param url - Target URL
191
- * @param status - Redirect status code (default: 302)
192
- */
193
- redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
194
- /**
195
- * Create a Response with no body
196
- * @param status - HTTP status code
197
- */
198
- body(data: BodyInit | null, status?: StatusCode): Response;
199
- /**
200
- * Stream a response
201
- * @param stream - ReadableStream to send
202
- * @param status - HTTP status code (default: 200)
203
- */
204
- stream(stream: ReadableStream, status?: ContentfulStatusCode): Response;
205
- /**
206
- * Send a 404 Not Found response
207
- */
208
- notFound(message?: string): Response;
209
- /**
210
- * Send a 403 Forbidden response
211
- */
212
- forbidden(message?: string): Response;
213
- /**
214
- * Send a 401 Unauthorized response
215
- */
216
- unauthorized(message?: string): Response;
217
- /**
218
- * Send a 400 Bad Request response
219
- */
220
- badRequest(message?: string): Response;
221
- /**
222
- * Set a response header
223
- * @param name - Header name
224
- * @param value - Header value
225
- * @param options - Options (append: true to add multiple values)
226
- */
227
- header(name: string, value: string, options?: {
228
- append?: boolean;
229
- }): void;
230
- /**
231
- * Get a request header
232
- * @param name - Header name (case-insensitive)
233
- */
234
- header(name: string): string | undefined;
235
- /**
236
- * Set the response status code
237
- * @param code - HTTP status code
238
- */
239
- status(code: StatusCode): void;
240
- /**
241
- * Get a context variable
242
- * @param key - Variable key
243
- */
244
- get<K extends keyof V>(key: K): V[K];
245
- /**
246
- * Set a context variable
247
- * @param key - Variable key
248
- * @param value - Variable value
249
- */
250
- set<K extends keyof V>(key: K, value: V[K]): void;
251
- /**
252
- * Get the execution context (for Cloudflare Workers, etc.)
253
- */
254
- readonly executionCtx?: ExecutionContext;
255
- /**
256
- * Get environment bindings (for Cloudflare Workers, etc.)
257
- */
258
- readonly env?: Record<string, unknown>;
259
- /**
260
- * Access the native context object from the underlying HTTP engine.
261
- *
262
- * ⚠️ WARNING: Using this ties your code to a specific adapter.
263
- * Prefer using the abstraction methods when possible.
264
- *
265
- * @example
266
- * ```typescript
267
- * // Only when absolutely necessary
268
- * const photonCtx = ctx.native as Context // Photon Context
269
- * ```
270
- */
271
- readonly native: unknown;
272
- }
273
- /**
274
- * Next function for middleware chain
275
- */
276
- export type GravitoNext = () => Promise<Response | undefined>;
277
- /**
278
- * GravitoHandler - Standard route handler type
279
- *
280
- * @typeParam V - Context variables type
281
- *
282
- * @example
283
- * ```typescript
284
- * const handler: GravitoHandler = async (ctx) => {
285
- * return ctx.json({ message: 'Hello, World!' })
286
- * }
287
- * ```
288
- */
289
- export type GravitoHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
290
- /**
291
- * GravitoMiddleware - Standard middleware type
292
- *
293
- * @typeParam V - Context variables type
294
- *
295
- * @example
296
- * ```typescript
297
- * const logger: GravitoMiddleware = async (ctx, next) => {
298
- * console.log(`${ctx.req.method} ${ctx.req.path}`)
299
- * await next()
300
- * return undefined
301
- * }
302
- * ```
303
- */
304
- export type GravitoMiddleware<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>, next: GravitoNext) => Response | undefined | Promise<Response | undefined | undefined>;
305
- /**
306
- * Error handler type
307
- */
308
- export type GravitoErrorHandler<V extends GravitoVariables = GravitoVariables> = (error: Error, ctx: GravitoContext<V>) => Response | Promise<Response>;
309
- /**
310
- * Not found handler type
311
- */
312
- export type GravitoNotFoundHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
@@ -1,60 +0,0 @@
1
- /**
2
- * @gravito/core
3
- *
4
- * The core micro-kernel for the Galaxy Architecture.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { GravitoConfig } from './PlanetCore';
9
- export declare const VERSION: string;
10
- export { createGravitoAdapter, createPhotonAdapter, GravitoAdapter, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, } from './adapters/PhotonAdapter';
11
- export type { AdapterConfig, AdapterFactory, HttpAdapter, RouteDefinition } from './adapters/types';
12
- export { isHttpAdapter } from './adapters/types';
13
- export type { ContentfulStatusCode, GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNext, GravitoNotFoundHandler, GravitoRequest, GravitoVariables, HttpMethod, StatusCode, ValidationTarget, } from './http/types';
14
- export { Application, type ApplicationConfig } from './Application';
15
- export { ConfigManager } from './ConfigManager';
16
- export { Container, type Factory } from './Container';
17
- export { EventManager } from './EventManager';
18
- export * from './exceptions';
19
- export { type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, type RegisterGlobalErrorHandlersOptions, registerGlobalErrorHandlers, } from './GlobalErrorHandlers';
20
- export { type GravitoManifest, GravitoServer } from './GravitoServer';
21
- export type { ActionCallback, FilterCallback } from './HookManager';
22
- export { HookManager } from './HookManager';
23
- export * from './helpers';
24
- export { CookieJar, type CookieOptions } from './http/CookieJar';
25
- export { type BodySizeLimitOptions, bodySizeLimit } from './http/middleware/BodySizeLimit';
26
- export { type CorsOptions, type CorsOrigin, cors } from './http/middleware/Cors';
27
- export { type CsrfOptions, csrfProtection, getCsrfToken } from './http/middleware/Csrf';
28
- export { createHeaderGate, type HeaderTokenGateOptions, type RequireHeaderTokenOptions, requireHeaderToken, } from './http/middleware/HeaderTokenGate';
29
- export { type HstsOptions, type SecurityHeadersOptions, securityHeaders, } from './http/middleware/SecurityHeaders';
30
- export { ThrottleRequests } from './http/middleware/ThrottleRequests';
31
- export type { Listener, ShouldQueue } from './Listener';
32
- export type { Logger } from './Logger';
33
- export { ConsoleLogger } from './Logger';
34
- export { type CacheService, type ErrorHandlerContext, type GravitoConfig, type GravitoOrbit, PlanetCore, type ViewService, } from './PlanetCore';
35
- export { Route } from './Route';
36
- export { type ControllerClass, type FormRequestClass, type FormRequestLike, type RouteHandler, type RouteOptions, Router, } from './Router';
37
- export { ServiceProvider } from './ServiceProvider';
38
- export { Encrypter, type EncrypterOptions } from './security/Encrypter';
39
- export type { Channel, ShouldBroadcast } from './types/events';
40
- export { Event } from './types/events';
41
- export * from './testing';
42
- export { createSqliteDatabase, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, } from './runtime';
43
- export * as engine from './engine';
44
- /**
45
- * Configure your Gravito application
46
- *
47
- * @example
48
- * ```typescript
49
- * const config = defineConfig({
50
- * config: {
51
- * APP_NAME: 'My App',
52
- * PORT: 3000,
53
- * },
54
- * orbits: [], // Add your orbits here
55
- * })
56
- *
57
- * const core = await PlanetCore.boot(config)
58
- * ```
59
- */
60
- export declare function defineConfig(config: GravitoConfig): GravitoConfig;
@@ -1,63 +0,0 @@
1
- export type RuntimeKind = 'bun' | 'node' | 'deno' | 'unknown';
2
- export interface RuntimeSpawnOptions {
3
- cwd?: string;
4
- env?: Record<string, string | undefined>;
5
- stdin?: 'pipe' | 'inherit' | 'ignore';
6
- stdout?: 'pipe' | 'inherit' | 'ignore';
7
- stderr?: 'pipe' | 'inherit' | 'ignore';
8
- }
9
- export interface RuntimeProcess {
10
- exited: Promise<number>;
11
- stdout?: ReadableStream<Uint8Array> | null;
12
- stderr?: ReadableStream<Uint8Array> | null;
13
- kill?: (signal?: string | number) => void;
14
- }
15
- export interface RuntimeFileStat {
16
- size: number;
17
- }
18
- export interface RuntimeServeConfig {
19
- port?: number;
20
- fetch: (req: Request, server?: unknown) => Response | Promise<Response>;
21
- websocket?: unknown;
22
- }
23
- export interface RuntimeServer {
24
- stop?: () => void;
25
- }
26
- export interface RuntimeAdapter {
27
- kind: RuntimeKind;
28
- spawn(command: string[], options?: RuntimeSpawnOptions): RuntimeProcess;
29
- writeFile(path: string, data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<void>;
30
- readFile(path: string): Promise<Uint8Array>;
31
- readFileAsBlob(path: string): Promise<Blob>;
32
- exists(path: string): Promise<boolean>;
33
- stat(path: string): Promise<RuntimeFileStat>;
34
- deleteFile(path: string): Promise<void>;
35
- serve(config: RuntimeServeConfig): RuntimeServer;
36
- }
37
- export interface RuntimePasswordAdapter {
38
- hash(value: string, options: {
39
- algorithm: 'bcrypt';
40
- cost?: number;
41
- } | {
42
- algorithm: 'argon2id';
43
- memoryCost?: number;
44
- timeCost?: number;
45
- parallelism?: number;
46
- }): Promise<string>;
47
- verify(value: string, hashed: string): Promise<boolean>;
48
- }
49
- export interface RuntimeSqliteStatement {
50
- run(params?: Record<string, unknown>): void;
51
- get(params?: Record<string, unknown>): unknown;
52
- all(params?: Record<string, unknown>): unknown[];
53
- }
54
- export interface RuntimeSqliteDatabase {
55
- run(sql: string): void;
56
- prepare(sql: string): RuntimeSqliteStatement;
57
- query(sql: string): RuntimeSqliteStatement;
58
- close(): void;
59
- }
60
- export declare const getRuntimeEnv: () => Record<string, string | undefined>;
61
- export declare const getRuntimeAdapter: () => RuntimeAdapter;
62
- export declare const getPasswordAdapter: () => RuntimePasswordAdapter;
63
- export declare const createSqliteDatabase: (path: string) => Promise<RuntimeSqliteDatabase>;
@@ -1,24 +0,0 @@
1
- export interface EncrypterOptions {
2
- key: string;
3
- cipher?: string;
4
- }
5
- export declare class Encrypter {
6
- private algorithm;
7
- private key;
8
- constructor(options: EncrypterOptions);
9
- /**
10
- * Encrypt a value
11
- */
12
- encrypt(value: unknown, serialize?: boolean): string;
13
- /**
14
- * Decrypt a value
15
- */
16
- decrypt(payload: string, deserialize?: boolean): unknown;
17
- private hash;
18
- private validPayload;
19
- private validMac;
20
- /**
21
- * Generate a new key
22
- */
23
- static generateKey(cipher?: string): string;
24
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Hashing interface
3
- */
4
- export interface Hasher {
5
- /**
6
- * Hash the given value
7
- */
8
- make(value: string, options?: Record<string, unknown>): Promise<string>;
9
- /**
10
- * Check the given plain value against a hash
11
- */
12
- check(value: string, hashedValue: string): Promise<boolean>;
13
- /**
14
- * Check if the given hash has been hashed using the given options
15
- */
16
- needsRehash(hashedValue: string, options?: Record<string, unknown>): boolean;
17
- }
18
- /**
19
- * Bun Hasher
20
- * Uses Bun's native password hashing (bcrypt by default)
21
- */
22
- export declare class BunHasher implements Hasher {
23
- make(value: string, options?: {
24
- algorithm?: 'bcrypt' | 'argon2id';
25
- cost?: number;
26
- }): Promise<string>;
27
- check(value: string, hashedValue: string): Promise<boolean>;
28
- needsRehash(_hashedValue: string, _options?: Record<string, unknown>): boolean;
29
- }
@@ -1,38 +0,0 @@
1
- import type { PlanetCore } from '../PlanetCore';
2
- import { TestResponse } from './TestResponse';
3
- /**
4
- * HttpTester provides a way to simulate HTTP requests against a PlanetCore instance
5
- * and returns a TestResponse for assertions.
6
- */
7
- export declare class HttpTester {
8
- private core;
9
- constructor(core: PlanetCore);
10
- /**
11
- * Make a GET request
12
- */
13
- get(uri: string, headers?: Record<string, string>): Promise<TestResponse>;
14
- /**
15
- * Make a POST request
16
- */
17
- post(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
18
- /**
19
- * Make a PUT request
20
- */
21
- put(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
22
- /**
23
- * Make a PATCH request
24
- */
25
- patch(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
26
- /**
27
- * Make a DELETE request
28
- */
29
- delete(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
30
- /**
31
- * Core call method
32
- */
33
- private call;
34
- }
35
- /**
36
- * Helper to create an HttpTester for a PlanetCore instance
37
- */
38
- export declare function createHttpTester(core: PlanetCore): HttpTester;