@gravito/echo 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 (221) hide show
  1. package/README.md +211 -0
  2. package/dist/atlas/src/DB.d.ts +301 -0
  3. package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
  4. package/dist/atlas/src/config/defineConfig.d.ts +14 -0
  5. package/dist/atlas/src/config/index.d.ts +7 -0
  6. package/dist/atlas/src/config/loadConfig.d.ts +48 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +108 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
  9. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  10. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  11. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  12. package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
  13. package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
  14. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  15. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  16. package/dist/atlas/src/drivers/types.d.ts +260 -0
  17. package/dist/atlas/src/errors/index.d.ts +45 -0
  18. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  19. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  20. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  21. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  22. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  23. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  24. package/dist/atlas/src/index.d.ts +67 -0
  25. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  26. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  27. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  28. package/dist/atlas/src/migration/index.d.ts +6 -0
  29. package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
  30. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  31. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  32. package/dist/atlas/src/observability/index.d.ts +9 -0
  33. package/dist/atlas/src/orm/index.d.ts +5 -0
  34. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  35. package/dist/atlas/src/orm/model/Model.d.ts +449 -0
  36. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  37. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
  38. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  39. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
  40. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  41. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  42. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  43. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  44. package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
  45. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  46. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  47. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  48. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  49. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
  50. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  51. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  52. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  53. package/dist/atlas/src/query/Expression.d.ts +60 -0
  54. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  55. package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
  56. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  57. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  58. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  59. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  60. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  61. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  62. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  63. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  64. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  65. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  66. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  67. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  68. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  69. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  70. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  71. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  72. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  73. package/dist/atlas/src/schema/index.d.ts +8 -0
  74. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  75. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  76. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  77. package/dist/atlas/src/seed/index.d.ts +6 -0
  78. package/dist/atlas/src/types/index.d.ts +1100 -0
  79. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  80. package/dist/core/src/Application.d.ts +215 -0
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/ConfigManager.d.ts +26 -0
  83. package/dist/core/src/Container.d.ts +108 -0
  84. package/dist/core/src/ErrorHandler.d.ts +63 -0
  85. package/dist/core/src/Event.d.ts +5 -0
  86. package/dist/core/src/EventManager.d.ts +123 -0
  87. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  88. package/dist/core/src/GravitoServer.d.ts +28 -0
  89. package/dist/core/src/HookManager.d.ts +496 -0
  90. package/dist/core/src/Listener.d.ts +4 -0
  91. package/dist/core/src/Logger.d.ts +20 -0
  92. package/dist/core/src/PlanetCore.d.ts +289 -0
  93. package/dist/core/src/Route.d.ts +36 -0
  94. package/dist/core/src/Router.d.ts +284 -0
  95. package/dist/core/src/ServiceProvider.d.ts +156 -0
  96. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  97. package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
  98. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  99. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
  100. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  101. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  102. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  103. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  104. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  105. package/dist/core/src/adapters/types.d.ts +235 -0
  106. package/dist/core/src/engine/AOTRouter.d.ts +124 -0
  107. package/dist/core/src/engine/FastContext.d.ts +100 -0
  108. package/dist/core/src/engine/Gravito.d.ts +137 -0
  109. package/dist/core/src/engine/MinimalContext.d.ts +79 -0
  110. package/dist/core/src/engine/analyzer.d.ts +27 -0
  111. package/dist/core/src/engine/constants.d.ts +23 -0
  112. package/dist/core/src/engine/index.d.ts +26 -0
  113. package/dist/core/src/engine/path.d.ts +26 -0
  114. package/dist/core/src/engine/pool.d.ts +83 -0
  115. package/dist/core/src/engine/types.d.ts +143 -0
  116. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  117. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  118. package/dist/core/src/events/EventBackend.d.ts +11 -0
  119. package/dist/core/src/events/EventOptions.d.ts +109 -0
  120. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  121. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  122. package/dist/core/src/events/index.d.ts +14 -0
  123. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  124. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  125. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  126. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  127. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  128. package/dist/core/src/events/observability/index.d.ts +20 -0
  129. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  130. package/dist/core/src/events/types.d.ts +75 -0
  131. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  132. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  133. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  134. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  135. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  136. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  137. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  138. package/dist/core/src/exceptions/index.d.ts +7 -0
  139. package/dist/core/src/helpers/Arr.d.ts +19 -0
  140. package/dist/core/src/helpers/Str.d.ts +23 -0
  141. package/dist/core/src/helpers/data.d.ts +25 -0
  142. package/dist/core/src/helpers/errors.d.ts +34 -0
  143. package/dist/core/src/helpers/response.d.ts +41 -0
  144. package/dist/core/src/helpers.d.ts +338 -0
  145. package/dist/core/src/http/CookieJar.d.ts +51 -0
  146. package/dist/core/src/http/cookie.d.ts +29 -0
  147. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  148. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  149. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  150. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  151. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  152. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  153. package/dist/core/src/http/types.d.ts +355 -0
  154. package/dist/core/src/index.d.ts +76 -0
  155. package/dist/core/src/instrumentation/index.d.ts +35 -0
  156. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  157. package/dist/core/src/instrumentation/types.d.ts +182 -0
  158. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  159. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  160. package/dist/core/src/reliability/index.d.ts +6 -0
  161. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  162. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  163. package/dist/core/src/runtime.d.ts +119 -0
  164. package/dist/core/src/security/Encrypter.d.ts +33 -0
  165. package/dist/core/src/security/Hasher.d.ts +29 -0
  166. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  167. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  168. package/dist/core/src/testing/index.d.ts +2 -0
  169. package/dist/core/src/types/events.d.ts +94 -0
  170. package/dist/echo/src/OrbitEcho.d.ts +115 -0
  171. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  172. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  173. package/dist/echo/src/dlq/index.d.ts +2 -0
  174. package/dist/echo/src/index.d.ts +64 -0
  175. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  176. package/dist/echo/src/middleware/index.d.ts +8 -0
  177. package/dist/echo/src/observability/index.d.ts +3 -0
  178. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  179. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  180. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  181. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  182. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  183. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  184. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  185. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  186. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  187. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  188. package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
  189. package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
  190. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  191. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  192. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  193. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  194. package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
  195. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  196. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  197. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  198. package/dist/echo/src/providers/index.d.ts +14 -0
  199. package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
  200. package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
  201. package/dist/echo/src/receive/index.d.ts +2 -0
  202. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  203. package/dist/echo/src/replay/index.d.ts +1 -0
  204. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  205. package/dist/echo/src/resilience/index.d.ts +10 -0
  206. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  207. package/dist/echo/src/rotation/index.d.ts +10 -0
  208. package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
  209. package/dist/echo/src/send/index.d.ts +1 -0
  210. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  211. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  212. package/dist/echo/src/storage/index.d.ts +2 -0
  213. package/dist/echo/src/types.d.ts +756 -0
  214. package/dist/index.js +1332 -190
  215. package/dist/index.js.map +28 -10
  216. package/dist/photon/src/index.d.ts +84 -0
  217. package/dist/photon/src/middleware/binary.d.ts +31 -0
  218. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  219. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  220. package/dist/photon/src/openapi.d.ts +19 -0
  221. package/package.json +7 -5
