Framework for implicit and explicit typed JS model classes, for introspection, replication, automated, reactive multilingual UI generation, validation, en-/decoding.
Including JS primitives each class component can get typed, without wrapping objects into big memory chunks, using implicit skeletons and fields. This for instance allows to handle different kind of primitives like Double, Char, Byte, Long while JS only supports integer and floats, this can be used for a bunch different cases like typed arrays external interfaces, and porting / transpiling to different languages.
Explicit Class
Class('User', 'Model', { label: 'User', plural: 'Users', indexed: true, key: 'id', construct: function User(object) { /* Constructor not required by default, "created" will be called too if implemented, while function User() will ensure the instance constructor to be User instead Model */ this.TYPE.cast(this, object); }, struct: [ { label: 'ID', name: 'id', type: 'int', private: true }, { label: 'Username', placeholder: 'Your nickname', name: 'username', type: 'string', min: 3, max: 32 }, { label: 'Password', name: 'password', type: 'password', min: 6, max: 512 }, { label: 'Auto-login', name: 'autologin', type: 'bool', default: false }, { label: 'Reputation', name: 'reputation', type: 'float', default: 0.0, min: 0.0, max: 1.0 } ], public: { login: function() {} }, static: { find: function() {} } });
Implicit Class
// This or ES6 class syntax function User() {} User.find = function() {}; Object.assign(User.prototype, { reputation: 0.0, login: function() {} }); Class('User', 'Model', { label: 'User', plural: 'Users', indexed: true, key: 'id', target: User, struct: [ { label: 'ID', name: 'id', type: 'int', private: true }, { label: 'Username', placeholder: 'Your nickname', name: 'username', type: 'string', min: 3, max: 32 }, { label: 'Password', name: 'password', type: 'password', min: 6, max: 512 }, { label: 'Reputation', name: 'reputation', type: 'float', default: 0.0, min: 0.0, max: 1.0 } ] });
Custom displays example
Class('User', 'Model', { label: 'User', plural: 'Users', indexed: true, key: 'id', construct: function User(object) { this.TYPE.cast(this, object); }, struct: [ { label: 'ID', name: 'id', type: 'int', private: true }, { label: 'Username', placeholder: 'Your nickname', name: 'username', type: 'string', min: 3, max: 32 }, { label: 'Password', name: 'password', type: 'password', min: 6, max: 512 }, { label: 'Auto-login', name: 'autologin', type: 'bool', default: false }, { label: 'Reputation', name: 'reputation', type: 'float', default: 0.0, min: 0.0, max: 1.0 } ], displays: { preview: { template: '
Copyright © 2024 Mevedia. All rights reserved.