tupleson icon indicating copy to clipboard operation
tupleson copied to clipboard

Sync API Refactor

Open helmturner opened this issue 2 years ago • 3 comments

PR Checklist

Overview

Refactor sync api to be easier to follow and map nicely with the new async api (wip)

  • use maps/sets for more declarative code
  • rename things Change the api for guards to be separate from that of serialize/deserialize type handlers
  • give guards their own configuration, but still run them for any unhandled values

helmturner avatar Nov 25 '23 13:11 helmturner

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tupleson-async ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 4, 2024 6:35am

vercel[bot] avatar Nov 25 '23 13:11 vercel[bot]

Codecov Report

Attention: 300 lines in your changes are missing coverage. Please review.

Comparison is base (9bf904f) 94.08% compared to head (9aa3dc1) 85.64%. Report is 1 commits behind head on main.

Files Patch % Lines
src/async/createFoldAsyncFn.ts 0.00% 120 Missing :warning:
src/async/createUnfoldAsyncFn.ts 0.00% 62 Missing :warning:
src/iterableTypes.ts 0.00% 33 Missing :warning:
src/async/serializeAsync2.ts 93.07% 26 Missing and 1 partial :warning:
src/tsonAssert.ts 0.00% 24 Missing :warning:
src/async/handlers/tsonPromise2.ts 77.04% 14 Missing :warning:
src/internals/testUtils.ts 86.36% 12 Missing :warning:
src/async/iterableUtils.ts 87.50% 4 Missing :warning:
src/internals/isComplexValue.ts 57.14% 3 Missing :warning:
src/sync/serialize.ts 98.30% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
- Coverage   94.08%   85.64%   -8.44%     
==========================================
  Files          31       40       +9     
  Lines        1876     2864     +988     
  Branches      194      258      +64     
==========================================
+ Hits         1765     2453     +688     
- Misses        109      407     +298     
- Partials        2        4       +2     
Flag Coverage Δ
unit 85.64% <73.30%> (-8.44%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Nov 26 '23 00:11 codecov[bot]

I've got the async serializer (mostly) spitting out the expected result. The main feature here is using an iterative algorithm for serialization, rather than a recursive one. There's more to do, but this is illustrative enough to be a PoC.

The benefits I'm hoping to achieve:

  • Better error handling
  • Deep-serialization of of arbitrarily complex values (e.g. Promise<AsyncIterable<Promise<string>>>)
  • Separation from, but interoperability with, the transport layer
  • Separation of concerns between streaming and serializing
  • An API that is easy to customize for your use-case (websocket, http JSON streams, http2/3 SSE streams, etc)
  • AsyncGenerators are a first class-citizen

Todos:

  • Clean up & normalize error handling
  • Change string flags to numbers
  • Improve serialization output of built-ins (e.g. Arrrays, POJOs)
  • Deserialization
  • Lots of cleanup

helmturner avatar Jan 04 '24 00:01 helmturner