First commit

This commit is contained in:
2025-12-25 11:16:59 +01:00
commit 0c5ca09a63
720 changed files with 329234 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class cacheManager{
objects = new Array();
getObjectByClassName( object, id, classname ) {
var arrayWithObjects = this.objects[ classname ];
if( arrayWithObjects ) {
var output = arrayWithObjects[ id ];
if( output ) {
object.serialize( output );
return object;
} else {
object.id = id;
var row = object.getRow();
arrayWithObjects[ id ] = row;
object.serialize( row );
return object;
}
} else {
this.objects[ classname ] = new Array();
return this.getObjectByClassName( object, id, classname );
}
}
getObject( object, id ) {
var className = object.getClassName();
return this.getObjectByClassName( object, id, className );
}
getLocalObject( object, id, classname ) {
var arrayWithObjects = this.objects[ classname ];
if( arrayWithObjects ) {
var output = arrayWithObjects[ id ];
if( output ) {
return output;
} else {
return false;
}
} else {
this.objects[ classname ] = new Array();
return this.getLocalObject( object, id, classname );
}
}
addObject( object, id, classname ) {
this.objects[ classname ][ id ] = object;
}
}

1749
framework/unify/clonedeep.js Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,387 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import tools from './tools.js';
import serverCollection from '../server/collection/collection.js';
import defaultObject from './defaultObject.js';
import unify from './unify.js';
export default class collection extends serverCollection {
__className = "collection";
type = "collection";
rows = new Array();
filterObject = false;
object;
tableName;
parentName;
constructor( object ){
super();
if( object ) {
this.object = object;
}
unify.extend( this )
}
createInstance() {
return new this.object();
}
getParentName() {
var parentTable = this.parent;
//console.log("get table from this", this.parent);
if( !tools.objectIsTable( this.parent ) ) {
parentTable = tools.getTableFromObject( this.parent );
}
var parentClassName = tools.getClassName( parentTable );
// todo: not good but works -> userB.friends.remove( userA ); selectuser.checkbox.js doesnt
// work if this is disabled. userB is a collection but doesnt get an parentName
// with this function
if( !parentClassName ) {
parentClassName = this.tableName;
}
return parentClassName;
}
getTableName() {
var tableInstance = new this.object();
return tools.getClassName( tableInstance );
}
getRight( update = true ) {
if( update ) {
this.update();
}
var tableName = this.tableName;
if( tableName == this.parentName ) {
tableName += 0;
}
return tableName;
}
getLeft( update = true ) {
if( update ) {
this.update();
}
if( this.parentName ) {
var parentName = this.parentName;
} else {
var parentName = this.getParentName();
}
if( this.tableName == parentName ) {
parentName += 1;
}
return parentName;
}
update() {
if( !this.enabled) {
this.tableName = this.getTableName();
if( this.parent ) {
this.parentName = this.getParentName();
}
}
}
getColumnName() {
var parentClassName = this.getParentName();
return parentClassName + "_" + this.propertyName + "_id";
}
set( objects ){
this.rows = objects;
}
addObject( object ) {
this.rows.push( object );
}
filter( by, term ) {
switch( by.toLowerCase() ) {
case "custom":
this.filterCustom( term );
break;
case "class":
this.filterByClassName( term );
break;
case "name":
this.filterByName( term );
break;
case "id":
this.filterByID( term );
break;
case "parent":
this.filterByParent( term );
break;
case "parentName":
this.filterByParentName( term );
break;
case "type":
this.filterByType( term );
break;
}
}
filterCustom( func ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( func( object ) ) {
this.rows.push(object);
}
}
}
filterByType( type ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( object.type == type ) {
this.rows.push(object);
}
}
}
filterByCollection( collection_a ) {
this.rows = new Array();
var objects = this.rows;
for( var c = 0; c < objects.length; c++ ) {
var renderCollection = objects[c];
var collection_b = renderCollection.getCollection();
if( collection_b.propertyName == collection_a.propertyName ) {
this.rows.push( object );
}
}
}
filterByClassName( className ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( tools.getClassName( object ) == className ) {
this.rows.push( object );
}
}
}
filterByName( name ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( object.propertyName == name ) {
this.rows.push( object );
}
}
}
filterByID( id ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( object.id == id ) {
this.rows.push( object );
}
}
}
filterByParent( parent ) {
this.filterByParentName( tools.getClassName( parent ) );
}
filterByParentName( parentName ) {
var objects = this.rows;
this.rows = new Array();
for( var c = 0; c < objects.length; c++ ) {
var object = objects[c];
if( tools.getClassName( object.parent ) == parentName ) {
this.rows.push( object );
}
}
}
getFirstRow() {
return this.rows[0];
}
}

182
framework/unify/column.js Normal file
View File

@@ -0,0 +1,182 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import document from './document.js';
import datatype from './datatype.js';
export default class column{
datatype = datatype.VARCHAR;
value = "";
type = "column";
defineSetter() {
var that = this;
this.__defineSetter__( "useCustomElement", function( value ) {
that._useCustomElement = value;
that.setupElement();
});
}
defineGetter() {
var that = this;
this.__defineGetter__( "useCustomElement", function( value ){
if( typeof that._useCustomElement == "undefined" ) {
that._useCustomElement = false;
return false;
} else {
return that._useCustomElement;
}
});
}
setup( ) {
this._useCustomElement = this.useCustomElement;
this.defineSetter();
this.defineGetter();
this.setupElement();
}
setAttributes() {
this.customElement.setAttribute( "type", this.inputType );
this.customElement.setAttribute( "autocomplete", this.autocomplete );
this.customElement.setAttribute( "placeholder", this.placeholder );
if( this.step ) {
this.customElement.setAttribute( "step", this.step );
}
if( this.placeholder && this.customElement ) {
this.customElement.setAttribute( "placeholder", this.placeholder );
}
}
serializeSizing() {
if( this.width ) {
if( typeof this.width == "number" ) {
this.customElement.style.width = this.width + "px";
} else {
this.customElement.style.width = this.width;
}
}
}
replaceCustomElement( parentNode ) {
parentNode.replaceChild( this.customElement, this.element );
this.element = this.customElement;
}
replaceDefaultElement( parentNode ) {
parentNode.replaceChild( this.defaultElement, this.element );
this.element = this.defaultElement;
}
handleDOMReplacement() {
var parentNode = this.element.parentNode;
if( this.useCustomElement ) {
if( this.element.tagName != this.customElement.tagName ) {
this.replaceCustomElement( parentNode );
}
} else {
if( this.element.tagName != this.defaultElement.tagName ) {
this.replaceDefaultElement( parentNode );
}
}
}
setupElement() {
if( this.customElement ) {
this.setAttributes();
this.serializeSizing();
}
if( this.element ) {
this.handleDOMReplacement();
this.updateElementContent();
}
}
}

View File

@@ -0,0 +1,36 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import tools from '../unify/tools.js';
import document from '../unify/document.js';
import deepclone from '../unify/clonedeep.js';
class Console{
log( ...args ) {
console.log( "Console.js:", args[0], args[1], args[2], args[2], args[3] );
}
}
export default new Console();

View File

@@ -0,0 +1,199 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
class consoleColors{
colors = new Array();
backgroundColors = new Array();
addColor( colorName, colorCode ) {
var color = new Object();
color.name = colorName;
color.code = colorCode;
this.colors.push( color );
}
addBackgroundColor( colorName, colorCode ) {
var color = new Object();
color.name = colorName;
color.code = colorCode;
this.backgroundColors.push( color );
}
constructor() {
this.createTextColors();
this.createBackgroundColors();
return this.createMethods();
}
createTextColors() {
this.addColor( "white", 37 );
this.addColor( "black", 30 );
this.addColor( "blue", 34 );
this.addColor( "cyan", 36 );
this.addColor( "green", 32 );
this.addColor( "magenta", 35 );
this.addColor( "red", 31 );
this.addColor( "yellow", 33 );
this.addColor( "brightBlack", 90 );
this.addColor( "brightRed", 91 );
this.addColor( "brightGreen", 92 );
this.addColor( "brightYellow", 93 );
this.addColor( "brightBlue", 94 );
this.addColor( "brightMagenta", 95 );
this.addColor( "brightCyan", 96 );
this.addColor( "brightWhite", 97 );
}
createBackgroundColors() {
this.addBackgroundColor( "bgBlack", 40 );
this.addBackgroundColor( "bgRed", 41 );
this.addBackgroundColor( "bgGreen", 42 );
this.addBackgroundColor( "bgYellow", 43 );
this.addBackgroundColor( "bgBlue", 44 );
this.addBackgroundColor( "bgMagenta", 45 );
this.addBackgroundColor( "bgCyan", 46 );
this.addBackgroundColor( "bgWhite", 47 );
this.addBackgroundColor( "bgBrightBlack", 100 );
this.addBackgroundColor( "bgBrightRed", 101 );
this.addBackgroundColor( "bgBrightGreen", 102 );
this.addBackgroundColor( "bgBrightYellow", 103 );
this.addBackgroundColor( "bgBrightBlue", 104 );
this.addBackgroundColor( "bgBrightMagenta", 105 );
this.addBackgroundColor( "bgBrightCyan", 106 );
this.addBackgroundColor( "bgBrightWhite", 107 );
}
createMethodsForTextColor( color, colorMethods ) {
var name = color.name;
var code = color.code;
var open = '\u001b[' + code + 'm';
var close = '\u001b[39m';
colorMethods[ name ] = function ( value ) {
return open + value + close;
}
}
createMethodsForBackgroundColor( color, colorMethods ) {
var name = color.name;
var code = color.code;
var open = '\u001b[' + code + 'm';
var close = '\u001b[49m';
colorMethods[ name ] = function ( value ) {
return open + value + close;
}
}
createMethods() {
var colors = this.colors;
var colorMethods = new Array();
for ( var i = 0; i < colors.length; i++ ) {
var textColor = colors[i];
this.createMethodsForTextColor( textColor, colorMethods );
}
var backgroundColors = this.backgroundColors;
for ( var i = 0; i < backgroundColors.length; i++ ) {
var backgroundColor = backgroundColors[i];
this.createMethodsForBackgroundColor( backgroundColor, colorMethods );
}
return colorMethods;
}
}
export default new consoleColors();

