@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9
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/Application-DtWDHXr1.d.ts +2110 -0
- package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
- package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
- package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
- package/dist/EventManager-CmIoLt7r.d.ts +207 -0
- package/dist/Gate-CNkBYf8m.d.ts +268 -0
- package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
- package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
- package/dist/LogManager-7mxnkaPM.d.ts +256 -0
- package/dist/MailManager-DpMvYiP9.d.ts +292 -0
- package/dist/Scheduler-BstvSca7.d.ts +469 -0
- package/dist/StorageManager-oZTHqaza.d.ts +337 -0
- package/dist/api-token-JOif2CtG.d.ts +1792 -0
- package/dist/app-key-CsBfRC_Q.d.ts +214 -0
- package/dist/auth/index.d.ts +418 -0
- package/dist/auth/index.js +6742 -0
- package/dist/authorization/index.d.ts +129 -0
- package/dist/authorization/index.js +621 -0
- package/dist/broadcasting/index.d.ts +233 -0
- package/dist/broadcasting/index.js +907 -0
- package/dist/cache/index.d.ts +233 -0
- package/dist/cache/index.js +817 -0
- package/dist/encryption/index.d.ts +222 -0
- package/dist/encryption/index.js +602 -0
- package/dist/events/index.d.ts +155 -0
- package/dist/events/index.js +330 -0
- package/dist/health/index.d.ts +185 -0
- package/dist/health/index.js +379 -0
- package/dist/i18n/index.d.ts +101 -0
- package/dist/i18n/index.js +597 -0
- package/dist/index-9_Jzj5jo.d.ts +7 -0
- package/dist/index.d.ts +2628 -619
- package/dist/index.js +22229 -3116
- package/dist/lambda/index.d.ts +156 -0
- package/dist/lambda/index.js +91 -0
- package/dist/logging/index.d.ts +50 -0
- package/dist/logging/index.js +557 -0
- package/dist/mail/index.d.ts +288 -0
- package/dist/mail/index.js +695 -0
- package/dist/mcp/index.d.ts +139 -0
- package/dist/mcp/index.js +382 -0
- package/dist/notifications/index.d.ts +271 -0
- package/dist/notifications/index.js +741 -0
- package/dist/queue/index.d.ts +423 -0
- package/dist/queue/index.js +958 -0
- package/dist/runtime/index.d.ts +93 -0
- package/dist/runtime/index.js +834 -0
- package/dist/scheduling/index.d.ts +41 -0
- package/dist/scheduling/index.js +836 -0
- package/dist/storage/index.d.ts +196 -0
- package/dist/storage/index.js +832 -0
- package/dist/vite/index.js +203 -3
- package/package.json +93 -6
- package/dist/chunk-FK2XQSBF.js +0 -160
package/dist/index.d.ts
CHANGED
|
@@ -1,670 +1,2679 @@
|
|
|
1
|
+
import { E as ErrorResponse, S as ServiceProvider, C as Container, c as ServiceBindings, Q as QueueManager, N as NotificationManager } from './Application-DtWDHXr1.js';
|
|
2
|
+
export { A as Application, d as ApplicationListenOptions, e as AuthPayload, f as CSRF_FORM_FIELD, g as CSRF_HEADER_NAME, h as CSRF_TOKEN_KEY, P as ContainerProvider, i as ContextualBinding, j as ContextualBindingBuilder, k as ContextualNeedsBuilder, m as Controller, n as ControllerInertiaProps, o as CsrfOptions, p as DatabaseChannelOptions, q as DatabaseNotification, r as ExceptionClass, t as ExceptionHandler, u as ExceptionHandlerOptions, v as ExceptionRenderer, w as ExceptionReporter, F as FailedJob, H as HostAuthorizationOptions, x as HstsOptions, I as InertiaOptions, y as InertiaPagePayload, z as InertiaResponse, B as InertiaSharedProps, J as InertiaSsrContext, K as InertiaSsrOptions, L as InertiaSsrRenderer, M as InertiaSsrResult, O as InferInertiaProps, R as Job, T as JobClass, U as JobFailureHandler, V as JobHandler, W as JobOptions, X as Notifiable, Y as Notification, Z as NotificationAttachment, _ as NotificationChannel, $ as NotificationChannelFactory, a0 as NotificationClass, a1 as NotificationMailMessage, a2 as NotificationManagerOptions, a3 as ProviderManager, a4 as QueueConfig, a5 as QueueDriver, a6 as QueueDriverFactory, a7 as QueuedJob, a8 as RendererRegistration, a9 as ResolvedSharedInertiaProps, aa as ResourceRouteOptions, ab as RouteBuilder, ac as RouteContractOptions, ad as RouteDefinition, ae as RouteOpenApiMetadata, af as RouteResourceAction, ag as Router, ah as SecurityHeadersOptions, ai as SentNotification, aj as ServiceBinding, ak as ServiceClass, al as ServiceFactory, am as ServiceProviderClass, an as ServiceProviderConstructor, ao as ServiceProviderOptions, ap as SharedInertiaPropsResolver, aq as SlackAttachment, ar as SlackBlock, as as SlackMessage, at as VALIDATED_DATA_KEY, au as ValidateRequestOptions, av as ValidationSchema, aw as WorkerOptions, ax as abort, ay as abortIf, az as abortUnless, aA as clearJobRegistry, aB as createApp, aC as createContainer, aD as createCsrfMiddleware, aE as createExceptionHandler, aF as createHostAuthorizationMiddleware, aG as createNotificationManager, aH as createQueueManager, aI as createSecurityHeaders, aJ as csrfField, aK as formatValidationErrors, aL as getContainer, aM as getCsrfToken, aN as getExceptionHandler, aO as getJob, aP as getNotificationManager, aQ as getQueueDriver, aR as getRegisteredJobs, aS as getValidatedData, aT as inertia, aU as parseRequestPayload, aV as registerJob, aW as resolve, aX as setContainer, aY as setExceptionHandler, aZ as setInertiaSharedProps, a_ as setNotificationManager, a$ as setQueueDriver, b0 as validate, b1 as validateRequest, b2 as validateRequestWith, b3 as validateSafe, b4 as verifyCsrfToken } from './Application-DtWDHXr1.js';
|
|
1
3
|
import * as hono from 'hono';
|
|
2
|
-
import {
|
|
4
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
3
5
|
export { Context } from 'hono';
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
read(id: string): Promise<SessionData | undefined>;
|
|
46
|
-
write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
|
|
47
|
-
destroy(id: string): Promise<void>;
|
|
48
|
-
}
|
|
49
|
-
declare class MemorySessionStore implements SessionStore {
|
|
50
|
-
private readonly now;
|
|
51
|
-
private readonly store;
|
|
52
|
-
constructor(now?: () => number);
|
|
53
|
-
read(id: string): Promise<SessionData | undefined>;
|
|
54
|
-
write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
|
|
55
|
-
destroy(id: string): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
interface SessionOptions {
|
|
58
|
-
cookieName?: string;
|
|
59
|
-
cookiePath?: string;
|
|
60
|
-
cookieDomain?: string;
|
|
61
|
-
cookieSecure?: boolean;
|
|
62
|
-
cookieSameSite?: 'Strict' | 'Lax' | 'None';
|
|
63
|
-
cookieHttpOnly?: boolean;
|
|
64
|
-
cookieMaxAgeSeconds?: number;
|
|
65
|
-
ttlSeconds?: number;
|
|
66
|
-
store?: SessionStore;
|
|
67
|
-
}
|
|
68
|
-
interface Session {
|
|
69
|
-
readonly id: string;
|
|
70
|
-
readonly isNew: boolean;
|
|
71
|
-
get<T = unknown>(key: string): T | undefined;
|
|
72
|
-
set<T = unknown>(key: string, value: T): void;
|
|
73
|
-
has(key: string): boolean;
|
|
74
|
-
forget(key: string): void;
|
|
75
|
-
flush(): void;
|
|
76
|
-
all(): SessionData;
|
|
77
|
-
regenerate(): void;
|
|
78
|
-
invalidate(): void;
|
|
79
|
-
}
|
|
80
|
-
interface CreateSessionMiddlewareOptions extends SessionOptions {
|
|
81
|
-
}
|
|
82
|
-
declare function createSessionMiddleware(options?: CreateSessionMiddlewareOptions): MiddlewareHandler;
|
|
83
|
-
declare function getSessionFromContext<T extends Session = Session>(ctx: {
|
|
84
|
-
get: (key: string) => unknown;
|
|
85
|
-
}): T | undefined;
|
|
6
|
+
import { a as AuthContext } from './api-token-JOif2CtG.js';
|
|
7
|
+
export { c as API_TOKEN_KEY, b as ApiToken, d as ApiTokenStore, e as AuthCredentials, A as AuthManager, f as AuthManagerOptions, g as Authenticatable, B as BaseUserProvider, h as BearerTokenMiddlewareOptions, i as CreateApiTokenOptions, j as CreateApiTokenResult, G as Guard, k as GuardContext, l as GuardFactory, M as MemoryApiTokenStore, m as MemoryOAuthStateStore, n as MemorySessionStore, o as ModelUserProvider, p as OAuthAuthorizeOptions, q as OAuthCallbackPayload, O as OAuthManager, r as OAuthManagerOptions, s as OAuthProviderConfig, t as OAuthProviderFactoryInput, u as OAuthStateConfig, v as OAuthStatePayload, w as OAuthStateStore, x as OAuthTokenResult, y as OAuthUserProfile, P as ProviderFactory, S as Session, z as SessionData, D as SessionStore, U as UserProvider, E as buildOAuthAuthorizeUrl, F as buildOAuthRedirectUrl, H as createApiToken, I as createBearerTokenMiddleware, J as createDiscordOAuthProviderConfig, K as createGitHubOAuthProviderConfig, L as createGoogleOAuthProviderConfig, N as createOAuthManager, Q as createOAuthState, R as createSessionMiddleware, T as exchangeOAuthCode, V as fetchOAuthUserProfile, W as getApiToken, X as getApiTokenOrFail, Y as getSessionFromContext, Z as getUserApiTokens, _ as parseApiToken, $ as parseOAuthRedirectUrl, a0 as revokeAllApiTokens, a1 as revokeApiToken, a2 as tokenCan, a3 as tokenCanAll, a4 as tokenCanAny, a5 as verifyApiToken, a6 as verifyOAuthState } from './api-token-JOif2CtG.js';
|
|
8
|
+
export { AuthenticatableModel, EmailVerificationConfig, EmailVerificationToken, EmailVerificationTokenResult, EmailVerificationTokenStore, ScryptHasher as Hash, MemoryEmailVerificationStore, MemoryPasswordResetStore, NodeHasher, PasswordResetConfig, PasswordResetTokenResult, PasswordResetTokenStore, ScryptHasher, SessionGuard, buildPasswordResetUrl, buildVerificationUrl, completeEmailVerification, completePasswordReset, createEmailVerificationToken, createPasswordResetToken, isEmailVerified, parsePasswordResetUrl, parseVerificationUrl, requireVerifiedEmail, verifyEmailToken, verifyPasswordResetToken } from './auth/index.js';
|
|
9
|
+
export { M as Middleware, d as defineMiddleware, j as jsonResponse } from './index-9_Jzj5jo.js';
|
|
10
|
+
import { E as EventManager } from './EventManager-CmIoLt7r.js';
|
|
11
|
+
export { a as Event, b as EventClass, c as EventListener, d as EventSubscription, L as ListenerOptions, R as RegisteredListener, e as createEventManager } from './EventManager-CmIoLt7r.js';
|
|
12
|
+
export { ApplicationShutdown, ApplicationStarted, JobFailed, JobProcessed, Listener, ListenerClass, RequestFinished, RequestReceived, UserAuthenticated, UserLoggedOut } from './events/index.js';
|
|
13
|
+
export { FailedJobHandler, FailedJobInfo, FailedJobReporter, MemoryDriver, RedisDriver, RedisDriverOptions, SqsDriver, Worker, WorkerEvents, createSqsAdapter, processJob } from './queue/index.js';
|
|
14
|
+
import { M as MailManager } from './MailManager-DpMvYiP9.js';
|
|
15
|
+
export { a as MailAddress, b as MailAttachment, c as MailConfig, d as MailMessage, e as MailTransport, f as MailTransportConfig, g as MailTransportFactory, h as MemoryTransportOptions, R as ResendTransportOptions, S as SendResult, i as SmtpTransportOptions, j as createMailManager } from './MailManager-DpMvYiP9.js';
|
|
16
|
+
export { Mail, MemoryTransport, ResendTransport, SmtpTransport, getMailManager, mail, setMailManager } from './mail/index.js';
|
|
17
|
+
import { C as CacheManager } from './CacheManager-BkvHEOZX.js';
|
|
18
|
+
export { a as CacheConfig, b as CacheStore, c as CacheStoreFactory, d as createCacheManager } from './CacheManager-BkvHEOZX.js';
|
|
19
|
+
export { FileStore as FileCacheStore, MemoryStore as MemoryCacheStore, RedisStore as RedisCacheStore, TaggedCache } from './cache/index.js';
|
|
20
|
+
import { S as StorageManager } from './StorageManager-oZTHqaza.js';
|
|
21
|
+
export { D as DiskConfig, F as FileMetadata, P as PutOptions, a as StorageConfig, b as StorageDriver, c as StorageDriverFactory, d as createStorageManager } from './StorageManager-oZTHqaza.js';
|
|
22
|
+
export { LocalDriver as LocalStorageDriver, MemoryDriver as MemoryStorageDriver, S3Driver } from './storage/index.js';
|
|
23
|
+
import { S as Scheduler } from './Scheduler-BstvSca7.js';
|
|
24
|
+
export { P as ParsedCron, a as PendingSchedule, b as Schedule, J as ScheduledJobClass, c as ScheduledTask, d as SchedulerOptions, T as TaskCallback, e as TaskDefinition, f as createScheduler } from './Scheduler-BstvSca7.js';
|
|
25
|
+
export { getNextOccurrence, getNextOccurrences, isDue, isDueInTimezone, matchesCron, parseCron, toTimezone } from './scheduling/index.js';
|
|
26
|
+
import { L as LogManager } from './LogManager-7mxnkaPM.js';
|
|
27
|
+
export { C as ConsoleChannelConfig, D as DailyFileChannelConfig, F as FileChannelConfig, a as LOG_LEVEL_PRIORITY, b as LogChannel, c as LogChannelConfig, d as LogChannelFactory, e as LogConfig, f as LogContext, g as LogEntry, h as LogFormatter, i as LogLevel, j as Logger, k as LoggerOptions, S as StackChannelConfig, l as createLogManager, m as filterSensitiveData, n as getLogManager, s as setLogManager } from './LogManager-7mxnkaPM.js';
|
|
28
|
+
export { ConsoleChannel, DailyFileChannel, FileChannel } from './logging/index.js';
|
|
29
|
+
import { I as I18nManager } from './I18nManager-Dtgzsf5n.js';
|
|
30
|
+
export { a as I18nConfig, P as PluralizationRule, R as ReplacementValues, T as TranslationLoader, b as TranslationLoaderFactory, c as TranslationMessages, d as Translator, e as TranslatorOptions, f as createI18n, g as getI18n, s as setI18n, t, h as tc } from './I18nManager-Dtgzsf5n.js';
|
|
31
|
+
export { JsonLoader, MemoryLoader, getPluralizationRule, pluralizationRules, selectPluralForm } from './i18n/index.js';
|
|
32
|
+
export { C as CheckResult, a as HealthCheck, b as HealthCheckOptions, H as HealthManager, c as HealthMiddlewareOptions, d as HealthReport, e as HealthStatus, f as createHealthManager } from './HealthManager-DUyMIzsZ.js';
|
|
33
|
+
export { CacheCheck, CacheCheckOptions, CacheStoreInterface, CustomCheck, CustomCheckCallback, DatabaseCheck, DatabaseCheckOptions, DatabaseConnection, MemoryCheck, MemoryCheckOptions, RedisCheck, RedisCheckOptions, RedisClient, StorageCheck, StorageCheckOptions, StorageDriverInterface, customCheck } from './health/index.js';
|
|
34
|
+
export { DatabaseChannel, MailChannel, MailChannelOptions, MemoryChannel, SlackChannel, SlackChannelOptions } from './notifications/index.js';
|
|
35
|
+
import { B as BroadcastManager } from './BroadcastManager-AkIWUGJo.js';
|
|
36
|
+
export { A as AuthMiddlewareOptions, a as BroadcastDriver, b as BroadcastDriverFactory, c as BroadcastEvent, d as BroadcastManagerOptions, e as BroadcastableEvent, C as Channel, f as ChannelAuthorizer, g as ChannelRegistration, P as PresenceBroadcastDriver, h as PresenceChannel, i as PresenceChannelAuthorizer, j as PresenceMember, k as PrivateChannel, S as SSEClient, l as SSEMiddlewareOptions, W as WebSocketClient, m as createBroadcastManager, n as getBroadcastManager, s as setBroadcastManager } from './BroadcastManager-AkIWUGJo.js';
|
|
37
|
+
export { RedisClient as BroadcastRedisClient, RedisDriverOptions as BroadcastRedisDriverOptions, MemoryDriver as MemoryBroadcastDriver, RedisDriver as RedisBroadcastDriver, createTypedBroadcaster } from './broadcasting/index.js';
|
|
38
|
+
import { I as InputInterface, P as ParsedSignature, O as OptionDefinition, a as CommandInstance, b as OutputInterface } from './ConsoleKernel-CqCVrdZs.js';
|
|
39
|
+
export { A as ArgumentDefinition, c as CommandClass, C as ConsoleKernel, d as ConsoleKernelOptions, e as ProgressInterface, f as PromptInterface, S as ScheduledCommand, g as createConsoleKernel } from './ConsoleKernel-CqCVrdZs.js';
|
|
40
|
+
import * as readline from 'readline';
|
|
41
|
+
export { R as AuthResponse, A as AuthUser, a as AuthorizationResponse, b as AuthorizeOptions, G as Gate, c as GateCallback, d as GateDefinition, e as GateOptions, P as PolicyClass, f as PolicyInterface, g as PolicyMethod, h as PolicyRegistration, i as ResourceAction, j as ResponseBuilder, k as authorizeAbility, l as can, m as cannot, n as createGate, o as defineGate, p as getGate, s as setGate } from './Gate-CNkBYf8m.js';
|
|
42
|
+
export { AuthorizedContext, Policy, authorizeAllMiddleware, authorizeMiddleware, authorizeResourceMiddleware, definePolicy, withAuthorization } from './authorization/index.js';
|
|
43
|
+
export { A as AppKeyring, D as DecryptOptions, a as EncryptOptions, b as EncryptedPayload, E as Encrypter, c as EncrypterConfig, H as HashAlgorithm, d as HmacOptions, P as PasswordHashOptions, R as RandomStringOptions, e as createEncrypter, f as decrypt, g as deriveAppKey, h as deriveAppKeyring, i as encrypt, j as generateAppKey, k as generateKey, l as getAppKeyringFromEnv, m as getEncrypter, n as normalizeAppKey, p as parseAppKey, o as parsePreviousAppKeys, s as setEncrypter } from './app-key-CsBfRC_Q.js';
|
|
44
|
+
export { MessageSigner, SignMessageOptions, SignedMessageClaims, SignedUrlOptions, VerifySignedMessageOptions, VerifySignedUrlOptions, check as checkHash, generateOtp, generatePassword, generateSlug, hash, hashPassword, hmac, md5, needsRehash, pick, random, randomBase64, randomBase64Url, randomHex, randomInt, randomString, sample, secureCompare, sha256, sha512, shuffle, signUrl, urlSafeToken, uuid, verifyHmac, verifyPassword, verifySignedUrl } from './encryption/index.js';
|
|
45
|
+
import Redis, { RedisOptions } from 'ioredis';
|
|
46
|
+
import 'vite';
|
|
86
47
|
|
|
87
48
|
interface RequireAuthOptions {
|
|
88
49
|
redirectTo?: string;
|
|
89
50
|
status?: number;
|
|
90
51
|
responseFactory?: () => Response;
|
|
91
52
|
}
|
|
53
|
+
declare const AUTH_CONTEXT_KEY = "guren:auth";
|
|
92
54
|
declare function attachAuthContext(contextFactory: (ctx: Context) => AuthContext): MiddlewareHandler;
|
|
93
55
|
declare function requireAuthenticated(options?: RequireAuthOptions): MiddlewareHandler;
|
|
94
56
|
declare function requireGuest(options?: RequireAuthOptions): MiddlewareHandler;
|
|
95
57
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
getAuthPassword(): string | null | undefined;
|
|
103
|
-
getRememberToken?(): string | null | undefined;
|
|
104
|
-
setRememberToken?(token: string | null): void | Promise<void>;
|
|
105
|
-
}
|
|
106
|
-
interface Guard<User = Authenticatable> {
|
|
107
|
-
check(): Promise<boolean>;
|
|
108
|
-
guest(): Promise<boolean>;
|
|
109
|
-
user<T = User>(): Promise<T | null>;
|
|
110
|
-
id(): Promise<unknown>;
|
|
111
|
-
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
112
|
-
logout(): Promise<void>;
|
|
113
|
-
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
114
|
-
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
115
|
-
session<T extends Session = Session>(): T | undefined;
|
|
116
|
-
}
|
|
117
|
-
interface UserProvider<User = Authenticatable> {
|
|
118
|
-
retrieveById(identifier: unknown): Promise<User | null>;
|
|
119
|
-
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
120
|
-
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
121
|
-
getId(user: User): unknown;
|
|
122
|
-
setRememberToken?(user: User, token: string | null): Promise<void> | void;
|
|
123
|
-
getRememberToken?(user: User): Promise<string | null> | string | null;
|
|
124
|
-
}
|
|
125
|
-
interface GuardContext {
|
|
126
|
-
ctx: Context;
|
|
127
|
-
session: Session | undefined;
|
|
128
|
-
manager: AuthManagerContract;
|
|
129
|
-
}
|
|
130
|
-
type GuardFactory<User = Authenticatable> = (context: GuardContext) => Guard<User>;
|
|
131
|
-
interface ProviderFactory<User = Authenticatable> {
|
|
132
|
-
(manager: AuthManagerContract): UserProvider<User>;
|
|
133
|
-
}
|
|
134
|
-
interface AuthManagerOptions {
|
|
135
|
-
defaultGuard?: string;
|
|
136
|
-
}
|
|
137
|
-
interface AttachContextOptions {
|
|
138
|
-
guard?: string;
|
|
139
|
-
}
|
|
140
|
-
interface AuthContext<User = Authenticatable> {
|
|
141
|
-
check(): Promise<boolean>;
|
|
142
|
-
guest(): Promise<boolean>;
|
|
143
|
-
user<T = User>(): Promise<T | null>;
|
|
144
|
-
id(): Promise<unknown>;
|
|
145
|
-
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
146
|
-
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
147
|
-
logout(): Promise<void>;
|
|
148
|
-
guard<T = User>(name?: string): Guard<T>;
|
|
149
|
-
session<T extends Session = Session>(): T | undefined;
|
|
150
|
-
}
|
|
151
|
-
interface AuthManagerContract {
|
|
152
|
-
registerGuard<User = Authenticatable>(name: string, factory: GuardFactory<User>): void;
|
|
153
|
-
registerProvider<User = Authenticatable>(name: string, factory: ProviderFactory<User>): void;
|
|
154
|
-
getProvider<User = Authenticatable>(name: string): UserProvider<User>;
|
|
155
|
-
createGuard<User = Authenticatable>(name: string, context: GuardContext): Guard<User>;
|
|
156
|
-
guardNames(): string[];
|
|
157
|
-
setDefaultGuard(name: string): void;
|
|
158
|
-
getDefaultGuard(): string;
|
|
159
|
-
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
declare class AuthManager implements AuthManagerContract {
|
|
163
|
-
private readonly guards;
|
|
164
|
-
private readonly providers;
|
|
165
|
-
private defaultGuard;
|
|
166
|
-
constructor(options?: AuthManagerOptions);
|
|
167
|
-
registerGuard<User>(name: string, factory: GuardFactory<User>): void;
|
|
168
|
-
registerProvider<User>(name: string, factory: ProviderFactory<User>): void;
|
|
169
|
-
getProvider<User>(name: string): UserProvider<User>;
|
|
170
|
-
createGuard<User>(name: string, context: GuardContext): Guard<User>;
|
|
171
|
-
guardNames(): string[];
|
|
172
|
-
setDefaultGuard(name: string): void;
|
|
173
|
-
getDefaultGuard(): string;
|
|
174
|
-
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
175
|
-
attempt(name: string, ctx: Context, credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
interface SessionGuardOptions {
|
|
179
|
-
provider: UserProvider;
|
|
180
|
-
sessionKey?: string;
|
|
181
|
-
rememberSessionKey?: string;
|
|
182
|
-
session: Session | undefined;
|
|
183
|
-
}
|
|
184
|
-
declare class SessionGuard<User extends Authenticatable = Authenticatable> implements Guard<User> {
|
|
185
|
-
private readonly options;
|
|
186
|
-
private cachedUser;
|
|
187
|
-
constructor(options: SessionGuardOptions);
|
|
188
|
-
private get currentSession();
|
|
189
|
-
private get provider();
|
|
190
|
-
private sessionKey;
|
|
191
|
-
private rememberSessionKey;
|
|
192
|
-
private loadRememberedUser;
|
|
193
|
-
private resolveUser;
|
|
194
|
-
check(): Promise<boolean>;
|
|
195
|
-
guest(): Promise<boolean>;
|
|
196
|
-
user<T = User>(): Promise<T | null>;
|
|
197
|
-
id(): Promise<unknown>;
|
|
198
|
-
private remember;
|
|
199
|
-
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
200
|
-
logout(): Promise<void>;
|
|
201
|
-
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
202
|
-
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
203
|
-
session<T extends Session = Session>(): T | undefined;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
declare abstract class BaseUserProvider<User extends Authenticatable = Authenticatable> implements UserProvider<User> {
|
|
207
|
-
abstract retrieveById(identifier: unknown): Promise<User | null>;
|
|
208
|
-
abstract retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
209
|
-
abstract validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
210
|
-
abstract getId(user: User): unknown;
|
|
211
|
-
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
212
|
-
getRememberToken(user: User): Promise<string | null>;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
type PlainObject = Record<string, unknown>;
|
|
216
|
-
type RelationShape = Record<string, unknown>;
|
|
217
|
-
type WhereValue<Value> = Value | readonly Value[] | null;
|
|
218
|
-
type WhereClause<TRecord extends PlainObject = PlainObject> = Partial<{
|
|
219
|
-
[K in keyof TRecord & string]?: WhereValue<TRecord[K]>;
|
|
220
|
-
}>;
|
|
221
|
-
type OrderDirection = 'asc' | 'desc';
|
|
222
|
-
type OrderDefinition<TRecord extends PlainObject = PlainObject> = {
|
|
223
|
-
column: keyof TRecord & string;
|
|
224
|
-
direction: OrderDirection;
|
|
225
|
-
};
|
|
226
|
-
type OrderExpression<TRecord extends PlainObject = PlainObject> = (keyof TRecord & string) | readonly [keyof TRecord & string, OrderDirection] | {
|
|
227
|
-
column: keyof TRecord & string;
|
|
228
|
-
direction?: OrderDirection;
|
|
229
|
-
};
|
|
230
|
-
type OrderByInput<TRecord extends PlainObject = PlainObject> = OrderExpression<TRecord> | readonly OrderExpression<TRecord>[];
|
|
231
|
-
type OrderByClause<TRecord extends PlainObject = PlainObject> = readonly OrderDefinition<TRecord>[];
|
|
232
|
-
interface FindManyOptions<TRecord extends PlainObject = PlainObject> {
|
|
233
|
-
where?: WhereClause<TRecord>;
|
|
234
|
-
orderBy?: OrderByClause<TRecord>;
|
|
235
|
-
limit?: number;
|
|
236
|
-
offset?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Rate limit entry stored in the backing store.
|
|
60
|
+
*/
|
|
61
|
+
interface RateLimitEntry {
|
|
62
|
+
count: number;
|
|
63
|
+
resetAt: number;
|
|
237
64
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Store interface for rate limit data.
|
|
67
|
+
* Implement this for Redis or database-backed storage.
|
|
68
|
+
*/
|
|
69
|
+
interface RateLimitStore {
|
|
70
|
+
/**
|
|
71
|
+
* Get the current rate limit entry for a key.
|
|
72
|
+
*/
|
|
73
|
+
get(key: string): Promise<RateLimitEntry | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Increment the count for a key and return the new entry.
|
|
76
|
+
* If the key doesn't exist, create it with count=1.
|
|
77
|
+
*/
|
|
78
|
+
increment(key: string, windowMs: number): Promise<RateLimitEntry>;
|
|
79
|
+
/**
|
|
80
|
+
* Reset the count for a key.
|
|
81
|
+
*/
|
|
82
|
+
reset(key: string): Promise<void>;
|
|
243
83
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Base class for in-memory rate limit stores with automatic cleanup.
|
|
86
|
+
*/
|
|
87
|
+
declare abstract class BaseMemoryStore implements RateLimitStore {
|
|
88
|
+
protected cleanupInterval?: ReturnType<typeof setInterval>;
|
|
89
|
+
constructor(cleanupIntervalMs?: number);
|
|
90
|
+
abstract get(key: string): Promise<RateLimitEntry | null>;
|
|
91
|
+
abstract increment(key: string, windowMs: number): Promise<RateLimitEntry>;
|
|
92
|
+
abstract reset(key: string): Promise<void>;
|
|
93
|
+
abstract cleanup(): void;
|
|
94
|
+
abstract clear(): void;
|
|
95
|
+
abstract get size(): number;
|
|
96
|
+
destroy(): void;
|
|
252
97
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
98
|
+
/**
|
|
99
|
+
* In-memory rate limit store.
|
|
100
|
+
* Suitable for single-process development, not for production clusters.
|
|
101
|
+
*/
|
|
102
|
+
declare class MemoryRateLimitStore extends BaseMemoryStore {
|
|
103
|
+
private entries;
|
|
104
|
+
get(key: string): Promise<RateLimitEntry | null>;
|
|
105
|
+
increment(key: string, windowMs: number): Promise<RateLimitEntry>;
|
|
106
|
+
reset(key: string): Promise<void>;
|
|
107
|
+
cleanup(): void;
|
|
108
|
+
clear(): void;
|
|
109
|
+
get size(): number;
|
|
256
110
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
} : {} : {};
|
|
310
|
-
interface BaseRelationDefinition {
|
|
311
|
-
type: 'hasMany' | 'belongsTo';
|
|
312
|
-
name: string;
|
|
313
|
-
related: typeof Model;
|
|
314
|
-
}
|
|
315
|
-
interface HasManyRelationDefinition extends BaseRelationDefinition {
|
|
316
|
-
type: 'hasMany';
|
|
317
|
-
foreignKey: string;
|
|
318
|
-
localKey: string;
|
|
319
|
-
}
|
|
320
|
-
interface BelongsToRelationDefinition extends BaseRelationDefinition {
|
|
321
|
-
type: 'belongsTo';
|
|
322
|
-
foreignKey: string;
|
|
323
|
-
ownerKey: string;
|
|
324
|
-
}
|
|
325
|
-
type RelationDefinition = HasManyRelationDefinition | BelongsToRelationDefinition;
|
|
326
|
-
|
|
327
|
-
interface PasswordHasher {
|
|
328
|
-
hash(plain: string): Promise<string>;
|
|
329
|
-
verify(hashed: string, plain: string): Promise<boolean>;
|
|
330
|
-
needsRehash?(hashed: string): boolean;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
interface ModelUserProviderOptions {
|
|
334
|
-
idColumn?: string;
|
|
335
|
-
usernameColumn?: string;
|
|
336
|
-
passwordColumn?: string;
|
|
337
|
-
rememberTokenColumn?: string;
|
|
338
|
-
hasher?: PasswordHasher;
|
|
339
|
-
credentialsPasswordField?: string;
|
|
340
|
-
}
|
|
341
|
-
declare class ModelUserProvider<User extends Authenticatable = Authenticatable> extends BaseUserProvider<User> {
|
|
342
|
-
private readonly model;
|
|
343
|
-
private readonly idColumn;
|
|
344
|
-
private readonly usernameColumn;
|
|
345
|
-
private readonly passwordColumn;
|
|
346
|
-
private readonly rememberTokenColumn;
|
|
347
|
-
private readonly hasher;
|
|
348
|
-
private readonly credentialsPasswordField;
|
|
349
|
-
constructor(model: typeof Model, options?: ModelUserProviderOptions);
|
|
350
|
-
private cast;
|
|
351
|
-
retrieveById(identifier: unknown): Promise<User | null>;
|
|
352
|
-
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
353
|
-
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
354
|
-
getId(user: User): unknown;
|
|
355
|
-
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
356
|
-
getRememberToken(user: User): Promise<string | null>;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
type Argon2Algorithm = 'argon2id' | 'argon2i' | 'argon2d';
|
|
360
|
-
type SupportedAlgorithm = Argon2Algorithm | 'bcrypt';
|
|
361
|
-
interface BunPasswordHasherOptions {
|
|
362
|
-
/**
|
|
363
|
-
* Hashing algorithm to use. Defaults to Bun's Argon2id implementation.
|
|
364
|
-
*/
|
|
365
|
-
algorithm?: SupportedAlgorithm;
|
|
366
|
-
/** Argon2 memory cost (in kibibytes). */
|
|
367
|
-
memoryCost?: number;
|
|
368
|
-
/** Argon2 time cost (number of iterations). */
|
|
369
|
-
timeCost?: number;
|
|
370
|
-
/** Bcrypt cost factor (log rounds). */
|
|
371
|
-
cost?: number;
|
|
372
|
-
}
|
|
373
|
-
declare class ScryptHasher implements PasswordHasher {
|
|
374
|
-
private readonly algorithm;
|
|
375
|
-
private readonly memoryCost?;
|
|
376
|
-
private readonly timeCost?;
|
|
377
|
-
private readonly cost?;
|
|
378
|
-
constructor(options?: BunPasswordHasherOptions);
|
|
379
|
-
hash(plain: string): Promise<string>;
|
|
380
|
-
verify(hashed: string, plain: string): Promise<boolean>;
|
|
381
|
-
needsRehash(hashed: string): boolean;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
declare abstract class AuthenticatableModel<TRecord extends PlainObject = PlainObject> extends Model<TRecord> {
|
|
385
|
-
protected static passwordField: string;
|
|
386
|
-
protected static passwordHashField: string;
|
|
387
|
-
protected static passwordHasher: PasswordHasher | null;
|
|
388
|
-
protected static resolvePasswordField(): string;
|
|
389
|
-
protected static resolvePasswordHashField(): string;
|
|
390
|
-
protected static resolvePasswordHasher(): PasswordHasher;
|
|
391
|
-
protected static preparePersistencePayload(data: PlainObject): Promise<PlainObject>;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
type DefaultInertiaProps = Record<string, unknown>;
|
|
395
|
-
type InertiaResponseMarker<Component extends string, Props extends DefaultInertiaProps> = {
|
|
396
|
-
readonly __gurenInertia?: {
|
|
397
|
-
readonly component: Component;
|
|
398
|
-
readonly props: Props;
|
|
399
|
-
};
|
|
400
|
-
};
|
|
401
|
-
type InertiaResponse<Component extends string, Props extends DefaultInertiaProps> = Response & InertiaResponseMarker<Component, Props>;
|
|
402
|
-
type InferInertiaProps<T> = [T] extends [InertiaResponse<string, infer Props>] ? Props : [T] extends [Promise<infer Awaited>] ? InferInertiaProps<Awaited> : DefaultInertiaProps;
|
|
403
|
-
type ControllerInertiaProps<TController extends Controller, TAction extends keyof TController> = TController[TAction] extends (...args: any[]) => infer TResult ? InferInertiaProps<Awaited<TResult>> : DefaultInertiaProps;
|
|
404
|
-
interface RedirectOptions {
|
|
405
|
-
status?: number;
|
|
406
|
-
headers?: HeadersInit;
|
|
111
|
+
/**
|
|
112
|
+
* Configuration options for rate limiting.
|
|
113
|
+
*/
|
|
114
|
+
interface RateLimitOptions {
|
|
115
|
+
/**
|
|
116
|
+
* Maximum number of requests allowed in the time window.
|
|
117
|
+
* @default 100
|
|
118
|
+
*/
|
|
119
|
+
limit?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Time window in milliseconds.
|
|
122
|
+
* @default 60000 (1 minute)
|
|
123
|
+
*/
|
|
124
|
+
windowMs?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Function to extract the rate limit key from the request.
|
|
127
|
+
* Defaults to using the client IP address.
|
|
128
|
+
*/
|
|
129
|
+
keyGenerator?: (ctx: Context) => string | Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Rate limit store implementation.
|
|
132
|
+
* Defaults to in-memory store.
|
|
133
|
+
*/
|
|
134
|
+
store?: RateLimitStore;
|
|
135
|
+
/**
|
|
136
|
+
* Whether to skip rate limiting for certain requests.
|
|
137
|
+
*/
|
|
138
|
+
skip?: (ctx: Context) => boolean | Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Custom handler when rate limit is exceeded.
|
|
141
|
+
*/
|
|
142
|
+
onRateLimited?: (ctx: Context, retryAfter: number) => Response | Promise<Response>;
|
|
143
|
+
/**
|
|
144
|
+
* Whether to add rate limit headers to all responses.
|
|
145
|
+
* @default true
|
|
146
|
+
*/
|
|
147
|
+
headers?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Custom message when rate limit is exceeded.
|
|
150
|
+
* @default 'Too many requests, please try again later.'
|
|
151
|
+
*/
|
|
152
|
+
message?: string;
|
|
153
|
+
/**
|
|
154
|
+
* HTTP status code when rate limit is exceeded.
|
|
155
|
+
* @default 429
|
|
156
|
+
*/
|
|
157
|
+
statusCode?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Prefix for rate limit keys.
|
|
160
|
+
* @default 'rl:'
|
|
161
|
+
*/
|
|
162
|
+
keyPrefix?: string;
|
|
407
163
|
}
|
|
408
|
-
type InertiaResponseOptions = Omit<InertiaOptions, 'url' | 'request'> & {
|
|
409
|
-
url?: string;
|
|
410
|
-
};
|
|
411
164
|
/**
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
165
|
+
* Create a rate limiting middleware.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* // Basic usage - 100 requests per minute per IP
|
|
170
|
+
* app.use('*', createRateLimitMiddleware())
|
|
171
|
+
*
|
|
172
|
+
* // Stricter limit for login endpoint
|
|
173
|
+
* router.post('/login', [AuthController, 'login'],
|
|
174
|
+
* createRateLimitMiddleware({
|
|
175
|
+
* limit: 5,
|
|
176
|
+
* windowMs: 15 * 60 * 1000, // 15 minutes
|
|
177
|
+
* })
|
|
178
|
+
* )
|
|
179
|
+
*
|
|
180
|
+
* // Custom key based on authenticated user
|
|
181
|
+
* app.use('/api/*', createRateLimitMiddleware({
|
|
182
|
+
* limit: 1000,
|
|
183
|
+
* windowMs: 60 * 60 * 1000, // 1 hour
|
|
184
|
+
* keyGenerator: async (ctx) => {
|
|
185
|
+
* const user = await ctx.get('user')
|
|
186
|
+
* return user?.id?.toString() ?? defaultKeyGenerator(ctx)
|
|
187
|
+
* },
|
|
188
|
+
* }))
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare function createRateLimitMiddleware(options?: RateLimitOptions): MiddlewareHandler;
|
|
192
|
+
/**
|
|
193
|
+
* Rate limit result information.
|
|
194
|
+
*/
|
|
195
|
+
interface RateLimitInfo {
|
|
196
|
+
limit: number;
|
|
197
|
+
remaining: number;
|
|
198
|
+
resetAt: Date;
|
|
199
|
+
isLimited: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get rate limit information for a key without incrementing.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* const info = await getRateLimitInfo('user:123', store, { limit: 100 })
|
|
207
|
+
* console.log(`${info.remaining} requests remaining`)
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function getRateLimitInfo(key: string, store: RateLimitStore, options?: {
|
|
211
|
+
limit: number;
|
|
212
|
+
keyPrefix?: string;
|
|
213
|
+
}): Promise<RateLimitInfo>;
|
|
214
|
+
/**
|
|
215
|
+
* Reset rate limit for a specific key.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* // Reset rate limit after successful captcha
|
|
220
|
+
* await resetRateLimit(clientIp, store)
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function resetRateLimit(key: string, store: RateLimitStore, options?: {
|
|
224
|
+
keyPrefix?: string;
|
|
225
|
+
}): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Sliding window rate limit store.
|
|
228
|
+
* More accurate than fixed window but uses more memory.
|
|
229
|
+
*/
|
|
230
|
+
declare class SlidingWindowRateLimitStore extends BaseMemoryStore {
|
|
231
|
+
private requests;
|
|
232
|
+
get(key: string): Promise<RateLimitEntry | null>;
|
|
233
|
+
increment(key: string, windowMs: number): Promise<RateLimitEntry>;
|
|
234
|
+
reset(key: string): Promise<void>;
|
|
235
|
+
cleanup(): void;
|
|
236
|
+
clear(): void;
|
|
237
|
+
get size(): number;
|
|
459
238
|
}
|
|
460
239
|
|
|
461
|
-
|
|
240
|
+
interface CspDirectives {
|
|
241
|
+
defaultSrc?: string[];
|
|
242
|
+
scriptSrc?: string[];
|
|
243
|
+
styleSrc?: string[];
|
|
244
|
+
imgSrc?: string[];
|
|
245
|
+
fontSrc?: string[];
|
|
246
|
+
connectSrc?: string[];
|
|
247
|
+
mediaSrc?: string[];
|
|
248
|
+
objectSrc?: string[];
|
|
249
|
+
frameSrc?: string[];
|
|
250
|
+
childSrc?: string[];
|
|
251
|
+
workerSrc?: string[];
|
|
252
|
+
frameAncestors?: string[];
|
|
253
|
+
formAction?: string[];
|
|
254
|
+
baseUri?: string[];
|
|
255
|
+
manifestSrc?: string[];
|
|
256
|
+
upgradeInsecureRequests?: boolean;
|
|
257
|
+
blockAllMixedContent?: boolean;
|
|
258
|
+
/** Escape hatch for directives not listed above. */
|
|
259
|
+
[directive: string]: string[] | boolean | undefined;
|
|
260
|
+
}
|
|
261
|
+
interface CspOptions {
|
|
262
|
+
/** CSP directives configuration. */
|
|
263
|
+
directives?: CspDirectives;
|
|
264
|
+
/** Use Content-Security-Policy-Report-Only instead. Default: false */
|
|
265
|
+
reportOnly?: boolean;
|
|
266
|
+
/** URI for CSP violation reports. */
|
|
267
|
+
reportUri?: string;
|
|
268
|
+
/** Generate a per-request nonce and auto-append to script-src and style-src. Default: false */
|
|
269
|
+
useNonce?: boolean;
|
|
270
|
+
}
|
|
271
|
+
declare const CSP_NONCE_KEY = "csp-nonce";
|
|
462
272
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
273
|
+
* Retrieve the CSP nonce for the current request.
|
|
274
|
+
* Only available when `useNonce: true` is set.
|
|
465
275
|
*/
|
|
466
|
-
declare
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
276
|
+
declare function getCspNonce(ctx: Context): string;
|
|
277
|
+
/**
|
|
278
|
+
* Middleware that sets Content-Security-Policy headers.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* import { createCspMiddleware, getCspNonce } from '@guren/core'
|
|
283
|
+
*
|
|
284
|
+
* app.use('*', createCspMiddleware({
|
|
285
|
+
* directives: {
|
|
286
|
+
* defaultSrc: ["'self'"],
|
|
287
|
+
* scriptSrc: ["'self'", 'https://cdn.example.com'],
|
|
288
|
+
* styleSrc: ["'self'", "'unsafe-inline'"],
|
|
289
|
+
* imgSrc: ["'self'", 'data:', 'https:'],
|
|
290
|
+
* objectSrc: ["'none'"],
|
|
291
|
+
* },
|
|
292
|
+
* useNonce: true,
|
|
293
|
+
* reportUri: '/csp-report',
|
|
294
|
+
* }))
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function createCspMiddleware(options?: CspOptions): MiddlewareHandler;
|
|
298
|
+
|
|
299
|
+
interface CorsOptions {
|
|
300
|
+
/**
|
|
301
|
+
* Allowed origins. Default: none (same-origin policy applies).
|
|
302
|
+
* - A string: exact origin match (use '*' to allow all origins)
|
|
303
|
+
* - An array of strings: multiple allowed origins
|
|
304
|
+
* - A function: dynamic origin evaluation
|
|
305
|
+
*/
|
|
306
|
+
origin?: string | string[] | ((origin: string, ctx: unknown) => string | undefined | null);
|
|
307
|
+
/** Allowed HTTP methods. Default: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH'] */
|
|
308
|
+
allowMethods?: string[];
|
|
309
|
+
/** Allowed request headers. */
|
|
310
|
+
allowHeaders?: string[];
|
|
311
|
+
/** Headers exposed to the browser. */
|
|
312
|
+
exposeHeaders?: string[];
|
|
313
|
+
/** Preflight cache max-age in seconds. */
|
|
314
|
+
maxAge?: number;
|
|
315
|
+
/** Allow credentials (cookies, authorization headers). Default: false */
|
|
316
|
+
credentials?: boolean;
|
|
471
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* CORS middleware powered by Hono's built-in CORS support.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* import { createCorsMiddleware } from '@guren/core'
|
|
324
|
+
*
|
|
325
|
+
* // Allow specific origins
|
|
326
|
+
* app.use('/api/*', createCorsMiddleware({
|
|
327
|
+
* origin: ['https://example.com', 'https://app.example.com'],
|
|
328
|
+
* credentials: true,
|
|
329
|
+
* }))
|
|
330
|
+
*
|
|
331
|
+
* // Dynamic origin
|
|
332
|
+
* app.use('/api/*', createCorsMiddleware({
|
|
333
|
+
* origin: (origin) => origin.endsWith('.example.com') ? origin : null,
|
|
334
|
+
* }))
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function createCorsMiddleware(options?: CorsOptions): MiddlewareHandler;
|
|
472
338
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
get hono(): Hono;
|
|
479
|
-
get routes(): typeof Route;
|
|
480
|
-
get views(): typeof ViewEngine;
|
|
481
|
-
get auth(): AuthManager;
|
|
339
|
+
interface RedirectSafetyOptions {
|
|
340
|
+
/** Additional external hosts allowed as redirect targets. */
|
|
341
|
+
allowedHosts?: string[];
|
|
342
|
+
/** Fallback URL when an unsafe redirect is blocked. Default: '/' */
|
|
343
|
+
fallbackUrl?: string;
|
|
482
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Middleware that prevents open redirect attacks by validating
|
|
347
|
+
* redirect destinations in 3xx responses.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* import { createRedirectSafetyMiddleware } from '@guren/core'
|
|
352
|
+
*
|
|
353
|
+
* app.use('*', createRedirectSafetyMiddleware({
|
|
354
|
+
* allowedHosts: ['accounts.google.com'],
|
|
355
|
+
* }))
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function createRedirectSafetyMiddleware(options?: RedirectSafetyOptions): MiddlewareHandler;
|
|
359
|
+
/**
|
|
360
|
+
* Check whether a redirect URL is safe (same-origin or in the allowed list).
|
|
361
|
+
*
|
|
362
|
+
* @param url - The redirect target URL
|
|
363
|
+
* @param requestUrl - The current request URL (used to determine the origin)
|
|
364
|
+
* @param allowedHosts - Additional allowed external hosts
|
|
365
|
+
*/
|
|
366
|
+
declare function isSafeRedirectUrl(url: string, requestUrl: string, allowedHosts?: string[]): boolean;
|
|
483
367
|
|
|
484
|
-
interface
|
|
485
|
-
|
|
486
|
-
|
|
368
|
+
interface ForceHttpsOptions {
|
|
369
|
+
/**
|
|
370
|
+
* HSTS max-age in seconds. Default: 31536000 (1 year).
|
|
371
|
+
*/
|
|
372
|
+
hstsMaxAge?: number;
|
|
373
|
+
/**
|
|
374
|
+
* Include subdomains in HSTS. Default: true.
|
|
375
|
+
*/
|
|
376
|
+
hstsIncludeSubDomains?: boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Enable HSTS preload. Default: false.
|
|
379
|
+
*/
|
|
380
|
+
hstsPreload?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Paths to exclude from HTTPS redirect (e.g., health checks).
|
|
383
|
+
*/
|
|
384
|
+
exclude?: string[];
|
|
487
385
|
}
|
|
488
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Middleware that redirects HTTP requests to HTTPS and sets the
|
|
388
|
+
* Strict-Transport-Security header. Equivalent to Rails' `force_ssl`.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { createForceHttpsMiddleware } from '@guren/core'
|
|
393
|
+
*
|
|
394
|
+
* // In production only
|
|
395
|
+
* if (process.env.NODE_ENV === 'production') {
|
|
396
|
+
* app.use('*', createForceHttpsMiddleware())
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
declare function createForceHttpsMiddleware(options?: ForceHttpsOptions): MiddlewareHandler;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Middleware that generates a unique request ID for each request.
|
|
404
|
+
* Reads from the `X-Request-ID` header if present, otherwise generates one
|
|
405
|
+
* using `crypto.randomUUID()`.
|
|
406
|
+
* Attaches the ID to the Hono context (`c.get('requestId')`) and sets it
|
|
407
|
+
* on the response header.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { requestIdMiddleware } from '@guren/core'
|
|
412
|
+
*
|
|
413
|
+
* app.use('*', requestIdMiddleware())
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
declare function requestIdMiddleware(): hono.MiddlewareHandler<{
|
|
417
|
+
Variables: {
|
|
418
|
+
requestId: string;
|
|
419
|
+
};
|
|
420
|
+
}, string, {}, Response>;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Middleware that logs HTTP requests with method, path, status, and duration.
|
|
424
|
+
* Uses structured JSON format suitable for production monitoring and log collectors.
|
|
425
|
+
*
|
|
426
|
+
* Pairs well with {@link requestIdMiddleware} — if a `requestId` is set on the
|
|
427
|
+
* context, it will be included in the log entry.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* import { requestIdMiddleware, requestLoggingMiddleware } from '@guren/core'
|
|
432
|
+
*
|
|
433
|
+
* app.use('*', requestIdMiddleware())
|
|
434
|
+
* app.use('*', requestLoggingMiddleware())
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function requestLoggingMiddleware(): hono.MiddlewareHandler<any, string, {}, Response>;
|
|
489
438
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
439
|
+
/**
|
|
440
|
+
* Base HTTP exception class.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* // Using factory methods
|
|
445
|
+
* throw HttpException.notFound('User not found')
|
|
446
|
+
* throw HttpException.unauthorized('Invalid credentials')
|
|
447
|
+
*
|
|
448
|
+
* // Custom status code
|
|
449
|
+
* throw new HttpException(418, "I'm a teapot")
|
|
450
|
+
*
|
|
451
|
+
* // With validation errors
|
|
452
|
+
* throw HttpException.unprocessable('Validation failed', {
|
|
453
|
+
* email: ['Email is required', 'Email must be valid'],
|
|
454
|
+
* password: ['Password is too short'],
|
|
455
|
+
* })
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
declare class HttpException extends Error {
|
|
459
|
+
/**
|
|
460
|
+
* HTTP status code.
|
|
461
|
+
*/
|
|
462
|
+
readonly statusCode: number;
|
|
463
|
+
/**
|
|
464
|
+
* Validation or field-specific errors.
|
|
465
|
+
*/
|
|
466
|
+
readonly errors?: Record<string, string[]>;
|
|
467
|
+
/**
|
|
468
|
+
* Additional error data.
|
|
469
|
+
*/
|
|
470
|
+
readonly data?: Record<string, unknown>;
|
|
471
|
+
constructor(statusCode: number, message: string, errors?: Record<string, string[]>, data?: Record<string, unknown>);
|
|
472
|
+
/**
|
|
473
|
+
* Convert to response format.
|
|
474
|
+
*/
|
|
475
|
+
toResponse(debug?: boolean): {
|
|
476
|
+
status: number;
|
|
477
|
+
body: ErrorResponse;
|
|
478
|
+
};
|
|
479
|
+
/**
|
|
480
|
+
* Convert to JSON.
|
|
481
|
+
*/
|
|
482
|
+
toJSON(): Record<string, unknown>;
|
|
483
|
+
/**
|
|
484
|
+
* Create a 400 Bad Request exception.
|
|
485
|
+
*/
|
|
486
|
+
static badRequest(message?: string): HttpException;
|
|
487
|
+
/**
|
|
488
|
+
* Create a 401 Unauthorized exception.
|
|
489
|
+
*/
|
|
490
|
+
static unauthorized(message?: string): HttpException;
|
|
491
|
+
/**
|
|
492
|
+
* Create a 403 Forbidden exception.
|
|
493
|
+
*/
|
|
494
|
+
static forbidden(message?: string): HttpException;
|
|
495
|
+
/**
|
|
496
|
+
* Create a 404 Not Found exception.
|
|
497
|
+
*/
|
|
498
|
+
static notFound(message?: string): HttpException;
|
|
499
|
+
/**
|
|
500
|
+
* Create a 405 Method Not Allowed exception.
|
|
501
|
+
*/
|
|
502
|
+
static methodNotAllowed(message?: string): HttpException;
|
|
503
|
+
/**
|
|
504
|
+
* Create a 409 Conflict exception.
|
|
505
|
+
*/
|
|
506
|
+
static conflict(message?: string): HttpException;
|
|
507
|
+
/**
|
|
508
|
+
* Create a 410 Gone exception.
|
|
509
|
+
*/
|
|
510
|
+
static gone(message?: string): HttpException;
|
|
511
|
+
/**
|
|
512
|
+
* Create a 422 Unprocessable Entity exception.
|
|
513
|
+
*/
|
|
514
|
+
static unprocessable(message?: string, errors?: Record<string, string[]>): HttpException;
|
|
515
|
+
/**
|
|
516
|
+
* Create a 429 Too Many Requests exception.
|
|
517
|
+
*/
|
|
518
|
+
static tooManyRequests(message?: string): HttpException;
|
|
519
|
+
/**
|
|
520
|
+
* Create a 500 Internal Server Error exception.
|
|
521
|
+
*/
|
|
522
|
+
static internal(message?: string): HttpException;
|
|
523
|
+
/**
|
|
524
|
+
* Create a 501 Not Implemented exception.
|
|
525
|
+
*/
|
|
526
|
+
static notImplemented(message?: string): HttpException;
|
|
527
|
+
/**
|
|
528
|
+
* Create a 502 Bad Gateway exception.
|
|
529
|
+
*/
|
|
530
|
+
static badGateway(message?: string): HttpException;
|
|
531
|
+
/**
|
|
532
|
+
* Create a 503 Service Unavailable exception.
|
|
533
|
+
*/
|
|
534
|
+
static serviceUnavailable(message?: string): HttpException;
|
|
535
|
+
/**
|
|
536
|
+
* Create a 504 Gateway Timeout exception.
|
|
537
|
+
*/
|
|
538
|
+
static gatewayTimeout(message?: string): HttpException;
|
|
539
|
+
/**
|
|
540
|
+
* Check if an error is an HTTP exception.
|
|
541
|
+
*/
|
|
542
|
+
static isHttpException(error: unknown): error is HttpException;
|
|
495
543
|
}
|
|
496
|
-
declare function logDevServerBanner({ hostname, port, assetsUrl, }: DevBannerOptions): void;
|
|
497
544
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
545
|
+
/**
|
|
546
|
+
* Validation exception.
|
|
547
|
+
*
|
|
548
|
+
* Thrown when request validation fails.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```typescript
|
|
552
|
+
* throw new ValidationException({
|
|
553
|
+
* email: ['Email is required', 'Email must be valid'],
|
|
554
|
+
* password: ['Password is too short'],
|
|
555
|
+
* })
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
declare class ValidationException extends HttpException {
|
|
559
|
+
constructor(errors: Record<string, string[]>, message?: string);
|
|
560
|
+
/**
|
|
561
|
+
* Create from Zod error.
|
|
562
|
+
*/
|
|
563
|
+
static fromZodError(zodError: ZodLikeError): ValidationException;
|
|
564
|
+
/**
|
|
565
|
+
* Get errors for a specific field.
|
|
566
|
+
*/
|
|
567
|
+
getFieldErrors(field: string): string[];
|
|
568
|
+
/**
|
|
569
|
+
* Check if a field has errors.
|
|
570
|
+
*/
|
|
571
|
+
hasFieldError(field: string): boolean;
|
|
572
|
+
/**
|
|
573
|
+
* Get the first error for a field.
|
|
574
|
+
*/
|
|
575
|
+
getFirstError(field: string): string | null;
|
|
576
|
+
/**
|
|
577
|
+
* Get all error messages as a flat array.
|
|
578
|
+
*/
|
|
579
|
+
getAllMessages(): string[];
|
|
580
|
+
/**
|
|
581
|
+
* Create a ValidationException from a plain messages object.
|
|
582
|
+
*
|
|
583
|
+
* Useful for business-logic validation (e.g. duplicate email checks)
|
|
584
|
+
* where Zod is not involved.
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```typescript
|
|
588
|
+
* throw ValidationException.withMessages({ email: 'Email already registered' })
|
|
589
|
+
* throw ValidationException.withMessages({ email: ['Must be unique', 'Must be corporate'] })
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
static withMessages(messages: Record<string, string | string[]>): ValidationException;
|
|
503
593
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
594
|
+
/**
|
|
595
|
+
* Zod-like error interface for compatibility.
|
|
596
|
+
*/
|
|
597
|
+
interface ZodLikeError {
|
|
598
|
+
issues: Array<{
|
|
599
|
+
path: PropertyKey[];
|
|
600
|
+
message: string;
|
|
601
|
+
}>;
|
|
508
602
|
}
|
|
509
|
-
declare function startViteDevServer(options?: StartViteDevServerOptions): Promise<StartedViteDevServer>;
|
|
510
603
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
604
|
+
/**
|
|
605
|
+
* Authentication exception.
|
|
606
|
+
*
|
|
607
|
+
* Thrown when a user is not authenticated or credentials are invalid.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* throw new AuthenticationException()
|
|
612
|
+
* throw new AuthenticationException('Invalid token')
|
|
613
|
+
* throw new AuthenticationException('Session expired', 'login')
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
declare class AuthenticationException extends HttpException {
|
|
617
|
+
/**
|
|
618
|
+
* The guard that threw the exception.
|
|
619
|
+
*/
|
|
620
|
+
readonly guard?: string;
|
|
621
|
+
/**
|
|
622
|
+
* URL to redirect to for authentication.
|
|
623
|
+
*/
|
|
624
|
+
readonly redirectTo?: string;
|
|
625
|
+
constructor(message?: string, guard?: string, redirectTo?: string);
|
|
626
|
+
/**
|
|
627
|
+
* Create exception with redirect URL.
|
|
628
|
+
*/
|
|
629
|
+
static withRedirect(redirectTo: string, message?: string): AuthenticationException;
|
|
630
|
+
/**
|
|
631
|
+
* Create exception for a specific guard.
|
|
632
|
+
*/
|
|
633
|
+
static forGuard(guard: string, message?: string): AuthenticationException;
|
|
515
634
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Authorization exception.
|
|
638
|
+
*
|
|
639
|
+
* Thrown when a user is authenticated but not authorized to perform an action.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ```typescript
|
|
643
|
+
* throw new AuthorizationException()
|
|
644
|
+
* throw new AuthorizationException('You cannot edit this post')
|
|
645
|
+
* throw new AuthorizationException('Access denied', 'edit', 'Post')
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
declare class AuthorizationException extends HttpException {
|
|
649
|
+
/**
|
|
650
|
+
* The action that was attempted.
|
|
651
|
+
*/
|
|
652
|
+
readonly action?: string;
|
|
653
|
+
/**
|
|
654
|
+
* The resource that was being accessed.
|
|
655
|
+
*/
|
|
656
|
+
readonly resource?: string;
|
|
657
|
+
constructor(message?: string, action?: string, resource?: string);
|
|
658
|
+
/**
|
|
659
|
+
* Create exception for a specific action and resource.
|
|
660
|
+
*/
|
|
661
|
+
static forAction(action: string, resource?: string): AuthorizationException;
|
|
662
|
+
/**
|
|
663
|
+
* Deny access to a resource.
|
|
664
|
+
*/
|
|
665
|
+
static deny(resource?: string): AuthorizationException;
|
|
521
666
|
}
|
|
667
|
+
|
|
522
668
|
/**
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
669
|
+
* Not Found HTTP exception.
|
|
670
|
+
*
|
|
671
|
+
* Thrown when a requested resource cannot be found.
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* throw new NotFoundHttpException()
|
|
676
|
+
* throw new NotFoundHttpException('User not found')
|
|
677
|
+
* throw NotFoundHttpException.forModel('User', 123)
|
|
678
|
+
* ```
|
|
526
679
|
*/
|
|
527
|
-
declare class
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
constructor(
|
|
537
|
-
|
|
680
|
+
declare class NotFoundHttpException extends HttpException {
|
|
681
|
+
/**
|
|
682
|
+
* The type of resource that was not found.
|
|
683
|
+
*/
|
|
684
|
+
readonly resourceType?: string;
|
|
685
|
+
/**
|
|
686
|
+
* The ID of the resource that was not found.
|
|
687
|
+
*/
|
|
688
|
+
readonly resourceId?: string | number;
|
|
689
|
+
constructor(message?: string, resourceType?: string, resourceId?: string | number);
|
|
690
|
+
/**
|
|
691
|
+
* Create exception for a model not found.
|
|
692
|
+
*/
|
|
693
|
+
static forModel(model: string, id: string | number): NotFoundHttpException;
|
|
538
694
|
/**
|
|
539
|
-
*
|
|
695
|
+
* Create exception for a route not found.
|
|
540
696
|
*/
|
|
541
|
-
|
|
697
|
+
static forRoute(path: string): NotFoundHttpException;
|
|
542
698
|
/**
|
|
543
|
-
*
|
|
699
|
+
* Create exception for a resource not found.
|
|
544
700
|
*/
|
|
545
|
-
|
|
701
|
+
static forResource(resource: string): NotFoundHttpException;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Method Not Allowed exception.
|
|
706
|
+
*
|
|
707
|
+
* Thrown when an HTTP method is not allowed for a route.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* throw new MethodNotAllowedException()
|
|
712
|
+
* throw new MethodNotAllowedException('POST', ['GET', 'HEAD'])
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
declare class MethodNotAllowedException extends HttpException {
|
|
546
716
|
/**
|
|
547
|
-
*
|
|
717
|
+
* The HTTP method that was attempted.
|
|
548
718
|
*/
|
|
549
|
-
|
|
719
|
+
readonly method?: string;
|
|
550
720
|
/**
|
|
551
|
-
*
|
|
721
|
+
* The allowed HTTP methods.
|
|
552
722
|
*/
|
|
553
|
-
|
|
723
|
+
readonly allowedMethods?: string[];
|
|
724
|
+
constructor(method?: string, allowedMethods?: string[], message?: string);
|
|
554
725
|
/**
|
|
555
|
-
*
|
|
726
|
+
* Get the Allow header value.
|
|
556
727
|
*/
|
|
557
|
-
|
|
558
|
-
register(provider: Provider | ProviderConstructor): this;
|
|
559
|
-
registerMany(providers: Array<Provider | ProviderConstructor>): this;
|
|
728
|
+
getAllowHeader(): string;
|
|
560
729
|
/**
|
|
561
|
-
*
|
|
730
|
+
* Create exception with method details.
|
|
562
731
|
*/
|
|
563
|
-
|
|
564
|
-
private resolveContext;
|
|
565
|
-
private registerDefaultProviders;
|
|
566
|
-
private closeViteDevServer;
|
|
567
|
-
private registerViteTeardown;
|
|
732
|
+
static forMethod(method: string, allowedMethods: string[]): MethodNotAllowedException;
|
|
568
733
|
}
|
|
569
734
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
*
|
|
658
|
-
*/
|
|
659
|
-
declare
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
735
|
+
/**
|
|
736
|
+
* Generate a production-friendly HTML error page.
|
|
737
|
+
* Shows status code, a generic message, and a link back to the home page.
|
|
738
|
+
* No stack traces or internal details are exposed.
|
|
739
|
+
*/
|
|
740
|
+
declare function renderErrorPage(statusCode: number, message?: string): string;
|
|
741
|
+
|
|
742
|
+
type ViewRenderer = (template: string, props: Record<string, unknown>) => Response | Promise<Response>;
|
|
743
|
+
/**
|
|
744
|
+
* Registry for view renderers. Engines are typically registered via service
|
|
745
|
+
* providers so applications can opt into or replace implementations.
|
|
746
|
+
*/
|
|
747
|
+
declare class ViewEngine {
|
|
748
|
+
private static readonly engines;
|
|
749
|
+
static register(name: string, renderer: ViewRenderer): void;
|
|
750
|
+
static has(name: string): boolean;
|
|
751
|
+
static render(name: string, template: string, props: Record<string, unknown>): Response | Promise<Response>;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Registers the Inertia view engine and wires up validation error handling
|
|
756
|
+
* for Inertia requests (Laravel-style automatic redirect with flashed errors).
|
|
757
|
+
*/
|
|
758
|
+
declare class InertiaServiceProvider extends ServiceProvider {
|
|
759
|
+
register(): void;
|
|
760
|
+
boot(): void;
|
|
761
|
+
/**
|
|
762
|
+
* Register a custom renderer for ValidationException on Inertia requests.
|
|
763
|
+
* Non-Inertia requests fall through to the default JSON 422 response.
|
|
764
|
+
*/
|
|
765
|
+
private registerValidationRenderer;
|
|
766
|
+
/**
|
|
767
|
+
* Wrap existing shared props resolver to auto-inject flashed `errors`.
|
|
768
|
+
*/
|
|
769
|
+
private registerSharedErrors;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Sets up authentication guards, session middleware, and auth context.
|
|
774
|
+
*/
|
|
775
|
+
declare class AuthServiceProvider extends ServiceProvider {
|
|
776
|
+
register(): void;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Binds OAuthManager as a singleton in the container.
|
|
781
|
+
*/
|
|
782
|
+
declare class OAuthServiceProvider extends ServiceProvider {
|
|
783
|
+
register(): void;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Binds the EventManager as a singleton in the container.
|
|
788
|
+
*/
|
|
789
|
+
declare class EventServiceProvider extends ServiceProvider {
|
|
790
|
+
register(): void;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Binds the CacheManager as a singleton in the container.
|
|
795
|
+
*/
|
|
796
|
+
declare class CacheServiceProvider extends ServiceProvider {
|
|
797
|
+
register(): void;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Binds the QueueManager as a singleton in the container.
|
|
802
|
+
*/
|
|
803
|
+
declare class QueueServiceProvider extends ServiceProvider {
|
|
804
|
+
register(): void;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Binds the MailManager as a singleton in the container.
|
|
809
|
+
*/
|
|
810
|
+
declare class MailServiceProvider extends ServiceProvider {
|
|
811
|
+
register(): void;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Binds the LogManager as a singleton in the container.
|
|
816
|
+
*/
|
|
817
|
+
declare class LogServiceProvider extends ServiceProvider {
|
|
818
|
+
register(): void;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Binds the I18nManager as a singleton in the container.
|
|
823
|
+
*/
|
|
824
|
+
declare class I18nServiceProvider extends ServiceProvider {
|
|
825
|
+
register(): void;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Binds the NotificationManager as a singleton in the container.
|
|
830
|
+
*/
|
|
831
|
+
declare class NotificationServiceProvider extends ServiceProvider {
|
|
832
|
+
register(): void;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Binds the BroadcastManager as a singleton in the container.
|
|
837
|
+
*/
|
|
838
|
+
declare class BroadcastServiceProvider extends ServiceProvider {
|
|
839
|
+
register(): void;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Binds the Encrypter as a singleton in the container.
|
|
844
|
+
*/
|
|
845
|
+
declare class EncryptionServiceProvider extends ServiceProvider {
|
|
846
|
+
register(): void;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Binds the StorageManager as a singleton in the container.
|
|
851
|
+
*/
|
|
852
|
+
declare class StorageServiceProvider extends ServiceProvider {
|
|
853
|
+
register(): void;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Binds the HealthManager as a singleton in the container.
|
|
858
|
+
*/
|
|
859
|
+
declare class HealthServiceProvider extends ServiceProvider {
|
|
860
|
+
register(): void;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Binds the Scheduler as a singleton in the container.
|
|
865
|
+
*/
|
|
866
|
+
declare class SchedulingServiceProvider extends ServiceProvider {
|
|
867
|
+
register(): void;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Binds the Gate as a singleton in the container.
|
|
872
|
+
*/
|
|
873
|
+
declare class AuthorizationServiceProvider extends ServiceProvider {
|
|
874
|
+
register(): void;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Binds the ExceptionHandler as a singleton in the container
|
|
879
|
+
* and attaches it as global error-handling middleware.
|
|
880
|
+
*/
|
|
881
|
+
declare class ErrorServiceProvider extends ServiceProvider {
|
|
882
|
+
register(): void;
|
|
883
|
+
boot(): void;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Validation rule function type.
|
|
888
|
+
*/
|
|
889
|
+
type ValidationRule<T = unknown> = (value: T, field: string, data: Record<string, unknown>) => true | string | Promise<true | string>;
|
|
890
|
+
/**
|
|
891
|
+
* Validation rule definition.
|
|
892
|
+
*/
|
|
893
|
+
interface RuleDefinition {
|
|
894
|
+
name: string;
|
|
895
|
+
validate: ValidationRule;
|
|
896
|
+
message?: string;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Validation result.
|
|
900
|
+
*/
|
|
901
|
+
interface ValidationResult {
|
|
902
|
+
success: boolean;
|
|
903
|
+
data?: Record<string, unknown>;
|
|
904
|
+
errors?: Record<string, string[]>;
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* File validation options.
|
|
908
|
+
*/
|
|
909
|
+
interface FileValidationOptions {
|
|
910
|
+
/**
|
|
911
|
+
* Maximum file size in bytes.
|
|
912
|
+
*/
|
|
913
|
+
maxSize?: number;
|
|
914
|
+
/**
|
|
915
|
+
* Allowed MIME types.
|
|
916
|
+
*/
|
|
917
|
+
mimes?: string[];
|
|
918
|
+
/**
|
|
919
|
+
* Allowed file extensions.
|
|
920
|
+
*/
|
|
921
|
+
extensions?: string[];
|
|
922
|
+
/**
|
|
923
|
+
* Minimum file size in bytes.
|
|
924
|
+
*/
|
|
925
|
+
minSize?: number;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Image validation options.
|
|
929
|
+
*/
|
|
930
|
+
interface ImageValidationOptions extends FileValidationOptions {
|
|
931
|
+
/**
|
|
932
|
+
* Maximum width in pixels.
|
|
933
|
+
*/
|
|
934
|
+
maxWidth?: number;
|
|
935
|
+
/**
|
|
936
|
+
* Maximum height in pixels.
|
|
937
|
+
*/
|
|
938
|
+
maxHeight?: number;
|
|
939
|
+
/**
|
|
940
|
+
* Minimum width in pixels.
|
|
941
|
+
*/
|
|
942
|
+
minWidth?: number;
|
|
943
|
+
/**
|
|
944
|
+
* Minimum height in pixels.
|
|
945
|
+
*/
|
|
946
|
+
minHeight?: number;
|
|
947
|
+
/**
|
|
948
|
+
* Required aspect ratio (width/height).
|
|
949
|
+
*/
|
|
950
|
+
ratio?: number;
|
|
951
|
+
/**
|
|
952
|
+
* Allowed aspect ratio tolerance.
|
|
953
|
+
*/
|
|
954
|
+
ratioTolerance?: number;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Validator options.
|
|
958
|
+
*/
|
|
959
|
+
interface ValidatorOptions {
|
|
960
|
+
/**
|
|
961
|
+
* Stop on first error for each field.
|
|
962
|
+
* @default true
|
|
963
|
+
*/
|
|
964
|
+
stopOnFirstError?: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* Custom error messages.
|
|
967
|
+
*/
|
|
968
|
+
messages?: Record<string, string>;
|
|
969
|
+
/**
|
|
970
|
+
* Custom attribute names for error messages.
|
|
971
|
+
*/
|
|
972
|
+
attributes?: Record<string, string>;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* File-like interface for validation.
|
|
976
|
+
*/
|
|
977
|
+
interface FileLike {
|
|
978
|
+
name: string;
|
|
979
|
+
size: number;
|
|
980
|
+
type: string;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Base class for form request validation.
|
|
985
|
+
*
|
|
986
|
+
* FormRequest encapsulates both validation rules and authorization logic
|
|
987
|
+
* for a single request type. Extend this class and define `rules()` and
|
|
988
|
+
* optionally `authorize()` to create type-safe request validation.
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* ```typescript
|
|
992
|
+
* interface StorePostData {
|
|
993
|
+
* title: string
|
|
994
|
+
* content: string
|
|
995
|
+
* status: 'draft' | 'published'
|
|
996
|
+
* }
|
|
997
|
+
*
|
|
998
|
+
* class StorePostRequest extends FormRequest<StorePostData> {
|
|
999
|
+
* rules() {
|
|
1000
|
+
* return {
|
|
1001
|
+
* title: [required(), stringRule(), min(3), max(255)],
|
|
1002
|
+
* content: [required(), stringRule()],
|
|
1003
|
+
* status: [required(), inValues(['draft', 'published'])],
|
|
1004
|
+
* }
|
|
1005
|
+
* }
|
|
1006
|
+
*
|
|
1007
|
+
* authorize() {
|
|
1008
|
+
* return this.user() !== null
|
|
1009
|
+
* }
|
|
1010
|
+
* }
|
|
1011
|
+
*
|
|
1012
|
+
* // In controller:
|
|
1013
|
+
* const data = await this.validate(StorePostRequest)
|
|
1014
|
+
* // data is typed as StorePostData
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
declare abstract class FormRequest<T = Record<string, unknown>> {
|
|
1018
|
+
protected ctx: Context;
|
|
1019
|
+
/**
|
|
1020
|
+
* Define validation rules for this request.
|
|
1021
|
+
* Return an object mapping field names to arrays of validation rules.
|
|
1022
|
+
*/
|
|
1023
|
+
abstract rules(): Record<string, ValidationRule[]>;
|
|
1024
|
+
/**
|
|
1025
|
+
* Determine if the user is authorized to make this request.
|
|
1026
|
+
* Override to implement authorization logic. Defaults to true.
|
|
1027
|
+
*/
|
|
1028
|
+
authorize(): boolean | Promise<boolean>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Custom error messages for validation rules.
|
|
1031
|
+
* Override to provide custom messages.
|
|
1032
|
+
*/
|
|
1033
|
+
messages(): Record<string, string>;
|
|
1034
|
+
/**
|
|
1035
|
+
* Custom attribute names for validation errors.
|
|
1036
|
+
* Override to provide human-readable field names.
|
|
1037
|
+
*/
|
|
1038
|
+
attributes(): Record<string, string>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Get the authenticated user from the request context.
|
|
1041
|
+
*/
|
|
1042
|
+
protected user(): unknown;
|
|
1043
|
+
/**
|
|
1044
|
+
* Handle the form request: authorize, parse body, validate, return typed data.
|
|
1045
|
+
* @internal Called by Controller.validate()
|
|
1046
|
+
*/
|
|
1047
|
+
handle(ctx: Context): Promise<T>;
|
|
1048
|
+
private parseBody;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Field validator builder.
|
|
1053
|
+
*/
|
|
1054
|
+
declare class FieldValidator {
|
|
1055
|
+
private field;
|
|
1056
|
+
private _rules;
|
|
1057
|
+
private isNullable;
|
|
1058
|
+
private isSometimes;
|
|
1059
|
+
private bailOnFirstError;
|
|
1060
|
+
private conditions;
|
|
1061
|
+
constructor(field: string);
|
|
1062
|
+
/**
|
|
1063
|
+
* Add a validation rule.
|
|
1064
|
+
*/
|
|
1065
|
+
rule(rule: ValidationRule): this;
|
|
1066
|
+
/**
|
|
1067
|
+
* Add multiple validation rules.
|
|
1068
|
+
*/
|
|
1069
|
+
rules(...rules: ValidationRule[]): this;
|
|
1070
|
+
/**
|
|
1071
|
+
* Mark field as nullable (allows null values).
|
|
1072
|
+
*/
|
|
1073
|
+
nullable(): this;
|
|
1074
|
+
/**
|
|
1075
|
+
* Only validate if field is present.
|
|
1076
|
+
*/
|
|
1077
|
+
sometimes(): this;
|
|
1078
|
+
/**
|
|
1079
|
+
* Stop validation on first error.
|
|
1080
|
+
*/
|
|
1081
|
+
bail(): this;
|
|
1082
|
+
/**
|
|
1083
|
+
* Continue validation even after errors.
|
|
1084
|
+
*/
|
|
1085
|
+
continueOnError(): this;
|
|
1086
|
+
/**
|
|
1087
|
+
* Add a condition - only validate if condition is true.
|
|
1088
|
+
*/
|
|
1089
|
+
when(condition: (data: Record<string, unknown>) => boolean): this;
|
|
1090
|
+
/**
|
|
1091
|
+
* Add a condition - only validate if condition is false.
|
|
1092
|
+
*/
|
|
1093
|
+
unless(condition: (data: Record<string, unknown>) => boolean): this;
|
|
1094
|
+
/**
|
|
1095
|
+
* Validate the field.
|
|
1096
|
+
*/
|
|
1097
|
+
validate(value: unknown, data: Record<string, unknown>, options?: ValidatorOptions): Promise<string[]>;
|
|
1098
|
+
/**
|
|
1099
|
+
* Format error message.
|
|
1100
|
+
*/
|
|
1101
|
+
private formatMessage;
|
|
1102
|
+
/**
|
|
1103
|
+
* Get the field name.
|
|
1104
|
+
*/
|
|
1105
|
+
getField(): string;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Validator class for validating data against rules.
|
|
1109
|
+
*
|
|
1110
|
+
* @example
|
|
1111
|
+
* ```typescript
|
|
1112
|
+
* import { Validator, required, email, min } from '@guren/server'
|
|
1113
|
+
*
|
|
1114
|
+
* const validator = new Validator()
|
|
1115
|
+
* .field('name', required(), min(2))
|
|
1116
|
+
* .field('email', required(), email())
|
|
1117
|
+
* .field('password', required(), min(8))
|
|
1118
|
+
* .field('password_confirmation', required())
|
|
1119
|
+
*
|
|
1120
|
+
* const result = await validator.validate(data)
|
|
1121
|
+
* if (!result.success) {
|
|
1122
|
+
* console.log(result.errors)
|
|
1123
|
+
* }
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
declare class Validator {
|
|
1127
|
+
private fields;
|
|
1128
|
+
private options;
|
|
1129
|
+
/**
|
|
1130
|
+
* Create a new validator.
|
|
1131
|
+
*/
|
|
1132
|
+
constructor(options?: ValidatorOptions);
|
|
1133
|
+
/**
|
|
1134
|
+
* Add a field with rules.
|
|
1135
|
+
*/
|
|
1136
|
+
field(name: string, ...rules: ValidationRule[]): this;
|
|
1137
|
+
/**
|
|
1138
|
+
* Add a field validator.
|
|
1139
|
+
*/
|
|
1140
|
+
addField(validator: FieldValidator): this;
|
|
1141
|
+
/**
|
|
1142
|
+
* Get a field validator for fluent configuration.
|
|
1143
|
+
*/
|
|
1144
|
+
for(name: string): FieldValidator;
|
|
1145
|
+
/**
|
|
1146
|
+
* Set custom error messages.
|
|
1147
|
+
*/
|
|
1148
|
+
messages(messages: Record<string, string>): this;
|
|
1149
|
+
/**
|
|
1150
|
+
* Set custom attribute names.
|
|
1151
|
+
*/
|
|
1152
|
+
attributes(attributes: Record<string, string>): this;
|
|
1153
|
+
/**
|
|
1154
|
+
* Validate data.
|
|
1155
|
+
*/
|
|
1156
|
+
validate(data: Record<string, unknown>): Promise<ValidationResult>;
|
|
1157
|
+
/**
|
|
1158
|
+
* Validate and throw if invalid.
|
|
1159
|
+
*/
|
|
1160
|
+
validateOrThrow(data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
1161
|
+
/**
|
|
1162
|
+
* Create a new validator from rules object.
|
|
1163
|
+
*/
|
|
1164
|
+
static make(rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Validator;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Create a new validator.
|
|
1168
|
+
*/
|
|
1169
|
+
declare function createValidator(options?: ValidatorOptions): Validator;
|
|
1170
|
+
/**
|
|
1171
|
+
* Quick validate function.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function quickValidate(data: Record<string, unknown>, rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Promise<ValidationResult>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Quick validate and throw function.
|
|
1176
|
+
*/
|
|
1177
|
+
declare function quickValidateOrThrow(data: Record<string, unknown>, rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Promise<Record<string, unknown>>;
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Built-in validation rules.
|
|
1181
|
+
*/
|
|
1182
|
+
/**
|
|
1183
|
+
* Required rule - value must be present and not empty.
|
|
1184
|
+
*/
|
|
1185
|
+
declare function required(): ValidationRule;
|
|
1186
|
+
/**
|
|
1187
|
+
* Nullable rule - allows null values (removes other validation if null).
|
|
1188
|
+
*/
|
|
1189
|
+
declare function nullable(): ValidationRule;
|
|
1190
|
+
/**
|
|
1191
|
+
* Required if another field equals a value.
|
|
1192
|
+
*/
|
|
1193
|
+
declare function requiredIf(field: string, value: unknown): ValidationRule;
|
|
1194
|
+
/**
|
|
1195
|
+
* Required unless another field equals a value.
|
|
1196
|
+
*/
|
|
1197
|
+
declare function requiredUnless(field: string, value: unknown): ValidationRule;
|
|
1198
|
+
/**
|
|
1199
|
+
* Required with - field is required if any of the other fields are present.
|
|
1200
|
+
*/
|
|
1201
|
+
declare function requiredWith(...fields: string[]): ValidationRule;
|
|
1202
|
+
/**
|
|
1203
|
+
* Required without - field is required if any of the other fields are not present.
|
|
1204
|
+
*/
|
|
1205
|
+
declare function requiredWithout(...fields: string[]): ValidationRule;
|
|
1206
|
+
/**
|
|
1207
|
+
* String rule - value must be a string.
|
|
1208
|
+
*/
|
|
1209
|
+
declare function string(): ValidationRule;
|
|
1210
|
+
/**
|
|
1211
|
+
* Numeric rule - value must be a number.
|
|
1212
|
+
*/
|
|
1213
|
+
declare function numeric(): ValidationRule;
|
|
1214
|
+
/**
|
|
1215
|
+
* Integer rule - value must be an integer.
|
|
1216
|
+
*/
|
|
1217
|
+
declare function integer(): ValidationRule;
|
|
1218
|
+
/**
|
|
1219
|
+
* Boolean rule - value must be a boolean.
|
|
1220
|
+
*/
|
|
1221
|
+
declare function boolean(): ValidationRule;
|
|
1222
|
+
/**
|
|
1223
|
+
* Array rule - value must be an array.
|
|
1224
|
+
*/
|
|
1225
|
+
declare function array(): ValidationRule;
|
|
1226
|
+
/**
|
|
1227
|
+
* Object rule - value must be an object.
|
|
1228
|
+
*/
|
|
1229
|
+
declare function object(): ValidationRule;
|
|
1230
|
+
/**
|
|
1231
|
+
* Email rule - value must be a valid email.
|
|
1232
|
+
*/
|
|
1233
|
+
declare function email(): ValidationRule;
|
|
1234
|
+
/**
|
|
1235
|
+
* URL rule - value must be a valid URL.
|
|
1236
|
+
*/
|
|
1237
|
+
declare function url(): ValidationRule;
|
|
1238
|
+
/**
|
|
1239
|
+
* UUID rule - value must be a valid UUID.
|
|
1240
|
+
*/
|
|
1241
|
+
declare function uuid(): ValidationRule;
|
|
1242
|
+
/**
|
|
1243
|
+
* Minimum rule - value must be at least min.
|
|
1244
|
+
*/
|
|
1245
|
+
declare function min(minValue: number): ValidationRule;
|
|
1246
|
+
/**
|
|
1247
|
+
* Maximum rule - value must be at most max.
|
|
1248
|
+
*/
|
|
1249
|
+
declare function max(maxValue: number): ValidationRule;
|
|
1250
|
+
/**
|
|
1251
|
+
* Between rule - value must be between min and max.
|
|
1252
|
+
*/
|
|
1253
|
+
declare function between(minValue: number, maxValue: number): ValidationRule;
|
|
1254
|
+
/**
|
|
1255
|
+
* Size rule - value must be exactly size.
|
|
1256
|
+
*/
|
|
1257
|
+
declare function size(exactSize: number): ValidationRule;
|
|
1258
|
+
/**
|
|
1259
|
+
* In rule - value must be in the given array.
|
|
1260
|
+
*/
|
|
1261
|
+
declare function inValues(values: unknown[]): ValidationRule;
|
|
1262
|
+
/**
|
|
1263
|
+
* Not in rule - value must not be in the given array.
|
|
1264
|
+
*/
|
|
1265
|
+
declare function notIn(values: unknown[]): ValidationRule;
|
|
1266
|
+
/**
|
|
1267
|
+
* Regex rule - value must match the regex.
|
|
1268
|
+
*/
|
|
1269
|
+
declare function regex(pattern: RegExp): ValidationRule;
|
|
1270
|
+
/**
|
|
1271
|
+
* Confirmed rule - field must have a matching field_confirmation.
|
|
1272
|
+
*/
|
|
1273
|
+
declare function confirmed(): ValidationRule;
|
|
1274
|
+
/**
|
|
1275
|
+
* Same rule - field must match another field.
|
|
1276
|
+
*/
|
|
1277
|
+
declare function same(otherField: string): ValidationRule;
|
|
1278
|
+
/**
|
|
1279
|
+
* Different rule - field must be different from another field.
|
|
1280
|
+
*/
|
|
1281
|
+
declare function different(otherField: string): ValidationRule;
|
|
1282
|
+
/**
|
|
1283
|
+
* After rule - date must be after another date.
|
|
1284
|
+
*/
|
|
1285
|
+
declare function after(date: string | Date): ValidationRule;
|
|
1286
|
+
/**
|
|
1287
|
+
* After or equal rule - date must be after or equal to another date.
|
|
1288
|
+
*/
|
|
1289
|
+
declare function afterOrEqual(date: string | Date): ValidationRule;
|
|
1290
|
+
/**
|
|
1291
|
+
* Before rule - date must be before another date.
|
|
1292
|
+
*/
|
|
1293
|
+
declare function before(date: string | Date): ValidationRule;
|
|
1294
|
+
/**
|
|
1295
|
+
* Before or equal rule - date must be before or equal to another date.
|
|
1296
|
+
*/
|
|
1297
|
+
declare function beforeOrEqual(date: string | Date): ValidationRule;
|
|
1298
|
+
/**
|
|
1299
|
+
* Date rule - value must be a valid date.
|
|
1300
|
+
*/
|
|
1301
|
+
declare function date(): ValidationRule;
|
|
1302
|
+
/**
|
|
1303
|
+
* Date format rule - value must match the given format.
|
|
1304
|
+
*/
|
|
1305
|
+
declare function dateFormat(format: string): ValidationRule;
|
|
1306
|
+
/**
|
|
1307
|
+
* Alpha rule - value must only contain letters.
|
|
1308
|
+
*/
|
|
1309
|
+
declare function alpha(): ValidationRule;
|
|
1310
|
+
/**
|
|
1311
|
+
* Alpha numeric rule - value must only contain letters and numbers.
|
|
1312
|
+
*/
|
|
1313
|
+
declare function alphaNum(): ValidationRule;
|
|
1314
|
+
/**
|
|
1315
|
+
* Alpha dash rule - value must only contain letters, numbers, dashes, and underscores.
|
|
1316
|
+
*/
|
|
1317
|
+
declare function alphaDash(): ValidationRule;
|
|
1318
|
+
/**
|
|
1319
|
+
* Starts with rule - value must start with one of the given prefixes.
|
|
1320
|
+
*/
|
|
1321
|
+
declare function startsWith(...prefixes: string[]): ValidationRule;
|
|
1322
|
+
/**
|
|
1323
|
+
* Ends with rule - value must end with one of the given suffixes.
|
|
1324
|
+
*/
|
|
1325
|
+
declare function endsWith(...suffixes: string[]): ValidationRule;
|
|
1326
|
+
/**
|
|
1327
|
+
* JSON rule - value must be a valid JSON string.
|
|
1328
|
+
*/
|
|
1329
|
+
declare function json(): ValidationRule;
|
|
1330
|
+
/**
|
|
1331
|
+
* IP rule - value must be a valid IP address.
|
|
1332
|
+
*/
|
|
1333
|
+
declare function ip(): ValidationRule;
|
|
1334
|
+
/**
|
|
1335
|
+
* IPv4 rule - value must be a valid IPv4 address.
|
|
1336
|
+
*/
|
|
1337
|
+
declare function ipv4(): ValidationRule;
|
|
1338
|
+
/**
|
|
1339
|
+
* IPv6 rule - value must be a valid IPv6 address.
|
|
1340
|
+
*/
|
|
1341
|
+
declare function ipv6(): ValidationRule;
|
|
1342
|
+
/**
|
|
1343
|
+
* File rule - validates a file object.
|
|
1344
|
+
*/
|
|
1345
|
+
declare function file(options?: FileValidationOptions): ValidationRule;
|
|
1346
|
+
/**
|
|
1347
|
+
* Image rule - validates an image file.
|
|
1348
|
+
*/
|
|
1349
|
+
declare function image(options?: ImageValidationOptions): ValidationRule;
|
|
1350
|
+
/**
|
|
1351
|
+
* Mimes rule - validates file MIME types.
|
|
1352
|
+
*/
|
|
1353
|
+
declare function mimes(...mimeTypes: string[]): ValidationRule;
|
|
1354
|
+
/**
|
|
1355
|
+
* Max file size rule.
|
|
1356
|
+
*/
|
|
1357
|
+
declare function maxFileSize(bytes: number): ValidationRule;
|
|
1358
|
+
/**
|
|
1359
|
+
* Min file size rule.
|
|
1360
|
+
*/
|
|
1361
|
+
declare function minFileSize(bytes: number): ValidationRule;
|
|
1362
|
+
/**
|
|
1363
|
+
* Custom rule - create a custom validation rule.
|
|
1364
|
+
*/
|
|
1365
|
+
declare function custom(validate: (value: unknown, field: string, data: Record<string, unknown>) => boolean | string | Promise<boolean | string>, message?: string): ValidationRule;
|
|
1366
|
+
/**
|
|
1367
|
+
* Unique rule (async) - checks uniqueness via callback.
|
|
1368
|
+
*/
|
|
1369
|
+
declare function unique(callback: (value: unknown, field: string) => Promise<boolean>): ValidationRule;
|
|
1370
|
+
/**
|
|
1371
|
+
* Exists rule (async) - checks existence via callback.
|
|
1372
|
+
*/
|
|
1373
|
+
declare function exists(callback: (value: unknown, field: string) => Promise<boolean>): ValidationRule;
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Seeder class interface.
|
|
1377
|
+
*/
|
|
1378
|
+
interface SeederClass {
|
|
1379
|
+
new (): Seeder;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Abstract seeder interface.
|
|
1383
|
+
*/
|
|
1384
|
+
interface Seeder {
|
|
1385
|
+
run(): Promise<void>;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Factory class interface.
|
|
1389
|
+
*/
|
|
1390
|
+
interface FactoryClass<T> {
|
|
1391
|
+
new (): Factory<T>;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Abstract factory interface.
|
|
1395
|
+
*/
|
|
1396
|
+
interface Factory<T> {
|
|
1397
|
+
definition(): Partial<T>;
|
|
1398
|
+
make(overrides?: Partial<T>): T;
|
|
1399
|
+
makeMany(count: number, overrides?: Partial<T>): T[];
|
|
1400
|
+
create(overrides?: Partial<T>): Promise<T>;
|
|
1401
|
+
createMany(count: number, overrides?: Partial<T>): Promise<T[]>;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Seeder runner options.
|
|
1405
|
+
*/
|
|
1406
|
+
interface SeederRunnerOptions {
|
|
1407
|
+
/**
|
|
1408
|
+
* Path to seeders directory.
|
|
1409
|
+
*/
|
|
1410
|
+
seedersPath?: string;
|
|
1411
|
+
/**
|
|
1412
|
+
* Default seeder class name.
|
|
1413
|
+
*/
|
|
1414
|
+
defaultSeeder?: string;
|
|
1415
|
+
/**
|
|
1416
|
+
* Force run in production.
|
|
1417
|
+
*/
|
|
1418
|
+
force?: boolean;
|
|
1419
|
+
/**
|
|
1420
|
+
* Silent mode (no console output).
|
|
1421
|
+
*/
|
|
1422
|
+
silent?: boolean;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* Reset called seeders tracking (for testing).
|
|
1427
|
+
*/
|
|
1428
|
+
declare function resetCalledSeeders(): void;
|
|
1429
|
+
/**
|
|
1430
|
+
* Abstract base class for database seeders.
|
|
1431
|
+
*/
|
|
1432
|
+
declare abstract class BaseSeeder {
|
|
1433
|
+
/**
|
|
1434
|
+
* Run the seeder.
|
|
1435
|
+
*/
|
|
1436
|
+
abstract run(): Promise<void>;
|
|
1437
|
+
/**
|
|
1438
|
+
* Call another seeder.
|
|
1439
|
+
*/
|
|
1440
|
+
protected call(SeederClass: SeederClass): Promise<void>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Call another seeder only once.
|
|
1443
|
+
* Useful for avoiding duplicate data when seeders have dependencies.
|
|
1444
|
+
*/
|
|
1445
|
+
protected callOnce(SeederClass: SeederClass): Promise<void>;
|
|
1446
|
+
/**
|
|
1447
|
+
* Call multiple seeders in sequence.
|
|
1448
|
+
*/
|
|
1449
|
+
protected callMany(seeders: SeederClass[]): Promise<void>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Call multiple seeders in parallel.
|
|
1452
|
+
*/
|
|
1453
|
+
protected callParallel(seeders: SeederClass[]): Promise<void>;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* State definition for factories.
|
|
1458
|
+
*/
|
|
1459
|
+
type StateDefinition<T> = Partial<T> | ((attributes: Partial<T>) => Partial<T>);
|
|
1460
|
+
/**
|
|
1461
|
+
* Abstract base class for model factories.
|
|
1462
|
+
*/
|
|
1463
|
+
declare abstract class BaseFactory<T> {
|
|
1464
|
+
private _sequence;
|
|
1465
|
+
private _states;
|
|
1466
|
+
private _activeStates;
|
|
1467
|
+
private _afterCreatingCallbacks;
|
|
1468
|
+
private _afterMakingCallbacks;
|
|
1469
|
+
/**
|
|
1470
|
+
* Get the current sequence number.
|
|
1471
|
+
*/
|
|
1472
|
+
protected get sequence(): number;
|
|
1473
|
+
/**
|
|
1474
|
+
* Define the default attributes for the model.
|
|
1475
|
+
*/
|
|
1476
|
+
abstract definition(): Partial<T>;
|
|
1477
|
+
/**
|
|
1478
|
+
* Create a model instance (to be overridden for persistence).
|
|
1479
|
+
*/
|
|
1480
|
+
protected persist(attributes: Partial<T>): Promise<T>;
|
|
1481
|
+
/**
|
|
1482
|
+
* Define a state.
|
|
1483
|
+
*/
|
|
1484
|
+
state(name: string, state: StateDefinition<T>): this;
|
|
1485
|
+
/**
|
|
1486
|
+
* Apply a state to the factory.
|
|
1487
|
+
*/
|
|
1488
|
+
withState(name: string): this;
|
|
1489
|
+
/**
|
|
1490
|
+
* Apply multiple states.
|
|
1491
|
+
*/
|
|
1492
|
+
withStates(...names: string[]): this;
|
|
1493
|
+
/**
|
|
1494
|
+
* Register a callback to run after creating.
|
|
1495
|
+
*/
|
|
1496
|
+
afterCreating(callback: (model: T) => void | Promise<void>): this;
|
|
1497
|
+
/**
|
|
1498
|
+
* Register a callback to run after making.
|
|
1499
|
+
*/
|
|
1500
|
+
afterMaking(callback: (model: T) => void | Promise<void>): this;
|
|
1501
|
+
/**
|
|
1502
|
+
* Make a model instance without persisting.
|
|
1503
|
+
*/
|
|
1504
|
+
make(overrides?: Partial<T>): T;
|
|
1505
|
+
/**
|
|
1506
|
+
* Make multiple model instances without persisting.
|
|
1507
|
+
*/
|
|
1508
|
+
makeMany(count: number, overrides?: Partial<T>): T[];
|
|
1509
|
+
/**
|
|
1510
|
+
* Create and persist a model instance.
|
|
1511
|
+
*/
|
|
1512
|
+
create(overrides?: Partial<T>): Promise<T>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Create and persist multiple model instances.
|
|
1515
|
+
*/
|
|
1516
|
+
createMany(count: number, overrides?: Partial<T>): Promise<T[]>;
|
|
1517
|
+
/**
|
|
1518
|
+
* Reset the sequence counter.
|
|
1519
|
+
*/
|
|
1520
|
+
resetSequence(): this;
|
|
1521
|
+
/**
|
|
1522
|
+
* Clear active states.
|
|
1523
|
+
*/
|
|
1524
|
+
clearStates(): this;
|
|
1525
|
+
/**
|
|
1526
|
+
* Create a new factory instance with fresh state.
|
|
1527
|
+
*/
|
|
1528
|
+
fresh(): this;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Helper to create a simple factory with a definition function.
|
|
1533
|
+
*/
|
|
1534
|
+
declare function defineFactory<T>(definition: (sequence: number) => Partial<T>, persist?: (attributes: Partial<T>) => Promise<T>): BaseFactory<T>;
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* Seeder runner for executing database seeders.
|
|
1538
|
+
*/
|
|
1539
|
+
declare class SeederRunner {
|
|
1540
|
+
private options;
|
|
1541
|
+
private seeders;
|
|
1542
|
+
constructor(options?: SeederRunnerOptions);
|
|
1543
|
+
/**
|
|
1544
|
+
* Register a seeder class.
|
|
1545
|
+
*/
|
|
1546
|
+
register(name: string, seeder: SeederClass): this;
|
|
1547
|
+
/**
|
|
1548
|
+
* Register multiple seeder classes.
|
|
1549
|
+
*/
|
|
1550
|
+
registerMany(seeders: Record<string, SeederClass>): this;
|
|
1551
|
+
/**
|
|
1552
|
+
* Run a specific seeder by name or class.
|
|
1553
|
+
*/
|
|
1554
|
+
run(seeder?: string | SeederClass): Promise<void>;
|
|
1555
|
+
/**
|
|
1556
|
+
* Run multiple seeders in sequence.
|
|
1557
|
+
*/
|
|
1558
|
+
runMany(seeders: Array<string | SeederClass>): Promise<void>;
|
|
1559
|
+
/**
|
|
1560
|
+
* Resolve a seeder by name.
|
|
1561
|
+
*/
|
|
1562
|
+
private resolveSeeder;
|
|
1563
|
+
/**
|
|
1564
|
+
* Get available seeders from the seeders directory.
|
|
1565
|
+
*/
|
|
1566
|
+
getAvailableSeeders(): Promise<string[]>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Log a message if not silent.
|
|
1569
|
+
*/
|
|
1570
|
+
private log;
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Create a seeder runner.
|
|
1574
|
+
*/
|
|
1575
|
+
declare function createSeederRunner(options?: SeederRunnerOptions): SeederRunner;
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* Resource data type.
|
|
1579
|
+
*/
|
|
1580
|
+
type ResourceData = Record<string, unknown>;
|
|
1581
|
+
type ValidationErrors<TField extends string = string> = Partial<Record<TField | 'message', string>>;
|
|
1582
|
+
/**
|
|
1583
|
+
* Pagination meta information.
|
|
1584
|
+
*/
|
|
1585
|
+
interface PaginationMeta {
|
|
1586
|
+
currentPage: number;
|
|
1587
|
+
lastPage: number;
|
|
1588
|
+
perPage: number;
|
|
1589
|
+
total: number;
|
|
1590
|
+
from: number | null;
|
|
1591
|
+
to: number | null;
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Pagination links.
|
|
1595
|
+
*/
|
|
1596
|
+
interface PaginationPageLink {
|
|
1597
|
+
page: number;
|
|
1598
|
+
url: string | null;
|
|
1599
|
+
active: boolean;
|
|
1600
|
+
}
|
|
1601
|
+
interface PaginationLinks {
|
|
1602
|
+
first: string | null;
|
|
1603
|
+
last: string | null;
|
|
1604
|
+
prev: string | null;
|
|
1605
|
+
next: string | null;
|
|
1606
|
+
pages: PaginationPageLink[];
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Paginated response structure.
|
|
1610
|
+
*/
|
|
1611
|
+
interface PaginatedResponse<T> {
|
|
1612
|
+
data: T[];
|
|
1613
|
+
meta: PaginationMeta;
|
|
1614
|
+
links: PaginationLinks;
|
|
1615
|
+
}
|
|
1616
|
+
interface PaginatedPageProps<T> extends Record<string, unknown> {
|
|
1617
|
+
data: T[];
|
|
1618
|
+
pagination: {
|
|
1619
|
+
meta: PaginationMeta;
|
|
1620
|
+
links: PaginationLinks;
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Cursor pagination meta information.
|
|
1625
|
+
*/
|
|
1626
|
+
interface CursorPaginationMeta {
|
|
1627
|
+
perPage: number;
|
|
1628
|
+
nextCursor: string | null;
|
|
1629
|
+
prevCursor: string | null;
|
|
1630
|
+
hasMore: boolean;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Cursor paginated response structure.
|
|
1634
|
+
*/
|
|
1635
|
+
interface CursorPaginatedResponse<T> {
|
|
1636
|
+
data: T[];
|
|
1637
|
+
meta: CursorPaginationMeta;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Paginator options.
|
|
1641
|
+
*/
|
|
1642
|
+
interface PaginatorOptions {
|
|
1643
|
+
path?: string;
|
|
1644
|
+
query?: Record<string, string>;
|
|
1645
|
+
fragment?: string;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Cursor paginator options.
|
|
1649
|
+
*/
|
|
1650
|
+
interface CursorPaginatorOptions {
|
|
1651
|
+
cursorName?: string;
|
|
1652
|
+
parameters?: Record<string, string>;
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Resource class type.
|
|
1656
|
+
*/
|
|
1657
|
+
interface ResourceClass<T, R extends BaseResource<T>> {
|
|
1658
|
+
new (resource: T): R;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Base resource interface.
|
|
1662
|
+
*/
|
|
1663
|
+
interface BaseResource<T> {
|
|
1664
|
+
toArray(): ResourceData;
|
|
1665
|
+
toJSON(): ResourceData;
|
|
1666
|
+
}
|
|
1667
|
+
type InferResourceData<TResource extends BaseResource<unknown>> = ReturnType<TResource['toJSON']>;
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* Abstract base class for API resources.
|
|
1671
|
+
* Transforms model data into API response format.
|
|
1672
|
+
*/
|
|
1673
|
+
declare abstract class Resource<T> {
|
|
1674
|
+
/**
|
|
1675
|
+
* The underlying resource.
|
|
1676
|
+
*/
|
|
1677
|
+
protected resource: T;
|
|
1678
|
+
/**
|
|
1679
|
+
* Additional data to merge with the resource.
|
|
1680
|
+
*/
|
|
1681
|
+
protected additionalData: ResourceData;
|
|
1682
|
+
constructor(resource: T);
|
|
1683
|
+
/**
|
|
1684
|
+
* Transform the resource into an array/object.
|
|
1685
|
+
* Must be implemented by subclasses.
|
|
1686
|
+
*/
|
|
1687
|
+
abstract toArray(): ResourceData;
|
|
1688
|
+
/**
|
|
1689
|
+
* Transform the resource to JSON.
|
|
1690
|
+
*/
|
|
1691
|
+
toJSON(): ResourceData;
|
|
1692
|
+
/**
|
|
1693
|
+
* Add additional data to the resource.
|
|
1694
|
+
*/
|
|
1695
|
+
additional(data: ResourceData): this;
|
|
1696
|
+
/**
|
|
1697
|
+
* Conditionally include a value.
|
|
1698
|
+
*/
|
|
1699
|
+
when<V>(condition: boolean, value: V | (() => V)): V | undefined;
|
|
1700
|
+
/**
|
|
1701
|
+
* Conditionally include a value with a default.
|
|
1702
|
+
*/
|
|
1703
|
+
whenOr<V>(condition: boolean, value: V | (() => V), defaultValue: V): V;
|
|
1704
|
+
/**
|
|
1705
|
+
* Include a value only if a relation is loaded.
|
|
1706
|
+
*/
|
|
1707
|
+
whenLoaded<V>(relation: string, value: V | (() => V), defaultValue?: V): V | undefined;
|
|
1708
|
+
/**
|
|
1709
|
+
* Include a value only if it's not null/undefined.
|
|
1710
|
+
*/
|
|
1711
|
+
whenNotNull<V>(value: V | null | undefined): V | undefined;
|
|
1712
|
+
/**
|
|
1713
|
+
* Merge another resource's data.
|
|
1714
|
+
*/
|
|
1715
|
+
merge(data: ResourceData): ResourceData;
|
|
1716
|
+
/**
|
|
1717
|
+
* Create a new resource instance.
|
|
1718
|
+
*/
|
|
1719
|
+
static make<T, R extends Resource<T>>(this: new (resource: T) => R, resource: T): R;
|
|
1720
|
+
/**
|
|
1721
|
+
* Create a collection of resources.
|
|
1722
|
+
*/
|
|
1723
|
+
static collection<T, R extends Resource<T>>(this: new (resource: T) => R, resources: T[]): ResourceData[];
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Create a resource collection from a resource class.
|
|
1727
|
+
*/
|
|
1728
|
+
declare function collect<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceData[];
|
|
1729
|
+
/**
|
|
1730
|
+
* Simple resource wrapper for objects without transformation.
|
|
1731
|
+
*/
|
|
1732
|
+
declare class JsonResource<T extends Record<string, unknown>> extends Resource<T> {
|
|
1733
|
+
toArray(): ResourceData;
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
interface PaginatedResultLike<T> {
|
|
1737
|
+
data: T[];
|
|
1738
|
+
meta: {
|
|
1739
|
+
total: number;
|
|
1740
|
+
perPage: number;
|
|
1741
|
+
currentPage: number;
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* Paginator for offset-based pagination.
|
|
1746
|
+
*/
|
|
1747
|
+
declare class Paginator<T> {
|
|
1748
|
+
protected _items: T[];
|
|
1749
|
+
protected _total: number;
|
|
1750
|
+
protected _perPage: number;
|
|
1751
|
+
protected _currentPage: number;
|
|
1752
|
+
protected _options: PaginatorOptions;
|
|
1753
|
+
constructor(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions);
|
|
1754
|
+
/**
|
|
1755
|
+
* Get the paginated items.
|
|
1756
|
+
*/
|
|
1757
|
+
items(): T[];
|
|
1758
|
+
/**
|
|
1759
|
+
* Get total number of items.
|
|
1760
|
+
*/
|
|
1761
|
+
total(): number;
|
|
1762
|
+
/**
|
|
1763
|
+
* Get items per page.
|
|
1764
|
+
*/
|
|
1765
|
+
perPage(): number;
|
|
1766
|
+
/**
|
|
1767
|
+
* Get current page number.
|
|
1768
|
+
*/
|
|
1769
|
+
currentPage(): number;
|
|
1770
|
+
/**
|
|
1771
|
+
* Get last page number.
|
|
1772
|
+
*/
|
|
1773
|
+
lastPage(): number;
|
|
1774
|
+
/**
|
|
1775
|
+
* Check if there are more pages.
|
|
1776
|
+
*/
|
|
1777
|
+
hasMorePages(): boolean;
|
|
1778
|
+
/**
|
|
1779
|
+
* Check if on first page.
|
|
1780
|
+
*/
|
|
1781
|
+
onFirstPage(): boolean;
|
|
1782
|
+
/**
|
|
1783
|
+
* Check if on last page.
|
|
1784
|
+
*/
|
|
1785
|
+
onLastPage(): boolean;
|
|
1786
|
+
/**
|
|
1787
|
+
* Get the "from" index (1-based).
|
|
1788
|
+
*/
|
|
1789
|
+
firstItem(): number | null;
|
|
1790
|
+
/**
|
|
1791
|
+
* Get the "to" index (1-based).
|
|
1792
|
+
*/
|
|
1793
|
+
lastItem(): number | null;
|
|
1794
|
+
/**
|
|
1795
|
+
* Get the number of items on current page.
|
|
1796
|
+
*/
|
|
1797
|
+
count(): number;
|
|
1798
|
+
/**
|
|
1799
|
+
* Check if the paginator is empty.
|
|
1800
|
+
*/
|
|
1801
|
+
isEmpty(): boolean;
|
|
1802
|
+
/**
|
|
1803
|
+
* Check if the paginator is not empty.
|
|
1804
|
+
*/
|
|
1805
|
+
isNotEmpty(): boolean;
|
|
1806
|
+
/**
|
|
1807
|
+
* Get pagination meta information.
|
|
1808
|
+
*/
|
|
1809
|
+
meta(): PaginationMeta;
|
|
1810
|
+
/**
|
|
1811
|
+
* Build URL for a page.
|
|
1812
|
+
*/
|
|
1813
|
+
protected url(page: number): string;
|
|
1814
|
+
/**
|
|
1815
|
+
* Get pagination links.
|
|
1816
|
+
*/
|
|
1817
|
+
links(): PaginationLinks;
|
|
1818
|
+
/**
|
|
1819
|
+
* Set the base path for pagination links.
|
|
1820
|
+
*/
|
|
1821
|
+
withPath(path: string): this;
|
|
1822
|
+
/**
|
|
1823
|
+
* Set query parameters for pagination links.
|
|
1824
|
+
*/
|
|
1825
|
+
withQuery(query: Record<string, string>): this;
|
|
1826
|
+
/**
|
|
1827
|
+
* Set fragment for pagination links.
|
|
1828
|
+
*/
|
|
1829
|
+
fragment(fragment: string): this;
|
|
1830
|
+
/**
|
|
1831
|
+
* Transform items to resources.
|
|
1832
|
+
*/
|
|
1833
|
+
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): PaginatedResponse<ResourceData>;
|
|
1834
|
+
/**
|
|
1835
|
+
* Transform to JSON.
|
|
1836
|
+
*/
|
|
1837
|
+
toJSON(): PaginatedResponse<T>;
|
|
1838
|
+
/**
|
|
1839
|
+
* Map over items.
|
|
1840
|
+
*/
|
|
1841
|
+
map<U>(callback: (item: T, index: number) => U): Paginator<U>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Get items as array.
|
|
1844
|
+
*/
|
|
1845
|
+
toArray(): T[];
|
|
1846
|
+
/**
|
|
1847
|
+
* Iterate over items.
|
|
1848
|
+
*/
|
|
1849
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Create paginator from array (slices the array).
|
|
1852
|
+
*/
|
|
1853
|
+
static fromArray<T>(items: T[], page: number, perPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
1854
|
+
/**
|
|
1855
|
+
* Create paginator from an ORM-style paginated result.
|
|
1856
|
+
*/
|
|
1857
|
+
static fromPaginatedResult<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Create a paginator.
|
|
1861
|
+
*/
|
|
1862
|
+
declare function paginate<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
1863
|
+
declare function paginate<T>(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* Collection of resources with additional metadata.
|
|
1867
|
+
*/
|
|
1868
|
+
declare class ResourceCollection<T, R extends Resource<T>> {
|
|
1869
|
+
protected resources: T[];
|
|
1870
|
+
protected resourceClass: ResourceClass<T, R>;
|
|
1871
|
+
protected additionalData: ResourceData;
|
|
1872
|
+
protected wrapKey: string | null;
|
|
1873
|
+
constructor(resources: T[], resourceClass: ResourceClass<T, R>);
|
|
1874
|
+
/**
|
|
1875
|
+
* Transform all resources to an array.
|
|
1876
|
+
*/
|
|
1877
|
+
toArray(): ResourceData[];
|
|
1878
|
+
/**
|
|
1879
|
+
* Add additional data to the collection response.
|
|
1880
|
+
*/
|
|
1881
|
+
additional(data: ResourceData): this;
|
|
1882
|
+
/**
|
|
1883
|
+
* Set the wrapper key for the collection.
|
|
1884
|
+
*/
|
|
1885
|
+
wrap(key: string | null): this;
|
|
1886
|
+
/**
|
|
1887
|
+
* Disable wrapping.
|
|
1888
|
+
*/
|
|
1889
|
+
withoutWrapping(): this;
|
|
1890
|
+
/**
|
|
1891
|
+
* Get the number of resources.
|
|
1892
|
+
*/
|
|
1893
|
+
count(): number;
|
|
1894
|
+
/**
|
|
1895
|
+
* Check if collection is empty.
|
|
1896
|
+
*/
|
|
1897
|
+
isEmpty(): boolean;
|
|
1898
|
+
/**
|
|
1899
|
+
* Check if collection is not empty.
|
|
1900
|
+
*/
|
|
1901
|
+
isNotEmpty(): boolean;
|
|
1902
|
+
/**
|
|
1903
|
+
* Transform to JSON response.
|
|
1904
|
+
*/
|
|
1905
|
+
toJSON(): ResourceData;
|
|
1906
|
+
/**
|
|
1907
|
+
* Map over the resources.
|
|
1908
|
+
*/
|
|
1909
|
+
map<U>(callback: (resource: T, index: number) => U): U[];
|
|
1910
|
+
/**
|
|
1911
|
+
* Filter resources.
|
|
1912
|
+
*/
|
|
1913
|
+
filter(callback: (resource: T, index: number) => boolean): ResourceCollection<T, R>;
|
|
1914
|
+
/**
|
|
1915
|
+
* Get the underlying resources.
|
|
1916
|
+
*/
|
|
1917
|
+
all(): T[];
|
|
1918
|
+
/**
|
|
1919
|
+
* Create a resource collection.
|
|
1920
|
+
*/
|
|
1921
|
+
static make<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceCollection<T, R>;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* Cursor paginator for cursor-based pagination.
|
|
1926
|
+
* Ideal for infinite scroll and real-time data.
|
|
1927
|
+
*/
|
|
1928
|
+
declare class CursorPaginator<T> {
|
|
1929
|
+
protected _items: T[];
|
|
1930
|
+
protected _perPage: number;
|
|
1931
|
+
protected _currentCursor: string | null;
|
|
1932
|
+
protected _nextCursor: string | null;
|
|
1933
|
+
protected _prevCursor: string | null;
|
|
1934
|
+
protected _hasMore: boolean;
|
|
1935
|
+
protected _options: CursorPaginatorOptions;
|
|
1936
|
+
constructor(items: T[], perPage: number, hasMore: boolean, options?: CursorPaginatorOptions & {
|
|
1937
|
+
currentCursor?: string | null;
|
|
1938
|
+
nextCursor?: string | null;
|
|
1939
|
+
prevCursor?: string | null;
|
|
1940
|
+
});
|
|
1941
|
+
/**
|
|
1942
|
+
* Get the paginated items.
|
|
1943
|
+
*/
|
|
1944
|
+
items(): T[];
|
|
1945
|
+
/**
|
|
1946
|
+
* Get items per page.
|
|
1947
|
+
*/
|
|
1948
|
+
perPage(): number;
|
|
1949
|
+
/**
|
|
1950
|
+
* Get the current cursor.
|
|
1951
|
+
*/
|
|
1952
|
+
currentCursor(): string | null;
|
|
1953
|
+
/**
|
|
1954
|
+
* Get the next cursor.
|
|
1955
|
+
*/
|
|
1956
|
+
nextCursor(): string | null;
|
|
1957
|
+
/**
|
|
1958
|
+
* Get the previous cursor.
|
|
1959
|
+
*/
|
|
1960
|
+
prevCursor(): string | null;
|
|
1961
|
+
/**
|
|
1962
|
+
* Check if there are more items.
|
|
1963
|
+
*/
|
|
1964
|
+
hasMorePages(): boolean;
|
|
1965
|
+
/**
|
|
1966
|
+
* Check if there are previous items.
|
|
1967
|
+
*/
|
|
1968
|
+
hasPreviousPages(): boolean;
|
|
1969
|
+
/**
|
|
1970
|
+
* Get the number of items.
|
|
1971
|
+
*/
|
|
1972
|
+
count(): number;
|
|
1973
|
+
/**
|
|
1974
|
+
* Check if empty.
|
|
1975
|
+
*/
|
|
1976
|
+
isEmpty(): boolean;
|
|
1977
|
+
/**
|
|
1978
|
+
* Check if not empty.
|
|
1979
|
+
*/
|
|
1980
|
+
isNotEmpty(): boolean;
|
|
1981
|
+
/**
|
|
1982
|
+
* Get cursor pagination meta.
|
|
1983
|
+
*/
|
|
1984
|
+
meta(): CursorPaginationMeta;
|
|
1985
|
+
/**
|
|
1986
|
+
* Transform items to resources.
|
|
1987
|
+
*/
|
|
1988
|
+
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): CursorPaginatedResponse<ResourceData>;
|
|
1989
|
+
/**
|
|
1990
|
+
* Transform to JSON.
|
|
1991
|
+
*/
|
|
1992
|
+
toJSON(): CursorPaginatedResponse<T>;
|
|
1993
|
+
/**
|
|
1994
|
+
* Map over items.
|
|
1995
|
+
*/
|
|
1996
|
+
map<U>(callback: (item: T, index: number) => U): CursorPaginator<U>;
|
|
1997
|
+
/**
|
|
1998
|
+
* Get items as array.
|
|
1999
|
+
*/
|
|
2000
|
+
toArray(): T[];
|
|
2001
|
+
/**
|
|
2002
|
+
* Iterate over items.
|
|
2003
|
+
*/
|
|
2004
|
+
[Symbol.iterator](): Iterator<T>;
|
|
2005
|
+
/**
|
|
2006
|
+
* Create cursor paginator from array with ID-based cursor.
|
|
2007
|
+
*/
|
|
2008
|
+
static fromArray<T extends {
|
|
2009
|
+
id: string | number;
|
|
2010
|
+
}>(items: T[], cursor: string | null, perPage: number, options?: CursorPaginatorOptions): CursorPaginator<T>;
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Encode a cursor value.
|
|
2014
|
+
*/
|
|
2015
|
+
declare function encodeCursor(value: string | number | Date): string;
|
|
2016
|
+
/**
|
|
2017
|
+
* Decode a cursor value.
|
|
2018
|
+
*/
|
|
2019
|
+
declare function decodeCursor(cursor: string): string;
|
|
2020
|
+
/**
|
|
2021
|
+
* Create a cursor paginator.
|
|
2022
|
+
*/
|
|
2023
|
+
declare function cursorPaginate<T>(items: T[], perPage: number, hasMore: boolean, options?: CursorPaginatorOptions & {
|
|
2024
|
+
currentCursor?: string | null;
|
|
2025
|
+
nextCursor?: string | null;
|
|
2026
|
+
prevCursor?: string | null;
|
|
2027
|
+
}): CursorPaginator<T>;
|
|
2028
|
+
|
|
2029
|
+
/**
|
|
2030
|
+
* Parse a command signature into argument and option definitions.
|
|
2031
|
+
*
|
|
2032
|
+
* Signature format:
|
|
2033
|
+
* - `command:name` - Command name
|
|
2034
|
+
* - `{argument}` - Required argument
|
|
2035
|
+
* - `{argument?}` - Optional argument
|
|
2036
|
+
* - `{argument=default}` - Argument with default
|
|
2037
|
+
* - `{argument*}` - Array argument (must be last)
|
|
2038
|
+
* - `{--option}` - Boolean option (flag)
|
|
2039
|
+
* - `{--option=}` - Option that requires a value
|
|
2040
|
+
* - `{--option=default}` - Option with default value
|
|
2041
|
+
* - `{-o|--option}` - Option with shortcut
|
|
2042
|
+
* - `{--option=*}` - Array option
|
|
2043
|
+
*
|
|
2044
|
+
* @example
|
|
2045
|
+
* ```typescript
|
|
2046
|
+
* parseSignature('users:create {name} {--admin} {--role=user}')
|
|
2047
|
+
* // => {
|
|
2048
|
+
* // name: 'users:create',
|
|
2049
|
+
* // arguments: [{ name: 'name', required: true, array: false }],
|
|
2050
|
+
* // options: [
|
|
2051
|
+
* // { name: 'admin', requiresValue: false },
|
|
2052
|
+
* // { name: 'role', requiresValue: true, defaultValue: 'user' }
|
|
2053
|
+
* // ]
|
|
2054
|
+
* // }
|
|
2055
|
+
* ```
|
|
2056
|
+
*/
|
|
2057
|
+
declare function parseSignature(signature: string): ParsedSignature;
|
|
2058
|
+
/**
|
|
2059
|
+
* Console input handler.
|
|
2060
|
+
*
|
|
2061
|
+
* @example
|
|
2062
|
+
* ```typescript
|
|
2063
|
+
* const input = new Input('users:create {name} {--admin}', ['John', '--admin'])
|
|
2064
|
+
* input.argument('name') // => 'John'
|
|
2065
|
+
* input.option('admin') // => true
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
declare class Input implements InputInterface {
|
|
2069
|
+
/**
|
|
2070
|
+
* Parsed signature.
|
|
2071
|
+
*/
|
|
2072
|
+
protected parsed: ParsedSignature;
|
|
2073
|
+
/**
|
|
2074
|
+
* Parsed argument values.
|
|
2075
|
+
*/
|
|
2076
|
+
protected argumentValues: Record<string, string | string[]>;
|
|
2077
|
+
/**
|
|
2078
|
+
* Parsed option values.
|
|
2079
|
+
*/
|
|
2080
|
+
protected optionValues: Record<string, string | boolean | string[]>;
|
|
2081
|
+
constructor(signature: string, argv?: string[]);
|
|
2082
|
+
/**
|
|
2083
|
+
* Parse command line arguments.
|
|
2084
|
+
*/
|
|
2085
|
+
protected parseArgv(argv: string[]): void;
|
|
2086
|
+
/**
|
|
2087
|
+
* Parse a long option.
|
|
2088
|
+
*/
|
|
2089
|
+
protected parseLongOption(option: string, argv: string[], index: number): void;
|
|
2090
|
+
/**
|
|
2091
|
+
* Parse a short option.
|
|
2092
|
+
*/
|
|
2093
|
+
protected parseShortOption(option: string, argv: string[], index: number): void;
|
|
2094
|
+
/**
|
|
2095
|
+
* Map positional arguments to definitions.
|
|
2096
|
+
*/
|
|
2097
|
+
protected mapArguments(args: string[]): void;
|
|
2098
|
+
/**
|
|
2099
|
+
* Find an option definition by name.
|
|
2100
|
+
*/
|
|
2101
|
+
protected findOption(name: string): OptionDefinition | undefined;
|
|
2102
|
+
/**
|
|
2103
|
+
* Find an option definition by shortcut.
|
|
2104
|
+
*/
|
|
2105
|
+
protected findOptionByShortcut(shortcut: string): OptionDefinition | undefined;
|
|
2106
|
+
/**
|
|
2107
|
+
* Check if an option requires a value.
|
|
2108
|
+
*/
|
|
2109
|
+
protected optionRequiresValue(name: string): boolean;
|
|
2110
|
+
/**
|
|
2111
|
+
* Get an argument value.
|
|
2112
|
+
*/
|
|
2113
|
+
argument<T = string>(name: string): T;
|
|
2114
|
+
/**
|
|
2115
|
+
* Get all argument values.
|
|
2116
|
+
*/
|
|
2117
|
+
arguments(): Record<string, string | string[]>;
|
|
2118
|
+
/**
|
|
2119
|
+
* Get an option value.
|
|
2120
|
+
*/
|
|
2121
|
+
option<T = string | boolean>(name: string): T | undefined;
|
|
2122
|
+
/**
|
|
2123
|
+
* Get all option values.
|
|
2124
|
+
*/
|
|
2125
|
+
options(): Record<string, string | boolean | string[]>;
|
|
2126
|
+
/**
|
|
2127
|
+
* Check if an option was provided.
|
|
2128
|
+
*/
|
|
2129
|
+
hasOption(name: string): boolean;
|
|
2130
|
+
/**
|
|
2131
|
+
* Get the parsed signature.
|
|
2132
|
+
*/
|
|
2133
|
+
getSignature(): ParsedSignature;
|
|
2134
|
+
/**
|
|
2135
|
+
* Get the command name.
|
|
2136
|
+
*/
|
|
2137
|
+
getCommandName(): string;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
/**
|
|
2141
|
+
* Base command class for console commands.
|
|
2142
|
+
*
|
|
2143
|
+
* @example
|
|
2144
|
+
* ```typescript
|
|
2145
|
+
* export class CreateUserCommand extends Command {
|
|
2146
|
+
* static signature = 'users:create {email} {--admin} {--role=user}'
|
|
2147
|
+
* static description = 'Create a new user'
|
|
2148
|
+
*
|
|
2149
|
+
* async handle(): Promise<void> {
|
|
2150
|
+
* const email = this.argument('email')
|
|
2151
|
+
* const isAdmin = this.hasOption('admin')
|
|
2152
|
+
* const role = this.option('role', 'user')
|
|
2153
|
+
*
|
|
2154
|
+
* const password = await this.secret('Enter password:')
|
|
2155
|
+
* const confirm = await this.confirm(`Create user ${email}?`)
|
|
2156
|
+
*
|
|
2157
|
+
* if (!confirm) {
|
|
2158
|
+
* this.warn('Cancelled')
|
|
2159
|
+
* return
|
|
2160
|
+
* }
|
|
2161
|
+
*
|
|
2162
|
+
* this.info(`Creating user: ${email}`)
|
|
2163
|
+
* this.success('User created!')
|
|
2164
|
+
* }
|
|
2165
|
+
* }
|
|
2166
|
+
* ```
|
|
2167
|
+
*/
|
|
2168
|
+
declare abstract class Command implements CommandInstance {
|
|
2169
|
+
/**
|
|
2170
|
+
* The command signature.
|
|
2171
|
+
* Format: 'command:name {arg} {--option}'
|
|
2172
|
+
*/
|
|
2173
|
+
static signature: string;
|
|
2174
|
+
/**
|
|
2175
|
+
* The command description.
|
|
2176
|
+
*/
|
|
2177
|
+
static description: string;
|
|
2178
|
+
/**
|
|
2179
|
+
* The command input.
|
|
2180
|
+
*/
|
|
2181
|
+
protected input: Input;
|
|
2182
|
+
/**
|
|
2183
|
+
* The command output.
|
|
2184
|
+
*/
|
|
2185
|
+
protected output: OutputInterface;
|
|
2186
|
+
/**
|
|
2187
|
+
* The service container.
|
|
2188
|
+
*/
|
|
2189
|
+
protected container?: Container;
|
|
2190
|
+
constructor(container?: Container);
|
|
2191
|
+
/**
|
|
2192
|
+
* Set the input for this command.
|
|
2193
|
+
*/
|
|
2194
|
+
setInput(argv: string[]): void;
|
|
2195
|
+
/**
|
|
2196
|
+
* Set the output for this command.
|
|
2197
|
+
*/
|
|
2198
|
+
setOutput(output: OutputInterface): void;
|
|
2199
|
+
/**
|
|
2200
|
+
* Execute the command.
|
|
2201
|
+
*/
|
|
2202
|
+
run(): Promise<number>;
|
|
2203
|
+
/**
|
|
2204
|
+
* Handle the command.
|
|
2205
|
+
* Must be implemented by subclasses.
|
|
2206
|
+
*/
|
|
2207
|
+
abstract handle(): Promise<number | void>;
|
|
2208
|
+
/**
|
|
2209
|
+
* Get an argument value.
|
|
2210
|
+
*/
|
|
2211
|
+
argument<T = string>(name: string): T;
|
|
2212
|
+
/**
|
|
2213
|
+
* Get all arguments.
|
|
2214
|
+
*/
|
|
2215
|
+
arguments(): Record<string, string | string[]>;
|
|
2216
|
+
/**
|
|
2217
|
+
* Get an option value with optional default.
|
|
2218
|
+
*/
|
|
2219
|
+
option<T = string>(name: string, defaultValue?: T): T;
|
|
2220
|
+
/**
|
|
2221
|
+
* Get all options.
|
|
2222
|
+
*/
|
|
2223
|
+
options(): Record<string, string | boolean | string[]>;
|
|
2224
|
+
/**
|
|
2225
|
+
* Check if an option was provided.
|
|
2226
|
+
*/
|
|
2227
|
+
hasOption(name: string): boolean;
|
|
2228
|
+
/**
|
|
2229
|
+
* Output an info message.
|
|
2230
|
+
*/
|
|
2231
|
+
info(message: string): void;
|
|
2232
|
+
/**
|
|
2233
|
+
* Output an error message.
|
|
2234
|
+
*/
|
|
2235
|
+
error(message: string): void;
|
|
2236
|
+
/**
|
|
2237
|
+
* Output a warning message.
|
|
2238
|
+
*/
|
|
2239
|
+
warn(message: string): void;
|
|
2240
|
+
/**
|
|
2241
|
+
* Output a success message.
|
|
2242
|
+
*/
|
|
2243
|
+
success(message: string): void;
|
|
2244
|
+
/**
|
|
2245
|
+
* Output a plain line.
|
|
2246
|
+
*/
|
|
2247
|
+
line(message: string): void;
|
|
2248
|
+
/**
|
|
2249
|
+
* Output new lines.
|
|
2250
|
+
*/
|
|
2251
|
+
newLine(count?: number): void;
|
|
2252
|
+
/**
|
|
2253
|
+
* Output a table.
|
|
2254
|
+
*/
|
|
2255
|
+
table(headers: string[], rows: string[][]): void;
|
|
2256
|
+
/**
|
|
2257
|
+
* Ask a question and get user input.
|
|
2258
|
+
*/
|
|
2259
|
+
ask(question: string, defaultValue?: string): Promise<string>;
|
|
2260
|
+
/**
|
|
2261
|
+
* Ask for confirmation.
|
|
2262
|
+
*/
|
|
2263
|
+
confirm(question: string, defaultValue?: boolean): Promise<boolean>;
|
|
2264
|
+
/**
|
|
2265
|
+
* Present choices to the user.
|
|
2266
|
+
*/
|
|
2267
|
+
choice<T extends string>(question: string, choices: T[], defaultValue?: T): Promise<T>;
|
|
2268
|
+
/**
|
|
2269
|
+
* Ask for secret input (password).
|
|
2270
|
+
*/
|
|
2271
|
+
secret(question: string): Promise<string>;
|
|
2272
|
+
/**
|
|
2273
|
+
* Create a readline interface.
|
|
2274
|
+
*/
|
|
2275
|
+
protected createReadline(): readline.Interface;
|
|
2276
|
+
/**
|
|
2277
|
+
* Process items with progress output.
|
|
2278
|
+
*/
|
|
2279
|
+
withProgress<T>(items: T[], callback: (item: T, index: number) => Promise<void>): Promise<void>;
|
|
2280
|
+
/**
|
|
2281
|
+
* Kernel reference for calling other commands.
|
|
2282
|
+
*/
|
|
2283
|
+
protected kernel?: {
|
|
2284
|
+
handle(argv: string[]): Promise<number>;
|
|
2285
|
+
};
|
|
2286
|
+
/**
|
|
2287
|
+
* Set the kernel reference.
|
|
2288
|
+
*/
|
|
2289
|
+
setKernel(kernel: {
|
|
2290
|
+
handle(argv: string[]): Promise<number>;
|
|
2291
|
+
}): void;
|
|
2292
|
+
/**
|
|
2293
|
+
* Call another command.
|
|
2294
|
+
*/
|
|
2295
|
+
call(command: string, args?: string[]): Promise<number>;
|
|
2296
|
+
/**
|
|
2297
|
+
* Call another command silently.
|
|
2298
|
+
*/
|
|
2299
|
+
callSilent(command: string, args?: string[]): Promise<number>;
|
|
2300
|
+
/**
|
|
2301
|
+
* Resolve a service from the container.
|
|
2302
|
+
*/
|
|
2303
|
+
protected resolve<T>(key: string): T;
|
|
2304
|
+
/**
|
|
2305
|
+
* Get the command signature.
|
|
2306
|
+
*/
|
|
2307
|
+
getSignature(): string;
|
|
2308
|
+
/**
|
|
2309
|
+
* Get the command description.
|
|
2310
|
+
*/
|
|
2311
|
+
getDescription(): string;
|
|
2312
|
+
/**
|
|
2313
|
+
* Get the command name.
|
|
2314
|
+
*/
|
|
2315
|
+
getName(): string;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
/**
|
|
2319
|
+
* ANSI color codes.
|
|
2320
|
+
*/
|
|
2321
|
+
declare const COLORS: {
|
|
2322
|
+
readonly reset: "\u001B[0m";
|
|
2323
|
+
readonly bold: "\u001B[1m";
|
|
2324
|
+
readonly dim: "\u001B[2m";
|
|
2325
|
+
readonly black: "\u001B[30m";
|
|
2326
|
+
readonly red: "\u001B[31m";
|
|
2327
|
+
readonly green: "\u001B[32m";
|
|
2328
|
+
readonly yellow: "\u001B[33m";
|
|
2329
|
+
readonly blue: "\u001B[34m";
|
|
2330
|
+
readonly magenta: "\u001B[35m";
|
|
2331
|
+
readonly cyan: "\u001B[36m";
|
|
2332
|
+
readonly white: "\u001B[37m";
|
|
2333
|
+
readonly bgRed: "\u001B[41m";
|
|
2334
|
+
readonly bgGreen: "\u001B[42m";
|
|
2335
|
+
readonly bgYellow: "\u001B[43m";
|
|
2336
|
+
readonly bgBlue: "\u001B[44m";
|
|
2337
|
+
readonly bgMagenta: "\u001B[45m";
|
|
2338
|
+
readonly bgCyan: "\u001B[46m";
|
|
2339
|
+
readonly bgWhite: "\u001B[47m";
|
|
2340
|
+
};
|
|
2341
|
+
/**
|
|
2342
|
+
* Console output handler.
|
|
2343
|
+
*
|
|
2344
|
+
* @example
|
|
2345
|
+
* ```typescript
|
|
2346
|
+
* const output = new Output()
|
|
2347
|
+
* output.info('Processing...')
|
|
2348
|
+
* output.success('Done!')
|
|
2349
|
+
* output.table(['Name', 'Age'], [['John', '30'], ['Jane', '25']])
|
|
2350
|
+
* ```
|
|
2351
|
+
*/
|
|
2352
|
+
declare class Output implements OutputInterface {
|
|
2353
|
+
/**
|
|
2354
|
+
* Whether to use colors.
|
|
2355
|
+
*/
|
|
2356
|
+
protected useColors: boolean;
|
|
2357
|
+
/**
|
|
2358
|
+
* Output stream.
|
|
2359
|
+
*/
|
|
2360
|
+
protected stdout: NodeJS.WriteStream;
|
|
2361
|
+
/**
|
|
2362
|
+
* Error stream.
|
|
2363
|
+
*/
|
|
2364
|
+
protected stderr: NodeJS.WriteStream;
|
|
2365
|
+
constructor(options?: {
|
|
2366
|
+
colors?: boolean;
|
|
2367
|
+
stdout?: NodeJS.WriteStream;
|
|
2368
|
+
stderr?: NodeJS.WriteStream;
|
|
2369
|
+
});
|
|
2370
|
+
/**
|
|
2371
|
+
* Apply color to text.
|
|
2372
|
+
*/
|
|
2373
|
+
protected color(text: string, ...codes: string[]): string;
|
|
2374
|
+
/**
|
|
2375
|
+
* Output an info message.
|
|
2376
|
+
*/
|
|
2377
|
+
info(message: string): void;
|
|
2378
|
+
/**
|
|
2379
|
+
* Output an error message.
|
|
2380
|
+
*/
|
|
2381
|
+
error(message: string): void;
|
|
2382
|
+
/**
|
|
2383
|
+
* Output a warning message.
|
|
2384
|
+
*/
|
|
2385
|
+
warn(message: string): void;
|
|
2386
|
+
/**
|
|
2387
|
+
* Output a success message.
|
|
2388
|
+
*/
|
|
2389
|
+
success(message: string): void;
|
|
2390
|
+
/**
|
|
2391
|
+
* Output a plain line.
|
|
2392
|
+
*/
|
|
2393
|
+
line(message: string): void;
|
|
2394
|
+
/**
|
|
2395
|
+
* Output new lines.
|
|
2396
|
+
*/
|
|
2397
|
+
newLine(count?: number): void;
|
|
2398
|
+
/**
|
|
2399
|
+
* Output a table.
|
|
2400
|
+
*/
|
|
2401
|
+
table(headers: string[], rows: string[][]): void;
|
|
2402
|
+
/**
|
|
2403
|
+
* Write raw text without newline.
|
|
2404
|
+
*/
|
|
2405
|
+
write(message: string): void;
|
|
2406
|
+
/**
|
|
2407
|
+
* Write a line to stdout.
|
|
2408
|
+
*/
|
|
2409
|
+
protected writeLine(message: string): void;
|
|
2410
|
+
/**
|
|
2411
|
+
* Write a line to stderr.
|
|
2412
|
+
*/
|
|
2413
|
+
protected writeErrorLine(message: string): void;
|
|
2414
|
+
/**
|
|
2415
|
+
* Output a comment.
|
|
2416
|
+
*/
|
|
2417
|
+
comment(message: string): void;
|
|
2418
|
+
/**
|
|
2419
|
+
* Output a question.
|
|
2420
|
+
*/
|
|
2421
|
+
question(message: string): void;
|
|
2422
|
+
/**
|
|
2423
|
+
* Output a bulleted list.
|
|
2424
|
+
*/
|
|
2425
|
+
listing(items: string[]): void;
|
|
2426
|
+
/**
|
|
2427
|
+
* Output text with specific color.
|
|
2428
|
+
*/
|
|
2429
|
+
colored(message: string, color: keyof typeof COLORS): void;
|
|
2430
|
+
/**
|
|
2431
|
+
* Create a progress bar string.
|
|
2432
|
+
*/
|
|
2433
|
+
progressBar(current: number, total: number, width?: number): string;
|
|
2434
|
+
/**
|
|
2435
|
+
* Clear the current line.
|
|
2436
|
+
*/
|
|
2437
|
+
clearLine(): void;
|
|
2438
|
+
/**
|
|
2439
|
+
* Check if colors are enabled.
|
|
2440
|
+
*/
|
|
2441
|
+
isColored(): boolean;
|
|
2442
|
+
/**
|
|
2443
|
+
* Enable or disable colors.
|
|
2444
|
+
*/
|
|
2445
|
+
setColors(enabled: boolean): void;
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Output that collects messages instead of printing.
|
|
2449
|
+
* Useful for testing.
|
|
2450
|
+
*/
|
|
2451
|
+
declare class BufferedOutput extends Output {
|
|
2452
|
+
/**
|
|
2453
|
+
* Collected messages.
|
|
2454
|
+
*/
|
|
2455
|
+
protected buffer: string[];
|
|
2456
|
+
constructor();
|
|
2457
|
+
protected writeLine(message: string): void;
|
|
2458
|
+
protected writeErrorLine(message: string): void;
|
|
2459
|
+
write(message: string): void;
|
|
2460
|
+
/**
|
|
2461
|
+
* Get all output as array.
|
|
2462
|
+
*/
|
|
2463
|
+
getLines(): string[];
|
|
2464
|
+
/**
|
|
2465
|
+
* Get all output as string.
|
|
2466
|
+
*/
|
|
2467
|
+
getOutput(): string;
|
|
2468
|
+
/**
|
|
2469
|
+
* Clear the buffer.
|
|
2470
|
+
*/
|
|
2471
|
+
clear(): void;
|
|
2472
|
+
/**
|
|
2473
|
+
* Check if buffer contains a string.
|
|
2474
|
+
*/
|
|
2475
|
+
contains(text: string): boolean;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
/**
|
|
2479
|
+
* Create a proxy-based facade that lazily resolves a service from an application container.
|
|
2480
|
+
*
|
|
2481
|
+
* The returned proxy intercepts all property access and method calls,
|
|
2482
|
+
* resolving the underlying service from the container on each access.
|
|
2483
|
+
* This ensures that container fakes and flushes are respected.
|
|
2484
|
+
*
|
|
2485
|
+
* @example
|
|
2486
|
+
* ```typescript
|
|
2487
|
+
* import { createFacades } from '@guren/server/facades'
|
|
2488
|
+
*
|
|
2489
|
+
* const { Cache, Events } = createFacades(container)
|
|
2490
|
+
* await Cache.get('key')
|
|
2491
|
+
* Events.emit('user.created', payload)
|
|
2492
|
+
* ```
|
|
2493
|
+
*/
|
|
2494
|
+
declare function createFacade<K extends keyof ServiceBindings>(container: Pick<Container, 'make'>, key: K): ServiceBindings[K];
|
|
2495
|
+
declare function createFacades(container: Pick<Container, 'make'>): {
|
|
2496
|
+
readonly Cache: CacheManager;
|
|
2497
|
+
readonly Events: EventManager;
|
|
2498
|
+
readonly Queue: QueueManager;
|
|
2499
|
+
readonly Mail: MailManager;
|
|
2500
|
+
readonly Log: LogManager;
|
|
2501
|
+
readonly I18n: I18nManager;
|
|
2502
|
+
readonly Notifications: NotificationManager;
|
|
2503
|
+
readonly Broadcast: BroadcastManager;
|
|
2504
|
+
readonly Storage: StorageManager;
|
|
2505
|
+
readonly Scheduler: Scheduler;
|
|
2506
|
+
};
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
* Options for configuring the auto-discovery engine.
|
|
2510
|
+
*/
|
|
2511
|
+
interface DiscoveryOptions {
|
|
2512
|
+
/** Base path for scanning. Defaults to `process.cwd()`. */
|
|
2513
|
+
basePath?: string;
|
|
2514
|
+
/** Whether to discover service providers in `app/Providers/`. Defaults to `true`. */
|
|
2515
|
+
providers?: boolean;
|
|
2516
|
+
/** Whether to discover event listeners in `app/Listeners/`. Defaults to `true`. */
|
|
2517
|
+
listeners?: boolean;
|
|
2518
|
+
/** Whether to discover jobs in `app/Jobs/`. Defaults to `true`. */
|
|
2519
|
+
jobs?: boolean;
|
|
2520
|
+
/** Whether to discover events in `app/Events/`. Defaults to `true`. */
|
|
2521
|
+
events?: boolean;
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Result of the auto-discovery scan.
|
|
2525
|
+
*/
|
|
2526
|
+
interface DiscoveryResult {
|
|
2527
|
+
/** Discovered service provider classes. */
|
|
2528
|
+
providers: Array<new (...args: unknown[]) => unknown>;
|
|
2529
|
+
/** Discovered event listeners with their associated event name. */
|
|
2530
|
+
listeners: Array<{
|
|
2531
|
+
event: string;
|
|
2532
|
+
listener: new () => unknown;
|
|
2533
|
+
}>;
|
|
2534
|
+
/** Discovered job classes. */
|
|
2535
|
+
jobs: Array<new () => unknown>;
|
|
2536
|
+
/** Discovered event classes. */
|
|
2537
|
+
events: Array<new () => unknown>;
|
|
2538
|
+
}
|
|
2539
|
+
/**
|
|
2540
|
+
* Auto-discovery engine that scans application directories and discovers
|
|
2541
|
+
* framework components (providers, listeners, jobs, events).
|
|
2542
|
+
*
|
|
2543
|
+
* Uses `Bun.Glob` to scan directories and dynamic `import()` to load modules.
|
|
2544
|
+
*
|
|
2545
|
+
* @example
|
|
2546
|
+
* ```typescript
|
|
2547
|
+
* const discovery = new AutoDiscovery({ basePath: '/app' })
|
|
2548
|
+
* const result = await discovery.discover()
|
|
2549
|
+
*
|
|
2550
|
+
* // Register discovered providers
|
|
2551
|
+
* for (const ProviderClass of result.providers) {
|
|
2552
|
+
* providerManager.register(ProviderClass)
|
|
2553
|
+
* }
|
|
2554
|
+
*
|
|
2555
|
+
* // Register discovered listeners
|
|
2556
|
+
* for (const { event, listener } of result.listeners) {
|
|
2557
|
+
* eventManager.listen(event, listener)
|
|
2558
|
+
* }
|
|
2559
|
+
* ```
|
|
2560
|
+
*/
|
|
2561
|
+
declare class AutoDiscovery {
|
|
2562
|
+
private basePath;
|
|
2563
|
+
private options;
|
|
2564
|
+
constructor(options?: DiscoveryOptions);
|
|
2565
|
+
/**
|
|
2566
|
+
* Run the discovery scan across all enabled directories.
|
|
2567
|
+
*/
|
|
2568
|
+
discover(): Promise<DiscoveryResult>;
|
|
2569
|
+
/**
|
|
2570
|
+
* Discover service providers in `app/Providers/`.
|
|
2571
|
+
*
|
|
2572
|
+
* A module is considered a provider if it exports a class (default or named)
|
|
2573
|
+
* that has a `register` method (i.e., implements the Provider interface).
|
|
2574
|
+
*/
|
|
2575
|
+
private discoverProviders;
|
|
2576
|
+
/**
|
|
2577
|
+
* Discover event listeners in `app/Listeners/`.
|
|
2578
|
+
*
|
|
2579
|
+
* A listener class must have a `static event` property (string) that indicates
|
|
2580
|
+
* which event it handles, and a `handle` method.
|
|
2581
|
+
*/
|
|
2582
|
+
private discoverListeners;
|
|
2583
|
+
/**
|
|
2584
|
+
* Discover jobs in `app/Jobs/`.
|
|
2585
|
+
*
|
|
2586
|
+
* A job class must have a `handle` method.
|
|
2587
|
+
*/
|
|
2588
|
+
private discoverJobs;
|
|
2589
|
+
/**
|
|
2590
|
+
* Discover events in `app/Events/`.
|
|
2591
|
+
*
|
|
2592
|
+
* Any exported class from the Events directory is considered an event class.
|
|
2593
|
+
*/
|
|
2594
|
+
private discoverEvents;
|
|
2595
|
+
/**
|
|
2596
|
+
* Scan a directory for TypeScript files using Bun.Glob.
|
|
2597
|
+
* Returns an array of imported modules. Skips `index.ts` barrel files.
|
|
2598
|
+
*/
|
|
2599
|
+
private scanDirectory;
|
|
2600
|
+
/**
|
|
2601
|
+
* Extract all class constructors (functions) from a module's exports.
|
|
2602
|
+
*/
|
|
2603
|
+
private extractClasses;
|
|
2604
|
+
/**
|
|
2605
|
+
* Check if a value is a constructor function (class).
|
|
2606
|
+
*/
|
|
2607
|
+
private isConstructor;
|
|
2608
|
+
/**
|
|
2609
|
+
* Check if a class looks like a service provider (has a `register` method).
|
|
2610
|
+
*/
|
|
2611
|
+
private isProvider;
|
|
2612
|
+
/**
|
|
2613
|
+
* Get the `static event` property from a class, if it exists and is a string.
|
|
2614
|
+
*/
|
|
2615
|
+
private getStaticEvent;
|
|
2616
|
+
/**
|
|
2617
|
+
* Check if a class has a `handle` method on its prototype.
|
|
2618
|
+
*/
|
|
2619
|
+
private hasHandleMethod;
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
/**
|
|
2623
|
+
* Render a rich HTML debug error page for development mode.
|
|
2624
|
+
*
|
|
2625
|
+
* When an error occurs and NODE_ENV is not 'production', this function
|
|
2626
|
+
* generates a helpful page displaying the error class, message, stack trace
|
|
2627
|
+
* with source context, and request details.
|
|
2628
|
+
*/
|
|
2629
|
+
declare function renderDebugPage(error: Error, request?: Request): string;
|
|
2630
|
+
/**
|
|
2631
|
+
* Middleware that catches errors and renders a debug page in development.
|
|
2632
|
+
* In production (NODE_ENV === 'production'), errors are re-thrown so
|
|
2633
|
+
* downstream handlers or the ExceptionHandler can process them normally.
|
|
2634
|
+
*
|
|
2635
|
+
* @example
|
|
2636
|
+
* ```typescript
|
|
2637
|
+
* import { debugErrorMiddleware } from '@guren/server/errors/debug-page'
|
|
2638
|
+
*
|
|
2639
|
+
* app.use('*', debugErrorMiddleware())
|
|
2640
|
+
* ```
|
|
2641
|
+
*/
|
|
2642
|
+
declare function debugErrorMiddleware(): MiddlewareHandler;
|
|
2643
|
+
|
|
2644
|
+
/**
|
|
2645
|
+
* Options for creating a Redis client.
|
|
2646
|
+
*/
|
|
2647
|
+
interface RedisClientOptions extends RedisOptions {
|
|
2648
|
+
/**
|
|
2649
|
+
* Redis connection URL (e.g., 'redis://localhost:6379').
|
|
2650
|
+
* If provided, overrides host/port/password.
|
|
2651
|
+
*/
|
|
2652
|
+
url?: string;
|
|
2653
|
+
/**
|
|
2654
|
+
* Key prefix for all operations.
|
|
2655
|
+
* @default ''
|
|
2656
|
+
*/
|
|
2657
|
+
keyPrefix?: string;
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* Create a Redis client with the given options.
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* ```ts
|
|
2664
|
+
* // Using URL
|
|
2665
|
+
* const redis = createRedisClient({ url: 'redis://localhost:6379' })
|
|
2666
|
+
*
|
|
2667
|
+
* // Using host/port
|
|
2668
|
+
* const redis = createRedisClient({ host: 'localhost', port: 6379 })
|
|
2669
|
+
*
|
|
2670
|
+
* // With key prefix
|
|
2671
|
+
* const redis = createRedisClient({
|
|
2672
|
+
* url: process.env.REDIS_URL,
|
|
2673
|
+
* keyPrefix: 'myapp:',
|
|
2674
|
+
* })
|
|
2675
|
+
* ```
|
|
2676
|
+
*/
|
|
2677
|
+
declare function createRedisClient(options?: RedisClientOptions): Redis;
|
|
2678
|
+
|
|
2679
|
+
export { AUTH_CONTEXT_KEY, AuthContext, AuthContext as AuthRuntimeContext, AuthServiceProvider, AuthenticationException, AuthorizationException, AuthorizationServiceProvider, AutoDiscovery, BaseFactory, type BaseResource, BaseSeeder, BroadcastManager, BroadcastServiceProvider, BufferedOutput, CSP_NONCE_KEY, CacheManager, CacheServiceProvider, Command, CommandInstance, Container, type CorsOptions, type CspDirectives, type CspOptions, type CursorPaginatedResponse, type CursorPaginationMeta, CursorPaginator, type CursorPaginatorOptions, type DiscoveryOptions, type DiscoveryResult, EncryptionServiceProvider, ErrorResponse, ErrorServiceProvider, EventManager, EventServiceProvider, BaseFactory as Factory, type FactoryClass, type Factory as FactoryInterface, FieldValidator, type FileLike, type FileValidationOptions, type ForceHttpsOptions, FormRequest, HealthServiceProvider, HttpException, I18nManager, I18nServiceProvider, type ImageValidationOptions, InertiaServiceProvider, type InferResourceData, Input, InputInterface, JsonResource, LogManager, LogServiceProvider, MailManager, MailServiceProvider, MemoryRateLimitStore, MethodNotAllowedException, NotFoundHttpException, NotificationManager, NotificationServiceProvider, OAuthServiceProvider, OptionDefinition, Output, OutputInterface, type PaginatedPageProps, type PaginatedResponse, type PaginatedResultLike, type PaginationLinks, type PaginationMeta, type PaginationPageLink, Paginator, type PaginatorOptions, ParsedSignature, QueueManager, QueueServiceProvider, type RateLimitEntry, type RateLimitInfo, type RateLimitOptions, type RateLimitStore, type RedirectSafetyOptions, type RequireAuthOptions, Resource, type ResourceClass, ResourceCollection, type ResourceData, type RuleDefinition, Scheduler, SchedulingServiceProvider, BaseSeeder as Seeder, type SeederClass, type Seeder as SeederInterface, SeederRunner, type SeederRunnerOptions, ServiceBindings, ServiceProvider, SlidingWindowRateLimitStore, StorageManager, StorageServiceProvider, type ValidationErrors, ValidationException, type ValidationResult, type ValidationRule, Validator, type ValidatorOptions, ViewEngine, after, afterOrEqual, alpha, alphaDash, alphaNum, array as arrayRule, attachAuthContext, before, beforeOrEqual, between, boolean as booleanRule, collect, confirmed, createCorsMiddleware, createCspMiddleware, createFacade, createFacades, createForceHttpsMiddleware, createRateLimitMiddleware, createRedirectSafetyMiddleware, createRedisClient, createSeederRunner, createValidator, cursorPaginate, custom, dateFormat, date as dateRule, debugErrorMiddleware, decodeCursor, defineFactory, different, email as emailRule, encodeCursor, endsWith, exists, file as fileRule, getCspNonce, getRateLimitInfo, image as imageRule, inValues, integer, ip, ipv4, ipv6, isSafeRedirectUrl, json as jsonRule, max, maxFileSize, mimes, min, minFileSize, notIn, nullable, numeric, object as objectRule, paginate, parseSignature, quickValidate, quickValidateOrThrow, regex, renderDebugPage, renderErrorPage, requestIdMiddleware, requestLoggingMiddleware, requireAuthenticated, requireGuest, required, requiredIf, requiredUnless, requiredWith, requiredWithout, resetCalledSeeders, resetRateLimit, same, size, startsWith, string as stringRule, unique, url as urlRule, uuid as uuidRule };
|