@arrirpc/codegen-ts 0.76.3 → 0.77.0
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 +19 -16
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +30 -4
- package/dist/index.d.mts +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.mjs +5 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
// arri.config.ts
|
|
9
|
-
import { defineConfig, generators } from
|
|
9
|
+
import { defineConfig, generators } from 'arri';
|
|
10
10
|
|
|
11
11
|
export default defineConfig({
|
|
12
12
|
generators: [
|
|
13
13
|
generators.typescriptClient({
|
|
14
|
-
clientName:
|
|
15
|
-
outputFile:
|
|
14
|
+
clientName: 'MyClient',
|
|
15
|
+
outputFile: './client/src/myClient.g.ts',
|
|
16
16
|
}),
|
|
17
17
|
],
|
|
18
18
|
});
|
|
@@ -20,11 +20,14 @@ export default defineConfig({
|
|
|
20
20
|
|
|
21
21
|
**Options:**
|
|
22
22
|
|
|
23
|
-
| Name | Description
|
|
24
|
-
| --------------------- |
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
23
|
+
| Name | Description |
|
|
24
|
+
| --------------------- | ---------------------------------------------------------- |
|
|
25
|
+
| outputFile (required) | Path to a file that will be created by the generator |
|
|
26
|
+
| clientName | The name of the generated client |
|
|
27
|
+
| typePrefix | Add a prefix to the generated type names |
|
|
28
|
+
| rootService | Set the root service of the generated client |
|
|
29
|
+
| prettierOptions | Formatting options for the generated code |
|
|
30
|
+
| rpcGenerators | Override the default function used for creating procedures |
|
|
28
31
|
|
|
29
32
|
### 2) Install the TS client library
|
|
30
33
|
|
|
@@ -44,13 +47,13 @@ pnpm i --save @arrirpc/client
|
|
|
44
47
|
|
|
45
48
|
```ts
|
|
46
49
|
// This will match whatever you put in the arri config
|
|
47
|
-
import { MyClient } from
|
|
50
|
+
import { MyClient } from './myClient.g';
|
|
48
51
|
|
|
49
52
|
const client = new MyClient({
|
|
50
|
-
baseUrl:
|
|
53
|
+
baseUrl: 'https://example.com',
|
|
51
54
|
headers: () => {
|
|
52
55
|
return {
|
|
53
|
-
Authorization:
|
|
56
|
+
Authorization: '<some-token>',
|
|
54
57
|
};
|
|
55
58
|
},
|
|
56
59
|
// optional
|
|
@@ -67,13 +70,13 @@ The root client will be a class containing all of the services and procedures in
|
|
|
67
70
|
For example if we have a some procedures grouped under `"users"` we can import just that service like so.
|
|
68
71
|
|
|
69
72
|
```ts
|
|
70
|
-
import { MyClientUsersService } from
|
|
73
|
+
import { MyClientUsersService } from './myClient.g';
|
|
71
74
|
|
|
72
75
|
const usersService = new MyClientUsersService({
|
|
73
|
-
baseUrl:
|
|
76
|
+
baseUrl: 'https://example.com',
|
|
74
77
|
headers: () => {
|
|
75
78
|
return {
|
|
76
|
-
Authorization:
|
|
79
|
+
Authorization: '<some-token>',
|
|
77
80
|
};
|
|
78
81
|
},
|
|
79
82
|
});
|
|
@@ -87,14 +90,14 @@ All generated types and serializers/parsers can be imported from the generated c
|
|
|
87
90
|
|
|
88
91
|
```ts
|
|
89
92
|
// import the user type and the user helper
|
|
90
|
-
import { type User, $$User } from
|
|
93
|
+
import { type User, $$User } from './myClient.g';
|
|
91
94
|
|
|
92
95
|
const bob: User = {
|
|
93
96
|
// field
|
|
94
97
|
};
|
|
95
98
|
|
|
96
99
|
$$User.serialize(bob); // outputs valid JSON
|
|
97
|
-
$$User.parse(
|
|
100
|
+
$$User.parse('<some-json-string>'); // outputs a User
|
|
98
101
|
```
|
|
99
102
|
|
|
100
103
|
# Development
|
package/dist/index.cjs
CHANGED
|
@@ -1109,7 +1109,7 @@ const typescriptClientGenerator = codegenUtils.defineGeneratorPlugin(
|
|
|
1109
1109
|
async function createTypescriptClient(def, options) {
|
|
1110
1110
|
const types = [];
|
|
1111
1111
|
const context = {
|
|
1112
|
-
clientName: options.clientName,
|
|
1112
|
+
clientName: options.clientName ?? "Client",
|
|
1113
1113
|
typePrefix: options.typePrefix ?? "",
|
|
1114
1114
|
generatedTypes: [],
|
|
1115
1115
|
instancePath: "",
|
|
@@ -1121,7 +1121,10 @@ async function createTypescriptClient(def, options) {
|
|
|
1121
1121
|
},
|
|
1122
1122
|
rpcGenerators: options.rpcGenerators ?? {}
|
|
1123
1123
|
};
|
|
1124
|
-
const serviceDefinitions = codegenUtils.unflattenProcedures(
|
|
1124
|
+
const serviceDefinitions = codegenUtils.unflattenProcedures(
|
|
1125
|
+
def.procedures,
|
|
1126
|
+
options.rootService
|
|
1127
|
+
);
|
|
1125
1128
|
const mainService = tsServiceFromDefinition(serviceDefinitions, context);
|
|
1126
1129
|
for (const key of Object.keys(def.definitions)) {
|
|
1127
1130
|
const typeDef = def.definitions[key];
|
package/dist/index.d.cts
CHANGED
|
@@ -32,24 +32,50 @@ interface CodegenContext {
|
|
|
32
32
|
sse: boolean;
|
|
33
33
|
ws: boolean;
|
|
34
34
|
};
|
|
35
|
-
rpcGenerators: Record<string, RpcGenerator
|
|
35
|
+
rpcGenerators: Partial<Record<string, RpcGenerator>>;
|
|
36
36
|
}
|
|
37
37
|
declare function getJsDocComment(metadata: Schema['metadata']): string;
|
|
38
38
|
declare function validVarName(name: string): string;
|
|
39
39
|
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
40
40
|
|
|
41
41
|
interface TypescriptGeneratorOptions {
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Defaults to 'Client'
|
|
44
|
+
*/
|
|
45
|
+
clientName?: string;
|
|
43
46
|
outputFile: string;
|
|
47
|
+
/**
|
|
48
|
+
* Add a prefix to the generated types
|
|
49
|
+
*/
|
|
44
50
|
typePrefix?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Set the root service of the generated client
|
|
53
|
+
*
|
|
54
|
+
* __Example:__
|
|
55
|
+
*
|
|
56
|
+
* Given the following procedures:
|
|
57
|
+
* - users.getUser
|
|
58
|
+
* - users.updateUser
|
|
59
|
+
* - posts.getPost
|
|
60
|
+
* - posts.updatePosts
|
|
61
|
+
*
|
|
62
|
+
* Setting the rootService to `posts` means the generated client will only have the following procedures:
|
|
63
|
+
* - getPost
|
|
64
|
+
* - updatePosts
|
|
65
|
+
*/
|
|
66
|
+
rootService?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Options for how to format the outputted typescript code
|
|
69
|
+
*/
|
|
45
70
|
prettierOptions?: Omit<prettier.Config, 'parser'>;
|
|
46
71
|
/**
|
|
47
72
|
* Override the default functions used for creating procedures
|
|
48
73
|
*/
|
|
49
|
-
rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator
|
|
74
|
+
rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
|
|
50
75
|
}
|
|
51
76
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
52
77
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
53
78
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
54
79
|
|
|
55
|
-
export {
|
|
80
|
+
export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
|
81
|
+
export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -32,24 +32,50 @@ interface CodegenContext {
|
|
|
32
32
|
sse: boolean;
|
|
33
33
|
ws: boolean;
|
|
34
34
|
};
|
|
35
|
-
rpcGenerators: Record<string, RpcGenerator
|
|
35
|
+
rpcGenerators: Partial<Record<string, RpcGenerator>>;
|
|
36
36
|
}
|
|
37
37
|
declare function getJsDocComment(metadata: Schema['metadata']): string;
|
|
38
38
|
declare function validVarName(name: string): string;
|
|
39
39
|
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
40
40
|
|
|
41
41
|
interface TypescriptGeneratorOptions {
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Defaults to 'Client'
|
|
44
|
+
*/
|
|
45
|
+
clientName?: string;
|
|
43
46
|
outputFile: string;
|
|
47
|
+
/**
|
|
48
|
+
* Add a prefix to the generated types
|
|
49
|
+
*/
|
|
44
50
|
typePrefix?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Set the root service of the generated client
|
|
53
|
+
*
|
|
54
|
+
* __Example:__
|
|
55
|
+
*
|
|
56
|
+
* Given the following procedures:
|
|
57
|
+
* - users.getUser
|
|
58
|
+
* - users.updateUser
|
|
59
|
+
* - posts.getPost
|
|
60
|
+
* - posts.updatePosts
|
|
61
|
+
*
|
|
62
|
+
* Setting the rootService to `posts` means the generated client will only have the following procedures:
|
|
63
|
+
* - getPost
|
|
64
|
+
* - updatePosts
|
|
65
|
+
*/
|
|
66
|
+
rootService?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Options for how to format the outputted typescript code
|
|
69
|
+
*/
|
|
45
70
|
prettierOptions?: Omit<prettier.Config, 'parser'>;
|
|
46
71
|
/**
|
|
47
72
|
* Override the default functions used for creating procedures
|
|
48
73
|
*/
|
|
49
|
-
rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator
|
|
74
|
+
rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
|
|
50
75
|
}
|
|
51
76
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
52
77
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
53
78
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
54
79
|
|
|
55
|
-
export {
|
|
80
|
+
export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
|
81
|
+
export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,24 +32,50 @@ interface CodegenContext {
|
|
|
32
32
|
sse: boolean;
|
|
33
33
|
ws: boolean;
|
|
34
34
|
};
|
|
35
|
-
rpcGenerators: Record<string, RpcGenerator
|
|
35
|
+
rpcGenerators: Partial<Record<string, RpcGenerator>>;
|
|
36
36
|
}
|
|
37
37
|
declare function getJsDocComment(metadata: Schema['metadata']): string;
|
|
38
38
|
declare function validVarName(name: string): string;
|
|
39
39
|
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
40
40
|
|
|
41
41
|
interface TypescriptGeneratorOptions {
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Defaults to 'Client'
|
|
44
|
+
*/
|
|
45
|
+
clientName?: string;
|
|
43
46
|
outputFile: string;
|
|
47
|
+
/**
|
|
48
|
+
* Add a prefix to the generated types
|
|
49
|
+
*/
|
|
44
50
|
typePrefix?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Set the root service of the generated client
|
|
53
|
+
*
|
|
54
|
+
* __Example:__
|
|
55
|
+
*
|
|
56
|
+
* Given the following procedures:
|
|
57
|
+
* - users.getUser
|
|
58
|
+
* - users.updateUser
|
|
59
|
+
* - posts.getPost
|
|
60
|
+
* - posts.updatePosts
|
|
61
|
+
*
|
|
62
|
+
* Setting the rootService to `posts` means the generated client will only have the following procedures:
|
|
63
|
+
* - getPost
|
|
64
|
+
* - updatePosts
|
|
65
|
+
*/
|
|
66
|
+
rootService?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Options for how to format the outputted typescript code
|
|
69
|
+
*/
|
|
45
70
|
prettierOptions?: Omit<prettier.Config, 'parser'>;
|
|
46
71
|
/**
|
|
47
72
|
* Override the default functions used for creating procedures
|
|
48
73
|
*/
|
|
49
|
-
rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator
|
|
74
|
+
rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
|
|
50
75
|
}
|
|
51
76
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
52
77
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
53
78
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
54
79
|
|
|
55
|
-
export {
|
|
80
|
+
export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
|
81
|
+
export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1103,7 +1103,7 @@ const typescriptClientGenerator = defineGeneratorPlugin(
|
|
|
1103
1103
|
async function createTypescriptClient(def, options) {
|
|
1104
1104
|
const types = [];
|
|
1105
1105
|
const context = {
|
|
1106
|
-
clientName: options.clientName,
|
|
1106
|
+
clientName: options.clientName ?? "Client",
|
|
1107
1107
|
typePrefix: options.typePrefix ?? "",
|
|
1108
1108
|
generatedTypes: [],
|
|
1109
1109
|
instancePath: "",
|
|
@@ -1115,7 +1115,10 @@ async function createTypescriptClient(def, options) {
|
|
|
1115
1115
|
},
|
|
1116
1116
|
rpcGenerators: options.rpcGenerators ?? {}
|
|
1117
1117
|
};
|
|
1118
|
-
const serviceDefinitions = unflattenProcedures(
|
|
1118
|
+
const serviceDefinitions = unflattenProcedures(
|
|
1119
|
+
def.procedures,
|
|
1120
|
+
options.rootService
|
|
1121
|
+
);
|
|
1119
1122
|
const mainService = tsServiceFromDefinition(serviceDefinitions, context);
|
|
1120
1123
|
for (const key of Object.keys(def.definitions)) {
|
|
1121
1124
|
const typeDef = def.definitions[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/codegen-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"prettier": "^3.5.
|
|
26
|
-
"@arrirpc/codegen-utils": "0.
|
|
25
|
+
"prettier": "^3.5.3",
|
|
26
|
+
"@arrirpc/codegen-utils": "0.77.0"
|
|
27
27
|
}
|
|
28
28
|
}
|