New version of Total.js 4 framework (0.0.43)
Tags: node, jsonschema, ldap, typescript
Published: 2021-06-08 19:43:28

- [Join Total.js Telegram](https://t.me/totaljs)
- [Sign-in to Total.js Platform](https://platform.totaljs.com/)

We have officially released a new version of Total.js framework 4 (v0.0.43). This version brings great new features that you will love. __Total.js framework is still without dependencies__, and that's a good benefit for all developers. The new version brings great new features and fixes.

- Install Total.js 4 framework via NPM: `$ npm install total4`
- or download [the Total.js framework source-code](https://github.com/totaljs/framework4) from GitHub

## Integrated LDAP search

We have integrated __LDAP search__ into the Total.js framework directly. So you can easily synchronize or sign-in user via LDAP protocol with your e.g. __Active Directory__ (AD) with the help of the Total.js framework directly.

- [Total.js __LDAP documentation__](https://docs.totaljs.com/total4/407ff001jy51c/#91810001ay51c)

__Example__:

```js
var opt = {};
opt.ldap = {};
opt.ldap.port = 389;
opt.ldap.host = 'IP_or_HOSTNAME';
opt.type = 'person';
opt.dn = 'ou=KIMS,dc=adtest,dc=ad';
opt.user = 'CN=op-user,OU=SOP_system_acc,OU=SOP,OU=Users,OU=KIMS,DC=adtest,DC=ad';
opt.password = 'password';
LDAP(opt, function(err, response) {
	// @err {Error}
	// @response {Object Array}
});
```

## Total.js framework supports TypeScript

[Helferino](https://github.com/Helferino) added support for __TypeScript__, but we don't recommend it for the development of Total.js applications. The reason is simple (many developers will not agree): we don't see any more significant advantage of TypeScript.

- Download: [Total.js TypeScript project template](https://github.com/totaljs/emptyproject-typescript)

## JSON schemas

The new version of Total.js supports JSON schemas. Total.js framework automatically processes all JSON schemas stored in `/app/jsonschemas/*.json` directory. Also JSON schemas can be defined programmatically via `NEWJSONSCHEMA()` method.

__Usage__:

```js
// Validates data according to the JSON schema
JSONSCHEMA('schema_name', { data }, function(err, response) {
	// @err {ErrorBuilder} error handling (nullable)
	// @response {Object} data will be prepared according to the JSON schema
});

// Validates data according to the raw JSON schema object
JSONSCHEMA({ $id: '', properties: {} }, { data }, function(err, response) {
	// @err {ErrorBuilder} error handling (nullable)
	// @response {Object} data will be prepared according to the JSON schema
});
```

JSON Schemas can be used instead of Total.js Schemas:

```js
NEWSCHEMA('Users', function(schema) {

	// This schema inherits all fields from the JSON schema "user"
	schema.jsonschema('user');

	schema.setInsert(function($) {
		// do something
		$.success();
	});

});
```

Inline generator for JSON schemas:

```js
console.log('name:String, age:Number'.toJSONSchema());
```

__Good to know:__

- JSON schemas can be generated from the Total.js Schemas too

## Total.js Message Service (TMS)

We have added a new pub/sub pattern for integrating multiple Total.js applications. You can use [Total.js FlowStream app](https://github.com/totaljs/flowstream) for integrating multiple Total.js applications via TMS. This is one of the most significant new feature in the Total.js framework. __TMS uses JSON schemas / Total.js schemas for preparing data__.

- Download [TMS Example](https://github.com/totaljs/examples/tree/master/tms)
- Download integrator app: [FlowStream app](https://github.com/totaljs/flowstream)

The integrator app automatically downloads all publishers and subscribers.  Then creates components for the FlowStream app. Look to the picture below:

![Total.js Message Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s967pqulpw5fz9nunc7s.png)

__First you need to define all publisher/subscribers__:

```js
// NEWPUBLISH('publisher_name', 'JSON Schema or Total.js Schema or Inline Schema');
NEWPUBLISH('users_insert', 'Users');
NEWPUBLISH('users_update', 'Users');
NEWPUBLISH('users_remove', 'Users');

NEWSUBSCRIBE('users_insert', 'Users');
NEWSUBSCRIBE('address_insert', 'city:String, zip:String(20), country:String');
```

__Usage__:

```js
NEWSCHEMA('Users', function(schema) {

	schema.setInsert(function($, model) {

		// ...
		// ...

		PUBLISH('users_insert', model);

		// ...
		// ...

		$.success();

	});

});
```

```js
SUBSCRIBE('users_insert', function(user) {
	EXEC('+Users --> insert', user, console.log);
});
```

We add step-by-step TMS integration to all Total.js open-source apps.

## Improved FlowStream

FlowStream is one of the best features in the Total.js 4 framework, and it opens many possibilities for various implementations/cases/projects. It's advanced version of Total.js Flow and fully customizable. The **FlowStream app** moves the FlowStream to the super level, and each FlowStream runs in an independent worker thread.

- Download [FlowStream app](https://github.com/totaljs/flowstream)

![FlowStream app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3gfumo1msrtctw7nwi7.png)

## Added support for debugging of bundles

This feature allows you to debug source-code in the `.src` directory. In other words: The total.js application doesn't extract and rewrite bundles.

__Usage__:

- create file `bundles.debug` in the root of app directory
- restart app
- and then you can modify each file in `.src` directory
- watcher will monitor only changes in `.src` directory

---

- [Join Total.js Telegram](https://t.me/totaljs)
- [Sign-in to Total.js Platform](https://platform.totaljs.com/)