Compare commits
5 commits
4a291d7935
...
206a6220cc
Author | SHA1 | Date | |
---|---|---|---|
206a6220cc | |||
640b8ce6a2 | |||
307a4c7533 | |||
3ee429c63b | |||
7d8c5f295a |
8 changed files with 119 additions and 18 deletions
|
@ -25,6 +25,7 @@ Use these to access CORE's modules.
|
||||||
- [`sms`](/reference/sms)
|
- [`sms`](/reference/sms)
|
||||||
- [`erm`](/reference/erm) (formerly `edl`)
|
- [`erm`](/reference/erm) (formerly `edl`)
|
||||||
- [`storage`](/reference/storage)
|
- [`storage`](/reference/storage)
|
||||||
|
- [`validation`](/reference/validation)
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
### *Array[String]* <u>modules</u> = *[ "logger", "misc", "sms", "logui", "erm", "storage" ]*
|
### *Array[String]* <u>modules</u> = *[ "logger", "misc", "sms", "logui", "erm", "storage" ]*
|
||||||
|
|
13
docs/docs/reference/validation.md
Normal file
13
docs/docs/reference/validation.md
Normal 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).
|
12
docs/docs/reference/validationschema.md
Normal file
12
docs/docs/reference/validationschema.md
Normal 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.
|
|
@ -1,10 +1,10 @@
|
||||||
---
|
---
|
||||||
sidebar_position: 10
|
sidebar_position: 11
|
||||||
description: Used for validating data.
|
description: Used for validating data.
|
||||||
---
|
---
|
||||||
|
|
||||||
# `CoreValidationSingle`
|
# `CoreValidationSingle`
|
||||||
Provides the default configuration for the CORE Framework.
|
Validates some data against a set of predefined rules.
|
||||||
|
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
"typecheck": "tsc"
|
"typecheck": "tsc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docusaurus/core": "3.2.1",
|
"@docusaurus/core": "3.3.2",
|
||||||
"@docusaurus/plugin-client-redirects": "^3.2.1",
|
"@docusaurus/plugin-client-redirects": "^3.3.2",
|
||||||
"@docusaurus/plugin-content-docs": "^3.2.1",
|
"@docusaurus/plugin-content-docs": "^3.3.2",
|
||||||
"@docusaurus/plugin-sitemap": "^3.2.1",
|
"@docusaurus/plugin-sitemap": "^3.3.2",
|
||||||
"@docusaurus/preset-classic": "3.2.1",
|
"@docusaurus/preset-classic": "3.3.2",
|
||||||
"@mdx-js/react": "^3.0.1",
|
"@mdx-js/react": "^3.0.1",
|
||||||
"clsx": "^2.1.0",
|
"clsx": "^2.1.0",
|
||||||
"prism-react-renderer": "^2.3.1",
|
"prism-react-renderer": "^2.3.1",
|
||||||
|
@ -27,9 +27,9 @@
|
||||||
"react-dom": "^18.2.0"
|
"react-dom": "^18.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@docusaurus/module-type-aliases": "3.2.1",
|
"@docusaurus/module-type-aliases": "3.3.2",
|
||||||
"@docusaurus/tsconfig": "3.2.1",
|
"@docusaurus/tsconfig": "3.3.2",
|
||||||
"@docusaurus/types": "3.2.1",
|
"@docusaurus/types": "3.3.2",
|
||||||
"@types/node": "^20.12.5",
|
"@types/node": "^20.12.5",
|
||||||
"typescript": "~5.4.4"
|
"typescript": "~5.4.4"
|
||||||
},
|
},
|
||||||
|
|
51
src/classes/validationschema.gd
Normal file
51
src/classes/validationschema.gd
Normal 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
|
|
@ -15,7 +15,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# 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
|
extends Node
|
||||||
class_name CoreValidationSingle
|
class_name CoreValidationSingle
|
||||||
|
|
||||||
|
@ -38,9 +38,10 @@ var rules: Array[Dictionary]
|
||||||
var failures: Array[String] = []
|
var failures: Array[String] = []
|
||||||
|
|
||||||
# +++ constructor +++
|
# +++ constructor +++
|
||||||
func _init(core_new: Core, data_new) -> void:
|
func _init(core_new: Core, data_new, parent_new: Node) -> void:
|
||||||
core = core_new
|
core = core_new
|
||||||
logger = core.logger.get_instance(core.basepath.replace("res://", "") + "src/classes/validationsingle.gd", self)
|
logger = core.logger.get_instance(core.basepath.replace("res://", "") + "src/classes/validationsingle.gd", self)
|
||||||
|
parent = parent_new
|
||||||
data = data_new
|
data = data_new
|
||||||
|
|
||||||
# +++ evaluation +++
|
# +++ evaluation +++
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
## Allows for data validation.
|
## Allows for data validation.
|
||||||
extends CoreBaseModule
|
extends CoreBaseModule
|
||||||
|
|
||||||
#var schemas: Dictionary
|
var schemas: Array[CoreValidationSchema]
|
||||||
var singles: Array[CoreValidationSingle]
|
var singles: Array[CoreValidationSingle]
|
||||||
|
|
||||||
# +++ module +++
|
# +++ module +++
|
||||||
func _cleanup() -> void:
|
func _cleanup() -> void:
|
||||||
|
# Singles
|
||||||
var singles_remove_enty: Array[CoreLoggerInstance] = []
|
var singles_remove_enty: Array[CoreLoggerInstance] = []
|
||||||
for single in singles:
|
for single in singles:
|
||||||
singles_remove_enty.append(single)
|
singles_remove_enty.append(single)
|
||||||
|
@ -32,16 +33,38 @@ func _cleanup() -> void:
|
||||||
single.queue_free()
|
single.queue_free()
|
||||||
for single in singles_remove_enty:
|
for single in singles_remove_enty:
|
||||||
singles.remove_at(singles.find(single))
|
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:
|
func _schedule() -> void:
|
||||||
|
# Singles
|
||||||
for single in singles:
|
for single in singles:
|
||||||
if is_instance_valid(single):
|
if is_instance_valid(single):
|
||||||
logger.diag("Removing single '" + single.name + "'")
|
logger.diag("Removing single '" + single.name + "'")
|
||||||
single.queue_free()
|
single.queue_free()
|
||||||
|
|
||||||
|
# Schemas
|
||||||
|
for schema in schemas:
|
||||||
|
if is_instance_valid(schema):
|
||||||
|
logger.diag("Removing schema '" + schema.name + "'")
|
||||||
|
schema.queue_free()
|
||||||
|
|
||||||
# +++ data validation +++
|
# +++ data validation +++
|
||||||
#func get_schema(Dictionary schema) -> CoreValidationSchema:
|
## Returns a new [CoreValidationSingle]
|
||||||
# return CoreValidationSchema.new(core, schema)
|
func get_single(data, parent: Node) -> CoreValidationSingle:
|
||||||
|
|
||||||
func get_single(data, parent) -> CoreValidationSingle:
|
|
||||||
singles.append(parent)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue