@@ -23,8 +23,8 @@ export interface User {
23
23
* It validates that the input contains a nonempty `login` and `password`.
24
24
*/
25
25
export const UserInputSchema = z . object ( {
26
- login : z . string ( ) . nonempty ( ) ,
27
- password : z . union ( [ z . string ( ) . nonempty ( ) , z . string ( ) . startsWith ( '0x' ) ] ) ,
26
+ login : z . string ( ) . min ( 1 ) ,
27
+ password : z . union ( [ z . string ( ) . min ( 1 ) , z . string ( ) . startsWith ( '0x' ) ] ) ,
28
28
} ) ;
29
29
30
30
/**
@@ -33,6 +33,31 @@ export const UserInputSchema = z.object({
33
33
*/
34
34
export type UserInputType = z . infer < typeof UserInputSchema > ;
35
35
36
+ /**
37
+ * User output schema
38
+ */
39
+ export const SafeUserSchema = z . object ( {
40
+ login : z . string ( ) . min ( 1 ) ,
41
+ isAdmin : z . boolean ( ) . optional ( ) ,
42
+ } ) ;
43
+
44
+ /**
45
+ * Users list output schema
46
+ */
47
+ export const UsersListOutputSchema = z . array ( SafeUserSchema ) ;
48
+
49
+ /**
50
+ * Type definition for sanitized User record,
51
+ * inferred from SafeUserSchema.
52
+ */
53
+ export type SafeUserType = z . infer < typeof SafeUserSchema > ;
54
+
55
+ /**
56
+ * Type definition for sanitized Users records list,
57
+ * inferred from UsersListOutputSchema.
58
+ */
59
+ export type UsersListOutputSchema = z . infer < typeof UsersListOutputSchema > ;
60
+
36
61
/**
37
62
* Interface defining the properties of UsersDb initialization options.
38
63
*/
@@ -130,7 +155,11 @@ export class UsersDb {
130
155
* @throws Will throw an error if a user with the same login already exists
131
156
* @memberof UsersDb
132
157
*/
133
- async add ( login : string , password : string , isAdmin = false ) : Promise < void > {
158
+ async add (
159
+ login : string ,
160
+ password : string ,
161
+ isAdmin : boolean = false ,
162
+ ) : Promise < void > {
134
163
const knownUser = await this . storage . get < User > ( `${ this . prefix } ${ login } ` ) ;
135
164
136
165
// Check if the user already exists
0 commit comments