SkillAgentSearch skills...

Jscomet

Create apps and a fast MVC website with OO class like ES6/TypeScript/Babel features with truly private vars and functions, type validations, function overloads, all in runtime and create libraries like browserify and reference this in your projects.

Install / Use

/learn @cirospaciari/Jscomet
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

npm package

NPM version NPM License Downloads ISSUES

Support me for future versions:

BMC

PAGSEGURO

JSComet is a easy way of creating apps with OO class like ES6/TypeScript/Babel features with truly private vars and functions, type validations, function overloads, all in runtime and can create libraries like browserify and reference this in projects. JSComet has an easy to use MVC platform with excellent performance for your web projects please check the benchmarks.

    Types and Return Types checked in runtime
    Truly private functions
    Can be used ahead-of-time (and i recommend it!)
    Can be used directly in the browser
    Fast build
    Fast for use as runtime on smaller frontend projects or used as generated library in bigger projects
    Easy to install, create, build and run
    Nice way to organize and reference js libraries
    
    

How install:

npm install jscomet -g

How use:

Project types available: app, console, library, web. (Desktop coming soon)

For documentation and more details click here

For examples click here

Command line:

    version                                  show JSComet version
    clean                                    clean all projects
    clean %PROJECT_NAME%                     clean a project
    build %PROJECT_NAME%                     build a project
    create solution                          create a empty solution file
    create %PROJECT_TYPE% %PROJECT_NAME%     create a project
     Default Options:
      create app MyProject
      create console MyProject
      create web MyProject
      create library MyProject

    remove %PROJECT_NAME%                    remove a project
    run %PROJECT_NAME%                       run a project
    publish %PROJECT_NAME% %OUT_DIRECTORY%   publish a project to folder

    reference add %PROJECT_NAME% %REFERENCE_PROJECT_NAME%            add project reference
    reference remove %PROJECT_NAME% %REFERENCE_PROJECT_NAME%         remove project reference
    add %FILE_TEMPLATE% %PROJECT_NAME% %FILE_PATH%                   add a file
     Default Options:
      add html  MyProject myHTMLFile
      add xml   MyProject myXMLFile
      add js    MyProject myJSFile
      add css   MyProject myCSSFile
      add class MyProject models\myModelClass
      add class MyProject models\myModelClass extended myModelBase
      add class MyProject models\myModelClass singleton
   

A new version with more features and MVVM comming soon.

For documentation and more details click here

For examples click here

Transpiler Features

main.js

import SampleModule, {url} from './js/SampleModule.js';


//Modules can be used as namespace
var sampleClient = SampleModule.Client.getByID(1);

//is possible use String Template, in this case for encodeURIComponent each parameter
var sampleTemplateFunction = url `/client/?email=${sampleClient.email}`;

./js/SampleMdule.js:

module SampleModule {
	//you can use import and export 
	//https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Statements/export
	export var UserType = {
		Default : 0,
		Guest : 1,
		Admin : 2,
		Premium : 3
	};

	class User {
		//typed fields are generated as properties get/set, and can be private, public, static, private static e public static
		//if you just want a easy way to create a property you can use any as type
		name : string;
		surname : string;
		email : string;
		password : string;
		type : int = UserType.Default;
		/*
		int is a special validator for number types:

		bit :  min: 0 max: 1
		sbyte :  min: -128 max: 127
		byte :  min: 0 max: 255
		short :  min: -32768 max: 32767
		ushort :  min: 0 max: 65535
		int :  min: -2147483648 max: 2147483647
		uint :  min: 0 max: 4294967295
		long :  min: -9007199254740991  max: 9007199254740991
		ulong :  min: 0  max: 9007199254740991

		this types cant be NaN, null or undefined

		for floats:

		float: min: -3.402823E+38 max: -3.402823E+38
		double: min: -1.7976931348623157e+308 max: 1.7976931348623157e+308

		this types cant be NaN, null or undefined

		you can use more than one type, for example for int nullable you can use:
		age: int | null;

	    For string, number, boolean, object, function e symbol, CANT be undefined and only boolean CANT be null 

		Typed Array shortcuts:

		sbyte[]: Int8Array
		byte[]: Uint8Array
		short[]: Int16Array
		ushort[]: Uint16Array
		int[]: Int32Array
		uint[]: Uint32Array
		float[]: Float32Array
		double[]: Float64Array

		Any type can be declared with Type[] but will be generated as a native Array type

		Samples:
		var a = new sbyte[];
		var a = new sbyte[](10);
		var a = new sbyte[]([1, 2, 3, 4]);
		types: int[];

		Other validators:
		any: accept any value
		char: only string with length equals 1 CANT be null or undefined
		void: force only undefined values can be used for validate returns
		undefined: like void only accept undefined (can be used for optionals params like : string | undefined)
		null: only accept null (can be used for create nullable values like: int | null)
		 */

	
		constructor(name : string, surname : string, email : string, password : string) {
			this.name = name;
			this.email = email;
			this.password = password;
			this.surname = surname;
		}

	
		get fullname() : string {
			return `${this.name} ${this.surname}`;
		}