@@ -0,0 +1,22 @@
1
+ import { GravitoException } from './GravitoException';
2
+ /**
3
+ * Structure of a validation error
4
+ * @public
5
+ */
6
+ export interface ValidationError {
7
+ field: string;
8
+ message: string;
9
+ code?: string;
10
+ }
11
+ /**
12
+ * Exception thrown when data validation fails.
13
+ * @public
14
+ */
15
+ export declare class ValidationException extends GravitoException {
16
+ readonly errors: ValidationError[];
17
+ redirectTo?: string;
18
+ input?: unknown;
19
+ constructor(errors: ValidationError[], message?: string);
20
+ withRedirect(url: string): this;
21
+ withInput(input: unknown): this;
22
+ }
@@ -0,0 +1,7 @@
1
+ export * from './AuthenticationException';
2
+ export * from './AuthorizationException';
3
+ export * from './CircularDependencyException';
4
+ export * from './GravitoException';
5
+ export * from './HttpException';
6
+ export * from './ModelNotFoundException';
7
+ export * from './ValidationException';
@@ -0,0 +1,19 @@
1
+ import { type DataPath } from './data';
2
+ /**
3
+ * Array and Collection Helpers.
4
+ * Provides utility methods for array manipulation and deep object access.
5
+ * @public
6
+ */
7
+ export declare const Arr: {
8
+ readonly get: <TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault) => unknown | TDefault;
9
+ readonly has: (target: unknown, path: DataPath | null | undefined) => boolean;
10
+ readonly set: (target: unknown, path: DataPath, value: unknown, overwrite?: boolean) => unknown;
11
+ readonly wrap: <T>(value: T | T[] | null | undefined) => T[];
12
+ readonly first: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
13
+ readonly last: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
14
+ readonly only: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
15
+ readonly except: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
16
+ readonly flatten: (items: unknown[], depth?: number) => unknown[];
17
+ readonly pluck: <TItem extends Record<string, unknown>>(items: readonly TItem[], valuePath: DataPath, keyPath?: DataPath) => unknown[] | Record<string, unknown>;
18
+ readonly where: <T>(items: readonly T[], callback: (value: T, index: number) => boolean) => T[];
19
+ };
@@ -0,0 +1,23 @@
1
+ type StartsEndsNeedle = string | readonly string[];
2
+ /**
3
+ * String Helper Utilities.
4
+ * Provides methods for string manipulation, case conversion, and UUID generation.
5
+ * @public
6
+ */
7
+ export declare const Str: {
8
+ readonly lower: (value: string) => string;
9
+ readonly upper: (value: string) => string;
10
+ readonly startsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
11
+ readonly endsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
12
+ readonly contains: (haystack: string, needles: StartsEndsNeedle) => boolean;
13
+ readonly snake: (value: string) => string;
14
+ readonly kebab: (value: string) => string;
15
+ readonly studly: (value: string) => string;
16
+ readonly camel: (value: string) => string;
17
+ readonly title: (value: string) => string;
18
+ readonly limit: (value: string, limit: number, end?: string) => string;
19
+ readonly slug: (value: string, separator?: string) => string;
20
+ readonly uuid: () => string;
21
+ readonly random: (length?: number) => string;
22
+ };
23
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Path segment (key) in a data structure.
3
+ * @public
4
+ */
5
+ export type PathSegment = string | number;
6
+ /**
7
+ * Path to a value (dot notation or array of segments).
8
+ * @public
9
+ */
10
+ export type DataPath = string | readonly PathSegment[];
11
+ /**
12
+ * Retrieve a value from a deep object using dot notation.
13
+ * @public
14
+ */
15
+ export declare function dataGet<TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault): unknown | TDefault;
16
+ /**
17
+ * Check if a key exists in a deep object using dot notation.
18
+ * @public
19
+ */
20
+ export declare function dataHas(target: unknown, path: DataPath | null | undefined): boolean;
21
+ /**
22
+ * Set a value in a deep object using dot notation.
23
+ * @public
24
+ */
25
+ export declare function dataSet(target: unknown, path: DataPath, setValue: unknown, overwrite?: boolean): unknown;
@@ -0,0 +1,34 @@
1
+ import type { GravitoContext } from '../http/types';
2
+ /**
3
+ * Interface for displaying validation errors in views.
4
+ * @public
5
+ */
6
+ export interface ErrorBag {
7
+ /** Check if a field has errors */
8
+ has(field: string): boolean;
9
+ /** Get the first error message for a field (or any first error if no field specified) */
10
+ first(field?: string): string | undefined;
11
+ /** Get all error messages for a field */
12
+ get(field: string): string[];
13
+ /** Get all errors for all fields */
14
+ all(): Record<string, string[]>;
15
+ /** Check if there are any errors */
16
+ any(): boolean;
17
+ /** Get total number of error messages */
18
+ count(): number;
19
+ }
20
+ /**
21
+ * Create a new ErrorBag instance from raw errors.
22
+ * @public
23
+ */
24
+ export declare function createErrorBag(errors: Record<string, string[]>): ErrorBag;
25
+ /**
26
+ * Helper to retrieve the ErrorBag from session flash data.
27
+ * @public
28
+ */
29
+ export declare function errors(c: GravitoContext): ErrorBag;
30
+ /**
31
+ * Helper to retrieve old input value from session flash.
32
+ * @public
33
+ */
34
+ export declare function old(c: GravitoContext, field: string, defaultValue?: unknown): unknown;
@@ -0,0 +1,41 @@
1
+ import type { ContentfulStatusCode, GravitoContext } from '../http/types';
2
+ /**
3
+ * Standard API Success Response Structure
4
+ * @public
5
+ */
6
+ export type ApiSuccess<T> = {
7
+ success: true;
8
+ data: T;
9
+ };
10
+ /**
11
+ * Standard API Failure Response Structure
12
+ * @public
13
+ */
14
+ export type ApiFailure = {
15
+ success: false;
16
+ error: {
17
+ message: string;
18
+ code?: string;
19
+ details?: unknown;
20
+ };
21
+ };
22
+ /**
23
+ * Create a success response object.
24
+ * @public
25
+ */
26
+ export declare function ok<T>(data: T): ApiSuccess<T>;
27
+ /**
28
+ * Create a failure response object.
29
+ * @public
30
+ */
31
+ export declare function fail(message: string, code?: string, details?: unknown): ApiFailure;
32
+ /**
33
+ * Return a JSON response with standard success structure.
34
+ * @public
35
+ */
36
+ export declare function jsonSuccess<T>(c: GravitoContext, data: T, status?: ContentfulStatusCode): Response;
37
+ /**
38
+ * Return a JSON response with standard failure structure.
39
+ * @public
40
+ */
41
+ export declare function jsonFail(c: GravitoContext, message: string, status?: ContentfulStatusCode, code?: string, details?: unknown): Response;
@@ -0,0 +1,338 @@
1
+ import type { ContentfulStatusCode } from './http/types';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ import type { Router } from './Router';
4
+ export { Arr } from './helpers/Arr';
5
+ export * from './helpers/data';
6
+ export * from './helpers/errors';
7
+ export * from './helpers/response';
8
+ export { Str } from './helpers/Str';
9
+ /**
10
+ * Error subclass used for dump and die functionality.
11
+ * @internal
12
+ */
13
+ export declare class DumpDieError extends Error {
14
+ readonly values: unknown[];
15
+ name: string;
16
+ constructor(values: unknown[]);
17
+ }
18
+ /**
19
+ * Options for dump output
20
+ * @public
21
+ */
22
+ export type DumpOptions = {
23
+ depth?: number | null;
24
+ colors?: boolean;
25
+ };
26
+ /**
27
+ * Dump data to console for debugging.
28
+ *
29
+ * Uses `console.dir` with configurable depth and colors to provide a
30
+ * readable representation of any value.
31
+ *
32
+ * @param values - One or more values to dump to the console.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * dump(user, { meta: 'data' });
37
+ * ```
38
+ *
39
+ * @public
40
+ * @since 3.0.0
41
+ */
42
+ export declare function dump(...values: unknown[]): void;
43
+ /**
44
+ * Dump data to console and exit process (or throw in HTTP context).
45
+ *
46
+ * Short for "Dump and Die". In a CLI environment, it exits the process.
47
+ * In an HTTP context (like a web request), it throws a `DumpDieError`
48
+ * which is caught by the exception handler to display the debug output.
49
+ *
50
+ * @param values - One or more values to dump and then die.
51
+ * @throws {DumpDieError} Always throws this error to halt execution.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * dd(user.permissions);
56
+ * ```
57
+ *
58
+ * @public
59
+ * @since 3.0.0
60
+ */
61
+ export declare function dd(...values: unknown[]): never;
62
+ /**
63
+ * Tap into a value, execute a callback, and return the value.
64
+ *
65
+ * This allows you to perform "side effects" on a value without breaking
66
+ * the chain of operations.
67
+ *
68
+ * @param value - The value to tap into.
69
+ * @param callback - A callback that receives the value.
70
+ * @returns The original value.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const user = tap(new User(), (u) => {
75
+ * u.name = 'Alice';
76
+ * u.save();
77
+ * });
78
+ * ```
79
+ *
80
+ * @public
81
+ * @since 3.0.0
82
+ */
83
+ export declare function tap<T>(value: T, callback: (value: T) => unknown): T;
84
+ /**
85
+ * Return the default value of the given value.
86
+ *
87
+ * If the value is a function, it will be executed with the provided arguments
88
+ * and its result will be returned. Otherwise, the value itself is returned.
89
+ * This is useful for handling optional lazy-loaded values.
90
+ *
91
+ * @param valueOrFactory - The value or a factory function.
92
+ * @param args - Arguments to pass to the factory function if it is a function.
93
+ * @returns The resolved value.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * value(10); // 10
98
+ * value(() => 10); // 10
99
+ * value((name) => `Hello ${name}`, 'World'); // "Hello World"
100
+ * ```
101
+ *
102
+ * @public
103
+ * @since 3.0.0
104
+ */
105
+ export declare function value<TArgs extends readonly unknown[], TResult>(valueOrFactory: TResult | ((...args: TArgs) => TResult), ...args: TArgs): TResult;
106
+ /**
107
+ * Determine if the given value is "blank".
108
+ *
109
+ * A value is considered blank if it is:
110
+ * - `null` or `undefined`
111
+ * - An empty string or a string containing only whitespace
112
+ * - An empty array
113
+ * - An empty object
114
+ * - An empty Map or Set
115
+ *
116
+ * @param value - The value to check.
117
+ * @returns `true` if the value is blank, `false` otherwise.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * blank(''); // true
122
+ * blank(' '); // true
123
+ * blank([]); // true
124
+ * blank({}); // true
125
+ * blank(0); // false
126
+ * ```
127
+ *
128
+ * @public
129
+ * @since 3.0.0
130
+ */
131
+ export declare function blank(value: unknown): boolean;
132
+ /**
133
+ * Determine if the given value is "filled" (not blank).
134
+ *
135
+ * This is the inverse of `blank()`.
136
+ *
137
+ * @param value - The value to check.
138
+ * @returns `true` if the value is not blank, `false` otherwise.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * filled('hello'); // true
143
+ * filled([1, 2, 3]); // true
144
+ * filled(''); // false
145
+ * ```
146
+ *
147
+ * @public
148
+ * @since 3.0.0
149
+ */
150
+ export declare function filled(value: unknown): boolean;
151
+ /**
152
+ * Throw an exception if the given condition is true.
153
+ *
154
+ * @param condition - The condition to evaluate.
155
+ * @param error - The exception to throw, a factory function, or an error message string.
156
+ * @throws {Error} If the condition evaluates to true.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * throwIf(user.isBanned, 'User is banned from the system');
161
+ * throwIf(count > 100, () => new ValidationError('Too many items'));
162
+ * ```
163
+ *
164
+ * @public
165
+ * @since 3.0.0
166
+ */
167
+ export declare function throwIf(condition: unknown, error?: Error | string | (() => Error)): void;
168
+ /**
169
+ * Throw an exception unless the given condition is true.
170
+ *
171
+ * @param condition - The condition to evaluate.
172
+ * @param error - The exception to throw, a factory function, or an error message string.
173
+ * @throws {Error} If the condition evaluates to false.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * throwUnless(user.isAdmin, 'Unauthorized access');
178
+ * ```
179
+ *
180
+ * @public
181
+ * @since 3.0.0
182
+ */
183
+ export declare function throwUnless(condition: unknown, error?: Error | string | (() => Error)): void;
184
+ /**
185
+ * Get the value of an environment variable.
186
+ *
187
+ * Automatically detects the runtime environment (Bun or Node.js) to retrieve
188
+ * the variable.
189
+ *
190
+ * @param key - The environment variable name.
191
+ * @param defaultValue - An optional default value to return if the variable is not defined.
192
+ * @returns The environment variable value or the default value.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const debug = env('DEBUG', 'false');
197
+ * const apiKey = env('API_KEY');
198
+ * ```
199
+ *
200
+ * @public
201
+ * @since 3.0.0
202
+ */
203
+ export declare function env<TDefault = string | undefined>(key: string, defaultValue?: TDefault): string | TDefault;
204
+ /**
205
+ * Set the global application instance.
206
+ *
207
+ * This is used internally during the bootstrap process to provide global
208
+ * access to the application instance via the `app()` helper.
209
+ *
210
+ * @param core - The PlanetCore instance to set as global.
211
+ * @internal
212
+ */
213
+ export declare function setApp(core: PlanetCore | null): void;
214
+ /**
215
+ * Check if the global application instance has been initialized and set.
216
+ *
217
+ * @returns `true` if the application instance is set, `false` otherwise.
218
+ *
219
+ * @public
220
+ * @since 3.0.0
221
+ */
222
+ export declare function hasApp(): boolean;
223
+ /**
224
+ * Get the global application instance.
225
+ *
226
+ * Provides access to the core application container, configuration, and services.
227
+ *
228
+ * @returns The initialized PlanetCore instance.
229
+ * @throws {Error} If the application has not been initialized.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const core = app();
234
+ * console.log(core.version);
235
+ * ```
236
+ *
237
+ * @public
238
+ * @since 3.0.0
239
+ */
240
+ export declare function app(): PlanetCore;
241
+ /**
242
+ * Get a configuration value from the application.
243
+ *
244
+ * Supports dot notation for accessing nested configuration properties.
245
+ *
246
+ * @param key - The configuration key in dot notation (e.g., 'app.name').
247
+ * @param defaultValue - An optional default value to return if the key is not found.
248
+ * @returns The configuration value or the default value.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const appName = config('app.name');
253
+ * const port = config('app.port', 3000);
254
+ * ```
255
+ *
256
+ * @public
257
+ * @since 3.0.0
258
+ */
259
+ export declare function config<T = unknown>(key: string, defaultValue?: T): T;
260
+ /**
261
+ * Get the global logger instance.
262
+ *
263
+ * Shortcut for `app().logger`.
264
+ *
265
+ * @returns The application's logger instance.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * logger().info('Operation completed successfully');
270
+ * ```
271
+ *
272
+ * @public
273
+ * @since 3.0.0
274
+ */
275
+ export declare function logger(): import("@gravito/core").Logger;
276
+ /**
277
+ * Get the application's primary router instance.
278
+ *
279
+ * Shortcut for `app().router`.
280
+ *
281
+ * @returns The router instance.
282
+ *
283
+ * @public
284
+ * @since 3.0.0
285
+ */
286
+ export declare function router(): Router;
287
+ /**
288
+ * Abort the current request with an HTTP exception.
289
+ *
290
+ * Throws an `HttpException` with the specified status code and optional message.
291
+ *
292
+ * @param status - The HTTP status code to return.
293
+ * @param message - An optional custom error message.
294
+ * @throws {HttpException} Always throws this exception.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * abort(403, 'You do not have permission to access this resource');
299
+ * ```
300
+ *
301
+ * @public
302
+ * @since 3.0.0
303
+ */
304
+ export declare function abort(status: ContentfulStatusCode, message?: string): never;
305
+ /**
306
+ * Abort the request if the given condition is true.
307
+ *
308
+ * @param condition - The condition to evaluate.
309
+ * @param status - The HTTP status code to return.
310
+ * @param message - An optional custom error message.
311
+ * @throws {HttpException} If the condition is true.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * abortIf(!user.isActive, 403, 'Account is deactivated');
316
+ * ```
317
+ *
318
+ * @public
319
+ * @since 3.0.0
320
+ */
321
+ export declare function abortIf(condition: unknown, status: ContentfulStatusCode, message?: string): void;
322
+ /**
323
+ * Abort the request unless the given condition is true.
324
+ *
325
+ * @param condition - The condition to evaluate.
326
+ * @param status - The HTTP status code to return.
327
+ * @param message - An optional custom error message.
328
+ * @throws {HttpException} If the condition is false.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * abortUnless(request.hasValidToken(), 401, 'Invalid authentication token');
333
+ * ```
334
+ *
335
+ * @public
336
+ * @since 3.0.0
337
+ */
338
+ export declare function abortUnless(condition: unknown, status: ContentfulStatusCode, message?: string): void;
@@ -0,0 +1,51 @@
1
+ import type { Encrypter } from '../security/Encrypter';
2
+ import type { GravitoContext } from './types';
3
+ /**
4
+ * Options for setting cookies
5
+ * @public
6
+ */
7
+ export interface CookieOptions {
8
+ path?: string;
9
+ domain?: string;
10
+ secure?: boolean;
11
+ httpOnly?: boolean;
12
+ sameSite?: 'Strict' | 'Lax' | 'None';
13
+ maxAge?: number;
14
+ expires?: Date;
15
+ encrypt?: boolean;
16
+ }
17
+ /**
18
+ * Utility for managing cookies (request/response/encryption).
19
+ * @public
20
+ */
21
+ export declare class CookieJar {
22
+ private encrypter?;
23
+ private queued;
24
+ constructor(encrypter?: Encrypter | undefined);
25
+ /**
26
+ * Parse cookies from a Cookie header string
27
+ * @param header - The Cookie header value
28
+ * @returns Parsed cookies as key-value pairs
29
+ */
30
+ static parseCookies(header: string): Record<string, string>;
31
+ /**
32
+ * Queue a cookie to be sent with the response
33
+ */
34
+ queue(name: string, value: string, minutes?: number, options?: CookieOptions): void;
35
+ /**
36
+ * Make a cookie that lasts "forever" (5 years)
37
+ */
38
+ forever(name: string, value: string, options?: CookieOptions): void;
39
+ /**
40
+ * Expire a cookie
41
+ */
42
+ forget(name: string, options?: CookieOptions): void;
43
+ /**
44
+ * Serialize a cookie to a Set-Cookie header value
45
+ */
46
+ private serializeCookie;
47
+ /**
48
+ * Attach queued cookies to the context
49
+ */
50
+ attach(c: GravitoContext): void;
51
+ }
@@ -0,0 +1,29 @@
1
+ import { type CookieOptions } from './CookieJar';
2
+ import type { GravitoContext } from './types';
3
+ /**
4
+ * Get a cookie value from the request
5
+ * @param c - Context object
6
+ * @param name - Cookie name
7
+ * @returns Cookie value or undefined
8
+ * @public
9
+ */
10
+ export declare function getCookie(c: GravitoContext, name: string): string | undefined;
11
+ /**
12
+ * Set a cookie in the response
13
+ * @param c - Context object
14
+ * @param name - Cookie name
15
+ * @param value - Cookie value
16
+ * @param options - Cookie options
17
+ * @public
18
+ */
19
+ export declare function setCookie(c: GravitoContext, name: string, value: string, options?: CookieOptions & {
20
+ maxAge?: number;
21
+ }): void;
22
+ /**
23
+ * Delete a cookie (expire it)
24
+ * @param c - Context object
25
+ * @param name - Cookie name
26
+ * @param options - Cookie options (path, domain, etc.)
27
+ * @public
28
+ */
29
+ export declare function deleteCookie(c: GravitoContext, name: string, options?: CookieOptions): void;
@@ -0,0 +1,16 @@
1
+ import type { GravitoMiddleware } from '../types';
2
+ /**
3
+ * Options for body size limiting
4
+ * @public
5
+ */
6
+ export type BodySizeLimitOptions = {
7
+ methods?: string[];
8
+ requireContentLength?: boolean;
9
+ };
10
+ /**
11
+ * Middleware to limit request body size.
12
+ * @param maxBytes - Maximum allowed size in bytes
13
+ * @param options - Configuration options
14
+ * @public
15
+ */
16
+ export declare function bodySizeLimit(maxBytes: number, options?: BodySizeLimitOptions): GravitoMiddleware;
@@ -0,0 +1,24 @@
1
+ import type { GravitoMiddleware } from '../types';
2
+ /**
3
+ * Allowed origin(s) configuration.
4
+ * @public
5
+ */
6
+ export type CorsOrigin = string | string[] | ((origin: string | undefined) => string | false);
7
+ /**
8
+ * Options for CORS middleware
9
+ * @public
10
+ */
11
+ export type CorsOptions = {
12
+ origin?: CorsOrigin;
13
+ methods?: string[];
14
+ allowedHeaders?: string[];
15
+ exposedHeaders?: string[];
16
+ credentials?: boolean;
17
+ maxAge?: number;
18
+ optionsSuccessStatus?: number;
19
+ };
20
+ /**
21
+ * Middleware handling Cross-Origin Resource Sharing (CORS).
22
+ * @public
23
+ */
24
+ export declare function cors(options?: CorsOptions): GravitoMiddleware;
@@ -0,0 +1,23 @@
1
+ import { type CookieOptions } from '../CookieJar';
2
+ import type { GravitoContext, GravitoMiddleware } from '../types';
3
+ /**
4
+ * Configuration for CSRF Protection
5
+ * @public
6
+ */
7
+ export type CsrfOptions = {
8
+ cookieName?: string;
9
+ headerName?: string;
10
+ formFieldName?: string;
11
+ cookie?: CookieOptions;
12
+ safeMethods?: string[];
13
+ };
14
+ /**
15
+ * Generate (or retrieve existing) CSRF token for the session.
16
+ * @public
17
+ */
18
+ export declare function getCsrfToken(c: GravitoContext, options?: CsrfOptions): string;
19
+ /**
20
+ * Middleware that validates CSRF tokens on unsafe requests.
21
+ * @public
22
+ */
23
+ export declare function csrfProtection(options?: CsrfOptions): GravitoMiddleware;
@@ -0,0 +1,28 @@
1
+ import type { GravitoContext, GravitoMiddleware } from '../types';
2
+ /**
3
+ * Options for header token gate
4
+ * @public
5
+ */
6
+ export type HeaderTokenGateOptions = {
7
+ headerName?: string;
8
+ token?: string | ((c: GravitoContext) => string | undefined);
9
+ };
10
+ /**
11
+ * Options for requireHeaderToken middleware
12
+ * @public
13
+ */
14
+ export type RequireHeaderTokenOptions = HeaderTokenGateOptions & {
15
+ status?: number;
16
+ message?: string;
17
+ };
18
+ /**
19
+ * Create a simple gate function to check a header token.
20
+ * @public
21
+ */
22
+ export declare function createHeaderGate(options?: HeaderTokenGateOptions): (c: GravitoContext) => Promise<boolean>;
23
+ /**
24
+ * Middleware that enforces a specific token in request headers.
25
+ * Useful for internal API authentication.
26
+ * @public
27
+ */
28
+ export declare function requireHeaderToken(options?: RequireHeaderTokenOptions): GravitoMiddleware;