Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeSharedCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Shared
NodeSharedCode
Commits
36004dfe
Commit
36004dfe
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
SharedAssignmentHelper => Adapt to zod library
parent
e24287ee
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
helpers/Dojo/SharedAssignmentHelper.ts
+10
-64
10 additions, 64 deletions
helpers/Dojo/SharedAssignmentHelper.ts
with
10 additions
and
64 deletions
helpers/Dojo/SharedAssignmentHelper.ts
+
10
−
64
View file @
36004dfe
import
Ajv
,
{
ErrorObject
,
JTDSchemaType
}
from
'
ajv/dist/jtd
'
;
import
fs
from
'
fs
'
;
import
JSON5
from
'
json5
'
;
import
AssignmentFile
from
'
../../types/Dojo/AssignmentFile
'
;
import
GitlabPipelineStatus
from
'
../../types/Gitlab/GitlabPipelineStatus
'
;
import
DojoStatusCode
from
'
../../types/Dojo/DojoStatusCode
'
;
import
GitlabPipeline
from
'
../../types/Gitlab/GitlabPipeline
'
;
import
SharedGitlabManager
from
'
../../managers/SharedGitlabManager
'
;
import
AssignmentFile
from
'
../../types/Dojo/AssignmentFile
'
;
import
GitlabPipelineStatus
from
'
../../types/Gitlab/GitlabPipelineStatus
'
;
import
DojoStatusCode
from
'
../../types/Dojo/DojoStatusCode
'
;
import
GitlabPipeline
from
'
../../types/Gitlab/GitlabPipeline
'
;
import
SharedGitlabManager
from
'
../../managers/SharedGitlabManager
'
;
import
Json5FileValidator
from
'
../Json5FileValidator
'
;
class
SharedAssignmentHelper
{
private
validateDescriptionFileV1
(
resultsFilePathOrStr
:
string
,
isFile
:
boolean
=
true
):
{
results
:
AssignmentFile
|
undefined
,
isValid
:
boolean
,
errors
:
Array
<
ErrorObject
|
string
>
|
null
|
undefined
}
{
const
ajv
=
new
Ajv
();
const
schema
:
JTDSchemaType
<
AssignmentFile
>
=
{
properties
:
{
dojoAssignmentVersion
:
{
type
:
'
uint32
'
},
version
:
{
type
:
'
uint32
'
},
immutable
:
{
elements
:
{
properties
:
{
path
:
{
type
:
'
string
'
}
},
optionalProperties
:
{
description
:
{
type
:
'
string
'
},
isDirectory
:
{
type
:
'
boolean
'
}
}
}
},
result
:
{
properties
:
{
container
:
{
type
:
'
string
'
}
},
optionalProperties
:
{
volume
:
{
type
:
'
string
'
}
}
}
},
additionalProperties
:
false
};
const
validator
=
ajv
.
compile
(
schema
);
try
{
const
results
=
JSON5
.
parse
(
isFile
?
fs
.
readFileSync
(
resultsFilePathOrStr
,
'
utf8
'
)
:
resultsFilePathOrStr
);
const
isValid
=
validator
(
results
);
return
{
results
:
isValid
?
results
:
results
as
AssignmentFile
,
isValid
:
isValid
,
errors
:
validator
.
errors
};
}
catch
(
error
)
{
return
{
results
:
undefined
,
isValid
:
false
,
errors
:
[
`JSON5 invalid :
${
JSON
.
stringify
(
error
)
}
`
]
};
}
}
validateDescriptionFile
(
resultsFilePathOrStr
:
string
,
isFile
:
boolean
=
true
,
version
:
number
=
1
):
{
results
:
AssignmentFile
|
undefined
,
isValid
:
boolean
,
errors
:
Array
<
ErrorObject
|
string
>
|
null
|
undefined
}
{
validateDescriptionFile
(
filePathOrStr
:
string
,
isFile
:
boolean
=
true
,
version
:
number
=
1
):
{
content
:
AssignmentFile
|
undefined
,
isValid
:
boolean
,
error
:
string
|
null
}
{
switch
(
version
)
{
case
1
:
return
this
.
validateDescriptionFileV1
(
resultsF
ilePathOrStr
,
isFile
);
return
Json5FileValidator
.
validateFile
(
AssignmentFile
,
f
ilePathOrStr
,
isFile
);
default
:
return
{
results
:
undefined
,
content
:
undefined
,
isValid
:
false
,
error
s
:
[
`Version
${
version
}
not supported`
]
error
:
`Version
${
version
}
not supported`
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment