17
17
import fs from "node:fs" ;
18
18
import Ajv from "ajv" ;
19
19
import addFormats from "ajv-formats" ;
20
- import { join } from "node:path" ;
20
+ import path from "node:path" ;
21
21
import yaml = require( "js-yaml" ) ;
22
22
23
23
export module SWSchemaValidator {
@@ -30,7 +30,7 @@ export module SWSchemaValidator {
30
30
export const defaultEncoding = "utf-8" ;
31
31
32
32
export function prepareSchemas ( ) {
33
- fs . readdirSync ( join ( __dirname , schemaPath ) , {
33
+ fs . readdirSync ( path . join ( __dirname , schemaPath ) , {
34
34
encoding : defaultEncoding ,
35
35
recursive : false ,
36
36
withFileTypes : true ,
@@ -41,20 +41,20 @@ export module SWSchemaValidator {
41
41
} ) ;
42
42
}
43
43
44
- function syncReadSchema ( filename : string ) {
45
- return toJSON ( join ( __dirname , `${ schemaPath } /${ filename } ` ) ) ;
44
+ function syncReadSchema ( filename : string ) : any {
45
+ return toJSON ( path . join ( __dirname , `${ schemaPath } /${ filename } ` ) ) ;
46
46
}
47
47
48
- export function toJSON ( filename : string ) {
48
+ export function toJSON ( filename : string ) : any {
49
49
const yamlObj = yaml . load ( fs . readFileSync ( filename , defaultEncoding ) , {
50
50
json : true ,
51
51
} ) ;
52
- return JSON . parse ( JSON . stringify ( yamlObj , null , 2 ) ) ;
52
+ return structuredClone ( yamlObj ) ;
53
53
}
54
54
55
- export function validateSchema ( workflow : JSON ) {
55
+ export function validateSchema ( workflow : Record < string , unknown > ) {
56
56
const validate = ajv . getSchema ( workflowSchemaId ) ;
57
- if ( validate != undefined ) {
57
+ if ( validate ) {
58
58
const isValid = validate ( workflow ) ;
59
59
return {
60
60
valid : isValid ,
0 commit comments