Comments (7)
I think I would prefer to keep it external to the core library.
from runtypes.
I must admit I don't fully understand the use case. The whole idea with runtypes is that they are constructed at the beginning of your app and have known types (thus they can be used to extract static types). So I don't understand why you'd want to serialize them. Can't your web worker code just construct runtypes itself, without the need to have them serialized? I guess I would need to see an example to understand better what you're trying to do.
from runtypes.
That's actually what we're doing now. Both the non-worker and worker code import the same runtypes individually. It's definitely a feasible solution. The only drawback is that it takes a little more explicit wiring of things together to make it work this way. It makes the code a little more tightly coupled and a bit less DRY. Having the ability to pass arbitrary serialized runtypes to a worker would simplify things.... so it's not a deal breaker but would be nice. I totally get it if you don't feel that's a compelling enough use case to include serialization within the library.
from runtypes.
I would say it probably doesn't rise to the level of compelling to me, but I will also say that this sort of thing should be quite straightforward to do externally without changing the core library; that's what the Reflect
type enables. See the show
* function for an example of writing a function against the runtime Reflect
information of a Runtype
. Basically you could write a recursive serializer / deserializer against Reflect
. The only caveat is that some runtypes, e.g. Constraint
, are inherently unserializable because their Reflect
information contains executable code in a closure, so the serializer should either throw or return a noop and print a warning if it encounters one of those.
* In case it's not clear, show
is a function which takes a runtype and produces a string representation of it, so it's very similar to how a serialize
function would work.
from runtypes.
Thanks for the info! Depending on how things play out I may end up writing a serialize/deserialize function. If I do end up doing that would you consider a PR or would you prefer to keep serialization outside of the library?
from runtypes.
Just came here for this! I think it could be very useful. Consider the case where schema is built up by composing schemas from multiple sources, programatically. Studying code is not a great mechanism then to get a "feel" for what the schema is. mySchema.toJSON()
to allow for printing a nice representation could lend itself for sharing full schemas in a flat, easy to grok format.
from runtypes.
ah, I see .show
on the RT prototype is now a thing. will experiment with that
from runtypes.
Related Issues (20)
- Is there a way to omit everything that's not defined by the Record instance? HOT 1
- Create runtypes from existing TypeScript types? HOT 1
- Printable form of type from runtype? HOT 1
- Unuseful error message on typechecking HOT 1
- Cannot validate optional+null circulare fields HOT 4
- Optional types in Tuple HOT 1
- How check for ObjectId? HOT 3
- Function which accepts a runtype and omits some fields HOT 1
- `omit` properties of a `Constraint` or `Intersect`? HOT 2
- Constraint::reflect does not expose .underlying
- Support for Set type HOT 2
- [Feature Request] Type Guard for ValidationError HOT 2
- Option to return errors instead of throwing them for performant validation. HOT 4
- Runtypes-like `.guard()` HOT 1
- How do I exclude undefined properties from record? HOT 2
- Is it possible to have more than one brand HOT 2
- Type validated by Dictionary is different than returned type
- How do I define an array which is optional yet in case it was defined it shouldn't be empty ? HOT 2
- Performance
- Publish to deno.land/x HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from runtypes.