Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-mvc-framework

Package Overview
Dependencies
Maintainers
0
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-mvc-framework - npm Package Compare versions

Comparing version 1.3.12 to 1.3.13

demonstrament/documents/test/coutil-methods/index.js

69

demonstrament/application.config.js

@@ -42,6 +42,7 @@ import { readFile } from 'node:fs/promises'

main: 'index.html',
ignore: ['static-cms', 'test'],
clear: {
target: [
'*.{html,css,js,md,map}',
'!static-cms',
// '!static-cms', '!test',
],

@@ -64,3 +65,3 @@ source: [

output: 'index.css',
watch: ['**/*.scss', '!static-cms'],
watch: ['**/*.scss'],
}],

@@ -71,3 +72,3 @@ scripts: [{

output: 'index.js',
watch: ['**/*.js', '!static-cms'],
watch: ['**/*.js'],
external: ['/dependencies/mvc-framework.js']

@@ -77,2 +78,3 @@ }],

type: 'struct',
localsName: '$content',
outputType: 'server',

@@ -82,9 +84,10 @@ model: 'index.json',

output: 'index.html',
watch: ['**/*.{ejs,json}', '!**/\$.ejs', '!static-cms'],
watch: ['**/*.{ejs,json}', '!**/\$.ejs'],
}, {
type: 'struct',
localsName: '$content',
outputType: 'client',
input: '**/*.ejs',
output: '',
watch: ['**/\$*.ejs', '!index.ejs', '!static-cms'],
watch: ['**/\$*.ejs', '!index.ejs'],
}],

@@ -99,2 +102,3 @@ }

main: 'index.html',
ignore: [],
clear: {

@@ -125,2 +129,3 @@ target: [

type: 'struct',
localsName: '$content',
outputType: 'server',

@@ -133,2 +138,3 @@ model: 'index.json',

type: 'struct',
localsName: '$content',
outputType: 'client',

@@ -147,5 +153,6 @@ input: '**/*.ejs',

main: 'index.html',
ignore: ['schema'],
clear: {
target: [
'/**/*.{html,css,js,md}',
'/**/*.{html,css,js,md}'
],

@@ -173,2 +180,3 @@ source: [

type: 'struct',
localsName: '$content',
outputType: 'server',

@@ -181,2 +189,3 @@ model: 'index.json',

type: 'struct',
localsName: '$content',
outputType: 'client',

@@ -188,4 +197,52 @@ input: '**/*.ejs',

}
},
{
name: 'Test | Schema',
url: '/test/schema',
source: 'documents/test/schema',
target: 'localhost/test/schema',
main: 'index.html',
ignore: [],
clear: {
target: [
'/**/*.{html,css,js,md}',
],
source: [
'**/template.js'
],
},
documents: {
simules: [],
styles: [{
type: 'style',
input: 'index.scss',
output: 'index.css',
watch: ['**/*.scss'],
}],
scripts: [{
type: 'script',
input: 'index.js',
output: 'index.js',
watch: ['**/*.js'],
external: ['/dependencies/mvc-framework.js']
}],
structs: [{
type: 'struct',
localsName: '$content',
outputType: 'server',
model: 'index.json',
input: 'index.ejs',
output: 'index.html',
watch: ['**/*.{ejs,json}', '!**/\$.ejs'],
}, {
type: 'struct',
localsName: '$content',
outputType: 'client',
input: '**/*.ejs',
output: '',
watch: ['**/\$*.ejs'],
}],
}
}
],
}

@@ -80,2 +80,3 @@ import './coutil/persist/index.js'

