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.6 to 1.3.7

development/Coutil/definePropertiesTree/index.js

206

demonstrament/documents/test/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: {
schema: [{ type: {
propertyA: { type: {
propertyB: { type: String }
} }
} }],
content: [{
propertyA: {
type: {
propertyB: { type: {
propertyC: { type: String }
} }
}
propertyB: "333"
}
},
content: {
}, {
propertyA: {
propertyB: {
propertyC: "CCC"
}
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: {
// propertyB: {
// propertyC: "333333"
// }
// }
},
localStorage: "/model",
events: {
// 'content validProperty': ($event) => {
// console.log($event.type, $event.path)
// },
// 'content nonvalidProperty': ($event) => {
// console.log($event.type, $event.path)
// },
'change': ($event) => {

@@ -25,16 +80,129 @@ console.log(

"\n", $event.type,
"\n", $event.path,
"\n", $event.detail,
// "\n", $event.detail
"\n", $event
// "\n", $event.path,
// "\n", $event.detail,
// "\n", $event.change,
)
}
}
}, { changeEvents: true })
model.content.assign({
propertyA: {
propertyB: {
propertyC: "3333"
}, {
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)

@@ -41,0 +209,0 @@ // console.log(model.content.get("propertyA.propertyB").root)

4

development/Coutil/index.js

@@ -6,9 +6,11 @@ import typeOf from './typeOf/index.js'

import regularExpressions from './regularExpressions/index.js'
import definePropertiesTree from './definePropertiesTree/index.js'
export {
typeOf,
impandEvents,
impandEvents,
expandEvents,
recursiveAssign,
regularExpressions,
definePropertiesTree,
}

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

export default class ChangeEvent extends Event {
export default class ChangeEvent extends CustomEvent {
#settings

@@ -16,2 +16,3 @@ #content

}
get change() { return this.#settings.change }
get value() { return this.#settings.value }

@@ -18,0 +19,0 @@ get path() { return this.#settings.path }

@@ -13,10 +13,7 @@ export default class ContentEvent extends Event {

if(this.#content.parent !== null) {
const { path, value, detail, change } = $event
this.#content.parent.dispatchEvent(
new ContentEvent(
this.type,
{
path: $event.path,
value: $event.value,
detail: $event.detail,
},
{ path, value, detail, change },
this.#content.parent

@@ -38,2 +35,3 @@ )

}
get change() { return this.#settings.change }
get value() { return this.#settings.value }

@@ -40,0 +38,0 @@ get path() { return this.#settings.path }

@@ -29,5 +29,5 @@ import { regularExpressions, recursiveAssign } from '../../../../../../../Coutil/index.js'

let propertyValue
const _path = (path !== null)
? String(path).concat('.', propertyKey)
: propertyKey
const contentPath = (path)
? (path, propertyKey).join('.')
: String(propertyKey)
// Return: Subproperty

@@ -50,3 +50,3 @@ if(subpaths.length) {

propertyValue = new Content(subcontent, subschema, Object.assign({}, contentOptions, {
path: _path,
path: contentPath,
parent: proxy,

@@ -67,19 +67,36 @@ }))

if(validationEvents) {
let type
const _path = [path, '.', propertyKey].join('')
let type, propertyType
const validatorEventPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(validSourceProp.valid) {
type = ['validProperty', ':', propertyKey].join('')
type = 'validProperty'
propertyType = ['validProperty', ':', propertyKey].join('')
}
else {
type = ['nonvalidProperty', ':', propertyKey].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', propertyKey].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validSourceProp,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorEventPath,
detail: validSourceProp,
}, $content)
)
}
}
if(!validSourceProp.valid) { return }
}
const change = {
preter: {
key: propertyKey,
value: source[propertyKey],
},
anter: {
key: propertyKey,
value: $value,
},
conter: undefined,
}
// Return: Property

@@ -96,3 +113,3 @@ // Value: Object Literal

{}, contentOptions, {
path: _path,
path: contentPath,
parent: proxy,

@@ -110,7 +127,11 @@ }

if(contentEvents) {
const contentEventPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(events['setProperty']) {
$content.dispatchEvent(
new ContentEvent('setProperty', {
path,
path: contentEventPath,
value: propertyValue,
change,
detail: {

@@ -125,7 +146,7 @@ key: propertyKey,

const type = ['setProperty', ':', propertyKey].join('')
const _path = [path, '.', propertyKey].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: propertyValue,
change,
detail: {

@@ -151,8 +172,8 @@ value: propertyValue,

else { subschema = undefined }
const _path = (path !== null)
? path.concat('.', propertyKey)
: propertyKey
const contentPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
propertyValue = new Content($value, subschema, Object.assign(
{}, contentOptions, {
path: _path,
path: contentPath,
parent: proxy,

@@ -168,6 +189,9 @@ }

if(contentEvents) {
const contentEventPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(events['setProperty']) {
$content.dispatchEvent(
new ContentEvent('setProperty', {
path,
path: contentEventPath,
value: propertyValue,

@@ -183,6 +207,5 @@ detail: {

const type = ['setProperty', ':', propertyKey].join('')
const _path = [path, '.', propertyKey].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: propertyValue,

@@ -189,0 +212,0 @@ detail: {

@@ -25,22 +25,28 @@ import Content from '../../../../index.js'

if(schema &&validationEvents) {
let type
const _path = [path, '.', valueIndex].join('')
let type, propertyType
const validatorPath = (path)
? [path, valueIndex].join('.')
: String(valueIndex)
if(validSourceProp.valid) {
type = ['validProperty', ':', valueIndex].join('')
type = 'validProperty'
propertyType = ['validProperty', ':', valueIndex].join('')
}
else {
type = ['nonvalidProperty', ':', valueIndex].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', valueIndex].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validValue,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorPath,
detail: validSourceProp,
}, $content)
)
}
}
if(!validValue.valid) { valueIndex++; continue iterateValues }
}
const _path = (path !== null)
? path.concat('.', valueIndex)
: valueIndex
const contentPath = (path)
? [path, valueIndex].join('.')
: String(valueIndex)
// Value: Object Type

@@ -52,3 +58,3 @@ if(typeof $value === 'object') {

const value = new Content($value, subschema, {
path: _path,
path: contentPath,
parent: proxy,

@@ -64,6 +70,9 @@ })

if(contentEvents) {
const contentEventPath = (path)
? [path, valueIndex].join('.')
: String(valueIndex)
if(events['concatValue']) {
$content.dispatchEvent(
new ContentEvent('concatValue', {
path,
path: contentEventPath,
value: values[valueIndex],

@@ -79,6 +88,5 @@ detail: {

const type = ['concatValue', ':', valueIndex].join('')
const _path = [path, '.', valueIndex].join('')
$content.dispatchEvent(
new ContentEvent('concatValue', {
path: _path,
path: contentEventPath,
value: values[valueIndex],

@@ -85,0 +93,0 @@ detail: {

@@ -39,2 +39,5 @@ import { ContentEvent } from '../../../../Events/index.js'

if(contentEvents) {
const contentEventPath = (path)
? [path, copyIndex].join('.')
: String(copyIndex)
if(events['copyWithinIndex']) {

@@ -45,3 +48,3 @@ $content.dispatchEvent(

{
path,
path: contentEventPath,
value: copyItem,

@@ -61,3 +64,2 @@ detail: {

const type = ['copyWithinIndex', ':', copyIndex].join('')
const _path = [path, '.', copyIndex].join('')
$content.dispatchEvent(

@@ -67,3 +69,4 @@ new ContentEvent(

{
path: _path,
path: contentEventPath,
value: copyItem,
detail: {

@@ -70,0 +73,0 @@ target: targetIndex,

@@ -33,22 +33,28 @@ import Content from '../../../../index.js'

if(validationEvents) {
let type
const _path = [path, '.', fillIndex].join('')
let type, propertyType
const validatorPath = (path)
? [path, fillIndex].join('.')
: String(fillIndex)
if(validSourceProp.valid) {
type = ['validProperty', ':', fillIndex].join('')
type = 'validProperty'
propertyType = ['validProperty', ':', fillIndex].join('')
}
else {
type = ['nonvalidProperty', ':', fillIndex].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', fillIndex].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validValue,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorPath,
detail: validSourceProp,
}, $content)
)
}
}
if(!validValue.valid) { continue iterateFillIndexes }
}
const _path = (path !== null)
? path.concat('.', fillIndex)
: fillIndex
const contentPath = (path)
? [path, fillIndex].join('.')
: String(fillIndex)
let value = $arguments[0]

@@ -59,3 +65,3 @@ if(typeof value === 'object') {

value = new Content(value, subschema, {
path: _path,
path: contentPath,
parent: proxy,

@@ -69,6 +75,9 @@ })

if(contentEvents) {
const contentEventPath = (path)
? [path, fillIndex].join('.')
: String(fillIndex)
if(events['fillIndex']) {
$content.dispatchEvent(
new ContentEvent('fillIndex', {
path,
path: contentEventPath,
value: value,

@@ -85,6 +94,5 @@ detail: {

const type = ['fillIndex', ':', fillIndex].join('')
const _path = [path, '.', fillIndex].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
detail: {

@@ -91,0 +99,0 @@ start: fillIndex,

@@ -11,2 +11,5 @@ import { ContentEvent } from '../../../../Events/index.js'

if(contentEvents && events['pop']) {
const contentEventPath = (path)
? [path, popElementIndex].join('.')
: String(popElementIndex)
$content.dispatchEvent(

@@ -16,3 +19,3 @@ new ContentEvent(

{
path,
path: contentEventPath,
value: popElement,

@@ -19,0 +22,0 @@ detail: {

@@ -18,22 +18,28 @@ import Content from '../../../../index.js'

if(validationEvents) {
let type
const _path = [path, '.', elementsIndex].join('')
let type, propertyType
const validatorPath = (path)
? [path, elementsIndex].join('.')
: String(elementsIndex)
if(validSourceProp.valid) {
type = ['validProperty', ':', elementsIndex].join('')
type = 'validProperty'
propertyType = ['validProperty', ':', elementsIndex].join('')
}
else {
type = ['nonvalidProperty', ':', elementsIndex].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', elementsIndex].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validElement,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorPath,
detail: validSourceProp,
}, $content)
)
}
}
if(!validElement.valid) { return source.length }
}
const _path = (path !== null)
? path.concat('.', elementsIndex)
: elementsIndex
const contentPath = (path)
? [path, elementsIndex].join('.')
: String(elementsIndex)
if(typeof $element === 'object') {

@@ -43,3 +49,3 @@ if($element?.classToString === Content.toString()) { $element = $element.object }

$element = new Content($element, subschema, {
path: _path,
path: contentPath,
parent: proxy,

@@ -54,6 +60,9 @@ })

if(contentEvents) {
const contentEventPath = (path)
? [path, '.', elementsIndex].join('')
: String(elementsIndex)
if(events['pushProp']) {
$content.dispatchEvent(
new ContentEvent('pushProp', {
path,
path: contentEventPath,
value: elements[elementsIndex],

@@ -69,6 +78,5 @@ detail: {

const type = ['pushProp', ':', elementsIndex].join('')
const _path = [path, '.', elementsIndex].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: elements[elementsIndex],

@@ -75,0 +83,0 @@ detail: {

@@ -11,2 +11,5 @@ import { ContentEvent } from '../../../../Events/index.js'

if(contentEvents && events['shift']) {
const contentEventPath = (path)
? [path, shiftElementIndex].join('.')
: String(shiftElementIndex)
$content.dispatchEvent(

@@ -16,3 +19,3 @@ new ContentEvent(

{
path,
path: contentEventPath,
value: shiftElement,

@@ -19,0 +22,0 @@ detail: {

@@ -30,6 +30,9 @@ import Content from '../../../../index.js'

if(contentEvents) {
const contentEventPath = (path)
? [path, deleteItemsIndex].join('.')
: String(deleteItemsIndex)
if(events['spliceDelete']) {
$content.dispatchEvent(
new ContentEvent('spliceDelete', {
path,
path: contentEventPath,
value: deleteItem,

@@ -46,6 +49,5 @@ detail: {

const type = ['spliceDelete', ':', deleteItemsIndex].join('')
const _path = [path, '.', deleteItemsIndex].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: deleteItem,

@@ -71,22 +73,28 @@ detail: {

if(validationEvents) {
let type
const _path = [path, '.', addItemsIndex].join('')
let type, propertyType
const validatorEventPath = (path)
? [path, addItemsIndex].join('.')
: String(addItemsIndex)
if(validSourceProp.valid) {
type = ['validProperty', ':', addItemsIndex].join('')
type = 'validProperty'
propertyType = ['validProperty', ':', addItemsIndex].join('')
}
else {
type = ['nonvalidProperty', ':', addItemsIndex].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', addItemsIndex].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validAddItem,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorEventPath,
detail: validSourceProp,
}, $content)
)
}
}
if(!validAddItem.valid) { addItemsIndex++; continue spliceAdd }
}
const _path = (path !== null)
? path.concat('.', addItemsIndex)
: addItemsIndex
const contentPath = (path)
? [path, addItemsIndex].join('.')
: String(addItemsIndex)
let startIndex = $start + addItemsIndex

@@ -98,3 +106,3 @@ // Add Item: Object Type

addItem = new Content(addItem, subschema, {
path: _path,
path: contentPath,
parent: proxy,

@@ -114,6 +122,9 @@ })

if(contentEvents) {
const contentEventPath = (path)
? [path, addItemsIndex].join('.')
: String(addItemsIndex)
if(events['spliceAdd']) {
$content.dispatchEvent(
new ContentEvent('spliceAdd', {
path,
path: contentEventPath,
value: addItem,

@@ -130,6 +141,5 @@ detail: {

const type = ['spliceAdd', ':', addItemsIndex].join('')
const _path = [path, '.', addItemsIndex].join('')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: addItem,

@@ -136,0 +146,0 @@ detail: {

import Content from '../../../../index.js'
import { ContentEvent } from '../../../../Events/index.js'
import { ContentEvent, ValidatorEvent } from '../../../../Events/index.js'
export default function unshift() {

@@ -8,3 +8,3 @@ const $content = Array.prototype.shift.call(arguments)

const { events } = $options
const { source, path, schema } = $content
const { source, path, schema, proxy } = $content
const { enableValidation, validationEvents, contentEvents } = $content.options

@@ -14,2 +14,3 @@ const elements = []

let elementIndex = elementsLength - 1
let elementCoindex = 0
iterateElements:

@@ -19,2 +20,7 @@ while(elementIndex > -1) {

let $element = $arguments[elementIndex]
let element
const sourceElement = source[elementIndex]
const sourceElementIsContentInstance = (
sourceElement?.classToString === Content.toString()
) ? true : false
// Validation

@@ -24,27 +30,44 @@ if(schema && enableValidation) {

if(validationEvents) {
let type
const _path = [path, '.', elementIndex].join('')
if(validSourceProp.valid) {
type = ['validProperty', ':', elementIndex].join('')
let type, propertyType
const validatorEventPath = (path)
? [path, '.', elementCoindex].join('')
: elementCoindex
if(validElement.valid) {
type = 'validProperty'
propertyType = ['validProperty', ':', elementCoindex].join('')
}
else {
type = ['nonvalidProperty', ':', elementIndex].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', ':', elementCoindex].join('')
}
$content.dispatchEvent(
new ValidatorEvent(type, {
path: _path,
detail: validElement,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorEventPath,
detail: validElement,
}, $content)
)
}
}
if(!validElement.valid) { return proxy.length }
}
const change = {
preter: {
key: elementCoindex,
value: source[elementCoindex],
},
anter: {
key: elementCoindex,
value: undefined,
},
conter: undefined,
}
// Element: Object Type
if(typeof $element === 'object') {
const subschema = schema?.context[0] || null
const _path = (path !== null)
? path.concat('.', elementIndex)
: elementIndex
const element = new Content($element, subschema, {
path: _path,
const contentPath = (path)
? path.concat('.', elementCoindex)
: String(elementCoindex)
element = new Content($element, subschema, {
path: contentPath,
parent: proxy,

@@ -57,14 +80,24 @@ })

else {
elements.unshift($element)
element = $element
elements.unshift(element)
Array.prototype.unshift.call(source, $element)
}
change.anter.value = element
change.conter = (sourceElementIsContentInstance)
? (sourceElement.string !== JSON.stringify(element))
: (JSON.stringify(sourceElement) !== JSON.stringify(element))
// Array Unshift Prop Event
if(contentEvents) {
const type = ['unshiftProp', elementCoindex].join(':')
const contentEventPath = (path)
? [path, elementCoindex].join('.')
: String(elementCoindex)
if(events['unshiftProp']) {
$content.dispatchEvent(
new ContentEvent('unshiftProp', {
path,
path: contentEventPath,
value: element,
change,
detail: {
elementIndex,
elementIndex: elementCoindex,
element: element,

@@ -76,10 +109,9 @@ },

if(events['unshiftProp:$index']) {
const type = ['unshiftProp', ':', elementIndex].join('')
const _path = [path, '.', elementIndex]
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
path: contentEventPath,
value: element,
change,
detail: {
elementIndex,
elementIndex: elementCoindex,
element: element,

@@ -93,2 +125,3 @@ },

elementIndex--
elementCoindex++
}

@@ -95,0 +128,0 @@ // Array Unshift Event

@@ -10,48 +10,71 @@ import { recursiveAssign } from '../../../../../../Coutil/index.js'

const { enableValidation, validationEvents, contentEvents } = $content.options
const sources = [...arguments]
const assignSources = [...arguments]
const assignedSources = []
// Iterate Sources
iterateSources:
for(let $source of sources) {
iterateAssignSources:
for(let $assignSource of assignSources) {
let assignedSource
if(Array.isArray($source)) { assignedSource = [] }
else if(typeof $source === 'object') { assignedSource = {} }
if(Array.isArray($assignSource)) { assignedSource = [] }
else if(typeof $assignSource === 'object') { assignedSource = {} }
// Iterate Source Props
iterateSourceProps:
for(let [$sourcePropKey, $sourcePropVal] of Object.entries($source)) {
for(let [$assignSourcePropKey, $assignSourcePropVal] of Object.entries($assignSource)) {
let sourcePropVal = source[$assignSourcePropKey]
let assignSourcePropVal
const sourcePropValIsContentInstance = (
source[$assignSourcePropKey]?.classToString === Content.toString()
) ? true : false
// Validation
if(schema && enableValidation) {
const validSourceProp = schema.validateProperty($sourcePropKey, $sourcePropVal)
const validSourceProp = schema.validateProperty($assignSourcePropKey, $assignSourcePropVal)
if(validationEvents) {
let type
const _path = [path, '.', $sourcePropKey].join('')
let type, propertyType
const validatorEventPath = (path)
? [path, $assignSourcePropKey].join('.')
: String($assignSourcePropKey)
if(validSourceProp.valid) {
type = ['validProperty', ':', $sourcePropKey].join('')
type = 'validProperty'
propertyType = ['validProperty', $assignSourcePropKey].join(':')
}
else {
type = ['nonvalidProperty', ':', $sourcePropKey].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', $assignSourcePropKey].join(':')
}
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorEventPath,
detail: validSourceProp,
}, $content)
)
}
// Validator Event: Validate Property
$content.dispatchEvent(
new ValidatorEvent('validateProperty', {
path,
detail: validSourceProp,
}, $content)
)
}
if(!validSourceProp.valid) { continue iterateSourceProps }
}
const change = {
preter: {
key: $assignSourcePropKey,
value: source[$assignSourcePropKey],
},
anter: {
key: $assignSourcePropKey,
value: undefined,
},
conter: undefined
}
// Source Prop: Object Type
if(typeof $sourcePropVal === 'object') {
if($sourcePropVal?.classToString === Content.toString()) { $sourcePropVal = $sourcePropVal.object }
if(typeof $assignSourcePropVal === 'object') {
if($assignSourcePropVal.classToString === Content.toString()) {
$assignSourcePropVal = $assignSourcePropVal.object
}
// Subschema
let subschema
if(schema?.type === 'array') { subschema = schema.context[0] }
else if(schema?.type === 'object') { subschema = schema.context[$sourcePropKey] }
else if(schema?.type === 'object') { subschema = schema.context[$assignSourcePropKey] }
else { subschema = null }
// Content
const _path = (path !== null)
? path.concat('.', $sourcePropKey)
: $sourcePropKey
let sourcePropVal = source[$sourcePropKey]
const contentPath = (path)
? [path, $assignSourcePropKey].join('.')
: String($assignSourcePropKey)
// Assignment

@@ -61,3 +84,3 @@ let assignment

if(sourceTree === false) {
assignment = { [$sourcePropKey]: content }
assignment = { [$assignSourcePropKey]: content }
}

@@ -67,10 +90,10 @@ // Source Tree: true

// Assignment: Existing Content Instance
if(sourcePropVal?.classToString === Content.toString()) {
sourcePropVal.assign($sourcePropVal)
if(sourcePropValIsContentInstance) {
sourcePropVal.assign($assignSourcePropVal)
}
// Assignment: New Content Instance
else {
sourcePropVal = new Content($sourcePropVal, subschema,
sourcePropVal = new Content($assignSourcePropVal, subschema,
recursiveAssign({}, $content.options, {
path: _path,
path: contentPath,
parent: proxy,

@@ -80,3 +103,3 @@ })

}
assignment = { [$sourcePropKey]: sourcePropVal }
assignment = { [$assignSourcePropKey]: sourcePropVal }
}

@@ -90,3 +113,3 @@ // Assignment

let assignment = {
[$sourcePropKey]: $sourcePropVal
[$assignSourcePropKey]: $assignSourcePropVal
}

@@ -98,13 +121,20 @@ // Assign Root

}
change.anter.value = sourcePropVal
change.conter = (sourcePropValIsContentInstance)
? (sourcePropVal.string !== JSON.stringify(sourcePropVal))
: (JSON.stringify(sourcePropVal) !== JSON.stringify(sourcePropVal))
change.anter.value = sourcePropVal
// Content Event: Assign Source Property
if(contentEvents) {
const contentEventPath = [path, $assignSourcePropKey].join('.')
if(events['assignSourceProperty']) {
$content.dispatchEvent(
new ContentEvent('assignSourceProperty', {
path,
value: $sourcePropVal,
path: contentEventPath,
value: $assignSourcePropVal,
change,
detail: {
key: $sourcePropKey,
value: $sourcePropVal,
source: $source,
key: $assignSourcePropKey,
value: $assignSourcePropVal,
source: $assignSource,
}

@@ -115,12 +145,12 @@ }, $content)

if(events['assignSourceProperty:$key']) {
const type = ['assignSourceProperty', ':', $sourcePropKey].join('')
const _path = [path, '.', $sourcePropKey].join('')
const type = ['assignSourceProperty', $assignSourcePropKey].join(':')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
value: $sourcePropVal,
path: contentEventPath,
value: $assignSourcePropVal,
change,
detail: {
key: $sourcePropKey,
value: $sourcePropVal,
source: $source,
key: $assignSourcePropKey,
value: $assignSourcePropVal,
source: $assignSource,
}

@@ -127,0 +157,0 @@ }, $content)

@@ -8,2 +8,3 @@ import Content from '../../../../index.js'

const { source, path, schema, proxy } = $content
const contentEvents = $content.options.contentEvents
const $propertyDescriptors = arguments[0]

@@ -23,3 +24,3 @@ const properties = Object.entries($propertyDescriptors)

// Property Descriptor Value Is Direct Instance Of Array/Object/Map
$trap.defineProperty($propertyKey, $propertyDescriptor)
proxy.defineProperty($propertyKey, $propertyDescriptor)
}

@@ -26,0 +27,0 @@ // Define Properties Event

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

import { typeOf } from '../../../../../../Coutil/index.js'
import { typeOf, definePropertiesTree } from '../../../../../../Coutil/index.js'
import Content from '../../../../index.js'

@@ -12,25 +12,51 @@ import { ContentEvent, ValidatorEvent } from '../../../../Events/index.js'

const propertyDescriptor = arguments[1]
const propertyValue = propertyDescriptor.value
const sourcePropertyDescriptor = Object.getOwnPropertyDescriptor(source, propertyKey) || {}
const sourcePropertyValue = sourcePropertyDescriptor.value
const sourcePropertyValueIsContentInstance = (
sourcePropertyValue?.classToString === Content.toString()
) ? true : false
// Validation
if(schema && enableValidation) {
const validSourceProp = schema.validateProperty(propertyKey, propertyDescriptor.value)
const flattenedPropertyValue = definePropertiesTree({
[propertyKey]: propertyDescriptor
})[propertyKey]
const validProperty = schema.validateProperty(propertyKey, flattenedPropertyValue)
if(validationEvents) {
let type
const _path = [path, '.', propertyKey].join('')
if(validSourceProp.valid) {
type = ['validProperty', ':', propertyKey].join('')
let type, propertyType
const validatorPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(validProperty.valid) {
type = 'validProperty'
propertyType = ['validProperty', propertyKey].join(':')
}
else {
type = ['nonvalidProperty', ':', propertyKey].join('')
type = 'nonvalidProperty'
propertyType = ['nonvalidProperty', propertyKey].join(':')
}
$content.dispatchEvent(
new ValidatorEvent('validateProperty', {
path,
detail: validSourceProp,
}, $content)
)
for(const $eventType of [type, propertyType]) {
$content.dispatchEvent(
new ValidatorEvent($eventType, {
path: validatorPath,
detail: validProperty,
}, $content)
)
}
}
if(!validSourceProp.valid) { return proxy }
if(!validProperty.valid) { return proxy }
}
const change = {
preter: {
key: propertyKey,
value: source[propertyKey],
},
anter: {
key: propertyKey,
value: undefined,
},
conter: undefined,
}
// Property Descriptor Value: Object Type
if(typeof propertyDescriptor.value === 'object') {
if(typeof propertyValue === 'object') {
// Subschema

@@ -41,13 +67,12 @@ let subschema

else { subschema = undefined}
const sourcePropertyDescriptor = Object.getOwnPropertyDescriptor(source, propertyKey) || {}
// const sourcePropertyDescriptor = Object.getOwnPropertyDescriptor(source, propertyKey) || {}
// Root Property Descriptor Value: Existent Content Instance
const _path = (
path !== null
) ? path.concat('.', propertyKey)
: propertyKey
if(sourcePropertyDescriptor.value.classToString === Content.toString()) {
const contentPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(sourcePropertyValueIsContentInstance) {
// Descriptor Tree: true
if(descriptorTree === true) {
propertyDescriptor.value = Object.assign(propertyDescriptor.value, { path: _path, parent: proxy })
sourcePropertyDescriptor.value.defineProperties(propertyDescriptor.value)
// propertyValue = Object.assign(propertyValue, { path: contentPath, parent: proxy })
sourcePropertyValue.defineProperties(propertyValue)
}

@@ -62,8 +87,8 @@ // Descriptor Tree: false

let _source
if(typeOf(propertyDescriptor.value) === 'object') { _source = {} }
else if (typeOf(propertyDescriptor.value) === 'array') { _source = [] }
if(typeOf(propertyValue) === 'object') { _source = {} }
else if (typeOf(propertyValue) === 'array') { _source = [] }
else { _source = {} }
const contentObject = new Content(
_source, subschema, {
path: _path,
path: contentPath,
parent: proxy,

@@ -74,3 +99,3 @@ }

if(descriptorTree === true) {
contentObject.defineProperties(propertyDescriptor.value)
contentObject.defineProperties(propertyValue)
source[propertyKey] = contentObject

@@ -88,9 +113,17 @@ } else

}
change.anter.value = propertyValue
change.conter = (sourcePropertyValueIsContentInstance)
? (sourcePropertyValue.string !== JSON.stringify(propertyValue))
: (JSON.stringify(sourcePropertyValue) !== JSON.stringify(propertyValue))
// Define Property Event
if(contentEvents) {
const contentEventPath = (path)
? [path, propertyKey].join('.')
: String(propertyKey)
if(events['defineProperty']) {
$content.dispatchEvent(
new ContentEvent('defineProperty', {
path,
value: propertyDescriptor.value,
path: contentEventPath,
value: propertyValue,
change,
detail: {

@@ -104,8 +137,8 @@ prop: propertyKey,

if(events['defineProperty:$key']) {
const type = ['defineProperty', ':', propertyKey].join('')
const _path = [path, '.', propertyKey].join('')
const type = ['defineProperty', propertyKey].join(':')
$content.dispatchEvent(
new ContentEvent(type, {
path: _path,
value: propertyDescriptor.value,
path: contentEventPath,
value: propertyValue,
change,
detail: {

@@ -112,0 +145,0 @@ prop: propertyKey,

@@ -6,11 +6,2 @@ import { typeOf, recursiveAssign } from '../../Coutil/index.js'

import ContentEvent from './Events/Content/index.js'
// const ChangeEvents = [
// // Accessor
// "getProperty", "setProperty", "deleteProperty",
// // Array
// "concatValue", "copyWithinIndex", "fillIndex", "pushProp",
// "spliceDelete", "spliceAdd", "unshiftProp",
// // Object
// "assignSourceProperty", "defineProperty",
// ]
export default class Content extends EventTarget {

@@ -111,4 +102,5 @@ #_properties

if(this.#_proxy !== undefined) return this.#_proxy
const { proxyAssignmentMethod } = this.options
this.#_proxy = new Proxy(this.source, this.#handler)
this.#_proxy.set(this.#properties)
this.#_proxy[proxyAssignmentMethod](this.#properties)
return this.#_proxy

@@ -115,0 +107,0 @@ }

@@ -10,2 +10,3 @@ export default {

subpathError: false,
proxyAssignmentMethod: 'set',
traps: {

@@ -12,0 +13,0 @@ accessor: {

@@ -32,4 +32,4 @@ import { recursiveAssign } from '../Coutil/index.js'

) { return null }
this.changeEvents = this.options.changeEvents
if(this.options.enableEvents === true) this.enableEvents()
this.changeEvents = this.options.changeEvents
}

@@ -99,7 +99,7 @@ get schema() {

this.save()
const { type, path, value } = $event
const { type, path, value, change } = $event
const detail = Object.assign({ type }, $event.detail)
const originalEvent = $event
this.dispatchEvent(
new ChangeEvent("change", { path, value, detail, originalEvent })
new ChangeEvent("change", { path, value, detail, change, originalEvent })
)

@@ -106,0 +106,0 @@ }

@@ -101,6 +101,6 @@ import { typeOf } from '../../Coutil/index.js'

], $validatorIndex, $contentEntries) => {
const validation = this.validateProperty($contentKey, $contentVal)
if(validation === null) return $validation
if($validation.valid !== false) $validation.valid = validation.valid
$validation.properties[$contentKey] = validation
const _validation = this.validateProperty($contentKey, $contentVal)
if(_validation === null) return $validation
if($validation.valid !== false) $validation.valid = _validation.valid
$validation.properties[$contentKey] = _validation
return $validation

@@ -114,3 +114,3 @@ }, structuredClone(Validation)

key: $key,
val: $val,
value: $val,
advance: [],

@@ -129,10 +129,9 @@ deadvance: [],

validation = new Validation({
context: contextVal,
context: this.context,
contentKey: $key,
contentVal: $val,
type: 'key',
// type: 'key',
valid: null,
})
propertyValidation.unadvance.push(validation)
return propertyValidation
}

@@ -144,7 +143,9 @@ // Context Val: Object

else if(validation.valid === false) { propertyValidation.deadvance.push(validation) }
if(this.validationType === 'object') { propertyValidation.valid === validation.valid }
if(this.validationType === 'object') {
propertyValidation.valid = validation.valid
}
else if(this.validationType === 'primitive') {
propertyValidation.valid = (validation.valid === false)
? !validation.valid
: validation.valid
: validation.valid
}

@@ -157,6 +158,4 @@ }

const validation = $validator.validate(contextVal, $key, $val)
//
if(validation.valid === true) { $propertyValidation.advance.push(validation) }
else if(validation.valid === false) { $propertyValidation.deadvance.push(validation) }
//
if($propertyValidation.valid !== false) $propertyValidation.valid = validation.valid

@@ -163,0 +162,0 @@ return $propertyValidation

export default class Validation extends EventTarget {
#settings
#_type
// #_type
#_valid

@@ -13,3 +13,3 @@ #_context

}
get type() { return this.#settings.type }
// get type() { return this.#settings.type }
get valid() { return this.#_valid }

@@ -33,5 +33,5 @@ set valid($valid) {

get contextKey() { return this.#settings.contentKey }
get contextVal() { return this.#settings.context[this.contentKey] }
get contextVal() { return this.#settings.context }
get contentKey() { return this.#settings.contentKey }
get contentVal() { return this.#settings.contentVal }
get contentVal() { return this.#settings.context[this.contextKey] }
}
{
"name": "js-mvc-framework",
"author": "Thomas Patrick Welborn",
"version": "1.3.6",
"version": "1.3.7",
"type": "module",

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

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