FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aRustyDev/data/validate.ts at main · aRustyDev/aRustyDev · GitHub
aRustyDev
/
aRustyDev
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
31
Pull requests
10
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aRustyDev
/
data
/
validate.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (70 loc) · 2.61 KB
Breadcrumbs
aRustyDev
/
data
/
validate.ts
Copy path
File metadata and controls
87 lines (70 loc) · 2.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
type
{
CV
,
ResumeProfile
}
from
"./schema.js"
;
const
COLLECTIONS
=
[
"experience"
,
"education"
,
"skills"
,
"projects"
,
"certifications"
]
as
const
;
export
function
validateCV
(
cv
:
unknown
)
: asserts
cv
is
CV
{
if
(
!
cv
||
typeof
cv
!==
"object"
)
{
throw
new
Error
(
"CV must be an object"
)
;
}
const
data
=
cv
as
Record
<
string
,
unknown
>
;
if
(
!
data
.
personal
||
typeof
data
.
personal
!==
"object"
)
{
throw
new
Error
(
"CV must have a personal section"
)
;
}
const
personal
=
data
.
personal
as
Record
<
string
,
unknown
>
;
for
(
const
field
of
[
"name"
,
"email"
,
"phone"
,
"location"
]
)
{
if
(
typeof
personal
[
field
]
!==
"string"
)
{
throw
new
Error
(
`personal.
${
field
}
must be a string`
)
;
}
}
if
(
!
personal
.
links
||
typeof
personal
.
links
!==
"object"
)
{
throw
new
Error
(
"personal.links must be an object"
)
;
}
for
(
const
collection
of
COLLECTIONS
)
{
if
(
!
Array
.
isArray
(
data
[
collection
]
)
)
{
throw
new
Error
(
`CV must have a
${
collection
}
array`
)
;
}
const
entries
=
data
[
collection
]
as
Array
<
Record
<
string
,
unknown
>
>
;
const
ids
=
new
Set
<
string
>
(
)
;
for
(
const
entry
of
entries
)
{
if
(
typeof
entry
.
id
!==
"string"
||
entry
.
id
===
""
)
{
throw
new
Error
(
`Each
${
collection
}
entry must have a non-empty id`
)
;
}
if
(
ids
.
has
(
entry
.
id
)
)
{
throw
new
Error
(
`Duplicate id "
${
entry
.
id
}
" in
${
collection
}
`
)
;
}
ids
.
add
(
entry
.
id
)
;
}
}
}
export
function
validateProfile
(
profile
:
unknown
)
: asserts
profile
is
ResumeProfile
{
if
(
!
profile
||
typeof
profile
!==
"object"
)
{
throw
new
Error
(
"Profile must be an object"
)
;
}
const
data
=
profile
as
Record
<
string
,
unknown
>
;
if
(
typeof
data
.
slug
!==
"string"
||
data
.
slug
===
""
)
{
throw
new
Error
(
"Profile must have a non-empty slug"
)
;
}
if
(
typeof
data
.
title
!==
"string"
||
data
.
title
===
""
)
{
throw
new
Error
(
"Profile must have a non-empty title"
)
;
}
if
(
!
data
.
include
||
typeof
data
.
include
!==
"object"
)
{
throw
new
Error
(
"Profile must have an include section"
)
;
}
const
include
=
data
.
include
as
Record
<
string
,
unknown
>
;
for
(
const
collection
of
COLLECTIONS
)
{
if
(
!
Array
.
isArray
(
include
[
collection
]
)
)
{
throw
new
Error
(
`include.
${
collection
}
must be an array`
)
;
}
}
if
(
data
.
overrides
)
{
if
(
typeof
data
.
overrides
!==
"object"
)
{
throw
new
Error
(
"overrides must be an object"
)
;
}
for
(
const
path
of
Object
.
keys
(
data
.
overrides
as
object
)
)
{
const
parts
=
path
.
split
(
"."
)
;
if
(
parts
.
length
!==
3
)
{
throw
new
Error
(
`Override path "
${
path
}
" must be <collection>.<id>.<field> (3 parts)`
,
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL