npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@arrirpc/codegen-swift

v0.81.1

Published

_Please note: The generated code does not yet support `swift-tools-version 6` or greater. Please track the status of this issue [here](https://github.com/modiimedia/arri/issues/167). In the meantime please set your `swift-tools-version` to `5.10` or lower

Downloads

579

Readme

Arri Swift Codegen

Please note: The generated code does not yet support swift-tools-version 6 or greater. Please track the status of this issue here. In the meantime please set your swift-tools-version to 5.10 or lower.

Setup

1) Add the Swift client generator to your arri config

// arri.config.ts
import { defineConfig, generators } from 'arri';

export default defineConfig({
    generators: [
        generators.swiftClient({
            clientName: 'MyClient',
            outputFile: './client/Sources/MyClient.g.swift',
        }),
    ],
});

Options:

| Name | Description | | --------------------- | ------------------------------------------------------ | | outputFile (required) | Path to the file that will be created by the generator | | clientName | The name of the generated client | | typePrefix | Add a prefix to all of the generated types | | rootService | The root service of the generated client |

2) Install the Swift client library

The generated code relies on the Arri Swift Client library, so be sure to add it to your swift project. The version number should match your Arri CLI version.

Swift Package Manager

Add the arri-client-swift git repo to your package dependencies

.package(
    url: "https://github.com/modiimedia/arri-client-swift.git",
    from: "<your-arri-cli-version>"
)

then add ArriClient as a dependency to your target

.target(
    name: "MyApp",
    dependencies: [
        .product(name: "ArriClient", package: "arri-client-swift")
    ]
)

Using the Generated Code

Initialize the client


let client = MyClient(
    baseURL: "https://example.com",
    delegate: DefaultRequestDelegate(),
    headers: {
        var headers: Dictionary<String, String> = Dictionary()
        return headers
    },
    // optional
    onError: { err in
        // do something
    }
)

await client.myProcedure()

The root client will be a struct containing all of the sub-services and procedures. If you only need a particular service you can initialize just that service.

For example if we have some procedures grouped under "users" we can initialize just the users service like so.

let usersService = MyClientUsersService(
    baseURL: "https://example.com",
    delegate: DefaultRequestDelegate(),
    headers: {
        var headers: Dictionary<String, String> = Dictionary()
        return headers
    }
)

usersService.someProcedure()

Using the Generated Types

All the generated structs, classes, and tagged unions implement the ArriClientModel protocol, which looks like this:

public protocol ArriClientModel: Equatable {
    init()
    init(json: JSON)
    init(JSONString: String)
    func toJSONString() -> String
    func toURLQueryParts() -> [URLQueryItem]
    func clone() -> Self
}

All generated standard enums implement the ArriClientEnum protocol, which looks like this:

public protocol ArriClientEnum: Equatable {
    init()
    init(serialValue: String)
    func serialValue() -> String
}

Calling Event Stream Procedures

Event Stream Procedures spawn a Task

var msgCount = 0
var openCount = 0
let params = WatchUserParams()

// event stream procedures return a task that you can cancel whenever
let task: Task<(), Never> = client.users.watchUser(
    params,
    options: EventSourceOptions(
        onMessage: { msg, eventSource in
            msgCount += 1
            print("New message: \(msg)")
        },
        onRequest: nil,
        onRequestError: nil,
        onResponse: { _, eventSource in
            openCount += 1
            print("Established connection!")
        },
        onResponseError: { err, eventSource in
            print("The server returned an error: \(err)")
            // you can also cancel the task from inside one of these hooks
            // by calling `cancel()` on the EventSource.
            // this will cause the parent Task to be completed
            eventSource.cancel()
        },
        onClose: nil,
        maxRetryCount: nil,
        maxRetryInterval: nil,
    )
)

// if you want to wait for the task to finished
await task.result
// this will continue indefinitely unless the server sends a "done" event
// or you call `cancel()` on the EventSource

Available Event Source Options

  • onMessage - Closure that fires whenever a "message" event is received from the server. This is the only required option.
  • onRequest - Closure that fires when a request has been created but has not been executed yet.
  • onRequestError - Closure that fires when there was an error in creating the request (i.e. a malformed URL), or if we were unable to connect to the server. (i.e a connectionRefused error)
  • onResponse - Closure that fires when we receive a response from the server
  • onResponseError - Closure that fires when the server has not responded with status code from 200 - 299 or the Content-Type header does not contain text/event-stream
  • onClose - Closure that fires when the EventSource is closed. (This will only fire if the EventSource was already able successfully receive a response from the server.)
  • maxRetryCount - Limit the number of times that the EventSource tries to reconnect to the server. When set to nil it will retry indefinitely. (Default is nil)
  • maxRetryInterval - Set the max delay time between retries in milliseconds. Default is 30000.

Additional Notes

Currently the DefaultRequestDelegate() relies on AsyncHTTPClient. I would like to eventually remove this dependency, so if anyone knows how to get Server Sent Events working with Foundation Swift libraries please open an issue. Please note that these clients needs to run on Linux, so the proposed solution needs to work without making use of URLSession.asyncBytes or any of the other APIs that only work on Apple platforms.