View File

@@ -0,0 +1,24 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class rule{
type = "allow";
right = "READ";
object;
}

View File

@@ -0,0 +1,157 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
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.
See the GNU AFFERO GENERAL PUBLIC LICENSE, for more details.
https://unifyjs.org
*/
import document from "./document.js"
class cookieManager{
constructor() {
if( document.cookie == "" ) {
this.createEmptyCookie( "cookieObject" )
}
}
createEmptyCookie( name ) {
this.setCookie( name, "" );
}
set( name, value ) {
var cookieObject = this.getCookieObject( "cookieObject" );
cookieObject[ name ] = value;
console.log("cookieObject", cookieObject);
this.setCookie( "cookieObject", JSON.stringify( cookieObject ) );
/*
if( !value ) {
this.createEmptyCookie( name )
} else {
var userObject = this.createCookieUser( value );
this.setCookie( name, JSON.stringify( userObject ) );
}
*/
}
get( name ) {
var cookieObject = this.getCookieObject( "cookieObject" );
return cookieObject[name];
}
getCookieObject( name ) {
var item = this.getCookie( name ).replace( name + "=", "" );
if( item == "undefined" || item == "" ) {
return new Object();
}
console.log(item);
return JSON.parse( item );
}
setCookie( name, value ){
var expirydate = new Date();
expirydate.setTime( expirydate.getTime() + ( 100 * 60 * 60 * 24 * 100 ) );
var jsonString = name + "=" + value + "; expires=" + expirydate.toGMTString();
document.cookie = jsonString;
}
getCookieStartIndex( cookieName ) {
return this.docCookie.indexOf( cookieName );
}
getCookieEndIndex( cookieName, cookieStart ) {
if ( cookieStart != -1 ) {
cookieStart = cookieStart + cookieName.length;
var end = this.docCookie.indexOf(";",cookieStart);
if ( end == -1 ) {
end = this.docCookie.length;
}
}
return end;
}
getCookieString( cookieStartIndex, cookieEndIndex ) {
return this.docCookie.substring( cookieStartIndex, cookieEndIndex );
}
getCookie( name ) {
var cookieName = name + "=";
this.docCookie = document.cookie;
if ( this.docCookie.length > 0 ) {
var cookieStartIndex = this.getCookieStartIndex( cookieName );
var cookieEndIndex = this.getCookieEndIndex( cookieName, cookieStartIndex );
var cookieString = this.getCookieString( cookieStartIndex, cookieEndIndex );
return unescape( cookieString );
}
return false
}
}
export default new cookieManager();

23
framework/unify/core.js Normal file
View File

@@ -0,0 +1,23 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class user{
}

View File

@@ -0,0 +1,31 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default {
'BOOLEAN' : 'BOOLEAN',
'INTEGER' : 'INTEGER',
'REAL' : 'REAL',
'VARCHAR' : 'TEXT',
'TEXT' : 'TEXT',
'BLOB' : 'BLOB'
}

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because one or more lines are too long

124
framework/unify/document.js Normal file
View File

@@ -0,0 +1,124 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
class documentTool {
createElementDummy( object ) {
object.createElement = function( tag ){
var object = new Object();
object.tag = tag;
return false;
}
}
createElementNSDummy( object ) {
object.createElementNS = function( tag ){
var object = new Object();
object.tag = tag;
return false;
}
}
createDummyDomMethods( object ) {
this.createElementDummy( object );
this.createElementNSDummy( object );
}
bindCustomStyleTerms( object ) {
object.customStyleTerms = ["background", "width", "height", "flexDirection", "color", "border", "margin", "padding", "boxBackground"];
}
addBoxProperties( object ) {
for( var c = 0; c < object.customStyleTerms.length; c++ ) {
object.customStyleTerms[ object.customStyleTerms[ c ] ] = "";
object.customStyleTerms[ "box" + this.CamelCase( object.customStyleTerms[ c ] ) ] = "";
}
}
createCustomStyleTerms( object ) {
this.bindCustomStyleTerms( object );
this.addBoxProperties( object );
}
getDocument(){
if( typeof document == "undefined" ){
var object = new Object();
this.createDummyDomMethods( object );
this.createCustomStyleTerms( object );
this.type = "server";
return object;
} else {
document.type = "client";
return document;
}
}
CamelCase( string ){
if( string ) {
string = string.toUpperCase();
string = string[0].toUpperCase() + string.slice(1,string.lenth).toLowerCase();
return string;
}
}
}
var object = new documentTool();
export default object.getDocument();

View File

@@ -0,0 +1,20 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class emptyObject{
}

26
framework/unify/error.js Normal file
View File

@@ -0,0 +1,26 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class Error{
data = "";
constructor( message ) {
this.data = message;
}
}

267
framework/unify/extender.js Normal file
View File

@@ -0,0 +1,267 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
https://unifyjs.org
*/
import tools from "./tools.js";
import omitMethods from "./extender.rejectMethods.js";
export default function extender( ...extenderArguments ) {
class dummyExtend {
callInstance( extenderArgument, argumentsOfSuper ) {
return new extenderArgument( ...argumentsOfSuper );
}
getExtendMap() {
if( typeof document != "undefined") {
return document.extendMap;
} else {
return global.extendMap;
}
}
removeDuplicates( extendMap, parentClassName ) {
extendMap[ parentClassName ] = extendMap[ parentClassName ].filter( ( obj, index, arr ) => {
return arr.map( mapObj => mapObj.__className ).indexOf( obj.__className ) === index;
});
}
saveInstanceInExtendMap( instance ) {
var parentClassName = this.constructor.name;
var extendMap = this.getExtendMap();
if( !extendMap[ parentClassName ] ) {
extendMap[ parentClassName ] = new Array();
}
extendMap[ parentClassName ].push( instance );
this.removeDuplicates( extendMap, parentClassName );
}
inheritPropertiesA( arg ) {
var properties = Object.getOwnPropertyNames( arg.prototype );
var propertiesFiltered = properties.filter( prop => prop !== "constructor" );
for ( const prop of propertiesFiltered ) {
if( !this[prop] ) {
this[ prop ] = arg.prototype[ prop ];
}
}
}
inheritPropertiesFromExtends( arg, root, level ) {
if( level > 0 ) {
var extendedInstance = new arg.constructor();
var prototype = Object.getPrototypeOf( extendedInstance );
var propertyNames = Object.getOwnPropertyNames( prototype );
propertyNames.forEach( methodName => {
if( !omitMethods.includes( methodName ) ) {
if( !root[ methodName ] ) {
root[ methodName ] = extendedInstance[ methodName ];
}
}
});
}
var extendedClass = tools.getExtendedClass( arg );
if( extendedClass ) {
this.inheritPropertiesFromExtends( extendedClass, root, level + 1 );
}
}
constructor( ...argumentsOfSuper ) {
// extenderArguments = this.constructor.extenderArguments;
for( const extenderArgument of extenderArguments ) {
var instance = this.callInstance( extenderArgument, argumentsOfSuper );
Object.assign( this, instance );
this.saveInstanceInExtendMap( instance );
this.inheritPropertiesA( extenderArgument );
this.inheritPropertiesFromExtends( extenderArgument, this, 0 );
}
}
}
class table {
createInstance() {
var instance = new arg();
Object.assign( this, instance );
return instance;
}
assureExtendMap() {
if( typeof document == "undefined") {
var extendMap = global.extendMap;
} else {
var extendMap = document.extendMap;
}
if( !extendMap[ parentClassName ] ) {
extendMap[ parentClassName ] = new Array();
}
}
addInstanceToExtendMap( extendMap, instance ) {
var parentClassName = this.constructor.name;
extendMap[ parentClassName ].push( instance );
}
updateExtendMap( instance ) {
this.assureExtendMap();
this.addInstanceToExtendMap( instance );
}
getProperties( arg ) {
return Object.getOwnPropertyNames( arg.prototype ).filter( prop => prop !== "constructor" );
}
updateProperties( arg ) {
var properties = this.getProperties( arg );
for ( const property of properties ){
this[ property ] = arg.prototype[ property ]
}
}
/**
* Creates an instance of Class.
*
* @memberOf Class
*/
constructor(...opts) {
for( const arg of extenderArguments ) {
var instance = this.createInstance();
this.updateExtendMap( instance );
this.updateProperties( arg );
}
}
}
var isTable = false;
for( const arg of extenderArguments ) {
var instance = new arg();
if( instance.constructor.name == "table" ) {
isTable = true;
}
}
if( isTable ) {
return table;
} else {
//dummyExtend.extenderArguments = extenderArguments;
return dummyExtend;
}
}

View File

