Repository navigation
Highlights
This release has some major breaking changes that affect all languages and the core schema(s). Run npx arri use latest at the root of your project to update all dependencies together.
New union schema form
Arri now has a general-purpose tagged union schema form. With the old discriminator schema form, every variant had to be an object. With the new union schema form, a variant can be any type: primitives, arrays, records, objects, refs and so on.
const CategoryFilter = a.union({
one: a.string(),
many: a.array(a.string()),
});
// { one: string } | { many: string[] }Unions can be serialized three ways:
| Style | Schema | JSON |
|---|---|---|
| Externally tagged (default) | { "union": {...} } |
{ "circle": { "radius": 2.5 } } |
| Internally tagged | { "tagKey": "kind", "union": {...} } |
{ "kind": "circle", "radius": 2.5 } |
| Adjacently tagged | { "tagKey": "kind", "valueKey": "data", "union": {...} } |
{ "kind": "circle", "data": { "radius": 2.5 } } |
Supported across the board:
- Schema / TS server:
a.union(), plus thematchUnion()andunwrapUnion()helpers - Go server: embed
arri.Unionin a struct. Each pointer field is a variant.tagKey/valueKey/tagstruct tags control serialization - Client codegen: TypeScript, Dart, Kotlin, Swift, Rust
- GET procedures: internally tagged unions whose variants are flat objects can be sent as query params (e.g.
?shape=rectangle&width=10&height=20) - JSON Schema export: unions are converted
The app definition schema version has been bumped to 0.0.9.
Discriminator schema deprecated
The discriminator schema form (a.discriminator()) is now deprecated in favor of union. It still works and is still supported by all generators. New code should use a.union({ ... }, { tagKey: '...' }), which gives the same JSON shape as a discriminator.
Initial Rust support (arri + arri_derive crates)
This is the first release of the Rust crates for defining Arri types.
#[derive(Arri)]on structs and enums generates their Arri Type Definition and JSON encoding/decoding.- Unit-only enums become enums. Enums with data become unions (externally, internally or adjacently tagged).
- Doc comments and
#[deprecated]become schema metadata.rename_allis supported. Option<T>maps to optional properties andNullable<T>maps to nullable values.
- Includes a built-in JSON encoder/decoder,
Timestamp(RFC 3339) andValue(any). serde is not required. - Optional
chrono,timeandserdefeatures. AppDef::builder()builds an Arri app definition from Rust types and serializes it to JSON for codegen.
Note: RPC/procedure support isn't implemented yet. Procedures are always encoded as
{}for now. This release covers type definitions and app definition generation only.
Background workers & lifecycle hooks (TS server)
ArriApp now supports background workers and lifecycle hooks. They only start when the server starts listening, not during arri build.
const app = new ArriApp({
onStart() {},
onStop() {},
onWorkerError(err, worker) {},
});
app.registerWorker(
defineWorker({
name: 'queue-consumer',
async start(signal) { /* runs until signal is aborted */ },
async stop() { /* optional cleanup */ },
}),
);ArriService can also register workers. They are added to the app when the service is mounted with app.use().
Spec clarifications
- 64-bit integers:
int64/uint64must be encoded as strings. Decoders should also accept whole JSON numbers. - Duplicate keys: implementations should reject objects where a key from the schema appears more than once.
Client Behavior Changes
Regenerating your clients with this release doesn't change any generated type or function names, and the JSON format is unchanged. A few runtime behaviors did change:
Default timestamps are now the Unix epoch
When a timestamp field is missing or can't be parsed, and when a model is created with new() / empty(), its timestamp fields now default to 1970-01-01T00:00:00Z. Previously the default depended on the language and was usually the current time, which made defaults non-deterministic.
| Client | Before | After |
|---|---|---|
| Kotlin | Instant.now() |
Instant.EPOCH |
| Swift | Date() |
Date(timeIntervalSince1970: 0) |
| Dart | DateTime(0) (year 0, local time) |
DateTime.fromMillisecondsSinceEpoch(0, isUtc: true) |
If your code compares against the old defaults (e.g. "is this timestamp recent?"), check it after upgrading.
Invalid timestamps no longer throw or produce invalid dates
- TypeScript: invalid date strings fall back to the default instead of producing an
Invalid Date. Generatedvalidatefunctions now rejectInvalid Datevalues. - Kotlin: malformed timestamps fall back to the epoch (or
nullfor nullable fields) instead of throwingDateTimeParseException. - Dart: uses
DateTime.tryParse, so malformed timestamps fall back to the default (ornull) instead of throwingFormatException.
Query params are now URL encoded (GET requests)
The Kotlin, Rust and Dart clients now properly percent-encode query param values. Swift now also encodes + (which servers otherwise decode as a space). Previously, values containing characters like &, =, #, + or spaces could arrive corrupted or be split into extra params.
Kotlin: SSE heartbeat detection
Kotlin SSE clients now read the heartbeat-interval header sent by the server. If nothing (data or heartbeat) is received within twice that interval, the client treats the connection as dead and reconnects.
Other fixes
- Swift: SSE requests now send the correct
Acceptheader (it was misspelledAccepts). - Dart: GET requests now respect the request timeout, as other methods already did.
- TypeScript: fixed
INT64_MINbeing positive, which broke the int64 lower-bound check. - TypeScript: generated
Clone/ serialization functions for discriminators now throw on an unknown variant - All: the warning logged when a nested union is skipped during query serialization now says "nested unions" instead of "nested objects".
Merged PRs:
- feature: add background workers and server lifecycle hooks to ts-server by @joshmossas in #201
- feature: new union schema by @joshmossas in #202
- chore: bump app definition schema version to 0.0.9 by @joshmossas in #206
- feat(rust): ArriModel derive + encoding/decoding for Rust by @joshmossas in #207
- refactor(rust): rename ArriModel to Arri and ArriSchema to Type by @joshmossas in #210
- feat(rust): add AppDef for building app definitions by @joshmossas in #212
New Contributors
- @joshmossas made their first contribution in #201 (first contribution on my new account)
Full Changelog: v0.84.1...v0.86.0