Anslo
A serializer/deserializer that can serialize pointer references and remember context.
npm install --save anslo
How does it work?
const Anslo = require("anslo");
let anslo = new Anslo();
let user = new User();
user.self = user;
let string = anslo.down(user)
let newUser = anslo.up(string);
console.log(newUser === newUser.self);
What about remembering context? Let's use the same example.
const Anslo = require("anslo");
let anslo = new Anslo({ User });
let user = new User();
user.self = user;
let string = anslo.down(user)
let newUser = anslo.up(string);
console.log(newUser === newUser.self);
Security Considerations
Serializing state down to a string and reviving it to its original state
raises strong security concerns. If there are any questions at all about
where serializations come from, use encryption and a signature to verify
you made it. Moreover, we are soon to be living in an time where quantum
computing is available; use a post-quantum algorithm.
"Be Kind and Rewind Encrypt Everything"
Caveats
- Properties that are functions will be serialized to null. Use classes with methods to provide functionality.
What does the serialized string look like?
Let's say we were to run this bit of code...
let data = [{
name: "something",
date: new Date()
}]
let string = anslo.down(data, 4)
console.log(string);
{
"pointers": [
[],
{},
"something",
{}
],
"graph": {
"r": 0,
"t": "array",
"c": {
"0": {
"r": 1,
"t": "object",
"c": {
"name": {
"r": 2,
"t": "string"
},
"date": {
"r": 3,
"t": "date",
"v": "2018-12-10T06:36:05.620Z"
}
}
}
}
}
}
Minified, it would look like this.
{"pointers":[[],{},"something",{}],"graph":{"r":0,"t":"array","c":{"0":{"r":1,"t":"object","c":{"name":{"r":2,"t":"string"},"date":{"r":3,"t":"date","v":"2018-12-10T06:40:51.342Z"}}}}}}