@@ -0,0 +1,68 @@
export default new Array(
"extendDefaultObject",
"exposeMethodsToObject",
"getID",
"getFirstID",
"getApplicationPath",
"getChildren",
"getProperties",
"getParentWithTable",
"getRoot",
"getCore",
"getExtendedClass",
"getExtendedClassName",
"parents",
"getAll",
"getObjectsByClassName",
"isTable",
"extendsTable",
"extendsClass",
"extend",
"setApplicationPath",
"getApplicationPathString",
"setID",
"setApplicationID",
"setParent",
"setUser",
"setUserChildren",
"isHidden",
"syncAllChildren",
"prepend",
"add",
"remove",
"serialize",
"clean",
"clear",
"hide",
"show",
"hideChildren",
"showChildren",
"processGridElement",
"allow",
"isAllowed",
"updatePermissions",
"log",
"updateElementContent",
"computePermissions",
"showParents",
"simpleClone",
"updateProperties",
"extendsClassWorking",
"getExtends",
"getExtendObjects",
"isVisible",
"getProperties",
"__defineGetter__",
"__defineSetter__",
"hasOwnProperty",
"__lookupGetter__",
"__lookupSetter__",
"isPrototypeOf",
"propertyIsEnumerable",
"toString",
"valueOf",
"toLocaleString",
"__proto__",
"collection" );

View File

@@ -0,0 +1,52 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import querySQL from './querySQL.js';
class joinSide{
table;
column;
}
export default class joinSQL extends querySQL{
__className = "joinSQL";
type = "join";
left = new joinSide();
right = new joinSide();
joins = new Array();
querys = new Array();
addJoin( join ) {
this.joins.push( join );
}
addQuery( query ) {
this.querys.push( query );
}
}

View File

@@ -0,0 +1,15 @@
export default class vector2{
constructor( x, y ) {
this.x = x;
this.y = y;
}
x = 0;
y = 0;
}

View File

@@ -0,0 +1,25 @@
export default (baseClass, ...mixins) => {
class base extends baseClass {
constructor (...args) {
super(...args);
mixins.forEach((mixin) => {
copyProps(this,(new mixin));
});
}
}
let copyProps = (target, source) => { // this function copies all properties and symbols, filtering out some special ones
Object.getOwnPropertyNames(source)
.concat(Object.getOwnPropertySymbols(source))
.forEach((prop) => {
if (!prop.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/))
Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop));
})
}
mixins.forEach((mixin) => { // outside contructor() to allow aggregation(A,B,C).staticFunction() to be called etc.
copyProps(base.prototype, mixin.prototype);
copyProps(base, mixin);
});
return base;
}

View File

@@ -0,0 +1,63 @@
export default [ "extendDefaultObject",
"exposeMethodsToObject",
"getID",
"getFirstID",
"getApplicationPath",
"getChildren",
"getProperties",
"getParentWithTable",
"getRoot",
"getCore",
"getExtendedClass",
"getExtendedClassName",
"parents",
"getAll",
"getObjectsByClassName",
"isTable",
"extendsTable",
"extendsClass",
"extend",
"setApplicationPath",
"getApplicationPathString",
"setID",
"setApplicationID",
"setParent",
"setUser",
"setUserChildren",
"isHidden",
"syncAllChildren",
"prepend",
"add",
"remove",
"serialize",
"clean",
"clear",
"hide",
"show",
"hideChildren",
"showChildren",
"processGridElement",
"allow",
"isAllowed",
"updatePermissions",
"log",
"updateElementContent",
"computePermissions",
"showParents",
"simpleClone",
"updateProperties",
"extendsClassWorking",
"getExtends",
"getExtendObjects",
"isVisible",
"getProperties",
"__defineGetter__",
"__defineSetter__",
"hasOwnProperty",
"__lookupGetter__",
"__lookupSetter__",
"isPrototypeOf",
"propertyIsEnumerable",
"toString",
"valueOf",
"toLocaleString","__proto__", "collection", "animationManager", "socketManager", "core", "isRenderCollection", "getClassName", "permission", "constructor", "filter", "filterCustom", "filterByType", "filterByCollection", "filterByClassName", "filterByName", "filterByID", "filterByParent", "filterByParentName", "getFirstRow", "getTableName", "createInstance", "getColumnName", "getFilter", "getParentName", "getLeft", "set", "addObject", "createVisitor", "process"];

View File

@@ -0,0 +1,23 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class permission{
userObject;
type;
}

View File

@@ -0,0 +1,485 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import unify from '../unify/unify.js';
import userPermission from '../unify/userPermission.js';
import validator from '../unify/validator.js';
class visitor{
value = 2.0;
label = "Member";
color = "black";
type = "userGroup";
}
export default class permissionManager{
__className = "permissionManager";
permissions = new Array();
addPermission( user, type ) {
var currentPermission = new userPermission( user, type, "allow" );
this.permissions.push( currentPermission );
}
allow( user, type ) {
// If the user is not signed in and this method has this.user as first argument
// user == false, to prevent that everybody gets access:
if( !user ) {
return false;
}
this.addPermission( user, type );
//this.permissions[ user.id ] = currentPermission; // performance upgrade
}
callPermissionMethod( object ) {
var clone = object.simpleClone();
if( object.type == "table" && !object.updated ) {
object.get();
}
object.permissionManager.permissions = new Array();
object.permissions = new Array(); // this is the working one
object.permission( clone );
}
noPermissionsWarning( object ) {
if( object.permissionManager.permissions.length == 0 ) {
if( object.debug ) {
console.log("No permissions are set for this object, All request are rejected..");
}
}
}
createVisitor( ) {
var table = new global.user();
table.username.value = "Visitor";
table.id = 0;
table.groups = new visitor();
return table;
}
isAllowed( user, type, object ) {
if( !user ) {
// todo: do this in the core
user = this.createVisitor( );
}
if( object.permission ) {
this.callPermissionMethod( object );
this.noPermissionsWarning( object );
}
var permission = new userPermission( user, type );
if( this.permissions.length == 0 ) {
return false;
}
var isPermitted = this.checkPermissions( permission );
if( isPermitted ) {
return true;
} else {
return false;
}
}
checkPermissions( permissionB ) {
for( var c = 0; c < this.permissions.length; c++ ) {
var permission = this.permissions[c];
if( this.checkPermission( permission, permissionB ) ) {
return true;
}
}
return false;
}
checkCollectionPermission( permission, permissionB ) {
var permissionA = new userPermission( permissionB.userObject, permission.type, permissionB.userObject );
if( this.comparePermission( permissionA, permissionB ) ) {
return true;
}
/*
var users = collection.querySelect();
for(var b = 0; b<users.length; b++) {
var permissionA = {};
permissionA.type = permission.type;
permissionA.policy = permission.policy;
permissionA.userObject = users[b];
if( this.comparePermission( permissionA, permissionB ) ) {
return true;
}
}
*/
}
checkRenderObjectPermissionUser( permissionA, permissionB, validator ) {
if( currentUser.value ) {
var permissionA = new userPermission();
permissionA.type = permission.type;
permissionA.policy = permission.policy;
permissionA.userObject = currentUser[ b ];
if( this.comparePermission( permissionA, permissionB ) ) {
validator.isValid = true;
}
}
}
checkRenderobjectPermission( permission, permissionB ) {
var userObject = permission.userObject;
var users = userObject.rows;
var validator = new validator();
for( var b = 0; b < users.length; b++ ) {
var currentUser = users[b];
this.checkRenderObjectPermissionUser( permissionA, permissionB, validator );
if( validator.isValid ) {
return true;
}
}
}
checkUserGroupPermission( permission, permissionB ) {
var user = permissionB.userObject;
var userGroup = permission.userObject;
if(!user.groups) {
return false;
}
//console.log(user);
if( user.groups.value != userGroup.value ) {
return false;
}
if( permissionB.type != permission.type ) {
return false;
}
return true;
}
isDefined( userObject, validator ) {
if( !userObject ) {
validator.isValid = false;
}
}
isUserPlaceholder( userObject, validator ) {
if( userObject == "userplaceholder" ) {
validator.isValid = false;
}
}
validateVisitor( permission, permissionB, validator ) {
if( !permissionB.userObject ) {
if( permission.userObject.__className == "visitor" ) {
validator.isValid = true;
} else {
validator.isValid = false;
}
}
}
compareUser( permission, permissionB, validator ) {
if( this.comparePermission( permission, permissionB ) ) {
validator.isValid = true;
}
}
compareCollection( permission, permissionB, validator ) {
if( this.checkCollectionPermission( permission, permissionB ) ) {
validator.isValid = true;
}
}
compareRenderCollection( permission, permissionB, validator ) {
if( this.checkRenderobjectPermission( permission, permissionB ) ) {
validator.isValid = true;
}
}
compareUserGroup( permission, permissionB, validator ) {
if( this.checkUserGroupPermission( permission, permissionB ) ) {
validator.isValid = true;
}
}
validateObjects( userObject, validator ) {
this.isDefined( userObject, validator );
this.isUserPlaceholder( userObject, validator );
}
compareObjects( userObject, permission, permissionB, validator ) {
switch( userObject.getClassName() ) {
case "user":
this.compareUser( permission, permissionB, validator );
break;
case "userObject":
this.compareUser( permission, permissionB, validator );
break;
case "collection":
this.compareCollection( permission, permissionB, validator );
break;
default:
if( userObject.type == "renderCollection") {
this.compareRenderCollection( permission, permissionB, validator );
}
if ( userObject.type == "userGroup") {
this.compareUserGroup( permission, permissionB, validator );
}
if ( userObject.isUser ) {
this.compareUser( permission, permissionB, validator );
}
}
return validator;
}
checkPermission( permission, permissionB ) {
var userObject = permission.userObject;
var validator = new Object();
validator.isValid = true;
this.validateObjects( userObject, validator );
this.validateVisitor( permission, permissionB, validator );
if( !validator.isValid ) {
return false;
}
validator.isValid = false;
unify.extend( userObject );
this.compareObjects( userObject, permission, permissionB, validator );
return validator.isValid;
}
comparePermission( permissionA, permissionB ) {
if( permissionA.userObject.id == 0 ) {
return false;
}
if( permissionA.userObject.id != permissionB.userObject.id ) {
return false;
}
if( permissionA.type != permissionB.type ) {
return false;
}
if( permissionA.policy != "allow" ) {
return false;
}
return true;
}
deny( user, type ) {
var currentPermission = new userPermission( user, type );
this.permissions.push( currentPermission );
}
}

