Feature/bringing pack unpack to dynamo #9005
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
The purpose of this PR is to bring a new concept of Pack and UnPack nodes inside Dynamo.
The idea behind Packing nodes is to bring in type definitions (partially) inside Dynamo and have a way of building multi-level custom types with basic validations.
TypeDefinition
This feature was initially started with a specific type definition format (pset as JSON). While integrating PackUnPack inside Dynamo Core, it was quite obvious that this needed to be generalized. Without being able to find a dynamo-wide solution that made sense regarding global types, I decided to propose a TypeScript-like syntax to define types on Packing nodes. It uses a simple Parser made using Sprache. Packing nodes will expect a string that fits the Typescript-like syntax.
Syntax
The syntax is quite simple. The initial keyword is
Type
, which must be followed by a word representing the type name and then a pair of{ }
containing one or more properties defined asname
,:
,Type
and seperated by a,
. Like in Typescript,[]
can be added to a property Type to indicate a collection.i.e:
Faulty Syntax
An error made in the syntax will be outlined by Sprache
Builder nodes
I've thought about adding builder nodes for TypeDefinitions, that is, a node with an UI that would allow to define properties and assign known or unknown types to them. I didn't jump in that yet and kept it as a "power-user" tool with the string definition, as I wasn't sure this TypeDefinition proposition would be accepted to begin with. Would be glad to get suggestions regarding this!
Pack
The purpose of the Pack node is to take in a TypeDefinition (currently from a string) and redefining its InPorts to fit with the given type. When running, some basic validation of types occurs.
Assuming no validation errors, it then outputs a dictionary (or list of dictionaries, as it does some lacing) corresponding to the input values.
i.e.:
UnPack
The purpose of the UnPack node is to complete the Pack node in a symmetric way. It takes in a TypeDefinition (currently from a string) and redefine its outports to show every property of that type definition. It then expects a dictionary (or list of dictionary) as an additional input and unpacks its content by mapping them to the different OutPorts.
i.e.:
Nested Types
It's possible to define types and re-use them in other Pack/UnPack nodes.
Notes
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@saintentropy
@mjkkirschner