@arrirpc/codegen-dart 0.50.0 → 0.51.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +3 -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
|
+
```
|
package/dist/index.cjs
CHANGED
@@ -1046,7 +1046,7 @@ function dartRefFromSchema(schema, context) {
|
|
1046
1046
|
};
|
1047
1047
|
}
|
1048
1048
|
|
1049
|
-
const dartClientGenerator = codegenUtils.
|
1049
|
+
const dartClientGenerator = codegenUtils.defineGeneratorPlugin(
|
1050
1050
|
(options) => {
|
1051
1051
|
return {
|
1052
1052
|
async generator(def) {
|
package/dist/index.d.cts
CHANGED
@@ -29,7 +29,7 @@ interface DartClientGeneratorOptions {
|
|
29
29
|
modelPrefix?: string;
|
30
30
|
format?: boolean;
|
31
31
|
}
|
32
|
-
declare const dartClientGenerator: _arrirpc_codegen_utils.
|
32
|
+
declare const dartClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<DartClientGeneratorOptions>;
|
33
33
|
declare function createDartClient(def: AppDefinition, options: DartClientGeneratorOptions): string;
|
34
34
|
declare function dartTypeFromSchema(schema: Schema, context: CodegenContext): DartProperty;
|
35
35
|
|
package/dist/index.d.mts
CHANGED
@@ -29,7 +29,7 @@ interface DartClientGeneratorOptions {
|
|
29
29
|
modelPrefix?: string;
|
30
30
|
format?: boolean;
|
31
31
|
}
|
32
|
-
declare const dartClientGenerator: _arrirpc_codegen_utils.
|
32
|
+
declare const dartClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<DartClientGeneratorOptions>;
|
33
33
|
declare function createDartClient(def: AppDefinition, options: DartClientGeneratorOptions): string;
|
34
34
|
declare function dartTypeFromSchema(schema: Schema, context: CodegenContext): DartProperty;
|
35
35
|
|
package/dist/index.d.ts
CHANGED
@@ -29,7 +29,7 @@ interface DartClientGeneratorOptions {
|
|
29
29
|
modelPrefix?: string;
|
30
30
|
format?: boolean;
|
31
31
|
}
|
32
|
-
declare const dartClientGenerator: _arrirpc_codegen_utils.
|
32
|
+
declare const dartClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<DartClientGeneratorOptions>;
|
33
33
|
declare function createDartClient(def: AppDefinition, options: DartClientGeneratorOptions): string;
|
34
34
|
declare function dartTypeFromSchema(schema: Schema, context: CodegenContext): DartProperty;
|
35
35
|
|
package/dist/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { execSync } from 'node:child_process';
|
2
2
|
import fs from 'node:fs/promises';
|
3
|
-
import { camelCase, pascalCase, removeDisallowedChars, isServiceDefinition, isRpcDefinition,
|
3
|
+
import { camelCase, pascalCase, removeDisallowedChars, isServiceDefinition, isRpcDefinition, defineGeneratorPlugin, unflattenProcedures, isSchemaFormType, isSchemaFormEnum, isSchemaFormProperties, isSchemaFormElements, isSchemaFormValues, isSchemaFormDiscriminator, isSchemaFormRef } from '@arrirpc/codegen-utils';
|
4
4
|
import path from 'pathe';
|
5
5
|
|
6
6
|
function outputIsNullable(schema, context) {
|
@@ -1039,7 +1039,7 @@ function dartRefFromSchema(schema, context) {
|
|
1039
1039
|
};
|
1040
1040
|
}
|
1041
1041
|
|
1042
|
-
const dartClientGenerator =
|
1042
|
+
const dartClientGenerator = defineGeneratorPlugin(
|
1043
1043
|
(options) => {
|
1044
1044
|
return {
|
1045
1045
|
async generator(def) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arrirpc/codegen-dart",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.51.1",
|
4
4
|
"type": "module",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": {
|
@@ -23,7 +23,7 @@
|
|
23
23
|
],
|
24
24
|
"dependencies": {
|
25
25
|
"pathe": "^1.1.2",
|
26
|
-
"@arrirpc/
|
27
|
-
"@arrirpc/
|
26
|
+
"@arrirpc/schema": "0.51.1",
|
27
|
+
"@arrirpc/codegen-utils": "0.51.1"
|
28
28
|
}
|
29
29
|
}
|