View File

@@ -0,0 +1,25 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class permissionObject{
READ;
WRITE;
DELETE;
}

View File

@@ -0,0 +1,21 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class placeholder{
}

View File

@@ -0,0 +1,109 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class promiseManager{
promises = new Array();
messages = new Array();
socketManager;
addPromise( promiseObject ) {
this.promises.push( promiseObject );
}
addMessage( message ) {
this.messages.push( message );
}
getPromiseByID( id ) {
var promises = this.promises;
for( var c = 0; c < promises.length; c++ ) {
var currentPromise = promises[c];
if( currentPromise.id == id ) {
return currentPromise;
}
}
console.error( "Promise with id " + id + " not found", this );
return false;
}
getMessageByID( id ) {
var messages = this.messages;
for( var c = 0; c < messages.length; c++ ) {
var message = messages[c];
if( message.id == id ) {
return message;
}
}
}
createPromise( messageID, resolveFunction, object ) {
var promiseObject = new Object();
promiseObject.id = messageID;
promiseObject.resolve = resolveFunction;
if( object ) {
promiseObject.object = object;
}
}
createPromiseFunction( messageID, object ) {
var promiseManager = this;
function promiseFunction( resolveFunction ){
var promiseObject = this.createPromise( messageID, resolveFunction, object );
promiseManager.addPromise( promiseObject );
}
return promiseFunction;
}
}

1636
framework/unify/purify.js Normal file
View File

File diff suppressed because it is too large Load Diff

484
framework/unify/querySQL.js Normal file
View File

@@ -0,0 +1,484 @@
import tools from '../unify/tools.js';
import Console from '../server/console.js';
export default class querySQL{
__className = "querySQL";
type = "select";
columns = new Array();
table;
sync = true;
values = new Array();
objects = new Array();
where = new Array();
groups = new Array();
union = new Array();
order = new Array();
direction;
limit;
count;
from;
to;
joins = new Array();
filter = false;
filterAddress = "";
constructor( query ) {
if( query ) {
var items = Object.entries( query );
var queryString = "";
for(var c = 0; c<items.length; c++){
var currentQuery = items[c];
var name = tools.getClassNameByEntry( currentQuery);
var value = tools.getObjectByEntry( currentQuery);
this[ name ] = value;
}
}
}
orderBy( order ) {
this.order.push( order );
}
addUnion( unionQuery ) {
this.union.push( unionQuery );
}
setFilterAddress( filter ) {
this.filterAddress = filter;
}
setFilter( filterAddress ) {
this.filter = filterAddress;
}
addJoin( join ) {
if( !join.name ) {
console.error( "join requires name", this, join );
}
this.joins.push( join );
}
addColumn( columnName ) {
this.columns.push( columnName );
}
addGroup( columnName ) {
var group = new Object();
group.columnName = columnName;
this.groups.push( group );
}
getWhereByColumnName( name ) {
for (var i = 0; i < this.where.length; i++) {
var where = this.where[i];
if( where.columnName == name ) {
return where.value;
}
}
return false;
}
find( columnName, value, type = "=", quotation = true, or = false ) {
var where = {};
where.columnName = columnName;
where.value = value;
where.type = type;
where.quotation = quotation;
where.or = or;
this.where.push( where );
}
getColumnByName( name ) {
for (var i = 0; i < this.values.length; i++) {
var column = this.values[i];
if( column.name == name ) {
return column;
}
}
return false;
}
setColumn( columnName, value ) {
if( typeof value == "boolean" ) {
if( value ) {
value = "1";
} else {
value = "0";
}
}
var column = new Object();
column.name = columnName;
column.value = value;
this.values.push( column );
}
setValue( columnName, value ) {
var column = {};
if( typeof value == "boolean" ) {
if( value ) {
value = "true";
} else {
value = "false";
}
}
column.name = columnName;
column.value = value;
this.values.push( column );
}
set( columnName, value ) {
var column = {};
column.name = columnName;
column.value = value;
this.values.push( column );
}
getColumnNames() {
var columnNames = new Array();
for(var c = 0; c<this.values.length;c++) {
columnNames.push( this.values[c].name );
}
return columnNames.join(", ");
}
getValues() {
var values = new Array();
for(var c = 0; c<this.values.length;c++) {
values.push( this.values[c].value );// todo : bug :
}
return values;
}
extractColumns( object, queryName ) {
var children = object.getChildren();
this.addColumn( queryName + ".id" );
for(var c = 0; c<children.length; c++) {
var child = children[c];
if( child.datatype ) {
this.addColumn( queryName + "." + child.propertyName );
}
if( child.type == "table" ) {
var name = child.propertyName;
var columnName = name + "_id";
this.addColumn( queryName + "." + columnName );
}
}
}
/* doesnt make sense
addRows( rows ) {
for (var i = 0; i < rows.length; i++) {
this.addRow( rows[i] );
}
}
*/
addRow( row ) {
const entries = Object.entries( row );
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
this.addColumn( entry[0] );
this.setColumn(entry[0], entry[1]);
}
}
addObject( object ) {
if( this.objects.length == 0 ) {
this.table = tools.getTableName( object );
if( !this.table ) {
this.table = tools.getTableName( object.parent );
this.setColumn( object.propertyName, object.value );
} else {
if( object.user && object.user.id ) {
var properties = object.getProperties();
for( var c = 0;c<properties.length;c++ ) {
var property = properties[c];
if( property.value == "userplaceholder" && property.name != "user") {
this.setColumn( property.name + "_id", object.user.id );
}
}
}
var children = object.getChildren();
for( var c = 0; c < children.length; c++ ) {
var child = children[c];
//console.log(child.propertyName, child.type, child.extendsClass( "table" ));
if( child.datatype ) {
if( typeof child.constraints == "object" ) {
if( child.constraints.includes("AUTOINCREMENT") ) {
//console.log("skip this row, Dont overide AUTOINCEMENT");
continue;
}
}
// get Column name
var columnName = child.getColumnName();
if( !columnName ) {
columnName = child.propertyName;
}
//console.log("save column", child.propertyName, child.getExtends(), child.getColumnName() );
this.setColumn( columnName , child.value );
}
// bug fixed.
if( child.type == "table" && child.extendsTable() ) { // && child.extendsClass( "table" )?? bug
var name = child.propertyName;
var columnName = name + "_id";
var id = child.id;
//console.log("id", id);
// ???
if( id ) {
this.setColumn( columnName, id );
}
} //else {
//if( child.type == "table" ) {
//console.log("what is so special about this", child);
//}
//}
}
}
if(this.type.toLowerCase() == "update") {
this.find( "id", object.id );
}
}
//console.log("added object to query", this);
this.objects.push( object );
}
queryUpdateChildren() {
var objects = this.objects;
var id = 0;
for(var c = 0; c<objects.length; c++) {
var object = objects[c];
var values = new Array();
var children = object.getChildren();
for(var c = 0; c<children.length; c++) {
var child = children[c];
if(child.datatype) {
values.push( child.value );
}
}
values.push( object.id );
//Console.log( "update children", values );
//this.sql.run( values );
}
}
}

View File

