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

as-serde

v0.3.0

Published

Serde-as is a simple (de)serialization framework for AssemblyScript

Downloads

72

Readme

as-serde

A simple (de)serialize library for AssemblyScript.

Usage

install

npm install --save-dev as-serde

Update your asconfig to include the transform:

{
  "options": {
    ... // other options here
    "transform": ["as-serde-transform"]
  }
}

APIs

This package defines four abstract classes: CoreSerializer/Serializer/CoreDeserializer/Deserializer.

All methods in CoreSerializer/CoreDeserializer are used by as-serde-transform. That is to say, the automatically generated code depends on these classes.

Serializer/Deserializer just simply expand CoreSerializer/CoreDeserializer, making it easier for serialization library authors to implement the required functions.

Decorator Syntax

Use decorator just like this:

@serialize()
@deserialize()
class Person {
    name: string;
    gender: bool;
}

or like this:

@serialize({ omitName: true })
@deserialize({ omitName: true })
class Person {
    name: string;
    gender: bool;
}

There are two decorators used for class: serialize and deserialize. There is currently no decorator that supports any class field or methods yet.

Commonly supported configuration items are as follows:

  • skipSuper: boolean: default to false. (de)serialize method will ignore fields of super class if true.
  • omitName: boolean: default to false. (de)serialize method will pass null to (de)serializeField and other method instead of the field name. It can save many bytes in wasm code if you do not care about field names.

TODO

Currently our decorator name serialize and deserialize occupies the global namespace. I hope that all decorators in the follow-up can be changed to the serde namespace, which is a bit troublesome, so I haven’t implemented it yet. Such as:

@serde.serialize()
@serde.deserialize()
class Person {
    name: string;
    gender: bool;
}

I hope to add some field and method decorators, such as serde.skip/serde.get/serde.set and others. Since I don't need these functions for the time being, and I haven't carefully considered the advantages and disadvantages of several implementation details, I still haven't implemented it.

At present, only the serialization of json has been implemented, and the deserialization has not been implemented because it is more troublesome. Subsequent implementations of json deserialization may redefine the interface of Deserialize according to the situation. I think the current interface is still not good enough.