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
f33e4e0c
Commit
f33e4e0c
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
EnonceHelper => Add enonce file validation
parent
2c20405b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
helpers/Dojo/SharedEnonceHelper.ts
+71
-0
71 additions, 0 deletions
helpers/Dojo/SharedEnonceHelper.ts
with
71 additions
and
0 deletions
helpers/Dojo/SharedEnonceHelper.ts
0 → 100644
+
71
−
0
View file @
f33e4e0c
import
Ajv
,
{
ErrorObject
,
JTDSchemaType
}
from
'
ajv/dist/jtd
'
;
import
fs
from
'
fs
'
;
import
JSON5
from
'
json5
'
;
import
EnonceFile
from
'
../../types/Dojo/EnonceFile
'
;
class
SharedEnonceHelper
{
private
validateDescriptionFileV1
(
resultsFilePathOrStr
:
string
,
isFile
:
boolean
=
true
):
{
results
:
EnonceFile
|
undefined
,
isValid
:
boolean
,
errors
:
Array
<
ErrorObject
|
string
>
|
null
|
undefined
}
{
const
ajv
=
new
Ajv
();
const
schema
:
JTDSchemaType
<
EnonceFile
>
=
{
properties
:
{
dojoEnonceVersion
:
{
type
:
'
uint32
'
},
version
:
{
type
:
'
uint32
'
},
immutable
:
{
elements
:
{
properties
:
{
description
:
{
type
:
'
string
'
},
path
:
{
type
:
'
string
'
},
isDirectory
:
{
type
:
'
boolean
'
}
}
}
},
result
:
{
properties
:
{
container
:
{
type
:
'
string
'
},
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
any
,
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
:
EnonceFile
|
undefined
,
isValid
:
boolean
,
errors
:
Array
<
ErrorObject
|
string
>
|
null
|
undefined
}
{
switch
(
version
)
{
case
1
:
return
this
.
validateDescriptionFileV1
(
resultsFilePathOrStr
,
isFile
);
default
:
return
{
results
:
undefined
,
isValid
:
false
,
errors
:
[
`Version
${
version
}
not supported`
]
};
}
}
}
export
default
new
SharedEnonceHelper
();
\ No newline at end of file
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