@@ -0,0 +1,486 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import tools from '../unify/tools.js';
import baseRenderCollection from '../server/renderCollection.js';
import shared from '../unify/shared.js';
import defaultObject from '../unify/defaultObject.js';
import collection from '../unify/collection.js';
import document from '../unify/document.js';
import userManager from '../server/userManager.js';
import searchable from '../unify/sql/searchable.js';
import unify from '../unify/unify.js';
import placeholder from '../unify/placeholder.js';
export default class renderCollection extends baseRenderCollection {
object;
collections = new Array();
collection = false; // Future
storageCollection = false;
type = "renderCollection";
rows = new Array();
filterObject = false;
processAsync = false;
handleRenderCollection( renderCollection ) {
var currentCollection = renderCollection.getCollection();
if( !renderCollection.storageCollection ) {
renderCollection.storageCollection = new collection( currentCollection.object );
renderCollection.storageCollection.enabled = false;
}
collection1 = renderCollection.storageCollection;
}
handleCollection( argument ) {
this.storageCollection = new collection( argument.object );
this.storageCollection.name = "storageCollection";
var defaultObjectInstance = new defaultObject();
defaultObjectInstance.exposeMethodsToObject( this.storageCollection );
this.setCollection( argument );
}
handleSecondArgument( argument ) {
switch( argument.type ) {
case "renderCollection":
this.handleRenderCollection( argument );
break;
case "collection":
this.handleCollection( argument );
break;
}
}
constructor( object, secondArgument ) {
super();
if( secondArgument ) {
this.handleSecondArgument( secondArgument );
} else {
if( object ) {
//return false;
//this.logMissingArgument();
}
}
this.object = object;
}
logMissingArgument() {
console.log("\n_______________________________________________\n\n\n\n");
console.error( '\x1b[31m%s\x1b[0m', 'Collection of renderCollection Not set:\n ' );
console.log("This renderCollection will not load anything, There is probably an typo in the second argument or no collection present as second argument. \n");
console.log( this )
console.log("\n_______________________________________________\n\n\n\n");
}
createInstance() {
var object = new this.object();
unify.extend( object );
return object;
}
setupObject( sourceObject, client, rowID ) {
var object = this.createInstance();
// todo : caution : this wasn't commented and can cause problems, But this can probably be removed because of multi extend.
//object.extend( this.getCollection().createInstance() );
object.id = sourceObject.id;
object.parent = this;
object.dynamic = true;
object.propertyName = object.getClassName() + object.id;
object.load = false;
object.rowID = rowID;
object.serialize( sourceObject, client );
return object;
}
callMethods( object, client ) {
if( client ) {
if( object.process ) {
object.process( object );
}
}
}
bindAsChild( object ) {
this[ object.propertyName ] = object;
}
updatePermissionsClientAndServer( object, client ) {
if( client ) {
this.getPermissionForHierarchy( object, client.user );
} else {
object.updatePermissions( object.permissions );
}
return object;
}
addToCollection( object ) {
var collection = this.getCollection();
collection.rows.push( object );
}
addRow( sourceObject, client, rowID ) {
var object = this.setupObject( sourceObject, client, rowID );
this.callMethods( object, client )
this.bindAsChild( object );
this.getCore().parse( object, client );
this.updatePermissionsClientAndServer( object, client );
this.addToCollection( object );
return object;
}
getPermissionForHierarchy( object, user ) {
object.permissions = userManager.computePermissions( object, user );
var children = object.getChildren();
for (var i = 0; i < children.length; i++) {
var child = children[i];
if( child.isAllowed ) {
this.getPermissionForHierarchy( child, user )
}
}
}
async addRowSync( sourceObject, client, rowID ) {
var object = this.setupObject( sourceObject, client, rowID );
this.callMethods( object, client )
this.bindAsChild( object );
if( client ) {
await this.getCore().parse( object, client );
} else {
await this.getCore().parse( object, true );
}
this.updatePermissionsClientAndServer( object, client );
this.addToCollection( object );
return object;
}
setCollection( collection ) {
if( !collection ) {
this.collections = new Array();
} else {
this.collections = [ collection ];
}
}
setCollectionObject( collectionObject ) {
var newCollection = new collection( collectionObject );
this.setCollection( newCollection );
this.object = collectionObject;
}
getCollection() {
return this.collections[0];
}
createFilterObject() {
if( !this.filterObject ) {
this.filterObject = new placeholder();
}
this.filterObject.__className = "placeholder";
unify.extend( this.filterObject );
}
createCollectionSearchable( collection, child ) {
var tableName = collection.createInstance().getClassName();
//tableName
var search = new searchable( "./" + collection.propertyName + "/" + child.propertyName );
this.filterObject[ collection.propertyName ][ child.propertyName ] = search;
}
handleFilterCollectionChildren( collectionObject, collection ) {
var collectionChildren = collectionObject.getChildren();
for( var b = 0; b < collectionChildren.length; b++ ) {
var child = collectionChildren[b];
this.createCollectionSearchable( collection, child );
}
}
handleCollectionSearchables( child ) {
if( child.type == "collection") {
var collectionObject = child.createInstance();
unify.extend( collectionObject );
this.filterObject[ child.propertyName ].tableName = collectionObject.getClassName()
this.filterObject[ child.propertyName ].type = "collection";
this.handleFilterCollectionChildren( collectionObject, child )
}
}
createSearchable( child, parent ) {
//console.log("get news from this", parent);
var search = new searchable( parent.getClassName() + "/" + child.propertyName );
this.filterObject[ child.propertyName ] = search;
}
createSearchables( object ) {
var children = object.getChildren();
for( var c = 0; c < children.length; c++ ) {
var child = children[c];
this.createSearchable( child, object );
this.handleCollectionSearchables( child );
}
}
createSearchableID() {
var search = new searchable( "./id" );
this.filterObject[ "id" ] = search;
}
getCollectionObject() {
var collection = this.getCollection();
var realObject = new collection.object();
unify.extend( realObject );
return realObject;
}
getFilter() {
/*
var collection = this.getCollection();
return collection.getFilter();
*/
this.createFilterObject();
this.createSearchableID();
var object = this.getCollectionObject();
this.createSearchables( object );
//console.log("this.filterObject", this.filterObject);
return this.filterObject;
}
createInstance() {
return new this.object();
}
getChildrenRenderCollections2( object, client ) {
var children = object.getChildren( );
for( var c = 0; c < children.length; c++ ) {
var child = children[ c ];
if( child.type == "renderCollection" ) {
child.id = object.id;
child = this.get( child, client );
}
}
}
getChildrenRenderCollections( client ) {
var rows = this.rows;
for( var b = 0; b < rows.length; b++ ) {
var row = rows[b];
this.getChildrenRenderCollections2( row, client );
}
}
}

View File

@@ -0,0 +1,21 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class serialized{
}

View File

