Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API #26

Merged
merged 120 commits into from
Oct 19, 2023
Merged

Plugin API #26

merged 120 commits into from
Oct 19, 2023

Conversation

lxsmnsyc
Copy link
Owner

@lxsmnsyc lxsmnsyc commented Oct 13, 2023

  • Add the Plugin API
    • This feature allows custom serialization/deserialization API in seroval. The feature required massive restructuring in the core, such as moving the whole parser, serializer and deserializer code from functions to class-based, which will allow deduping and a lot more. It's required so that the underlying methods can be exposed for the plugin methods.
    • This resolves Custom serialization API #17
    • This resolves Support for Class #14
    • Example:
    import { createPlugin, type SerovalNode } from 'seroval';
    
    const BufferPlugin = createPlugin<Buffer, SerovalNode>({
      tag: 'Buffer',
      test(value) {
        return value instanceof Buffer;
      },
      parse: {
        sync(value, ctx) {
          return ctx.parse(value.toString('base64'));
        },
        async async(value, ctx) {
          return ctx.parse(value.toString('base64'));
        },
        stream(value, ctx) {
          return ctx.parse(value.toString('base64'));
        },
      },
      serialize(node, ctx) {
        return `Buffer.from(${ctx.serialize(node)}, "base64")`;
      },
      deserialize(node, ctx) {
        return Buffer.from(ctx.deserialize(node) as string, 'base64');
      },
      isIterable() {
        return true;
      },
    });
  • Fixes Edge Case: Mistake on isolating Map entries #27
  • Fixes Inside of getCrossReferenceHeader script, getting error Uncaught SyntaxError: Unexpected identifier '_$HY'  #28

@lxsmnsyc lxsmnsyc marked this pull request as draft October 13, 2023 09:20
@lxsmnsyc lxsmnsyc marked this pull request as ready for review October 19, 2023 04:53
@lxsmnsyc lxsmnsyc merged commit 7d1e463 into main Oct 19, 2023
1 check passed
@lxsmnsyc lxsmnsyc deleted the plugin branch October 19, 2023 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant