-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: enhance utils, fixtures & imports
- Loading branch information
Showing
30 changed files
with
385 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * as eventsValidationSchemas from "./events/index"; | ||
export * as eventsValidationSchemas from "./events/index.js"; | ||
export { metadata } from "./metadata.json"; | ||
export { scope } from "./scope.json"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Import Third-party Dependencies | ||
import Ajv, { ErrorObject, ValidateFunction } from "ajv"; | ||
|
||
// Import Internal Dependencies | ||
import { eventsValidationSchemas } from "../schema/index.js"; | ||
|
||
// CONSTANTS | ||
const ajv = new Ajv(); | ||
|
||
export type NestedValidationFunctions = Map<string, ValidateFunction<Record<string, any>>>; | ||
|
||
type MappedEventsValidationFn = Map<string, NestedValidationFunctions>; | ||
|
||
export const eventsValidationFn: MappedEventsValidationFn = new Map<string, NestedValidationFunctions>(); | ||
|
||
for (const [name, validationSchemas] of Object.entries(eventsValidationSchemas)) { | ||
const operationsValidationFunctions: Map<string, ValidateFunction<Record<string, any>>> = new Map(); | ||
|
||
for (const [operation, validationSchema] of Object.entries(validationSchemas)) { | ||
operationsValidationFunctions.set(operation, ajv.compile(validationSchema)); | ||
} | ||
|
||
eventsValidationFn.set(name, operationsValidationFunctions); | ||
} | ||
|
||
export function concatErrors( | ||
errors: ErrorObject<string, Record<string, any>, unknown>[] | ||
): string { | ||
return errors | ||
.map((error) => `${error.instancePath ? `${error.instancePath}: ` : ""}${error.message}`) | ||
.join("|"); | ||
} |
Oops, something went wrong.