@@ -0,0 +1,797 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import placeholder from './placeholder.js';
import objectSerializer from "./serializer.object.js";
import tools from './tools.js';
import cssManager from "../client/css.js";
class cleanManager{
css = new cssManager();
clean( sourceObject, method ) {
if( tools.getEnvironment() == "Node" ) {
var cleanObject = this.cleanObject( sourceObject );
} else {
this.findColumns( sourceObject );
//this.preserveValues();
//console.log(sourceObject);
var cleanObject = this.cleanObject( sourceObject, method );
}
var name = sourceObject.getClassName();
var object = this.createOuterObject( name, cleanObject );
return object;
}
preserveValues() {
}
createOuterObject( classname, object ) {
var outerObject = new placeholder();
outerObject[ classname ] = object;
return outerObject;
}
findExtendedClass( child, extendedClass, table ) {
if( !extendedClass.datatype ) {
return false;
}
var column = tools.isUnifyColumn( extendedClass );
var columnName = tools.getClassName( extendedClass );
if( !column ) {
return false;
}
table[ columnName ].value = child.value;
}
findExtendedClasses( child, parent, table ) {
if( parent.type == "table" ) {
return false;
}
if( !child.datatype ) {
return false;
}
var extendedClasses = tools.getExtendedClassesMulti( child );
for ( var c = 0; c < extendedClasses.length; c++ ) {
var extendedClass = extendedClasses[ c ];
this.findExtendedClass( child, extendedClass, table );
}
}
findChild( child, parent, table ) {
this.findExtendedClasses( child, parent, table );
if( parent.type == "table" ) {
table = parent;
}
this.findColumns( child, table );
}
findColumns( parent, table = false ) {
if( !parent.getChildren ) {
return false;
}
var children = parent.getChildren();
for ( var i = 0; i < children.length; i++ ) {
var child = children[i];
this.findChild( child, parent, table );
}
}
cleanColumn( sourceObject, targetObject ) {
if( sourceObject.id ) {
targetObject.id = tools.validateNumber( sourceObject.id );
}
targetObject = objectSerializer.serializeValue( sourceObject, targetObject );
targetObject.type = "column";
}
searchValues( sourceObject, targetObject ) {
if( !sourceObject.getChildren ) {
return false;
}
var children = sourceObject.getChildren();
var preserveParent = false;
for ( var i = 0; i < children.length; i++ ) {
var sourceChild = children[i];
if( sourceChild.type == "table" ) {
continue;
}
var propertyName = tools.validateString( sourceChild.propertyName );
//console.log(sourceChild.getClassName(), sourceChild.getChildren(), sourceChild.value);
if( sourceChild.value != "" && sourceChild.value ) {
preserveParent = true;
sourceChild.preserve = true;
}
var preserveChild = this.searchValues( sourceChild ) //targetChild
if( preserveChild ) {
sourceChild.preserve = true;
preserveParent = true;
}
}
return preserveParent;
}
preserveTree( sourceObject, targetObject ) {
if( !sourceObject.getChildren ) {
return false;
}
var children = sourceObject.getChildren();
for (var i = 0; i < children.length; i++) {
var sourceChild = children[i];
var propertyName = tools.validateString( sourceChild.propertyName ); // target class is save
if( propertyName == "groups") {
continue;
}
if( propertyName == "group") {
continue;
}
if( sourceChild.preserve && !targetObject[ propertyName ] ) {
targetObject[ propertyName ] = this.cleanObject( sourceChild );
this.preserveTree( sourceChild, targetObject[ propertyName ] )
}
}
}
cleanObject( sourceObject, method ) {
if( sourceObject.scope == "private" ) {
return false;
}
var targetObject = new placeholder();
var preserve = true;
if( method == "get" && tools.getEnvironment() == "Browser" ) {
preserve = false;
}
if( preserve ) {
this.searchValues( sourceObject, targetObject);
this.preserveTree( sourceObject, targetObject);
}
switch( sourceObject.type ) {
case "column":
this.cleanColumn( sourceObject, targetObject );
targetObject = objectSerializer.serializeProperties( sourceObject, targetObject, method );
break;
case "table":
targetObject = objectSerializer.serializeProperties( sourceObject, targetObject );
this.cleanTable( sourceObject, targetObject, method );
targetObject = objectSerializer.serializeProperties( sourceObject, targetObject, method );
break;
case "renderCollection":
if( tools.getEnvironment() == "Node" ) {
this.cleanRenderCollection( sourceObject, targetObject );
}
targetObject = objectSerializer.serializeProperties( sourceObject, targetObject, method );
break;
default:
this.cleanDefault( sourceObject, targetObject, method );
}
if( tools.getEnvironment() == "Node" ) {
this.propegateNewPropertiesOutside( sourceObject, targetObject );
}
return targetObject;
}
cleanDefault( sourceObject, targetObject, method ) {
targetObject = objectSerializer.serializeProperties( sourceObject, targetObject, method );
targetObject = this.cleanProperties( sourceObject, targetObject );
targetObject.serializationType = "object";
this.cleanChildren( sourceObject, targetObject );
}
cleanColumn( sourceObject, targetObject ) {
if( sourceObject.id ) {
targetObject.id = tools.validateNumber( sourceObject.id );
}
targetObject = objectSerializer.serializeValue( sourceObject, targetObject );
targetObject.type = "column";
}
cleanChildren( sourceObject, targetObject, method ) {
if( sourceObject.getChildren ) {
var children = sourceObject.getChildren();
for( var c = 0; c < children.length; c++ ) {
var child = children[ c ];
var propertyName = child.propertyName;
//targetObject[ propertyName ] = this.cleanObject( child );
if( propertyName == "groups" ) {
continue;
}
if( method == "get" && tools.getEnvironment() == "Browser" ) {
continue;
}
if( child.type == "table" || child.value ) {
targetObject[ propertyName ] = this.cleanObject( child );
}
}
}
}
cleanTable( sourceObject, targetObject, method ) {
if( typeof sourceObject.value ) {
targetObject = objectSerializer.serializeValue( sourceObject, targetObject );
}
if( sourceObject.id ) {
targetObject.id = tools.validateNumber( sourceObject.id );
}
if( sourceObject.status ) {
targetObject.status = tools.validateString( sourceObject.status );
}
targetObject.type = "table";
targetObject.serializationType = "object";
//targetObject.collection = false;
if( method != "get" || tools.getEnvironment() == "Node" ) {
if( sourceObject.collections && sourceObject.collections.length > 0 ) {
var collection = sourceObject.getCollection();
//this.cleanCollection( sourceObject, targetObject )
}
this.cleanChildren( sourceObject, targetObject, method );
}
}
serializeCollection( sourceCollection, targetObject ) {
var targetCollection = new placeholder();
targetObject.collections = new Array();
targetCollection.id = sourceCollection.id;
targetObject.collections.push( targetCollection );
}
cleanRenderCollection( sourceObject, targetObject ) {
if( sourceObject.id ) {
targetObject.id = tools.validateNumber( sourceObject.id );
}
targetObject = objectSerializer.serializeValue( sourceObject, targetObject );
this.cleanRenderCollectionRows( sourceObject, targetObject );
//targetObject = this.cleanCollection( sourceObject, targetObject );
if( tools.getEnvironment() == "Browser" ) {
//this.propegateNewProperties( sourceObject, targetObject );
}
targetObject.type = "renderCollection";
targetObject.useCache = sourceObject.useCache;
targetObject.performCacheUpdate = sourceObject.performCacheUpdate;
}
cleanRenderCollectionRows( sourceObject, targetObject ) {
if( sourceObject.rows ) {
var rows = sourceObject.rows;
targetObject.rows = new Array();
for( var c = 0; c < rows.length; c++ ) {
var row = rows[c];
if( row.type == "table" ) {
var rowObject = this.cleanObject( row );
}
targetObject.rows.push( rowObject );
}
}
return targetObject;
}
cleanProperties( sourceObject, targetObject ) {
const allowedProperties = new Array( "permissionObjects", "childrenPermissions" );
for ( var i = 0; i < allowedProperties.length; i++ ) {
var propertieName = allowedProperties[i];
if( sourceObject[ propertieName ] ) {
targetObject[ propertieName ] = sourceObject[ propertieName ];
}
}
return targetObject;
}
cleanCollection( sourceObject, targetObject ) {
if( sourceObject.getCollection && sourceObject.getCollection() ) {
var collection = sourceObject.getCollection();
targetObject.collection = new placeholder();
targetObject.collection.objectName = tools.getClassName( new collection.object() ).split("$")[0];
targetObject.collection.propertyName = collection.propertyName;
if( collection.parent ) {
targetObject.collection.parentID = collection.parent.id;
targetObject.collection.parentName = tools.getClassName( tools.getTableFromObject( collection.parent ) );
}
}
return targetObject;
}
propegateRenderCollection( sourceObject, targetObject, newProperies ) {
var properties = sourceObject.getProperties();
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
this.propegateNewProperty( property, targetObject, newProperies );
}
}
propegateBrowserProperty( targetObject, property ) {
if( typeof property.value == "string" ) {
targetObject[ property.name ] = property.value;
}
}
propegateBrowserProperties( sourceObject, targetObject ) {
if( tools.getEnvironment() == "Node" ) {
return false;
}
var properties = tools.getProperties( sourceObject );
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
this.propegateBrowserProperty( targetObject, property );
}
}
propegateProperty( targetObject, property ) {
const preserved = new Array( "placeholder", "load", "permissions", "collections", "__sourcePath", "__sourcePath", "rowID", "tableName", "datatype", "_value", "__value", "__sourcePath", "synced", "permissionManager", "filterObject", "parent", "__nodeMethods", "__className", "join_id", "serializationType", "value", "clearOnSync","type","propertyName","showValue","propegateEvent","enabled","renderToDOM","isActive","parse","parseChildren","parseTable","layers", 'useCustomElement', 'editable', 'defaultDisplayType', 'scrollbarWidth', 'boxFlex', 'debug', "defaultBoxDisplayType");
if( !property.value ) {
return false;
}
if( typeof property.name != "string" ) {
return false;
}
if( this.css.propertyIsStyle( property.name.replace("__", "") ) ) {
return false;
}
if( targetObject[ property.name ] ) {
return false;
}
if( preserved.includes( property.name ) ) {
return false;
}
targetObject[ property.name ] = property.value;
}
propegateNewPropertiesOutside( sourceObject, targetObject ) {
if( sourceObject.permissions ) {
targetObject.permissions = objectSerializer.serializePermission( sourceObject.permissions );
}
if( sourceObject.permissionObjects ) {
targetObject.permissionObjects = sourceObject.permissionObjects;
}
if( sourceObject.data ) {
targetObject.data = sourceObject.data;
}
if( sourceObject.type == "renderCollection" ) {
return false;
}
var properties = tools.getProperties( sourceObject );
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
this.propegateProperty( targetObject, property );
}
}
propegateNewProperties( sourceObject, targetObject ) {
var newProperies = new Array();
if( sourceObject.getProperties ) {
if( sourceObject.type == "renderCollection" ) {
this.propegateRenderCollection( sourceObject, targetObject, newProperies );
}
} else {
this.propegateBrowserProperties( sourceObject, targetObject );
}
return newProperies;
}
propegateNewProperty( property, targetObject, newProperies ) {
this.propegateBoxProperty( property );
this.propegateValue( property, targetObject, newProperies );
}
propegateBoxProperty( property ) {
const preserved = new Array("serializationType", "value", "clearOnSync","type","propertyName","showValue","propegateEvent","enabled","renderToDOM","isActive","parse","parseChildren","parseTable","layers", 'useCustomElement', 'editable', 'defaultDisplayType', 'scrollbarWidth', 'boxFlex', 'debug', "defaultBoxDisplayType");
if( !property.name.toLowerCase().includes("box") ) {
return false;
}
if( preserved.includes( property.name.replace( "box", "" ) ) ) {
return false;
}
property.name = tools.firstLowerCase( property.name.replace( "box", "" ) );
}
propegateValue( property, targetObject, newProperies ) {
const preserved = new Array( "serializationType", "value", "clearOnSync","type","propertyName","showValue","propegateEvent","enabled","renderToDOM","isActive","parse","parseChildren","parseTable","layers", 'useCustomElement', 'editable', 'defaultDisplayType', 'scrollbarWidth', 'boxFlex', 'debug', "defaultBoxDisplayType" );
if( typeof property.name != "string" ) {
return false;
}
if( this.css.propertyIsStyle( property.name.replace("box", "") ) ) {
return false;
}
if( targetObject[ property.name ] ) {
return false;
}
if( !tools.validateValue( property.value ) ) {
return false;
}
if( preserved.includes( property.name ) ) {
return false;
}
newProperies.push( property );
targetObject[ property.name ] = property.value;
}
}
export default new cleanManager();

View File

@@ -0,0 +1,126 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import cacheManager from './cacheManager.js';
class databaseSerializer{
cache = new cacheManager();
setID( row, targetObject ) {
if( row.id && targetObject ) {
targetObject.id = row.id;
} else {
targetObject.id = row.id;
}
}
setJoinID( row, targetObject ) {
if( row.join_id && targetObject ) {
targetObject.join_id = row.join_id;
}
}
copyValue( row, child, value ) {
if( value == "true" ) {
value = true;
}
if( value == "false" ) {
value = false;
}
child.value = value;
}
getChildTable( children, row, child, propertyName ) {
var id = row[ propertyName + "_id" ];
//if( id ) {
row = this.cache.getObject( child, id );
//}
}
copyChild( children, child, row ) {
var propertyName = child.propertyName;
var value = row[ propertyName ];
if( child.datatype && value != null ) {
this.copyValue( row, child, value );
}
if( child.type == "table" ) {
this.getChildTable( children, row, child, propertyName );
}
}
copyProperties( row, targetObject ) {
var children = targetObject.getChildren( );
for( var c = 0; c < children.length; c++ ) {
var child = children[ c ];
this.copyChild( children, child, row );
}
}
serialize( row, targetObject, client ) {
this.setID( row, targetObject );
this.setJoinID( row, targetObject );
this.copyProperties( row, targetObject );
}
}
export default new databaseSerializer();

View File

