Compare commits

...

5 commits

Author SHA1 Message Date
206a6220cc
Add CoreValidationSchema online documentation
plus validation module docs
2024-05-05 15:02:59 +02:00
640b8ce6a2
Update docusaurus 2024-05-05 15:01:12 +02:00
307a4c7533
Update script documentation 2024-05-05 15:01:01 +02:00
3ee429c63b
Add CoreValidationSchema code 2024-05-05 14:53:35 +02:00
7d8c5f295a
Fix issues 2024-05-05 14:53:21 +02:00
8 changed files with 119 additions and 18 deletions

View file

@ -25,6 +25,7 @@ Use these to access CORE's modules.
- [`sms`](/reference/sms)
- [`erm`](/reference/erm) (formerly `edl`)
- [`storage`](/reference/storage)
- [`validation`](/reference/validation)
## Constants
### *Array[String]* <u>modules</u> = *[ "logger", "misc", "sms", "logui", "erm", "storage" ]*

View file

@ -0,0 +1,13 @@
---
sidebar_position: 10
description: Allows for data validation.
---
# `Validation (module)`
## Functions
### *CoreValidationSingle* <u>get_single</u>(*anything you like* <u>data</u>, *Node* <u>parent</u>)
Returns a new [`CoreValidationSingle`](/reference/validationsingle).
### *CoreValidationSchema* <u>get_schema</u>(*Dictionary* <u>schema</u>, *Node* <u>parent</u>)
Returns a new [`CoreValidationSchema`](/reference/validationschema).

View file

@ -0,0 +1,12 @@
---
sidebar_position: 12
description: Used for validating multiple CoreValidationSingles.
---
# `CoreValidationSchema`
Validates multiple `CoreValidationSingle`s at once.
## Functions
### *Array[String]* <u>evaluate</u>()
Evaluates all singles and returns the names of all failed singles in an array.

View file

@ -1,10 +1,10 @@
---
sidebar_position: 10
sidebar_position: 11
description: Used for validating data.
---
# `CoreValidationSingle`
Provides the default configuration for the CORE Framework.
Validates some data against a set of predefined rules.
## Variables

View file

@ -15,11 +15,11 @@
"typecheck": "tsc"
},
"dependencies": {
"@docusaurus/core": "3.2.1",
"@docusaurus/plugin-client-redirects": "^3.2.1",
"@docusaurus/plugin-content-docs": "^3.2.1",
"@docusaurus/plugin-sitemap": "^3.2.1",
"@docusaurus/preset-classic": "3.2.1",
"@docusaurus/core": "3.3.2",
"@docusaurus/plugin-client-redirects": "^3.3.2",
"@docusaurus/plugin-content-docs": "^3.3.2",
"@docusaurus/plugin-sitemap": "^3.3.2",
"@docusaurus/preset-classic": "3.3.2",
"@mdx-js/react": "^3.0.1",
"clsx": "^2.1.0",
"prism-react-renderer": "^2.3.1",
@ -27,9 +27,9 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.2.1",
"@docusaurus/tsconfig": "3.2.1",
"@docusaurus/types": "3.2.1",
"@docusaurus/module-type-aliases": "3.3.2",
"@docusaurus/tsconfig": "3.3.2",
"@docusaurus/types": "3.3.2",
"@types/node": "^20.12.5",
"typescript": "~5.4.4"
},

View file

@ -0,0 +1,51 @@
# CORE FRAMEWORK SOURCE FILE
# Copyright (c) 2024 The StarOpenSource Project & Contributors
# Licensed under the GNU Affero General Public License v3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Validates multiple [CoreValidationSingle]s at once.
extends Node
class_name CoreValidationSchema
## Internal, don't modify.
var core: Core
## Internal, don't modify.
var logger: CoreLoggerInstance
## Internal, don't modify.
var parent: Node
## Contains the schema to validate.[br]
## [b]Note: [i]Don't modify.[/i][/b]
var schema: Dictionary = {}
func _init(core_new: Core, schema_new: Dictionary, parent_new: Node) -> void:
core = core_new
logger = core.logger.get_instance(core.basepath.replace("res://", "") + "src/classes/validationschema.gd", self)
parent = parent_new
schema = schema_new
# Check Dictionary
for key in schema:
if typeof(key) != TYPE_STRING: logger.error(core.stringify_variables("Could not parse schema: Schema key %key% is not of type String", { "key": key }))
elif typeof(schema[key]) != TYPE_OBJECT: logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type Object", { "key": key }))
elif schema[key].get_class() != "Node": logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type Node", { "key": key }))
func evaluate() -> Array[String]:
var failed: Array[String] = []
for single in schema:
if !schema[single].evaluate():
logger.error(core.stringify_variables("Single %single% failed", { "single": single }))
failed.append(single)
return failed

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Validates some data against a set of rules.
## Validates some [param data] against a set of predefined rules.
extends Node
class_name CoreValidationSingle
@ -38,9 +38,10 @@ var rules: Array[Dictionary]
var failures: Array[String] = []
# +++ constructor +++
func _init(core_new: Core, data_new) -> void:
func _init(core_new: Core, data_new, parent_new: Node) -> void:
core = core_new
logger = core.logger.get_instance(core.basepath.replace("res://", "") + "src/classes/validationsingle.gd", self)
parent = parent_new
data = data_new
# +++ evaluation +++

View file

@ -18,11 +18,12 @@
## Allows for data validation.
extends CoreBaseModule
#var schemas: Dictionary
var schemas: Array[CoreValidationSchema]
var singles: Array[CoreValidationSingle]
# +++ module +++
func _cleanup() -> void:
# Singles
var singles_remove_enty: Array[CoreLoggerInstance] = []
for single in singles:
singles_remove_enty.append(single)
@ -32,16 +33,38 @@ func _cleanup() -> void:
single.queue_free()
for single in singles_remove_enty:
singles.remove_at(singles.find(single))
# Schemas
var schemas_remove_enty: Array[CoreLoggerInstance] = []
for schema in schemas:
singles_remove_enty.append(schema)
if !is_instance_valid(schema): continue
if !is_instance_valid(schema.parent):
logger.diag("Removing schema '" + schema.name + "'")
schema.queue_free()
for schema in schemas_remove_enty:
schemas.remove_at(schemas.find(schema))
func _schedule() -> void:
# Singles
for single in singles:
if is_instance_valid(single):
logger.diag("Removing single '" + single.name + "'")
single.queue_free()
# +++ data validation +++
#func get_schema(Dictionary schema) -> CoreValidationSchema:
# return CoreValidationSchema.new(core, schema)
# Schemas
for schema in schemas:
if is_instance_valid(schema):
logger.diag("Removing schema '" + schema.name + "'")
schema.queue_free()
func get_single(data, parent) -> CoreValidationSingle:
# +++ data validation +++
## Returns a new [CoreValidationSingle]
func get_single(data, parent: Node) -> CoreValidationSingle:
singles.append(parent)
return CoreValidationSingle.new(core, data)
return CoreValidationSingle.new(core, data, parent)
## Returns a new [CoreValidationSchema]
func get_schema(schema: Dictionary, parent: Node) -> CoreValidationSchema:
schemas.append(parent)
return CoreValidationSchema.new(core, schema, parent)