@arrirpc/codegen-dart 0.49.1 → 0.51.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +102 -5
- package/dist/index.cjs +1114 -914
- package/dist/index.d.cts +26 -38
- package/dist/index.d.mts +26 -38
- package/dist/index.d.ts +26 -38
- package/dist/index.mjs +1121 -919
- package/package.json +4 -3
package/README.md
CHANGED
@@ -1,11 +1,108 @@
|
|
1
|
-
#
|
1
|
+
# Arri Dart Codegen
|
2
|
+
|
3
|
+
## Setup
|
4
|
+
|
5
|
+
### 1) Add the generator to your arri config
|
6
|
+
|
7
|
+
```ts
|
8
|
+
// arri.config.ts
|
9
|
+
import { defineConfig, generators } from "arri";
|
10
|
+
|
11
|
+
export default defineConfig({
|
12
|
+
generators: [
|
13
|
+
generators.dartClient({
|
14
|
+
clientName: "MyClient",
|
15
|
+
outputFile: "./client/src/my_client.g.dart",
|
16
|
+
}),
|
17
|
+
],
|
18
|
+
});
|
19
|
+
```
|
20
|
+
|
21
|
+
**Options:**
|
22
|
+
|
23
|
+
| Name | Description |
|
24
|
+
| --------------------- | ------------------------------------------------------------- |
|
25
|
+
| clientName | The name of the generated client class (Defaults to "Client") |
|
26
|
+
| outputFile (required) | Path to the file that will be created by the generator |
|
27
|
+
| format | Run `dart format` on the generated file (Defaults to `true`) |
|
28
|
+
| modelPrefix | Add a prefix to the generated class names |
|
29
|
+
|
30
|
+
### 2) Install the Dart client library
|
31
|
+
|
32
|
+
The generated code relies on the Dart [arri_client](/languages/dart/dart-client/README.md) 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).
|
33
|
+
|
34
|
+
```bash
|
35
|
+
dart pub add arri_client
|
36
|
+
```
|
37
|
+
|
38
|
+
## Using the Generated Code
|
39
|
+
|
40
|
+
### Initialize the client
|
41
|
+
|
42
|
+
```dart
|
43
|
+
// this will match whatever you put in the arri config
|
44
|
+
import "./my_client.g.dart";
|
45
|
+
|
46
|
+
main() async {
|
47
|
+
final client = MyClient(
|
48
|
+
baseUrl: "https://example.com",
|
49
|
+
headers: () async {
|
50
|
+
return {
|
51
|
+
"Authorization": "<some-token>",
|
52
|
+
};
|
53
|
+
},
|
54
|
+
);
|
55
|
+
await client.myProcedure();
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
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.
|
60
|
+
|
61
|
+
```dart
|
62
|
+
final service = MyClientUsersService(
|
63
|
+
baseUrl: "https://example.com",
|
64
|
+
headers: () async {
|
65
|
+
return {
|
66
|
+
"Authorization": "<some-token>",
|
67
|
+
};
|
68
|
+
},
|
69
|
+
);
|
70
|
+
```
|
71
|
+
|
72
|
+
### Using Arri Models
|
73
|
+
|
74
|
+
All generated models will be immutable. They will have access to the following features:
|
75
|
+
|
76
|
+
**Methods**:
|
77
|
+
|
78
|
+
- `Map<String, dynamic> toJson()`
|
79
|
+
- `String toJsonString()`
|
80
|
+
- `String toUrlQueryParams()`
|
81
|
+
- `copyWith()`
|
82
|
+
|
83
|
+
**Factory Methods**:
|
84
|
+
|
85
|
+
- `empty()`
|
86
|
+
- `fromJson(Map<String, dynamic> input)`
|
87
|
+
- `fromJsonString(String input)`
|
88
|
+
|
89
|
+
**Overrides**:
|
90
|
+
|
91
|
+
- `==` operator (allows for deep equality checking)
|
92
|
+
- `hashMap` (allows for deep equality checking)
|
93
|
+
- `toString` (will print out all properties and values instead of `Instance of X`)
|
2
94
|
|
3
95
|
This library was generated with [Nx](https://nx.dev).
|
4
96
|
|
5
|
-
##
|
97
|
+
## Development
|
6
98
|
|
7
|
-
|
99
|
+
```bash
|
100
|
+
# build the library
|
101
|
+
pnpm nx build codegen-dart
|
8
102
|
|
9
|
-
|
103
|
+
# test
|
104
|
+
pnpm nx test codegen-dart
|
10
105
|
|
11
|
-
|
106
|
+
# lint
|
107
|
+
pnpm nx lint codegen-dart
|
108
|
+
```
|