@@ -0,0 +1,54 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import databaseSerializer from './serializer.database.js';
import databaseClean from './serializer.clean.js';
import databaseObject from './serializer.object.js';
export default class serializer {
clean( sourceObject, method ) {
return databaseClean.clean(sourceObject, method);
}
serialize( sourceObject, targetObject, client ) {
if( !sourceObject ) {
return false;
}
if( sourceObject.serializationType == "object" ) {
return databaseObject.serialize( sourceObject, targetObject, client );
} else {
databaseSerializer.serialize( sourceObject, targetObject, client );
}
}
}

View File

@@ -0,0 +1,580 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import tools from './tools.js';
import unify from './unify.js';
import defaultObject from './defaultObject.js';
import datatype from '../unify/datatype.js';
import placeholder from '../unify/placeholder.js';
import serialized from '../unify/serialized.js';
import permissionObject from '../unify/permissionObject.js';
import consoleColors from './consoleColors.js';
class objectSerializer{
serialize( sourceObject, targetObject, client, secure = false ) {
console.log("\n");
console.log( consoleColors.yellow("Serialize Object" ), consoleColors.yellow( targetObject.getClassName() ) );
var serializedObject = this.serializeObject( sourceObject, targetObject, client, secure );
this.findColumns( targetObject );
var defaultObjectInstance = new defaultObject();
console.log("\n");
return defaultObjectInstance.agregateDefaultObject( serializedObject );
}
serializeObject( sourceObject, targetObject, client, depth = 0, secure ) {
if( !sourceObject ) {
return false;
}
unify.extend( targetObject );
if( tools.getEnvironment() == "Browser" ) {
this.serializeID( sourceObject, targetObject ); // save
}
this.serializeProperties( sourceObject, targetObject, secure ); // save
this.serializeChildren( sourceObject, targetObject, depth, secure ); // save
this.serializePermissionObjects( sourceObject, targetObject ); // save
return targetObject;
}
serializeChildren( clientObject, targetObject, depth, secure ) {
if( !targetObject.getChildren ){
console.error( "This object cannot be serialized", targetObject );
return false;
}
var children = targetObject.getChildren();
for( var c = 0; c < children.length; c++ ) {
var child = children[c];
if( tools.getEnvironment() == "Node" ) {
if( child.type == "collection" || child.type == "table" || child.type == "renderCollection" ) {
continue;
}
if( child.propertyName == "groups" ) {
continue;
}
}
this.serializeChild( child, clientObject, targetObject, depth, secure );
}
}
serializeChild( child, clientObject, targetObject, depth, secure ) {
var propertyName = tools.validateString( child.propertyName ); // target class is save
var clientObjectChild = clientObject[ propertyName ];
console.log(" ".repeat( depth ), consoleColors.yellow(" - set value of" ), consoleColors.yellow( propertyName ) );
// bug fixen needs todo path
if( clientObjectChild ) {
targetObject[ propertyName ] = this.serializeObject( clientObjectChild, child, depth++, secure );
}
}
serializePermission( sourceObject, targetObject ) {
var targetObject = new permissionObject();
if( !sourceObject ) {
return false;
}
if( typeof sourceObject.WRITE == "boolean" ) {
targetObject.WRITE = tools.validateBoolean( sourceObject.WRITE );
}
if( typeof sourceObject.DELETE == "boolean" ) {
targetObject.DELETE = tools.validateBoolean( sourceObject.DELETE );
}
if( typeof sourceObject.READ == "boolean" ) {
targetObject.READ = tools.validateBoolean( sourceObject.READ );
}
return targetObject;
}
createPermissionObject( currentPermissionObject ) {
var permissionObject = new serialized();
permissionObject.path = tools.validateString( currentPermissionObject.path );
permissionObject.permission = this.validatePermission( currentPermissionObject.permission );
}
serializePermissionObject( currentPermissionObject, targetObject, c ) {
var permissionObject = this.createPermissionObject( currentPermissionObject );
targetObject.permissionObjects[ c ] = permissionObject;
}
serializePermissionObjects( sourceObject, targetObject ) {
if( !sourceObject.permissionObjects ) {
return false
}
if( !tools.isArray( sourceObject.permissionObjects ) ) {
return false
}
var permissionObjects = sourceObject.permissionObjects;
targetObject.permissionObjects = new Array();
for( var c = 0; c < permissionObjects.length;c++) {
var currentPermissionObject = permissionObjects[c];
this.serializePermissionObject( currentPermissionObject, targetObject, c );
}
}
serializeFilterObject( sourceObject, targetObject ) {
if( sourceObject.filterObject ) {
targetObject.filterObject = new serialized();
this.serializeObject( sourceObject.filterObject, targetObject.filterObject );
}
}
serializeIDNumber( sourceObject, targetObject ) {
var id = tools.validateNumber( sourceObject.id );
targetObject.id = id;
targetObject.setID( id );
}
serializeUndefinedID( targetObject ) {
if( tools.getEnvironment() == "Node" ) {
targetObject.id = false;
targetObject.setID( false );
}
}
serializeJoinID( sourceObject, targetObject ) {
var join_id = tools.validateNumber( sourceObject.join_id );
targetObject.join_id = join_id;
targetObject.setJoinID( id );
}
serializeID( sourceObject, targetObject ) {
if( sourceObject && sourceObject.id ) {
this.serializeIDNumber( sourceObject, targetObject );
} else {
this.serializeUndefinedID( targetObject );
}
if( sourceObject.join_id ) {
this.serializeJoinID( sourceObject, targetObject );
}
}
serializeNumberValue( sourceObject, targetObject ) {
targetObject.value = sourceObject.value;
}
serializeBooleanValue( sourceObject, targetObject ) {
if( !sourceObject.value ) {
targetObject.value = false;
} else {
targetObject.value = true;
}
}
serializeEmptyValue( targetObject ) {
targetObject.value = "";
}
serializeStringValue( sourceObject, targetObject ) {
targetObject.value = tools.validateValue( sourceObject.value );
}
serializeFalse( targetObject ) {
if( typeof targetObject.value ) {
targetObject.value = false;
}
}
serializeValue( sourceObject, targetObject ) {
if( typeof sourceObject.value == "number" ) {
this.serializeNumberValue( sourceObject, targetObject );
} else if( sourceObject.datatype == "BOOLEAN" ) {
this.serializeBooleanValue( sourceObject, targetObject );
} else if( sourceObject.value == "" ) {
this.serializeEmptyValue( targetObject );
} else if( typeof sourceObject.value && sourceObject.value != "undefined" ) {
this.serializeStringValue( sourceObject, targetObject );
} else {
this.serializeFalse( targetObject );
}
return targetObject;
}
serializeProperties( sourceObject, targetObject, method, type, secure ) {
this.serializeValue( sourceObject, targetObject );
if( !secure ) {
if( sourceObject.permissions ) {
targetObject.permissions = this.validatePermission( sourceObject.permissions );
}
/*
if( !method || method == "callNodeMethod" ) {
if( sourceObject.nodeMethodName ) {
targetObject.nodeMethodName = tools.validateValue( sourceObject.nodeMethodName );
}
if( sourceObject.nodeMethodArguments ) {
targetObject.nodeMethodArguments = tools.validateValue( sourceObject.nodeMethodArguments );
}
}
*/
}
//if( sourceObject.rowID ) {
// targetObject.rowID = tools.validateNumber( sourceObject.rowID );
//}
/*
if( typeof sourceObject.count ) {
targetObject.count = tools.validateNumber( sourceObject.count );
}
*/
/*
if( typeof sourceObject.WRITE == "boolean" ) {
targetObject.WRITE = tools.validateBoolean( sourceObject.WRITE );
}
if( typeof sourceObject.DELETE == "boolean" ) {
targetObject.DELETE = tools.validateBoolean( sourceObject.DELETE );
}
if( typeof sourceObject.READ == "boolean" ) {
targetObject.READ = tools.validateBoolean( sourceObject.READ );
}
*/
// bug. if enabled permissions dont work.
//if( tools.getEnvironment() == "Node" ) {
//}
//}
return targetObject;
}
validatePermission( sourcePermission ) {
var targetPermission = new permissionObject();
if( !sourcePermission ) {
return targetPermission;
}
if( typeof sourcePermission.READ == "boolean" ) {
targetPermission.READ = tools.validateBoolean( sourcePermission.READ );
}
targetPermission.WRITE = sourcePermission.WRITE;
if( typeof sourcePermission.WRITE == "boolean" ) {
targetPermission.WRITE = tools.validateBoolean( sourcePermission.WRITE );
}
if( typeof sourcePermission.DELETE == "boolean" ) {
targetPermission.DELETE = tools.validateBoolean( sourcePermission.DELETE );
}
return targetPermission;
}
// Everything above needs to be save.
copyValueToChild( child, extendedClass, column, table ) {
var columnName = tools.getClassName( extendedClass );
if( !extendedClass.datatype ) {
return false;
}
if( !column ) {
return false;
}
if( !table[ columnName ] ) {
return false;
}
child.value = table[ columnName ].value;
if( tools.getEnvironment() == "Browser" && child.updateElementContent ) {
child.updateElementContent()
}
}
findExtendedClasses( child, parent, table ) {
if( child.type == "collection" ) {
return false;
}
if( child.type == "renderCollection" ) {
return false;
}
if( !child.datatype ) {
return false;
}
var extendedClasses = tools.getExtendedClassesMulti( child );
for ( var c = 0; c < extendedClasses.length; c++) {
var extendedClass = extendedClasses[ c ];
var column = tools.isUnifyColumn( extendedClass ) ;
this.copyValueToChild( child, extendedClass, column, table );
}
//console.log("This is an floating column", child, extendedClasses );
}
findColumns( parent, table = false ) {
if( !parent.getChildren ) {
return false;
}
unify.extend( parent );
var children = parent.getChildren();
for ( var i = 0; i < children.length; i++ ) {
var child = children[i];
if( parent.type == "table" ) {
table = parent;
}
this.findExtendedClasses( child, parent, table );
//if( child.type != "collection" && child.type != "renderCollection" ) {
this.findColumns( child, table );
//}
}
}
}
export default new objectSerializer();

