@guren/server 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-GDCUIM6V.js +121 -0
- package/dist/index.d.ts +493 -0
- package/dist/index.js +1392 -0
- package/dist/vite/index.d.ts +31 -0
- package/dist/vite/index.js +7 -0
- package/package.json +49 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// src/vite/plugin.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
var defaultOptions = {
|
|
4
|
+
appAlias: "@",
|
|
5
|
+
appDir: "app",
|
|
6
|
+
resourcesAlias: "@resources",
|
|
7
|
+
resourcesDir: "resources/js",
|
|
8
|
+
entry: "resources/js/app.tsx",
|
|
9
|
+
outDir: "public/assets",
|
|
10
|
+
devPort: 5173,
|
|
11
|
+
previewPort: 4173,
|
|
12
|
+
entryFileNames: "[name]-[hash].js",
|
|
13
|
+
chunkFileNames: "[name]-[hash].js",
|
|
14
|
+
assetFileNames: "[name]-[hash][extname]"
|
|
15
|
+
};
|
|
16
|
+
function gurenVitePlugin(options = {}) {
|
|
17
|
+
const resolved = { ...defaultOptions, ...options };
|
|
18
|
+
return {
|
|
19
|
+
name: "guren:vite-config",
|
|
20
|
+
enforce: "pre",
|
|
21
|
+
config(config, _env) {
|
|
22
|
+
ensureDefaults(config, resolved);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function ensureDefaults(config, options) {
|
|
27
|
+
const root = resolveRoot(config.root);
|
|
28
|
+
ensureAliases(config, options, root);
|
|
29
|
+
ensureServer(config, options);
|
|
30
|
+
ensurePreview(config, options);
|
|
31
|
+
ensureBuild(config, options, root);
|
|
32
|
+
}
|
|
33
|
+
function ensureAliases(config, options, root) {
|
|
34
|
+
config.resolve ??= {};
|
|
35
|
+
const alias = toAliasArray(config.resolve.alias);
|
|
36
|
+
maybePushAlias(alias, options.appAlias, path.resolve(root, options.appDir));
|
|
37
|
+
maybePushAlias(alias, options.resourcesAlias, path.resolve(root, options.resourcesDir));
|
|
38
|
+
config.resolve.alias = alias;
|
|
39
|
+
}
|
|
40
|
+
function ensureServer(config, options) {
|
|
41
|
+
config.server ??= {};
|
|
42
|
+
if (config.server.host === void 0) {
|
|
43
|
+
config.server.host = true;
|
|
44
|
+
}
|
|
45
|
+
if (config.server.port === void 0) {
|
|
46
|
+
config.server.port = options.devPort;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function ensurePreview(config, options) {
|
|
50
|
+
config.preview ??= {};
|
|
51
|
+
if (config.preview.host === void 0) {
|
|
52
|
+
config.preview.host = true;
|
|
53
|
+
}
|
|
54
|
+
if (config.preview.port === void 0) {
|
|
55
|
+
config.preview.port = options.previewPort;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function ensureBuild(config, options, root) {
|
|
59
|
+
config.build ??= {};
|
|
60
|
+
if (config.build.outDir === void 0) {
|
|
61
|
+
config.build.outDir = options.outDir;
|
|
62
|
+
}
|
|
63
|
+
if (config.build.emptyOutDir === void 0) {
|
|
64
|
+
config.build.emptyOutDir = true;
|
|
65
|
+
}
|
|
66
|
+
if (config.build.manifest === void 0) {
|
|
67
|
+
config.build.manifest = true;
|
|
68
|
+
}
|
|
69
|
+
config.build.rollupOptions ??= {};
|
|
70
|
+
if (config.build.rollupOptions.input === void 0) {
|
|
71
|
+
config.build.rollupOptions.input = path.resolve(root, options.entry);
|
|
72
|
+
}
|
|
73
|
+
const output = normalizeRollupOutput(config.build.rollupOptions.output);
|
|
74
|
+
if (output.entryFileNames === void 0) {
|
|
75
|
+
output.entryFileNames = options.entryFileNames;
|
|
76
|
+
}
|
|
77
|
+
if (output.chunkFileNames === void 0) {
|
|
78
|
+
output.chunkFileNames = options.chunkFileNames;
|
|
79
|
+
}
|
|
80
|
+
if (output.assetFileNames === void 0) {
|
|
81
|
+
output.assetFileNames = options.assetFileNames;
|
|
82
|
+
}
|
|
83
|
+
config.build.rollupOptions.output = output;
|
|
84
|
+
}
|
|
85
|
+
function resolveRoot(root) {
|
|
86
|
+
if (!root) {
|
|
87
|
+
return process.cwd();
|
|
88
|
+
}
|
|
89
|
+
return path.isAbsolute(root) ? root : path.resolve(process.cwd(), root);
|
|
90
|
+
}
|
|
91
|
+
function toAliasArray(alias) {
|
|
92
|
+
if (Array.isArray(alias)) {
|
|
93
|
+
return alias.slice();
|
|
94
|
+
}
|
|
95
|
+
if (alias && typeof alias === "object") {
|
|
96
|
+
return Object.entries(alias).map(([find, replacement]) => ({
|
|
97
|
+
find,
|
|
98
|
+
replacement
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
function maybePushAlias(alias, find, replacement) {
|
|
104
|
+
const alreadyDefined = alias.some((entry) => entry.find === find);
|
|
105
|
+
if (!alreadyDefined) {
|
|
106
|
+
alias.push({ find, replacement });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function normalizeRollupOutput(output) {
|
|
110
|
+
if (Array.isArray(output)) {
|
|
111
|
+
if (output.length === 0) {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
return output[0];
|
|
115
|
+
}
|
|
116
|
+
return output ?? {};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
gurenVitePlugin
|
|
121
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import * as hono from 'hono';
|
|
2
|
+
import { MiddlewareHandler, Context, Hono, ExecutionContext } from 'hono';
|
|
3
|
+
export { Context } from 'hono';
|
|
4
|
+
export { GurenVitePluginOptions, default as gurenVitePlugin } from './vite/index.js';
|
|
5
|
+
|
|
6
|
+
interface InertiaOptions {
|
|
7
|
+
readonly url?: string;
|
|
8
|
+
readonly version?: string;
|
|
9
|
+
readonly status?: number;
|
|
10
|
+
readonly headers?: HeadersInit;
|
|
11
|
+
readonly request?: Request;
|
|
12
|
+
readonly title?: string;
|
|
13
|
+
readonly entry?: string;
|
|
14
|
+
readonly importMap?: Record<string, string>;
|
|
15
|
+
readonly styles?: string[];
|
|
16
|
+
}
|
|
17
|
+
interface InertiaPagePayload {
|
|
18
|
+
component: string;
|
|
19
|
+
props: Record<string, unknown>;
|
|
20
|
+
url: string;
|
|
21
|
+
version?: string;
|
|
22
|
+
}
|
|
23
|
+
declare function inertia(component: string, props: Record<string, unknown>, options?: InertiaOptions): Response;
|
|
24
|
+
|
|
25
|
+
type SessionData = Record<string, unknown>;
|
|
26
|
+
interface SessionStore {
|
|
27
|
+
read(id: string): Promise<SessionData | undefined>;
|
|
28
|
+
write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
|
|
29
|
+
destroy(id: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
declare class MemorySessionStore implements SessionStore {
|
|
32
|
+
private readonly now;
|
|
33
|
+
private readonly store;
|
|
34
|
+
constructor(now?: () => number);
|
|
35
|
+
read(id: string): Promise<SessionData | undefined>;
|
|
36
|
+
write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
|
|
37
|
+
destroy(id: string): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
interface SessionOptions {
|
|
40
|
+
cookieName?: string;
|
|
41
|
+
cookiePath?: string;
|
|
42
|
+
cookieDomain?: string;
|
|
43
|
+
cookieSecure?: boolean;
|
|
44
|
+
cookieSameSite?: 'Strict' | 'Lax' | 'None';
|
|
45
|
+
cookieHttpOnly?: boolean;
|
|
46
|
+
cookieMaxAgeSeconds?: number;
|
|
47
|
+
ttlSeconds?: number;
|
|
48
|
+
store?: SessionStore;
|
|
49
|
+
}
|
|
50
|
+
interface Session {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly isNew: boolean;
|
|
53
|
+
get<T = unknown>(key: string): T | undefined;
|
|
54
|
+
set<T = unknown>(key: string, value: T): void;
|
|
55
|
+
has(key: string): boolean;
|
|
56
|
+
forget(key: string): void;
|
|
57
|
+
flush(): void;
|
|
58
|
+
all(): SessionData;
|
|
59
|
+
regenerate(): void;
|
|
60
|
+
invalidate(): void;
|
|
61
|
+
}
|
|
62
|
+
interface CreateSessionMiddlewareOptions extends SessionOptions {
|
|
63
|
+
}
|
|
64
|
+
declare function createSessionMiddleware(options?: CreateSessionMiddlewareOptions): MiddlewareHandler;
|
|
65
|
+
declare function getSessionFromContext<T extends Session = Session>(ctx: {
|
|
66
|
+
get: (key: string) => unknown;
|
|
67
|
+
}): T | undefined;
|
|
68
|
+
|
|
69
|
+
interface RequireAuthOptions {
|
|
70
|
+
redirectTo?: string;
|
|
71
|
+
status?: number;
|
|
72
|
+
responseFactory?: () => Response;
|
|
73
|
+
}
|
|
74
|
+
declare function attachAuthContext(contextFactory: (ctx: Context) => AuthContext): MiddlewareHandler;
|
|
75
|
+
declare function requireAuthenticated(options?: RequireAuthOptions): MiddlewareHandler;
|
|
76
|
+
declare function requireGuest(options?: RequireAuthOptions): MiddlewareHandler;
|
|
77
|
+
|
|
78
|
+
type Middleware = MiddlewareHandler;
|
|
79
|
+
declare function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler;
|
|
80
|
+
|
|
81
|
+
type AuthCredentials = Record<string, unknown>;
|
|
82
|
+
interface Authenticatable {
|
|
83
|
+
getAuthIdentifier(): unknown;
|
|
84
|
+
getAuthPassword(): string | null | undefined;
|
|
85
|
+
getRememberToken?(): string | null | undefined;
|
|
86
|
+
setRememberToken?(token: string | null): void | Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
interface Guard<User = Authenticatable> {
|
|
89
|
+
check(): Promise<boolean>;
|
|
90
|
+
guest(): Promise<boolean>;
|
|
91
|
+
user<T = User>(): Promise<T | null>;
|
|
92
|
+
id(): Promise<unknown>;
|
|
93
|
+
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
94
|
+
logout(): Promise<void>;
|
|
95
|
+
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
96
|
+
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
97
|
+
session<T extends Session = Session>(): T | undefined;
|
|
98
|
+
}
|
|
99
|
+
interface UserProvider<User = Authenticatable> {
|
|
100
|
+
retrieveById(identifier: unknown): Promise<User | null>;
|
|
101
|
+
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
102
|
+
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
103
|
+
getId(user: User): unknown;
|
|
104
|
+
setRememberToken?(user: User, token: string | null): Promise<void> | void;
|
|
105
|
+
getRememberToken?(user: User): Promise<string | null> | string | null;
|
|
106
|
+
}
|
|
107
|
+
interface GuardContext {
|
|
108
|
+
ctx: Context;
|
|
109
|
+
session: Session | undefined;
|
|
110
|
+
manager: AuthManagerContract;
|
|
111
|
+
}
|
|
112
|
+
type GuardFactory<User = Authenticatable> = (context: GuardContext) => Guard<User>;
|
|
113
|
+
interface ProviderFactory<User = Authenticatable> {
|
|
114
|
+
(manager: AuthManagerContract): UserProvider<User>;
|
|
115
|
+
}
|
|
116
|
+
interface AuthManagerOptions {
|
|
117
|
+
defaultGuard?: string;
|
|
118
|
+
}
|
|
119
|
+
interface AttachContextOptions {
|
|
120
|
+
guard?: string;
|
|
121
|
+
}
|
|
122
|
+
interface AuthContext<User = Authenticatable> {
|
|
123
|
+
check(): Promise<boolean>;
|
|
124
|
+
guest(): Promise<boolean>;
|
|
125
|
+
user<T = User>(): Promise<T | null>;
|
|
126
|
+
id(): Promise<unknown>;
|
|
127
|
+
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
128
|
+
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
129
|
+
logout(): Promise<void>;
|
|
130
|
+
guard<T = User>(name?: string): Guard<T>;
|
|
131
|
+
session<T extends Session = Session>(): T | undefined;
|
|
132
|
+
}
|
|
133
|
+
interface AuthManagerContract {
|
|
134
|
+
registerGuard<User = Authenticatable>(name: string, factory: GuardFactory<User>): void;
|
|
135
|
+
registerProvider<User = Authenticatable>(name: string, factory: ProviderFactory<User>): void;
|
|
136
|
+
getProvider<User = Authenticatable>(name: string): UserProvider<User>;
|
|
137
|
+
createGuard<User = Authenticatable>(name: string, context: GuardContext): Guard<User>;
|
|
138
|
+
guardNames(): string[];
|
|
139
|
+
setDefaultGuard(name: string): void;
|
|
140
|
+
getDefaultGuard(): string;
|
|
141
|
+
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class AuthManager implements AuthManagerContract {
|
|
145
|
+
private readonly guards;
|
|
146
|
+
private readonly providers;
|
|
147
|
+
private defaultGuard;
|
|
148
|
+
constructor(options?: AuthManagerOptions);
|
|
149
|
+
registerGuard<User>(name: string, factory: GuardFactory<User>): void;
|
|
150
|
+
registerProvider<User>(name: string, factory: ProviderFactory<User>): void;
|
|
151
|
+
getProvider<User>(name: string): UserProvider<User>;
|
|
152
|
+
createGuard<User>(name: string, context: GuardContext): Guard<User>;
|
|
153
|
+
guardNames(): string[];
|
|
154
|
+
setDefaultGuard(name: string): void;
|
|
155
|
+
getDefaultGuard(): string;
|
|
156
|
+
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
157
|
+
attempt(name: string, ctx: Context, credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface SessionGuardOptions {
|
|
161
|
+
provider: UserProvider;
|
|
162
|
+
sessionKey?: string;
|
|
163
|
+
rememberSessionKey?: string;
|
|
164
|
+
session: Session | undefined;
|
|
165
|
+
}
|
|
166
|
+
declare class SessionGuard<User extends Authenticatable = Authenticatable> implements Guard<User> {
|
|
167
|
+
private readonly options;
|
|
168
|
+
private cachedUser;
|
|
169
|
+
constructor(options: SessionGuardOptions);
|
|
170
|
+
private get currentSession();
|
|
171
|
+
private get provider();
|
|
172
|
+
private sessionKey;
|
|
173
|
+
private rememberSessionKey;
|
|
174
|
+
private loadRememberedUser;
|
|
175
|
+
private resolveUser;
|
|
176
|
+
check(): Promise<boolean>;
|
|
177
|
+
guest(): Promise<boolean>;
|
|
178
|
+
user<T = User>(): Promise<T | null>;
|
|
179
|
+
id(): Promise<unknown>;
|
|
180
|
+
private remember;
|
|
181
|
+
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
182
|
+
logout(): Promise<void>;
|
|
183
|
+
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
184
|
+
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
185
|
+
session<T extends Session = Session>(): T | undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare abstract class BaseUserProvider<User extends Authenticatable = Authenticatable> implements UserProvider<User> {
|
|
189
|
+
abstract retrieveById(identifier: unknown): Promise<User | null>;
|
|
190
|
+
abstract retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
191
|
+
abstract validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
192
|
+
abstract getId(user: User): unknown;
|
|
193
|
+
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
194
|
+
getRememberToken(user: User): Promise<string | null>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type PlainObject = Record<string, unknown>;
|
|
198
|
+
type WhereClause = Record<string, unknown>;
|
|
199
|
+
interface ORMAdapter {
|
|
200
|
+
findMany<TRecord = PlainObject>(table: unknown, where?: WhereClause): Promise<TRecord[]>;
|
|
201
|
+
findUnique<TRecord = PlainObject>(table: unknown, where: WhereClause): Promise<TRecord | null>;
|
|
202
|
+
create<TRecord = PlainObject>(table: unknown, data: PlainObject): Promise<TRecord>;
|
|
203
|
+
update?<TRecord = PlainObject>(table: unknown, where: WhereClause, data: PlainObject): Promise<TRecord>;
|
|
204
|
+
delete?<TRecord = PlainObject>(table: unknown, where: WhereClause): Promise<number | PlainObject | void>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Minimal ActiveRecord-like wrapper around the configured ORM adapter. The API
|
|
208
|
+
* mirrors a subset of Laravel's Eloquent helpers and can be expanded over time.
|
|
209
|
+
*/
|
|
210
|
+
declare abstract class Model<TRecord extends object = PlainObject> {
|
|
211
|
+
protected static ormAdapter: ORMAdapter;
|
|
212
|
+
protected static table: unknown;
|
|
213
|
+
static readonly recordType: unknown;
|
|
214
|
+
static useAdapter(adapter: ORMAdapter): void;
|
|
215
|
+
static getAdapter(): ORMAdapter;
|
|
216
|
+
protected static resolveTable(): unknown;
|
|
217
|
+
static all<T extends typeof Model>(this: T): Promise<Array<TRecordFor<T>>>;
|
|
218
|
+
static find<T extends typeof Model>(this: T, id: unknown, key?: string): Promise<TRecordFor<T> | null>;
|
|
219
|
+
static where<T extends typeof Model>(this: T, where: WhereClause): Promise<TRecordFor<T>[]>;
|
|
220
|
+
static create<T extends typeof Model>(this: T, data: PlainObject): Promise<TRecordFor<T>>;
|
|
221
|
+
static update<T extends typeof Model>(this: T, where: WhereClause, data: PlainObject): Promise<TRecordFor<T>>;
|
|
222
|
+
static delete<T extends typeof Model>(this: T, where: WhereClause): Promise<number | PlainObject | void>;
|
|
223
|
+
}
|
|
224
|
+
type TRecordFor<T extends typeof Model> = T extends {
|
|
225
|
+
recordType: infer R;
|
|
226
|
+
} ? R extends object ? R : PlainObject : PlainObject;
|
|
227
|
+
|
|
228
|
+
interface PasswordHasher {
|
|
229
|
+
hash(plain: string): Promise<string>;
|
|
230
|
+
verify(hashed: string, plain: string): Promise<boolean>;
|
|
231
|
+
needsRehash?(hashed: string): boolean;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface ModelUserProviderOptions {
|
|
235
|
+
idColumn?: string;
|
|
236
|
+
usernameColumn?: string;
|
|
237
|
+
passwordColumn?: string;
|
|
238
|
+
rememberTokenColumn?: string;
|
|
239
|
+
hasher?: PasswordHasher;
|
|
240
|
+
credentialsPasswordField?: string;
|
|
241
|
+
}
|
|
242
|
+
declare class ModelUserProvider<User extends Authenticatable = Authenticatable> extends BaseUserProvider<User> {
|
|
243
|
+
private readonly model;
|
|
244
|
+
private readonly idColumn;
|
|
245
|
+
private readonly usernameColumn;
|
|
246
|
+
private readonly passwordColumn;
|
|
247
|
+
private readonly rememberTokenColumn;
|
|
248
|
+
private readonly hasher;
|
|
249
|
+
private readonly credentialsPasswordField;
|
|
250
|
+
constructor(model: typeof Model, options?: ModelUserProviderOptions);
|
|
251
|
+
private cast;
|
|
252
|
+
retrieveById(identifier: unknown): Promise<User | null>;
|
|
253
|
+
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
254
|
+
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
255
|
+
getId(user: User): unknown;
|
|
256
|
+
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
257
|
+
getRememberToken(user: User): Promise<string | null>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
type Argon2Algorithm = 'argon2id' | 'argon2i' | 'argon2d';
|
|
261
|
+
type SupportedAlgorithm = Argon2Algorithm | 'bcrypt';
|
|
262
|
+
interface BunPasswordHasherOptions {
|
|
263
|
+
/**
|
|
264
|
+
* Hashing algorithm to use. Defaults to Bun's Argon2id implementation.
|
|
265
|
+
*/
|
|
266
|
+
algorithm?: SupportedAlgorithm;
|
|
267
|
+
/** Argon2 memory cost (in kibibytes). */
|
|
268
|
+
memoryCost?: number;
|
|
269
|
+
/** Argon2 time cost (number of iterations). */
|
|
270
|
+
timeCost?: number;
|
|
271
|
+
/** Bcrypt cost factor (log rounds). */
|
|
272
|
+
cost?: number;
|
|
273
|
+
}
|
|
274
|
+
declare class ScryptHasher implements PasswordHasher {
|
|
275
|
+
private readonly algorithm;
|
|
276
|
+
private readonly memoryCost?;
|
|
277
|
+
private readonly timeCost?;
|
|
278
|
+
private readonly cost?;
|
|
279
|
+
constructor(options?: BunPasswordHasherOptions);
|
|
280
|
+
hash(plain: string): Promise<string>;
|
|
281
|
+
verify(hashed: string, plain: string): Promise<boolean>;
|
|
282
|
+
needsRehash(hashed: string): boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
type DefaultInertiaProps = Record<string, unknown>;
|
|
286
|
+
type InertiaResponseMarker<Component extends string, Props extends DefaultInertiaProps> = {
|
|
287
|
+
readonly __gurenInertia?: {
|
|
288
|
+
readonly component: Component;
|
|
289
|
+
readonly props: Props;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
type InertiaResponse<Component extends string, Props extends DefaultInertiaProps> = Response & InertiaResponseMarker<Component, Props>;
|
|
293
|
+
type InferInertiaProps<T> = [T] extends [InertiaResponse<string, infer Props>] ? Props : [T] extends [Promise<infer Awaited>] ? InferInertiaProps<Awaited> : DefaultInertiaProps;
|
|
294
|
+
interface RedirectOptions {
|
|
295
|
+
status?: number;
|
|
296
|
+
headers?: HeadersInit;
|
|
297
|
+
}
|
|
298
|
+
type InertiaResponseOptions = Omit<InertiaOptions, 'url' | 'request'> & {
|
|
299
|
+
url?: string;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Base controller inspired by Laravel's expressive API. Subclasses can access
|
|
303
|
+
* the current Hono context through the protected `ctx` getter and rely on the
|
|
304
|
+
* helper response builders for common patterns.
|
|
305
|
+
*/
|
|
306
|
+
declare class Controller {
|
|
307
|
+
private context?;
|
|
308
|
+
setContext(context: Context): void;
|
|
309
|
+
protected get ctx(): Context;
|
|
310
|
+
protected get request(): hono.HonoRequest<any, unknown>;
|
|
311
|
+
protected get auth(): AuthContext;
|
|
312
|
+
protected inertia<Component extends string, Props extends DefaultInertiaProps>(component: Component, props: Props, options?: InertiaResponseOptions): InertiaResponse<Component, Props>;
|
|
313
|
+
protected json<T>(data: T, init?: ResponseInit): Response;
|
|
314
|
+
protected text(body: string, init?: ResponseInit): Response;
|
|
315
|
+
protected redirect(url: string, options?: RedirectOptions): Response;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type ControllerConstructor<T extends Controller = Controller> = new () => T;
|
|
319
|
+
type ControllerMethod<T extends Controller> = {
|
|
320
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
321
|
+
}[keyof T] & string;
|
|
322
|
+
type ControllerAction<T extends Controller = Controller> = [ControllerConstructor<T>, ControllerMethod<T>];
|
|
323
|
+
type RouteResult = Response | string | number | boolean | Record<string, unknown> | Array<unknown> | null | void;
|
|
324
|
+
type RouteHandler<T extends Controller = Controller> = ((c: Context) => RouteResult | Promise<RouteResult>) | ControllerAction<T>;
|
|
325
|
+
interface RouteDefinition {
|
|
326
|
+
method: string;
|
|
327
|
+
path: string;
|
|
328
|
+
name?: string;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Route registry stores Laravel-style route declarations and eagerly mounts
|
|
332
|
+
* them onto a Hono instance when requested.
|
|
333
|
+
*/
|
|
334
|
+
declare class Route {
|
|
335
|
+
private static readonly registry;
|
|
336
|
+
private static readonly prefixStack;
|
|
337
|
+
private static add;
|
|
338
|
+
static on<T extends Controller>(method: string, path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
339
|
+
static get<T extends Controller>(path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
340
|
+
static post<T extends Controller>(path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
341
|
+
static put<T extends Controller>(path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
342
|
+
static patch<T extends Controller>(path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
343
|
+
static delete<T extends Controller>(path: string, handler: RouteHandler<T>, ...middlewares: MiddlewareHandler[]): typeof Route;
|
|
344
|
+
static group(prefix: string, callback: () => void): typeof Route;
|
|
345
|
+
static mount(app: Hono): void;
|
|
346
|
+
static clear(): void;
|
|
347
|
+
static definitions(): RouteDefinition[];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
type ViewRenderer = (template: string, props: Record<string, unknown>) => Response;
|
|
351
|
+
/**
|
|
352
|
+
* Registry for view renderers. Engines are typically registered via service
|
|
353
|
+
* providers so applications can opt into or replace implementations.
|
|
354
|
+
*/
|
|
355
|
+
declare class ViewEngine {
|
|
356
|
+
private static readonly engines;
|
|
357
|
+
static register(name: string, renderer: ViewRenderer): void;
|
|
358
|
+
static has(name: string): boolean;
|
|
359
|
+
static render(name: string, template: string, props: Record<string, unknown>): Response;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
declare class ApplicationContext {
|
|
363
|
+
private readonly application;
|
|
364
|
+
private readonly authManager;
|
|
365
|
+
constructor(application: Application, authManager: AuthManager);
|
|
366
|
+
get app(): Application;
|
|
367
|
+
get hono(): Hono;
|
|
368
|
+
get routes(): typeof Route;
|
|
369
|
+
get views(): typeof ViewEngine;
|
|
370
|
+
get auth(): AuthManager;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface Provider {
|
|
374
|
+
register?(context: ApplicationContext): void | Promise<void>;
|
|
375
|
+
boot?(context: ApplicationContext): void | Promise<void>;
|
|
376
|
+
}
|
|
377
|
+
type ProviderConstructor<T extends Provider = Provider> = new () => T;
|
|
378
|
+
|
|
379
|
+
type BootCallback = (app: Hono) => void | Promise<void>;
|
|
380
|
+
interface ApplicationOptions {
|
|
381
|
+
readonly boot?: BootCallback;
|
|
382
|
+
readonly providers?: Array<Provider | ProviderConstructor>;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Application wires the Route registry into a running Hono instance.
|
|
386
|
+
* It offers a small convenience layer so users can bootstrap a Bun server
|
|
387
|
+
* without touching the underlying Hono object directly.
|
|
388
|
+
*/
|
|
389
|
+
declare class Application {
|
|
390
|
+
private readonly options;
|
|
391
|
+
readonly hono: Hono;
|
|
392
|
+
private readonly plugins;
|
|
393
|
+
private context?;
|
|
394
|
+
private readonly authManager;
|
|
395
|
+
constructor(options?: ApplicationOptions);
|
|
396
|
+
get auth(): AuthManager;
|
|
397
|
+
/**
|
|
398
|
+
* Mounts all routes that were defined through the Route DSL.
|
|
399
|
+
*/
|
|
400
|
+
mountRoutes(): void;
|
|
401
|
+
/**
|
|
402
|
+
* Allows registering global middlewares directly on the underlying Hono app.
|
|
403
|
+
*/
|
|
404
|
+
use(path: string, ...middleware: MiddlewareHandler[]): void;
|
|
405
|
+
/**
|
|
406
|
+
* Executes the optional boot callback and mounts the registered routes.
|
|
407
|
+
*/
|
|
408
|
+
boot(): Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* Fetch handler to integrate with Bun.serve or any standard Fetch runtime.
|
|
411
|
+
*/
|
|
412
|
+
fetch(request: Request, env?: unknown, executionCtx?: ExecutionContext): Promise<Response>;
|
|
413
|
+
/**
|
|
414
|
+
* Convenience helper to start a Bun server when available.
|
|
415
|
+
*/
|
|
416
|
+
listen(options?: {
|
|
417
|
+
port?: number;
|
|
418
|
+
hostname?: string;
|
|
419
|
+
}): void;
|
|
420
|
+
register(provider: Provider | ProviderConstructor): this;
|
|
421
|
+
registerMany(providers: Array<Provider | ProviderConstructor>): this;
|
|
422
|
+
private resolveContext;
|
|
423
|
+
private registerDefaultProviders;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
interface DevAssetsOptions {
|
|
427
|
+
/** Absolute path to the resources directory (e.g. `/app/resources`). */
|
|
428
|
+
resourcesDir?: string;
|
|
429
|
+
/** Base import meta used to resolve relative paths. */
|
|
430
|
+
importMeta?: ImportMeta;
|
|
431
|
+
/** Relative path from `importMeta` to the resources directory. Defaults to `../resources`. */
|
|
432
|
+
resourcesPath?: string;
|
|
433
|
+
/** Path prefix to mount transpiled JS assets. Defaults to `/resources/js`. */
|
|
434
|
+
prefix?: string;
|
|
435
|
+
/** Enables serving the bundled inertia client. Defaults to true. */
|
|
436
|
+
inertiaClient?: boolean;
|
|
437
|
+
/** Path to the inertia client source. Defaults to the version bundled with Guren. */
|
|
438
|
+
inertiaClientSource?: string;
|
|
439
|
+
/** Public URL for the inertia client. Defaults to `/vendor/inertia-client.tsx`. */
|
|
440
|
+
inertiaClientPath?: string;
|
|
441
|
+
/** Override the remote JSX runtime URL. */
|
|
442
|
+
jsxRuntimeUrl?: string;
|
|
443
|
+
/** Absolute path to a directory with static assets (e.g. `/app/public`). */
|
|
444
|
+
publicDir?: string;
|
|
445
|
+
/** Relative path from `importMeta` to the static assets directory. Defaults to `../public`. */
|
|
446
|
+
publicPath?: string | false;
|
|
447
|
+
/** Route pattern used when serving static assets. Defaults to `/public/*`. */
|
|
448
|
+
publicRoute?: string;
|
|
449
|
+
/** Whether to register a no-op favicon route. Defaults to true when static assets are served. */
|
|
450
|
+
favicon?: boolean;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Registers development asset serving middleware.
|
|
454
|
+
* @param app
|
|
455
|
+
* @param options
|
|
456
|
+
*/
|
|
457
|
+
declare function registerDevAssets(app: Application, options: DevAssetsOptions): void;
|
|
458
|
+
|
|
459
|
+
interface InertiaAssetsOptions extends DevAssetsOptions {
|
|
460
|
+
/** Default stylesheet entry embedded into Inertia responses. */
|
|
461
|
+
stylesEntry?: string;
|
|
462
|
+
/** Default script entry embedded into Inertia responses (production). */
|
|
463
|
+
scriptEntry?: string;
|
|
464
|
+
}
|
|
465
|
+
declare function configureInertiaAssets(app: Application, options: InertiaAssetsOptions): void;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Parses the incoming request payload supporting both JSON bodies and form submissions.
|
|
469
|
+
* Falls back to an empty object if the payload cannot be parsed.
|
|
470
|
+
*/
|
|
471
|
+
declare function parseRequestPayload(ctx: Context): Promise<Record<string, unknown>>;
|
|
472
|
+
interface ValidationIssueLike {
|
|
473
|
+
path: Array<string | number>;
|
|
474
|
+
message: string;
|
|
475
|
+
}
|
|
476
|
+
interface ValidationErrorLike {
|
|
477
|
+
issues: ValidationIssueLike[];
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Converts a Zod-style validation error into a flat record usable by forms.
|
|
481
|
+
*/
|
|
482
|
+
declare function formatValidationErrors(error: ValidationErrorLike, fallbackMessage?: string): Record<string, string>;
|
|
483
|
+
|
|
484
|
+
declare class InertiaViewProvider implements Provider {
|
|
485
|
+
register(_context: ApplicationContext): void;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
declare class AuthServiceProvider implements Provider {
|
|
489
|
+
register(context: ApplicationContext): void;
|
|
490
|
+
boot(context: ApplicationContext): void;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export { Application, ApplicationContext, type AuthContext, type AuthCredentials, AuthManager, type AuthManagerOptions, type AuthContext as AuthRuntimeContext, AuthServiceProvider, type Authenticatable, BaseUserProvider, Controller, type Guard, type GuardContext, type GuardFactory, type InertiaOptions, type InertiaPagePayload, type InertiaResponse, InertiaViewProvider, type InferInertiaProps, MemorySessionStore, type Middleware, ModelUserProvider, type Provider, type ProviderConstructor, type ProviderFactory, type RequireAuthOptions, Route, type RouteDefinition, ScryptHasher, type Session, type SessionData, SessionGuard, type SessionStore, type UserProvider, ViewEngine, attachAuthContext, configureInertiaAssets, createSessionMiddleware, defineMiddleware, formatValidationErrors, getSessionFromContext, inertia, parseRequestPayload, registerDevAssets, requireAuthenticated, requireGuest };
|