npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lively.serializer2

v0.1.3

Published

Provides an object registry that continously tracks objects and is able to snapshot the object graph or parts of it to serialize objects and their state.

Downloads

6

Readme

lively.serializer 2.0

Provides an object registry that continously tracks objects and is able to snapshot the object graph or parts of it to serialize objects and their state.

Similarly, can re-create object (graphs) based on snapshots or update exising registered object graphs when parts change.

These features provide the base for persistent lively.next workspaces and are needed by lively.sync.

How the serializer works

ObjectRef

ObjectRefs manage the translation of "real objects" and their serialized version. The objects being managed are special in that they are required to have a property _rev, a version counter that is used to recognize new "versions" of that object.

An ObjectRef has the properties

id: STRING
realObj: {_rev, ...}
snapshotVersions: [...revs]
snapshots: {} mapping revs to snapshots

serialization

A snapshot can either be a manually produced representation of real object if real object implements a __serialize__ method (see below). If not then the standard serialization approach is:

  • Let snapshot be: {rev, props: []}
  • Get all the property names of real object
    • excluding those in realObj.__dont_serialize__ (merged with hierarchy) – priority 1
    • or only those properties in realObj.__only_serialize__ – priority 2
  • For each property let seraliized value be
    • if its a function ignore FIXME
    • if its a "primitive" use that verbatim
    • if its an Array: snapshot all elements
    • if it has a serialize function use the output of that
  • let the class plugin add meta data to the object ref FIXME
  • add the value to the object pool => produces either an object ref or an Array of refs a ref can be either a real object ref or an entry into serialized map: {ref: true, id, rev}

deserialization

An ObjectRef can deserialize an object from a snapshot {rev, exprs, props}.

  • If __expr__ is defined then use the expression evaluator (fancy eval) to get a new object.

  • If its a serialized class instance then instantiate the class

  • Otherwise create a new empty object

  • Assign ObjectRef>>rev as _rev to the object.

  • Make sure ObjectRef is known by the pool so that updates of the real object are directed to it.

  • for each property in props

    • if Array: recreate all elements
    • if expr: expression evaluator
    • otherwise try to find the ref for prop.id or create a new ObjectRef for it use ref.realObj (which recursively deserializes the property) as result.

real object

Here is what's expected / supported of the objects to be serialized

  • _rev version number

  • __serialize__ function Method of real object that produces a custom snapshot representation of real object. If no such method is present the default serialization approach is used.

  • __dont_serialize__: [STRING] Property names of real object to not snapshot

ObjectPool

The object pool manages object refs and is the interface to the serialization process for the outside world.

Methods:

  • knowsId(id) => has the pool the ref with id?

  • refForId(id) => finds the object ref with id

  • resolveToObj(id) => returns the object for the object ref with id

  • ref(obj) => returns the object ref for object

  • add(obj)

  • snapshot() => produces a JSON object

  • jsonSnapshot() => produces a stringified JSON object

  • readSnapshot()

Internal pool state:

  • _obj_ref_map maps real objects to refs
  • _id_ref_map map ids to object ref instances

additional

  • classHelper
  • uuidGen
  • expressionEvaluator

License

MIT