-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodetest.mjs
More file actions
45 lines (41 loc) · 969 Bytes
/
nodetest.mjs
File metadata and controls
45 lines (41 loc) · 969 Bytes
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
import { type } from "arktype";
const preference = type({
key: "string",
value: "string|number|boolean",
});
const userSchemaArktype = type({
id: "string",
email: "string",
profile: {
firstName: "string",
lastName: "string",
age: "number",
preferences: preference.array(),
},
metadata: "Record<string,unknown>",
createdAt: "Date",
"updatedAt?": "Date",
});
const validUserData = {
id: "123e4567-e89b-12d3-a456-426614174000",
email: "test@example.com",
profile: {
firstName: "John",
lastName: "Doe",
age: 30,
preferences: [
{ key: "theme", value: "dark" },
{ key: "notifications", value: true },
],
},
metadata: {
lastLogin: "2024-01-17T00:00:00.000Z",
},
createdAt: new Date(),
};
const result = userSchemaArktype(validUserData);
if (result instanceof type.errors) {
console.error("ERROR!", result);
} else {
console.log("Valid user data:", JSON.stringify(result, null, 2));
}