		toString() {
			return  `${this.name};${this.email};${this.password};${this.surname};${this.type}`;
		}
	}


	export { User as ClientBase };

	export class Client extends User {

		private id : int = 0;

		constructor() {
			super(null, null, null, null);
		}

		//You can create overloads create function/constructor but overloads are differentiated only by the number of parameters and types are not considered
		constructor(user : User) {
			super(user.name, user.surname, user.email, user.password); //super realiza chamadas do construtor da classe herdada
		}

		constructor(id : int, user : User) {
			this(user); //you can use this() for call constructor
			this.id = id;
		}

		public get ID() : int {
			return this.id;
		}

		toString() {
			//super.fieldOrFunction can access functions and fields of inherited class
			return `${super.toString()};${this.id}`;
		}

		private static generateNewPassword() : string {
			return 'xyxxyxyx'.replace(/[xy]/g, (_char) => {
					var random = Math.random() * 16 | 0;
					var value = _char == 'x' ? random : (random & 0x3 | 0x8);
					return value.toString(16);
				});
		}

		public static getByID(id : int) : User {
			/*FAKE QUERY*/
			return new Client(id, new User('Michael',
										   'Silva',
										   'michael.silva@gmail.com',
										   Client.generateNewPassword()));
		}

		public static find(email : string) {
			/*FAKE QUERY*/
			var list = new User[](10);
			for (var i = 0; i < 10; i++) {
				var user = Client.getByID(i + 1);
				user.email = email || user.email;
				list.push(user);
			}
			return list;
		}

		/*
    	Overloads are differentiated only by the number of parameters and types are not considered
		 */
		public static find(name : string, surname : string) {
			/*FAKE QUERY*/
			var list = new User[](10);
			for (var i = 0; i < 10; i++) {
				var user = Client.getByID(i + 1);
				user.name = name || user.name;
				user.surname = surname || user.surname;
				list.push(user);
			}
			return list;
		}

	}
}

/*
Is possible use "..." before a parameter name for create a REST parameter
 */
export function url(pieces, ...substitutions) {
	var result = pieces[0];
	for (var i = 0; i < substitutions.length; ++i) {
		result += encodeURIComponent(substitutions[i]) + pieces[i + 1];
	}
	return result;
}
export default SampleModule;

Sub Classes:

class MyClass { 
	class MySubClass{//public
				
	}
	private class MyPrivateSubClass{//private
			
	}
	public class MyPublicSubClass{//public
	}
}

ApacheBench MVC Test

A little benchmark using ApacheBench for simple performance test JSComet and Sails.

Command:

ab -k -l -p payload.json -T application/json -n 100000 -c 500 http://localhost:8080/

payload.json

{
"data": "{'job_id':'c4bb6d130003','container_id':'ab7b85dcac72','status':'Success: process exited with code 0.'}"
}

Configurations:

Intel Core i7-6700HQ @ 2.60GHz
16 GB RAM
Windows 10 Pro - 64 bits

Performance Results:

  • JSComet (default) - 7537.64 requests per sec
  • JSComet without cluster - 2233.26 requests per sec (3.37 times slower)
  • Sails (default) - 1374.82 requests per sec (5.48 times slower)
  • Sails with clus
View on GitHub
GitHub Stars15
CategoryDevelopment
Updated2y ago
Forks0

Languages

JavaScript

Security Score

60/100

Audited on Apr 3, 2023

No findings