41
framework/unify/shared.js Normal file
View File

@@ -0,0 +1,41 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
class shared {
get() {
if( typeof document == "undefined" && typeof global != "undefined" ){
return global;
} else if( typeof document != "undefined" ) {
return document;
} else{
return {};
}
}
}
var object = new shared();
export default object.get();

31
framework/unify/signed.js Normal file
View File

@@ -0,0 +1,31 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import datatypes from '../unify/datatype.js';
export default class signed{
datatype = datatypes.TEXT;
value = "false";
enabled = "false";
type = "column"
}

View File

@@ -0,0 +1,305 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class simplePath{
useSlash = true;
parts = new Array();
env = false;
beginWithSlash = true;
endWithSlash = true;
absolute = false;
constructor( part ) {
if( part ) {
this.preparePart( part );
this.parts.push( part );
}
}
preparePart( part ) {
if( this.parts.length == 0 ) {
if( part.slice( 0,2 ) == ".." ) {
this.beginWithSlash = false;
}
}
}
clone() {
var clone = new simplePath();
clone.useSlash = this.useSlash;
clone.parts = [...this.parts];
clone.env = this.env;
clone.beginWithSlash = this.beginWithSlash;
clone.endWithSlash = this.endWithSlash;
clone.absolute = this.absolute;
return clone;
}
getEnvironmentNative() {
if( typeof document != "undefined" ) {
return "Browser";
}
if( global ) {
return "Node"
}
}
getEnvironment() {
if( this.getEnvironmentNative() == "Browser" ) {
var env = "Browser";
} else {
var env = process.platform;
}
return env;
}
getSeparator() {
var env = this.getEnvironment();
if( env == "win32" || this.env == "win32" ) {
return '\\';
} else {
return "/";
}
}
slash( path ) {
const isExtendedLengthPath = path.startsWith('\\\\?\\');
if ( isExtendedLengthPath ) {
return path;
}
if( this.getSeparator() == "\\" ) {
return path.replace(/\//g, this.getSeparator());
} else {
return path.replace(/\\/g, this.getSeparator());
}
}
formatPath( part ) {
for (var i = 0; i < 4; i++) {
part = part.replace("//", "/")
}
for (var i = 0; i < 4; i++) {
part = part.replace("\\\\", "\\")
}
if( part.endsWith("/") || part.endsWith("\\") ) {
part = part.slice(0, -1)
}
if( part.startsWith("/") || part.startsWith("\\") ) {
part = part.substring(1);
}
return part;
}
add( part ) {
if( !part ) {
return false;
}
this.preparePart( part );
var formattedPath = this.formatPath( part );
this.parts.push( formattedPath );
}
removeFirstSlash( part ) {
if( part.startsWith("/") || part.startsWith("\\") ) {
part = part.substring(1);
}
return part;
}
assureFirstSlash( part ) {
if( !part.startsWith("/") || !part.startsWith("\\") ) {
part = "/" + part;
}
return part;
}
removeLastSlash( part ) {
if( part.endsWith("/") || part.endsWith("\\") ) {
part = part.slice(0, -1)
}
return part;
}
assureLastSlash( part ) {
if( !part.endsWith("/") || !part.endsWith("\\") ) {
part = part + "/";
}
return part;
}
lastItemHasExtension() {
var length = this.parts.length;
var lastItem = this.parts[ length - 1 ];
if( lastItem.includes(".") ) {
return true;
} else {
return false;
}
}
resolve() {
var parts = this.parts;
var joined = parts.join( this.getSeparator() );
if( this.useSlash ) {
joined = this.slash( joined );
}
if( !this.beginWithSlash ) {
joined = this.removeFirstSlash( joined );
} else {
joined = this.assureFirstSlash( joined );
}
if( !this.endWithSlash || this.lastItemHasExtension() ) {
joined = this.removeLastSlash( joined );
} else {
joined = this.assureLastSlash( joined );
}
if( this.absolute && global ) {
return global.path.resolve( joined );
}
return joined;
}
}

View File

@@ -0,0 +1,26 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class socketMessage{
id = 0;
type = "promise";
data = false;
}

View File

@@ -0,0 +1,27 @@
import searchable from "./searchable.js";
export default function AND( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = "AND";
return searchableObject;
}

View File

@@ -0,0 +1,26 @@
import searchable from "./searchable.js";
export default function GREATER( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = " > ";
return searchableObject;
}

View File

@@ -0,0 +1,27 @@
import searchable from "./searchable.js";
export default function GREATER_OR_EQUAL( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = " >= ";
return searchableObject;
}

27
framework/unify/sql/IS.js Normal file
View File

@@ -0,0 +1,27 @@
import searchable from "./searchable.js";
export default function IS( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = " = ";
return searchableObject;
}

View File

@@ -0,0 +1,26 @@
import searchable from "./searchable.js";
export default function LIKE( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = "LIKE";
return searchableObject;
}

26
framework/unify/sql/OR.js Normal file
View File

@@ -0,0 +1,26 @@
import searchable from "./searchable.js";
export default function OR( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = "OR";
return searchableObject;
}

View File

@@ -0,0 +1,26 @@
import searchable from "./searchable.js";
export default function SMALLER( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = " < ";
return searchableObject;
}

View File

@@ -0,0 +1,26 @@
import searchable from "./searchable.js";
export default function SMALLER_OR_EQUAL( a, b ) {
var searchableObject = new searchable();
if( !a ) {
a = "";
}
if( !b ) {
b = "";
}
searchableObject.a = a;
searchableObject.b = b;
searchableObject.operator = " <= ";
return searchableObject;
}

View File

@@ -0,0 +1,97 @@
export default class searchable{
constructor( path ) {
this.path = path;
}
path = false;
operator = false;
findPath( path, searchable = this, searchables = new Array() ) {
if( searchable.operator ) {
if(typeof searchable.a == "object") {
searchable.a.parent = searchable;
}
if(typeof searchable.b == "object") {
searchable.b.parent = searchable;
}
if( searchable.a ) {
var a = this.findPath( path, searchable.a, searchables );
}
if( searchable.b ) {
var b = this.findPath( path, searchable.b, searchables );
}
if( a || b ) {
return searchables;
}
}
if( searchable.path ) {
var currentPath = searchable.path;
var parts = currentPath.split("/");
var columnName = parts.pop();
var filterAddress = parts.join("/");
console.log("find path", filterAddress, path);
if( filterAddress == path ) {
searchables.push( searchable );
return searchables;
}
}
return false;
}
getColumnName() {
var currentPath = this.path;
var parts = currentPath.split("/");
return parts.pop();
}
getValue() {
return this.parent.b;
}
getOperator() {
return this.parent.operator;
}
}

127
framework/unify/table.js Normal file
View File

@@ -0,0 +1,127 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import tools from '../unify/tools.js';
import document from '../unify/document.js';
import serverTable from '../server/table.js';
import Console from '../server/console.js';
import datatypes from '../unify/datatype.js';
import collection from '../unify/collection.js';
import defaultObject from '../unify/defaultObject.js';
import signed from '../unify/signed.js';
import unify from '../unify/unify.js';
class user extends serverTable {
username = new username();
salt = new salt();
hash = new hash();
comments = new collection( comment ); // user -> comment -> owner (user)
}
export default class table extends serverTable{
__className = "table";
signed = new signed();
user = "userplaceholder";
permissions = new Array();
secure = false;
constructor( argument, parent ) {
super();
unify.extend( this );
// Todo bug, More cores this doesn't work serverside parsing of tables.
// console.log(typeof global);
//if( typeof global != "undefined" && global.core && !this.table && parameter != "skip_table_parsing" ) {
// global.core.tableManager.parse( this );
//}
if( argument ) {
this.handleArgument( argument );
}
if( parent ) {
this.parent = parent;
}
}
handleArgument( argument ) {
if( typeof argument == "number" ) {
this.id = argument;
}
if( tools.getClassName( argument ) == "collection" ) {
//console.log("set collection of table", this.constructor.name ) ;
this.setCollection( argument );
}
}
getCollection() {
if( this.collections.length > 0) {
return this.collections[0];
} else {
return false;
}
}
}

1931
framework/unify/tools.js Normal file
View File

File diff suppressed because it is too large Load Diff

50
framework/unify/unify.js Normal file
View File

@@ -0,0 +1,50 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import defaultObject from './defaultObject.js';
class unify{
//defaultObjectInstance = new defaultObject();
extendTree( object ) {
var defaultObjectInstance = new defaultObject();
defaultObjectInstance.agregateDefaultObject( object );
}
extend( object, force = false ) {
var defaultObjectInstance = new defaultObject();
if( defaultObjectInstance.exposeMethodsToObject( object, force ) ) {
return true;
} else {
return false;
}
}
}
export default new unify();

3
framework/unify/user.js Normal file
View File

@@ -0,0 +1,3 @@

View File

@@ -0,0 +1,47 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class userPermission{
constructor( user, type, policy ) {
if( user ) {
this.userObject = user;
}
if( type ) {
this.type = type;
}
if( policy ) {
this.policy = policy;
}
}
userObject;
type;
policy;
}

View File

@@ -0,0 +1,21 @@
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
export default class validator{
isValid = true;
}