files: this.#settings.browserSync.files,
// logLevel: 'silent',
proxy: {

@@ -82,0 +83,0 @@ target: [

5

demonstrament/application/pilers/ejs.piler.js

@@ -10,2 +10,3 @@ import createDir from '../coutil/createDir/index.js'

// Server
const localsName = $settings.localsName || '$content'
if($settings.outputType === 'server') {

@@ -18,3 +19,3 @@ try {

async: true,
localsName: '$content',
localsName,
root: [

@@ -42,3 +43,3 @@ path.join(

_with: false,
localsName: '$content',
localsName,
client: true,

@@ -45,0 +46,0 @@ compileDebug: false,

@@ -18,6 +18,6 @@ import * as Paths from './paths/index.js'

.then(() => {
this.structs
this.styles
this.scripts
this.simules
this.structs
this.styles
})

@@ -29,32 +29,38 @@ }

for(const $route of this.#_settings) {
// Ignore
for(const [
$ignorePathIndex, $ignorePath
] of Object.entries($route.ignore)) {
$route.ignore[$ignorePathIndex] = path.join(
'!'.concat($route.target), $ignorePath.replace(/^\!/, '')
)
}
// Clear Target
let clearTargetIndex = 0
for(const $clearTarget of $route.clear.target) {
for(const [
$clearTargetIndex, $clearTarget
] of Object.entries($route.clear.target)) {
if($clearTarget.charAt(0) === '!') {
$route.clear.target[clearTargetIndex] = path.join(
'!'.concat($route.target), $clearTarget
.replace(/^\!/, '')
$route.clear.target[$clearTargetIndex] = path.join(
'!'.concat($route.target), $clearTarget.replace(/^\!/, '')
)
} else {
$route.clear.target[clearTargetIndex] = path.join(
$route.clear.target[$clearTargetIndex] = path.join(
$route.target, $clearTarget
)
}
// $route.target, $clearTarget
clearTargetIndex++
$route.clear.target.unshift(...$route.ignore)
}
// Clear Source
let clearSourceIndex = 0
for(const $clearSource of $route.clear.source) {
for(const [
$clearSourceIndex, $clearSource
] of Object.entries($route.clear.source)) {
if($clearSource.charAt(0) === '!') {
$route.clear.target[clearSourceIndex] = path.join(
'!'.concat($route.source.replace), $clearSource
.replace(/^\!/, '')
$route.clear.target[$clearSourceIndex] = path.join(
'!'.concat($route.source.replace), $clearSource.replace(/^\!/, '')
)
} else {
$route.clear.target[clearSourceIndex] = path.join(
$route.clear.target[$clearSourceIndex] = path.join(
$route.source, $clearSource
)
}
clearSourceIndex++
}

@@ -78,2 +84,3 @@ // Documents

}
console.log(this)
}

@@ -109,3 +116,5 @@ #clear() {

const watcher = watch($document.watch, {
// ignore: this.#settings.ignore,
ignoreInitial: false,
awaitWriteFinish: true,
})

@@ -125,3 +134,5 @@ watcher.on('add', ($path, $stats) => Pilers.RollupPiler($document))

const watcher = watch($document.watch, {
// ignore: this.#settings.ignore,
ignoreInitial: false,
awaitWriteFinish: true,
})

@@ -141,3 +152,5 @@ watcher.on('add', ($path, $stats) => Pilers.SimulePiler($document, $route, $path))

const watcher = watch($document.watch, {
// ignore: this.#settings.ignore,
ignoreInitial: false,
awaitWriteFinish: true,
})

@@ -157,3 +170,5 @@ watcher.on('add', ($path, $stats) => Pilers.EJSPiler($document, $route, $path))

const watcher = watch($document.watch, {
// ignore: this.#settings.ignore,
ignoreInitial: false,
awaitWriteFinish: true,
})

@@ -160,0 +175,0 @@ watcher.on('add', ($path, $stats) => Pilers.SASSPiler($document))

@@ -13,3 +13,3 @@ import path from 'node:path'

path.join(
$route.source, $watchPath.replace(new RegExp(/^\!/), '')
$route.source, $watchPath.replace(new RegExp(/^\!*/), '')
)

@@ -24,2 +24,3 @@ )

}
$documentPath.unshift(...$route.ignore)
}

@@ -1,47 +0,48 @@

import { Control, Model, Schema, Content } from '/dependencies/mvc-framework.js'
import DefaultTemplate from './template.js'
const index = new Control({
models: {
default: [{
schema: [{
type: {
'data-href': { type: String },
'textContent': { type: String },
}
}],
content: [{
'data-href': "./static-cms",
'textContent': "Static CMS"
}],
}, {}],
},
views: {
default: [{
parent: document.querySelector('body > main'),
templates: {
default: DefaultTemplate
},
querySelectors: {
querySelectorAll: {
'button': ':scope > nav > button',
},
},
events: {
'querySelectors.button click': ($event) => {
window.location = $event.currentTarget.getAttribute('data-href')
}
},
}, {}],
},
}, {
defineProperties: {
start: { value: function () {
console.log(this.models.default.parse())
this.views.default.render(
this.models.default.parse()
)
return this
} }
}
})
index.start()
console.log("hello all dogs")
// import { Control, Model, Schema, Content } from '/dependencies/mvc-framework.js'
// import DefaultTemplate from './template.js'
// const index = new Control({
// models: {
// default: [{
// schema: [{
// type: {
// 'data-href': { type: String },
// 'textContent': { type: String },
// }
// }],
// content: [{
// 'data-href': "./static-cms",
// 'textContent': "Static CMS"
// }],
// }, {}],
// },
// views: {
// default: [{
// parent: document.querySelector('body > main'),
// templates: {
// default: DefaultTemplate
// },
// querySelectors: {
// querySelectorAll: {
// 'button': ':scope > nav > button',
// },
// },
// events: {
// 'querySelectors.button click': ($event) => {
// window.location = $event.currentTarget.getAttribute('data-href')
// }
// },
// }, {}],
// },
// }, {
// defineProperties: {
// start: { value: function () {
// console.log(this.models.default.parse())
// this.views.default.render(
// this.models.default.parse()
// )
// return this
// } }
// }
// })
// index.start()
import { Coutil } from "/dependencies/mvc-framework.js"
const { expandTree } = Coutil
const { expandTree, impandTree } = Coutil
const impandedTree = {
propertyA: Number,
propertyB: String,
propertyC: Boolean,
}
const expandedTree = {
propertyA: {
type: {
value: Number
}
},
propertyB: {
type: {
value: String
}
},
propertyC: {
type: {
value: Boolean
}
},
}
console.log("impandTree", impandTree(expandedTree, "type.value"))
console.log("expandTree", expandTree(impandedTree, "type.value"))
/*
console.log(
"\n", "expandTree", expandTree({
type: Number
}, "type.value")
)
console.log(
"\n", "impandTree", impandTree({
type: {
value: Number
}
}, "type.value")
)
*/
// console.log(impandTree({
// type: {
// value: Number
// }
// }, "type.value"))
/*
console.log("validatorTree", expandTree({

@@ -22,2 +66,3 @@ propertyA: {

}
}], "value"))
}], "value"))
*/

@@ -1,282 +0,1 @@

import "./schema/index.js"
// import "./content-handler-trap-methods/defineProperty/index.js"
// import "./coutil-methods/pandTree/index.js"
// import { Model } from "/dependencies/mvc-framework.js"
// const eventLog = ($event) => {
// const { type, path, value, change, detail } = $event
// console.log(
// "\n", "type", type,
// "\n", "path", path,
// "\n", "value", value,
// "\n", "change", change,
// "\n", "detail", detail,
// )
// }
/*
const model = new Model({
schema: [{ type: {
propertyA: { type: {
propertyB: { type: String }
} }
} }],
content: [{
propertyA: {
propertyB: "333"
}
}, {
propertyA: {
propertyB: "4444"
}
}],
events: {
"content unshiftProp": eventLog,
// "change": eventLog
}
}, {
changeEvents: true,
validationEvents: true,
schema: { validationType: 'primitive' },
content: { proxyAssignmentMethod: 'assign' },
})
model.content.unshift({
propertyA: {
propertyB: "1"
}
}, {
propertyA: {
propertyB: "22"
}
}, {
propertyA: {
propertyB: "333"
}
})
*/
// const model = new Model({
// schema: {
// propertyA: { type: {
// propertyB: { type: {
// propertyC: { type: String }
// } }
// } }
// },
// content: {
// propertyA: { value: {
// propertyB: { value: {
// propertyC: { value: "###" }
// } }
// } }
// },
// localStorage: "/model",
// events: {
// // 'content validProperty': eventLog,
// // 'content nonvalidProperty': eventLog,
// 'change': eventLog
// }
// }, {
// changeEvents: true,
// validationEvents: true,
// schema: { validationType: 'primitive' },
// content: { proxyAssignmentMethod: 'assign' },
// })
// model.content.defineProperties({
// propertyA: { value: {
// propertyB: { value: {
// propertyC: { value: "###" }
// } }
// } }
// })
/*
const propertyDescriptorTree = {
aaa: {
value: {
bbb: {
value: [{
value: "ccc"
}, {
value: "ddd"
}]
},
eee: {
value: "eee"
}
}
}
}
const definePropertiesTree = ($descriptorTree) => {
let properties
if(Array.isArray($descriptorTree)) { properties = [] }
else if(typeof $descriptorTree === 'object') { properties = {} }
for(const [$propertyKey, $propertyDescriptor] of Object.entries($descriptorTree)) {
const propertyDescriptorValue = $propertyDescriptor.value
if(typeof propertyDescriptorValue === 'object') {
properties[$propertyKey] = definePropertiesTree(propertyDescriptorValue)
}
else {
properties[$propertyKey] = propertyDescriptorValue
}
}
return properties
}
console.log(propertyDescriptorTree)
console.log(definePropertiesTree(propertyDescriptorTree))
*/
/*
import { Model } from "/dependencies/mvc-framework.js"
const model = new Model({
schema: {
propertyA: { type: {
propertyB: { type: {
propertyC: { type: String }
} }
} }
},
content: {
// propertyA: {
// propertyB: {
// propertyC: "333333"
// }
// }
},
localStorage: "/model",
events: {
// 'content validProperty': ($event) => {
// console.log($event.type)
// },
// 'content nonvalidProperty': ($event) => {
// console.log($event.type)
// },
// 'change': ($event) => {
// console.log(
// "\n", "-----",
// "\n", $event.type,
// "\n", $event.path,
// "\n", $event.detail,
// // "\n", $event.detail
// )
// }
}
}, {
changeEvents: true,
validationEvents: true,
schema: { validationType: 'primitive' },
content: { proxyAssignmentMethod: 'assign' },
})
model.content.defineProperties({
propertyA: { value: {
propertyB: { value: {
propertyC: { value: "###" }
} }
} }
})
*/
// model.content.assign({
// propertyA: {
// propertyB: {
// propertyC: "3333"
// }
// }
// })
// model.content.assign({
// propertyA: {
// propertyB: {
// propertyC: "3333"
// }
// }
// })
// model.content.assign({
// propertyA: {
// propertyB: {
// propertyC: 3333
// }
// }
// })
// console.log(model.content.source)
// console.log(model.content.get("propertyA.propertyB").root)
// model.save()
// console.log(model.localStorage.get())
// model.unload()
// console.log(model.localStorage.get())
/*
import { View } from "/dependencies/mvc-framework.js"
const view = new View({
parent: document.createElement("app"),
templates: { default: () => `
<button>BUTTON</button>
` },
querySelectors: {
querySelector: {
button: ':scope > button',
}
},
events: {
"querySelectors.button click": ($event) => {
console.log($event.type, $event)
}
},
}).render()
document
.querySelector('main')
.insertAdjacentElement('afterbegin', view.parent)
*/
/*
import { Content, Model } from '/dependencies/mvc-framework.js'
// const content = new Content({
// propertyA: "AAA",
// })
// content.addEventListener('getProperty:propertyA', function getPropertyA($event) {
// console.log($event.type, $event.basename, $event.detail)
// })
// content.addEventListener('setProperty:propertyA', function setPropertyA($event) {
// console.log($event.type, $event.basename, $event.detail)
// })
// content.addEventListener('deleteProperty:propertyA', function deletePropertyA($event) {
// console.log($event.type, $event.basename, $event.detail)
// })
// content.get('propertyA')
// content.set('propertyA', "AAAAAA")
// content.delete('propertyA')
// content.get('propertyA')
const { schema, content } = new Model({
schema: {
propertyA: {
type: {
propertyB: {
type: {
propertyC: {
type: String
}
}
}
}
}
},
content: {
propertyA: {
propertyB: {
propertyC: "CCC"
}
}
},
events: {
"content.propertyA.propertyB getProperty:propertyC": function getPropertyC($event) {
console.log($event.type, $event.basename, $event.detail)
},
"content.propertyA.propertyB setProperty:propertyC": function setPropertyC($event) {
console.log($event.type, $event.basename, $event.detail)
},
"content.propertyA.propertyB deleteProperty:propertyC": function deletePropertyC($event) {
console.log($event.type, $event.basename, $event.detail)
},
}
}, { enableEvents: true })
content.get("propertyA.propertyB.propertyC")
content.set("propertyA.propertyB.propertyC", "CCCCCCCCC")
content.delete("propertyA.propertyB.propertyC")
*/
console.log("Hello All Dogs")

@@ -12,2 +12,21 @@ {

}],
"structure": [{
"tag": "index",
"structure": [{
"tag": "header",
"structure": [{
"tag": "h1",
"textContent": "MVC Framework | Test"
}]
}, {
"tag": "navigation",
"structure": [{
"tag": "a",
"attributes": {
"href": "./schema"
},
"textContent": "Schema Test"
}]
}]
}],
"scripts": [{

@@ -14,0 +33,0 @@ "tag": "script",

@@ -9,3 +9,3 @@ import * as Logs from "../coutil/logs/index.js"

iterateTestGroups:
for(const [$testGroupID, $testGroup] of Object.entries(Tests)) {
for(const [$testGroupID, $testGroup] of Object.entries(Tests).reverse()) {
console.log(

@@ -16,3 +16,3 @@ "\n", "-----",

iterateTests:
for(const [$testID, $testSettings] of Object.entries($testGroup)) {
for(const [$testID, $testSettings] of Object.entries($testGroup).reverse()) {
const test = new Test($testSettings).execute()

@@ -19,0 +19,0 @@ tests[$testGroupID][$testID] = test

@@ -10,11 +10,14 @@ import { Schema, Coutil } from '/dependencies/mvc-framework.js'

method: function() {
const schema = new Schema(expandTree({
const schema = new Schema({
propertyA: Boolean
})
const schemaB = new Schema(expandTree({
propertyA: Boolean
}, "type"))
const contentA = { propertyA: true }
const contentB = { propertyA: false }
const contentC = { propertyA: undefined }
const contentD = { propertyA: 0 }
const contentE = { propertyA: "1" }
const contentF = { propertyA: null }
const contentA = { propertyA: true } // true
const contentB = { propertyA: false } // true
const contentC = { propertyA: undefined } // false
const contentD = { propertyA: 0 } // false
const contentE = { propertyA: "1" } // false
const contentF = { propertyA: null } // false
const solve = [true, true, false, false, false, false]

@@ -21,0 +24,0 @@ const quest = []

@@ -17,2 +17,21 @@ import { Schema, Coutil } from '/dependencies/mvc-framework.js'

})
const schemaB = new Schema({
propertyA: {
type: Number,
min: -{
value: 1000,
messages: {
'true': ($verification) => `${verification.pass}`,
'false': ($verification) => `${verification.pass}`,
}
},
max: {
value: 1000,
messages: {
'true': ($verification) => `${verification.pass}`,
'false': ($verification) => `${verification.pass}`,
},
}
}
})
const contentA = { propertyA: 500 } // true

@@ -19,0 +38,0 @@ const contentB = { propertyA: -500 } // true

import testA from './testA.js'
import testB from './testB.js'
// import testC from './testC.js'
export {
testA,
// testB,
testB,
// testC,
}

@@ -8,5 +8,5 @@ import { Schema, Coutil } from '/dependencies/mvc-framework.js'

name: "Validation Type: Object",
descript: ``,
descript: `When validation type is "object" all properties must pass validation to assign values.`,
method: function() {
const schema = new Schema(expandTree({
const schema = new Schema({
propertyA: String,

@@ -17,3 +17,3 @@ propertyB: Boolean,

propertyE: undefined,
}, "type"), {
}, {
validationType: "object"

@@ -65,2 +65,3 @@ })

for(const $content of contents) {
// const contentValidation = schema.validate($content)
const contentValidation = schema.validate($content)

@@ -80,2 +81,2 @@ validations.push(contentValidation)

},
}
}

@@ -8,7 +8,72 @@ import { Schema, Coutil } from '/dependencies/mvc-framework.js'

name: "Validation Type: Primitive",
descript: ``,
descript: `When validation type is "primitive" only valid properties values assigned.`,
method: function() {
const schema = new Schema({
propertyA: String,
propertyB: Boolean,
propertyC: Number,
propertyD: null,
propertyE: undefined,
}, {
validationType: "primitive"
})
const contentA = {
propertyA: "11111",
propertyB: false,
propertyC: 33333,
propertyD: null,
propertyE: "55555",
} // true
const contentB = {
propertyA: 11111,
propertyB: false,
propertyC: "33333",
propertyD: null,
propertyE: 55555,
} // true
const contentC = {
propertyA: "11111",
propertyB: "false",
propertyC: 33333,
propertyD: "null",
propertyE: "55555"
} // true
const contentD = {
propertyA: false,
propertyB: "true",
propertyC: "33333",
propertyD: 44444,
propertyE: undefined,
} // true
const contentE = {
propertyA: "111111",
propertyB: "true",
propertyC: "33333",
propertyD: "44444",
propertyE: undefined,
} // true
const solve = [
true, true, true, true, true
]
const quest = []
const contents = [
contentA, contentB, contentC, contentD, contentE
]
const validations = []
for(const $content of contents) {
// const contentValidation = schema.validate($content)
const contentValidation = schema.validate($content)
validations.push(contentValidation)
quest.push(contentValidation.valid)
}
this.pass = (JSON.stringify(quest) === JSON.stringify(solve))
this.detail = {
schema,
contents,
quest,
solve,
validations,
}
return this
},
}

@@ -21,4 +21,4 @@ import * as groupA from './groupA/index.js'

export {
// groupA,
groupA,
groupB
}

@@ -24,5 +24,6 @@ export default function anonymous($content, escapeFn, include, rethrow) {

if (s !== undefined && s !== null) __output += s
}
};
console.log($content)
return __output;
}

@@ -13,6 +13,6 @@ {

"devDependencies": {
"browser-sync": "^2.26.2",
"browser-sync-client": "^3.0.2",
"browser-sync": "^3.0.3",
"browser-sync-client": "^3.0.3",
"ejs": "^3.1.10",
"express": "^4.21.0",
"express": "^4.21.2",
"glob": "^11.0.0",

@@ -19,0 +19,0 @@ "glob-watcher": "^6.0.0",

@@ -1,17 +0,30 @@

import typeOf from './typeOf/index.js'
import { impandEvents, expandEvents } from './pandEvents/index.js'
import { impandTree, expandTree } from './pandTree/index.js'
import { expandEvents, impandEvents } from './pandEvents/index.js'
import { expandTree, impandTree } from './pandTree/index.js'
import isPropertyDefinition from './isPropertyDefinition/index.js'
import isPropertyValidator from './isPropertyValidator/index.js'
import * as path from './path/index.js'
import recursiveAssign from './recursiveAssign/index.js'
import regularExpressions from './regularExpressions/index.js'
import * as tree from './tree/index.js'
import typeOf from './typeOf/index.js'
import typedObjectLiteral from './typedObjectLiteral/index.js'
import typedObjectLiteralFromPath from './typedObjectLiteralFromPath/index.js'
import * as variables from './variables/index.js'
export {
typeOf,
// Pand Events
impandEvents, expandEvents,
expandEvents, impandEvents,
// Pand Tree
impandTree, expandTree,
expandTree, impandTree,
isPropertyDefinition,
isPropertyValidator,
path,
recursiveAssign,
regularExpressions,
tree,
typeOf,
typedObjectLiteral,
typedObjectLiteralFromPath,
variables,
}

@@ -0,12 +1,19 @@

import * as Variables from '../variables/index.js'
import * as Path from '../path/index.js'
import * as Tree from '../tree/index.js'
import typedObjectLiteral from "../typedObjectLiteral/index.js"
function impandTree($tree, $retainKey) {
let tree = typedObjectLiteral($tree)
for(const [$treeKey, $treeNode] of Object.entries($tree)) {
const retainValue = $treeNode[$retainKey]
if(retainValue && typeof retainValue === 'object') {
tree[$treeKey] = impandTree(retainValue, $retainKey)
function impandTree($root, $tree) {
const typeofTree = typeof $tree
const typeofRoot = typeof $root
if(
!['string', 'function'].includes(typeofTree) ||
typeofRoot && typeofRoot !== 'object'
) { return undefined /*$root*/ }
let tree = typedObjectLiteral($root)
if(typeofRoot === 'object') {
iterateRootEntries:
for(const [$rootKey, $rootValue] of Object.entries($root)) {
if(typeofTree === 'string') { tree[$rootKey] = Tree.get($tree, $rootValue) }
else if(typeofTree === 'function') { tree = $tree($rootValue) }
}
else {
tree[$treeKey] = retainValue
}
}

@@ -16,18 +23,21 @@ return tree

function expandTree($tree = {}, $retainKey, $altKeys = {}) {
if($retainKey === undefined) return undefined
let tree = typedObjectLiteral($tree)
for(const [$treeKey, $treeNode] of Object.entries($tree)) {
const retainValue = $treeNode
if(retainValue && typeof retainValue === 'object') {
tree[$treeKey] = Object.assign({
[$retainKey]: expandTree(retainValue, $retainKey, $altKeys)
}, $altKeys)
function expandTree($root, $tree) {
const typeofRoot = typeof $root
const typeofTree = typeof $tree
if(
!['string', 'function'].includes(typeofTree) // ||
// (typeofRoot && typeofRoot !== 'object')
) { return undefined /*$root*/ }
let tree
if($root && typeofRoot === 'object') {
iterateRootEntries:
for(const [$rootKey, $rootValue] of Object.entries($root)) {
if(typeofTree === 'string') { tree = Tree.set($tree, $rootValue) }
else if(typeofTree === 'function') { tree = $tree($rootValue) }
}
else {
tree[$treeKey] = Object.assign({
[$retainKey]: retainValue
}, $altKeys)
}
}
else {
if(typeofTree === 'string') { tree = Tree.set($tree, $root) }
else if(typeofTree === 'function') { tree = $tree($root) }
}
return tree

@@ -34,0 +44,0 @@ }

@@ -1,2 +0,4 @@

import { typeOf, typedObjectLiteral } from '../../Coutil/index.js'
import {
expandTree, isPropertyDefinition, typedObjectLiteral, typeOf, variables as Variables
} from '../../Coutil/index.js'
import Content from '../Content/index.js'

@@ -12,2 +14,3 @@ import Verification from './Verification/index.js'

}
export default class Schema extends EventTarget{

@@ -42,48 +45,73 @@ options

for(const [
$contextKey, $contextValue
$propertyKey, $propertyDefinition
] of Object.entries(properties)) {
let contextValue
// Context Value: Schema
if($contextValue instanceof Schema) {
this.#_context[$contextKey] = $contextValue
continue iterateProperties
const typeOfPropertyDefinition = typeOf($propertyDefinition)
let propertyDefinition
// Property Definition: Schema
if($propertyDefinition instanceof Schema) {
propertyDefinition = expandTree($propertyDefinition, 'type.value')
}
// Context Value: Object
else if(
typeof $contextValue.type === 'object' && $contextValue.type
) {
this.#_context[$contextKey] = new Schema($contextValue.type, this.options)
continue iterateProperties
// Property Definition: String, Number, Boolean, Object, Array, null, undefined
else if(Variables.TypeValues.includes($propertyDefinition)) {
propertyDefinition = expandTree($propertyDefinition, 'type.value')
}
// Context Value: Primitive, Null
else {
this.#_context[$contextKey] = $contextValue
// Property Definition: 'string', 'number', 'boolean', 'object', 'array', 'null', 'undefined'
else if(Variables.TypeKeys.includes($propertyDefinition)) {
propertyDefinition = expandTree(Variables.TypeValues[
Variables.TypeKeys.indexOf($propertyDefinition)
], 'type.value')
}
// Context Validators
this.#_context[$contextKey].validators = (this.#_context[$contextKey].validators)
? this.#_context[$contextKey].validators
: [new TypeValidator()]
// this.#_context[$contextKey].validators.unshift()
const addValidators = []
// Context Validator: Add Range
if(
typeof this.#_context[$contextKey].min === 'number' ||
typeof this.#_context[$contextKey].max === 'number'
) { addValidators.push(new RangeValidator({})) }
// Context Validator: Add Length
if(
typeof this.#_context[$contextKey].minLength === 'number' ||
typeof this.#_context[$contextKey].maxLength === 'number'
) { addValidators.push(new LengthValidator()) }
// Context Validator: Add Enum
if(
Array.isArray(this.#_context[$contextKey].enum) &&
this.#_context[$contextKey].enum.length > 0
) { addValidators.push(new EnumValidator()) }
// Context Validator: Add Match
if(
Array.isArray(this.#_context[$contextKey].match) &&
this.#_context[$contextKey].match.length > 0
) { addValidators.push(new MatchValidator()) }
this.#_context[$contextKey].validators = this.#_context[$contextKey].validators.concat(addValidators)
// Property Definition: Object Literal
else if(typeOfPropertyDefinition === 'object') {
let propertyDefinitionIsPropertyDefinition = isPropertyDefinition($propertyDefinition)
if(propertyDefinitionIsPropertyDefinition === false) {
propertyDefinition = {
type: {
value: new Schema($propertyDefinition, this.options)
}
}
}
else if(propertyDefinitionIsPropertyDefinition === true) {
propertyDefinition = {}
// Property Definition:
iteratePropertyValidators:
for(const [
$propertyValidatorName, $propertyValidator
] of Object.entries($propertyDefinition)) {
if($propertyValidatorName === 'validators') { continue iteratePropertyValidators }
const typeOfPropertyValidator = typeOf($propertyValidator)
let propertyValidator
if(typeOfPropertyValidator && typeOfPropertyValidator === 'object') {
propertyValidator = $propertyValidator
}
else {
propertyValidator = {
value: $propertyValidator
}
}
propertyDefinition[$propertyValidatorName] = propertyValidator
}
}
}
propertyDefinition.validators = []
const validators = {}
const {
type,
min, max,
minLength, maxLength,
match,
} = propertyDefinition
if(type) validators.type = { properties: { type }, validator: TypeValidator }
if(min || max) validators.range = { properties: { min, max }, validator: RangeValidator }
if(minLength || maxLength) validators.length = { properties: { minLength, maxLength }, validator: LengthValidator }
if(propertyDefinition.enum) validators.enum = { properties: { enum: propertyDefinition.enum }, validator: EnumValidator }
if(match) validators.match = { properties: { match }, validator: MatchValidator }
for(const [
$validatorName, $validatorSettings
] of Object.entries(validators)) {
const { properties, validator } = $validatorSettings
propertyDefinition.validators.push(new validator(properties))
}
this.#_context[$propertyKey] = propertyDefinition
}

@@ -143,3 +171,3 @@ return this.#_context

type: null,
context: contextValue,
context: null,
key: $key,

@@ -146,0 +174,0 @@ value: $value,

@@ -0,1 +1,5 @@

const Messages = {
'true': ($validation) => `${$validation.valid}`,
'false': ($validation) => `${$validation.valid}`,
}
export default class Validation extends EventTarget {

@@ -8,5 +12,5 @@ #settings

#_unadvance = []
constructor($settings) {
constructor($settings = {}) {
super()
this.#settings = $settings
this.#settings = Object.assign({ messages: Messages }, $settings)
}

@@ -13,0 +17,0 @@ get type() { return this.#settings.type }

@@ -0,1 +1,5 @@

const Messages = {
'true': ($verification) => `${$verification.pass}`,
'false': ($verification) => `${$verification.pass}`,
}
export default class Validator extends EventTarget {

@@ -5,3 +9,5 @@ #_settings

super()
this.settings = Object.freeze($settings)
this.settings = Object.freeze(
Object.assign({ messages: Messages }, $settings)
)
}

@@ -8,0 +14,0 @@ get settings() { return this.#_settings }

@@ -0,1 +1,2 @@

import { recursiveAssign } from '../../../../Coutil/index.js'
import Validator from '../../Validator/index.js'

@@ -10,13 +11,16 @@ import Verification from '../../Verification/index.js'

const verification = new Verification({
type: this.type,
context: $context,
key: $key,
value: $value,
type: this.type,
messages: recursiveAssign(this.messages, $context.type.messages),
})
let pass
if(!['string', 'number', 'boolean'].includes(typeof $value)) { pass = false}
if(![
'string', 'number', 'boolean'
].includes(typeof $value)) { pass = false}
else {
const enumeration = $context.enum
const enumeration = $context.enum.value
pass = enumeration.includes($value)
}
}
verification.pass = pass

@@ -23,0 +27,0 @@ return verification

@@ -0,1 +1,2 @@

import { recursiveAssign } from '../../../../Coutil/index.js'
import Validator from '../../Validator/index.js'

@@ -10,6 +11,7 @@ import Verification from '../../Verification/index.js'

const verification = new Verification({
type: this.type,
context: $context,
key: $key,
value: $value,
type: this.type,
messages: recursiveAssign(this.messages, $context.type.messages),
})

@@ -21,5 +23,9 @@ let pass

let validMin, validMax
if(minLength !== undefined) { validMin = ($value.length >= minLength) }
if(minLength.value !== undefined) {
validMin = ($value.length >= minLength.value)
}
else { validMin = true }
if(maxLength !== undefined) { validMax = ($value.length <= maxLength) }
if(maxLength.value !== undefined) {
validMax = ($value.length <= maxLength.value)
}
else { validMax = true }

@@ -26,0 +32,0 @@ if(validMin && validMax) { pass = true }

@@ -0,4 +1,4 @@

import { recursiveAssign } from '../../../../Coutil/index.js'
import Validator from '../../Validator/index.js'
import Verification from '../../Verification/index.js'
import Schema from '../../index.js'
export default class MatchValidator extends Validator {

@@ -10,12 +10,15 @@ constructor($settings = {}) {

const verification = new Verification({
type: this.type,
context: $context,
key: $key,
value: $value,
type: this.type,
messages: recursiveAssign(this.messages, $context.type.messages),
})
let pass
if(!['string', 'number', 'boolean'].includes(typeof $value)) { pass = false}
if(![
'string', 'number', 'boolean'
].includes(typeof $value)) { pass = false}
else {
const { match } = $context
const valueMatch = (match.exec($value) !== null)
const valueMatch = (match.value.exec($value) !== null)
}

@@ -22,0 +25,0 @@ verification.pass = pass

@@ -0,5 +1,4 @@

import { recursiveAssign } from '../../../../Coutil/index.js'
import Validator from '../../Validator/index.js'
import Verification from '../../Verification/index.js'
import Schema from '../../index.js'
export default class RangeValidator extends Validator {

@@ -11,6 +10,7 @@ constructor($settings = {}) {

const verification = new Verification({
type: this.type,
context: $context,
key: $key,
value: $value,
type: this.type,
messages: recursiveAssign(this.messages, $context.type.messages),
})

@@ -22,5 +22,5 @@ let pass

let validMin, validMax
if(min !== undefined) { validMin = ($value >= min) }
if(min.value !== undefined) { validMin = ($value >= min.value) }
else { validMin = true }
if(max !== undefined) { validMax = ($value <= max) }
if(max.value !== undefined) { validMax = ($value <= max.value) }
else { validMax = true }

@@ -27,0 +27,0 @@ if(validMin && validMax) { pass = true }

@@ -1,6 +0,7 @@

import { typeOf } from '../../../../Coutil/index.js'
import {
typeOf, variables as Variables, recursiveAssign
} from '../../../../Coutil/index.js'
import Validator from '../../Validator/index.js'
import Verification from '../../Verification/index.js'
import { Primitives, Objects } from '../../Variables/index.js'
import Schema from '../../index.js'
const { PrimitiveKeys, PrimitiveValues } = Variables

@@ -11,6 +12,2 @@ export default class TypeValidator extends Validator {

'type': 'type',
'messages': {
'true': ($verification) => `${$verification.pass}`,
'false': ($verification) => `${$verification.pass}`,
},
'validate': ($context, $key, $value) => {

@@ -22,18 +19,18 @@ let verification = new Verification({

value: $value,
messages: this.messages,
messages: recursiveAssign(this.messages, $context.type.messages),
})
let pass
const typeOfContextVal = (
$context.type === undefined || $context.type === null
) ? typeOf($context.type)
: typeOf($context.type())
const typeOfContentVal = typeOf($value)
if(typeOfContentVal === 'undefined') { pass = false }
else if(typeOfContextVal === 'undefined') { pass = true }
let typeOfContextValue = typeOf($context.type.value)
typeOfContextValue = (typeOfContextValue === 'function')
? typeOf($context.type.value())
: typeOfContextValue
const typeOfContentValue = typeOf($value)
if(typeOfContentValue === 'undefined') { pass = false }
else if(typeOfContextValue === 'undefined') { pass = true }
else {
if(
Object.values(Primitives).includes($context.type) &&
Object.keys(Primitives).includes(typeOfContentVal)
PrimitiveValues.includes($context.type.value) &&
PrimitiveKeys.includes(typeOfContentValue)
) {
if(typeOfContextVal === typeOfContentVal) { pass = true }
if(typeOfContextValue === typeOfContentValue) { pass = true }
else { pass = false }

@@ -40,0 +37,0 @@ }

@@ -13,10 +13,9 @@ export default class Verification extends EventTarget {

get value() { return this.#settings.value }
get messages() { return this.#settings.messages }
get message() {
if(this.#_message !== undefined) return this.#_message
if(
this.valid !== undefined &&
this.pass !== undefined &&
this.#_message === undefined
) {
this.#_message = this.messages[this.valid](this)
this.#_message = this.#settings.messages[String(this.pass)](this)
}

@@ -23,0 +22,0 @@ return this.#_message

@@ -14,4 +14,4 @@ {

"@rollup/plugin-commonjs": "^28.0.1",
"nodemon": "^3.1.6",
"rollup": "^4.21.3"
"nodemon": "^3.1.7",
"rollup": "^4.28.1"
},

@@ -18,0 +18,0 @@ "dependencies": {

@@ -1,2 +0,2 @@

import { match } from '../../../node_modules/path-to-regexp/dist/index.js'
import { match } from '../../../../node_modules/path-to-regexp/dist/index.js'
export default class Route extends EventTarget {

@@ -3,0 +3,0 @@ #_settings

# Schema Class
**MVC Framework \| Class System \| Model \| *Schema***
**MVC Framework \| Class System \| Model \| *Schema***
```
{
type: String
}
{
type: {
value: String
}
}
{
type: {
type: String
}
}
{
type: {
type: {
value: String
}
}
}
```
Object.get
$propertyDefinition?.type.type.value
$propertyDefinition?.type.type
Variables.TypeValues.includes()
### Expand Tree Statements
#### Statement 1
*statement*
```
expandTree(String, "0")
```
*returns*
```
[String]
```
#### Statement 2
*statement*
```
expandTree(Number, "value")
```
*returns*
```
{
value: Number
}
```
#### Statement 3
```
expandTree({
propertyA: String
}, "type.value")
```
*returns*
```
{
propertyA: {
type: {
value: String
}
}
}
```
#### Statement 4
```
expandTree({
propertyA: String
}, ($value) => {
type: { value: $value }
})
```
*returns*
```
{
propertyA: {
type: {
value: String
}
}
}
```
#### Statement 5
```
impandTree({})
```
### Impand Tree Statements
#### Statement 1
*statement*
```
impandTree([String], "0")
```
*returns*
```
String
```
#### Statement 2
*statement*
```
impandTree({
value: Number
}, "value")
```
*returns*
```
Number
```
#### Statement 3
```
impandTree({
propertyA: {
type: {
value: String
}
}
}, ":$property.type.value")
```
*returns*
```
{
propertyA: String
}
```
#### Statement 4
```
impandTree({
propertyA: {
type: {
value: String
}
}
}, ($value) => {
type: { value: $value }
})
```
*returns*
```
{
propertyA: String
}
```
#### Statement 5
```
expandTree({})
```
```
Schema Property Definitions ($propertyDefinitions)
{
[$propertyName]: $propertyDefinition
}
Schema Property Definition ($propertyDefinition)
{
[$validatorName]: $validator
}
Schema Property Definition Validator ($validator)
{
[$validatorSettingName]: $validatorSetting,
}
Schema Property Definition Validator Setting ($validatorSetting)
{
value: $value,
messages: {
"true": $messageTrue,
"false": $messageFalse,
},
}
Schema Property Definition Validator Keys ($validatorSetting)
[
"type", // TypeValidator
["length", ["min", "max"]], // LengthValidator
"minLength", "maxLength", // LengthValidator
["range", ["min", "max"]] // RangeValidator
"min", "max", // RangeValidator
"enum", // EnumValidator
"match", // MatchValidator
]
{
[$propertyName]: {
[$validatorName]: {
[$validatorSettingName]: {
value: $value,
messages: {
true: $messageTrue,
false: $messageFalse,
}
}
}
}
}
```
```
{
propertyA: String
}
{
propertyA: {
type: String
}
}
{
propertyA: {
type: {
value: String,
messages: {
true: ($verification) => `${$verification.pass}`,
false: ($verification) => `${$verification.pass}`,
}
}
}
}
```
```
{
propertyA: {
propertyB: {
propertyC: String
}
}
}
```
```
{
// Property A
propertyA: {
type: {
value: {
// Property B
propertyB: {
type: {
value: {
// Property C
propertyC: {
type: {
value: String
}
}
}
}
}
}
}
}
}
```
```
expandTree({
propertyA: String
}, ["type.value"])
```
{
"name": "js-mvc-framework",
"author": "Thomas Patrick Welborn",
"version": "1.3.12",
"version": "1.3.13",
"type": "module",

@@ -6,0 +6,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc