-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
89 lines (84 loc) · 2.32 KB
/
types.ts
File metadata and controls
89 lines (84 loc) · 2.32 KB
1
2
3
4
5
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Handlers, PageProps } from "./deps.ts";
import { type Auth, type JSX, WithCsrf, z } from "./deps.ts";
export interface GardenParams {
auth: Auth;
setupRootPath: string;
allowNoSessionPaths: (string | RegExp)[];
loginAfterPath: string;
logoutAfterPath: string;
resourceIdentifierName: string;
resourceName: string;
identifierSchema: z.ZodString;
passwordSchema: z.ZodString;
}
export interface GardenInnerParams {
auth: Auth;
loginAfterPath: string;
logoutAfterPath: string;
resourceIdentifierName: string;
resourceName: string;
paths: {
loginPath: string;
createPath: string;
logoutPath: string;
};
isAllowNoSessionPath: { (path: string): boolean };
isSessionLogicPath: { (path: string): boolean };
identifierSchema: z.ZodString;
passwordSchema: z.ZodString;
}
export type GardenRouteAction = "create" | "login" | "logout";
export type GardenHandlerAction = GardenRouteAction;
export type GardenComponentAction = Exclude<
GardenRouteAction,
"logout"
>;
export interface DefaultActions {
create: {
getHandler: (
{ auth, loginAfterPath, logoutAfterPath, resourceName, paths }:
GardenInnerParams,
) => Handlers<unknown, WithCsrf>;
getComponent: (
{ resourceIdentifierName, paths }: GardenInnerParams,
) => (
{ data, state }: PageProps<
{ errors: string[]; identifier: string },
WithCsrf
>,
) => JSX.Element;
};
login: {
getHandler: (
{ auth, loginAfterPath, logoutAfterPath, resourceName }:
GardenInnerParams,
) => Handlers<unknown, WithCsrf>;
getComponent: (
{ resourceIdentifierName, paths }: GardenInnerParams,
) => (
{ data, state }: PageProps<
{ errors: string[]; identifier: string },
WithCsrf
>,
) => JSX.Element;
};
logout: {
getHandler: (
{ auth, loginAfterPath, logoutAfterPath, resourceName, paths }:
GardenInnerParams,
) => Handlers<unknown, WithCsrf>;
};
}
type IdName<T extends string> = `${T}Id`;
type LuciaObjectKey<T extends string> = `auth${Capitalize<T>}Session`;
export interface WithGarden<Q extends string> extends Record<string, unknown> {
garden: {
[K in LuciaObjectKey<Q>]:
& {
[KK in Q]: {
[KKK in IdName<Q>]: string;
};
}
& { resourceName: string };
};
}