8000 feature: Should the arri specification support Tuples? · Issue #163 · modiimedia/arri · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feature: Should the arri specification support Tuples? #163

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

Open
joshmossas opened this issue Mar 29, 2025 · 6 comments
Open

feature: Should the arri specification support Tuples? #163

joshmossas opened this issue Mar 29, 2025 · 6 comments
Labels
discussion enhancement New feature or request schema Issues related to arri schemas and the arri schema builder

Comments

@joshmossas
Copy link
Member

Describe the feature

This feature would allow Arri servers and clients to send Tuple types over the wire. For JSON payloads, Tuples can be encoded as JSON arrays.

Supporting this feature would require adding a new tuple form to Arri Type Definition. Perhaps it could look something like this:

{
  "tuple": [
    { "type": "string" },
    { "type": "boolean" },
  ]
}

Additional context

Potential Downsides

Some popular languages do not have native Tuple support such as Java and Go. Meaning if we accept this that we potentially make it difficult to integrate those languages into the ecosystem. Of course Arri could create it's own Tuple implementation when targeting those languages but it's still something to consider.

There's also the case that while Typescript can define tuples like so type MyTuple = [number, number]. You don't actually get runtime safety for this, since it's still a JavaScript array under the hood. But I guess that's the case for most Typescript things 🤷

Would you be willing to implement this feature?

Yes

@joshmossas joshmossas added enhancement New feature or request schema Issues related to arri schemas and the arri schema builder discussion labels Mar 29, 2025
@joshmossas
Copy link
Member Author

As an alternative maybe we add support for Fixed-Size arrays instead? That could cover some of the cases where Tuples are useful, but would be easier to implement across different languages (*cough* *cough* go)

@Arthurdw
Copy link

As an alternative maybe we add support for Fixed-Size arrays instead? That could cover some of the cases where Tuples are useful, but would be easier to implement across different languages (*cough* *cough* go)

I believe both would be the more ideal option, and just using a fallback on the client size. (Eg a fixed size array on the client when no tuple support is present, and if no fixed size arrays exist just fallback to a regular array)

@joshmossas
Copy link
Member Author
joshmossas commented Apr 14, 2025

@Arthurdw

Yeah I guess the issue is that a fixed size array only works as a fallback when all the tuple subtypes are the same like this:

typedef MyTuple = (int, int);

Once we add multiple types falling back to a fixed size array doesn't work anymore:

// go literally has no way of representing this other than [3]any
typedef MyTuple = (int, bool, string);

My main concern adding tuples could create inconsistent experiences across different langs.

@joshmossas
Copy link
Member Author
joshmossas commented Apr 14, 2025

Ideally if we could get tuples to work that would be great. But I also don't want it to create this dynamic where devs have to keep track of which features work properly in which languages. Making things behave consistently is pretty important imho.

@Arthurdw
Copy link

@joshmossas

Yeah I guess the issue is that a fixed size array only works as a fallback when all the tuple subtypes are the same like this:

Ahh true, totally forgot about this.

// go literally has no way of representing this other than [3]any
typedef MyTuple = (int, bool, string);
My main concern adding tuples could create inconsistent experiences across different langs.

Since we are statically creating code anyway, can't we create an object that matches the used tuple struct? So that something like this gets generated:

type MyTuple struct {
     T0 int
     T1 bool
     T2 string
}

from

typedef MyTuple = (int, bool, string);

That should be supported in all languages right?

About the fixed size arrays, might be useful to have this as a type option as well, in the languages that don't support it can use a array implementation; but for the ones that do this might be a performance impr 8000 ovement.

@joshmossas
Copy link
Member Author
joshmossas commented Apr 22, 2025

@Arthurdw

Since we are statically creating code anyway, can't we create an object that matches the used tuple struct? So that something like this gets generated:

That's true. Using this approach we should be able to support this in any of the target clients. Tuple support would still be limited in the go server implementation, but at least any go clients would be supported easily. Also for the go server I prolly can make type helpers for tuples with 2 and 3 values which would be the most common tuple uses anyway.

About the fixed size arrays, might be useful to have this as a type option as well, in the languages that don't support it can use a array implementation; but for the ones that do this might be a performance improvement.

Yeah agreed. Maybe I'll add support for fixed size arrays first since that's more straightforward and then look to add true tuple support down the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request schema Issues related to arri schemas and the arri schema builder
Projects
None yet
Development

No branches or pull requests

2 participants
0