Compare commits
No commits in common. "206a6220cc62f99d8e9de8a09a4a658b608304d0" and "4a291d79351b2b90ff086340d9c51d35922cf41b" have entirely different histories.
206a6220cc
...
4a291d7935
8 changed files with 18 additions and 119 deletions
|
@ -25,7 +25,6 @@ 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" ]*
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
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).
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
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: 11
|
||||
sidebar_position: 10
|
||||
description: Used for validating data.
|
||||
---
|
||||
|
||||
# `CoreValidationSingle`
|
||||
Validates some data against a set of predefined rules.
|
||||
Provides the default configuration for the CORE Framework.
|
||||
|
||||
|
||||
## Variables
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@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",
|
||||
"@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.3.2",
|
||||
"@docusaurus/tsconfig": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/tsconfig": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@types/node": "^20.12.5",
|
||||
"typescript": "~5.4.4"
|
||||
},
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
# 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
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
## Validates some [param data] against a set of predefined rules.
|
||||
## Validates some data against a set of rules.
|
||||
extends Node
|
||||
class_name CoreValidationSingle
|
||||
|
||||
|
@ -38,10 +38,9 @@ var rules: Array[Dictionary]
|
|||
var failures: Array[String] = []
|
||||
|
||||
# +++ constructor +++
|
||||
func _init(core_new: Core, data_new, parent_new: Node) -> void:
|
||||
func _init(core_new: Core, data_new) -> 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 +++
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
## Allows for data validation.
|
||||
extends CoreBaseModule
|
||||
|
||||
var schemas: Array[CoreValidationSchema]
|
||||
#var schemas: Dictionary
|
||||
var singles: Array[CoreValidationSingle]
|
||||
|
||||
# +++ module +++
|
||||
func _cleanup() -> void:
|
||||
# Singles
|
||||
var singles_remove_enty: Array[CoreLoggerInstance] = []
|
||||
for single in singles:
|
||||
singles_remove_enty.append(single)
|
||||
|
@ -33,38 +32,16 @@ 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()
|
||||
|
||||
# Schemas
|
||||
for schema in schemas:
|
||||
if is_instance_valid(schema):
|
||||
logger.diag("Removing schema '" + schema.name + "'")
|
||||
schema.queue_free()
|
||||
|
||||
# +++ data validation +++
|
||||
## Returns a new [CoreValidationSingle]
|
||||
func get_single(data, parent: Node) -> CoreValidationSingle:
|
||||
singles.append(parent)
|
||||
return CoreValidationSingle.new(core, data, parent)
|
||||
#func get_schema(Dictionary schema) -> CoreValidationSchema:
|
||||
# return CoreValidationSchema.new(core, schema)
|
||||
|
||||
## Returns a new [CoreValidationSchema]
|
||||
func get_schema(schema: Dictionary, parent: Node) -> CoreValidationSchema:
|
||||
schemas.append(parent)
|
||||
return CoreValidationSchema.new(core, schema, parent)
|
||||
func get_single(data, parent) -> CoreValidationSingle:
|
||||
singles.append(parent)
|
||||
return CoreValidationSingle.new(core, data)
|
||||
|
|
Loading…
Reference in a new issue