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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arrirpc/codegen-dart

v0.69.2

Published

## Setup

Downloads

633

Readme

Arri Dart Codegen

Setup

1) Add the generator to your arri config

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

export default defineConfig({
    generators: [
        generators.dartClient({
            clientName: "MyClient",
            outputFile: "./client/src/my_client.g.dart",
        }),
    ],
});

Options:

| Name | Description | | --------------------- | ------------------------------------------------------------- | | clientName | The name of the generated client class (Defaults to "Client") | | outputFile (required) | Path to the file that will be created by the generator | | format | Run dart format on the generated file (Defaults to true) | | modelPrefix | Add a prefix to the generated class names |

2) Install the Dart client library

The generated code relies on the Dart arri_client library. So be sure to install it wherever the generated code is being used. The version number should match your Arri CLI version. (run arri version to check).

dart pub add arri_client

Using the Generated Code

Initialize the client

// this will match whatever you put in the arri config
import "./my_client.g.dart";

main() async {
    final client = MyClient(
        baseUrl: "https://example.com",
        headers: () async {
            return {
                "Authorization": "<some-token>",
            };
        },
    );
    await client.myProcedure();
}

The root client will be a class containing all of the services and procedures in a single class. If you only need a particular service, you can initialize just that service.

final service = MyClientUsersService(
    baseUrl: "https://example.com",
    headers: () async {
        return {
            "Authorization": "<some-token>",
        };
    },
);

Client / Service Options

| name | Type | description | | ---------- | ------------------------------------------- | ------------------------------------------------------------- | | httpClient | http.Client | Use this to pass in a custom http.Client instance | | baseUrl | String | The base url for the backend server | | headers | FutureOr<Map<String, String>> Function()? | A function that returns a Map of headers | | onError | Function(Object)? | A hook that fires whenever any error is thrown by the client. |

Using Arri Models

All generated models will be immutable. They will have access to the following features:

Methods:

  • Map<String, dynamic> toJson()
  • String toJsonString()
  • String toUrlQueryParams()
  • copyWith()

Factory Methods:

  • empty()
  • fromJson(Map<String, dynamic> input)
  • fromJsonString(String input)

Overrides:

  • == operator (allows for deep equality checking)
  • hashMap (allows for deep equality checking)
  • toString (will print out all properties and values instead of Instance of X)

This library was generated with Nx.

Development

# build the library
pnpm nx build codegen-dart

# test
pnpm nx test codegen-dart

# lint
pnpm nx lint codegen-dart