@arrirpc/codegen-ts 0.77.1 → 0.78.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 +20 -4
- package/dist/index.cjs +14 -9
- package/dist/index.mjs +14 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,19 +50,35 @@ pnpm i --save @arrirpc/client
|
|
|
50
50
|
import { MyClient } from './myClient.g';
|
|
51
51
|
|
|
52
52
|
const client = new MyClient({
|
|
53
|
+
// only required field
|
|
53
54
|
baseUrl: 'https://example.com',
|
|
55
|
+
|
|
56
|
+
// everything below is optional
|
|
54
57
|
headers: () => {
|
|
55
58
|
return {
|
|
56
59
|
Authorization: '<some-token>',
|
|
57
60
|
};
|
|
58
61
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
onError: (err) => {},
|
|
63
|
+
options: {
|
|
64
|
+
retry: 4,
|
|
65
|
+
retryDelay: 200,
|
|
66
|
+
retryStatusCodes: [400, 403, 500, 501],
|
|
67
|
+
onRequest: (ctx) => {},
|
|
68
|
+
onRequestError: (ctx) => {},
|
|
69
|
+
onResponse: (ctx) => {},
|
|
70
|
+
onResponseError: (ctx) => {},
|
|
71
|
+
signal: undefined, // abortcontroller signal
|
|
72
|
+
timeout: 200,
|
|
62
73
|
},
|
|
63
74
|
});
|
|
64
75
|
|
|
65
|
-
await client.myProcedure();
|
|
76
|
+
await client.myProcedure({ foo: 'foo' });
|
|
77
|
+
|
|
78
|
+
// individual procedures can also override the global request options
|
|
79
|
+
await client.myProcedure({ foo: 'foo' }, { timeout: 400 });
|
|
80
|
+
// be aware that these options are not merged with the global request options so you will have to
|
|
81
|
+
// re-specify every hook if you only want to change one thing
|
|
66
82
|
```
|
|
67
83
|
|
|
68
84
|
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 also import just that service.
|
package/dist/index.cjs
CHANGED
|
@@ -944,7 +944,7 @@ function httpRpcFromDefinition(def, context) {
|
|
|
944
944
|
return `${getJsDocComment({
|
|
945
945
|
description: def.description,
|
|
946
946
|
isDeprecated: def.isDeprecated
|
|
947
|
-
})} async ${key}(${params ? `params: ${params}` : ""}): Promise<${response ?? "undefined"}> {
|
|
947
|
+
})} async ${key}(${params ? `params: ${params}, ` : ""}options?: ArriRequestOptions): Promise<${response ?? "undefined"}> {
|
|
948
948
|
return arriRequest<${response ?? "undefined"}, ${params ?? "undefined"}>({
|
|
949
949
|
url: \`\${this._baseUrl}${def.path}\`,
|
|
950
950
|
method: "${def.method.toLowerCase()}",
|
|
@@ -956,6 +956,7 @@ function httpRpcFromDefinition(def, context) {
|
|
|
956
956
|
responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
|
|
957
957
|
serializer: ${params ? `$$${params}.${serializerMethod}` : "() => {}"},
|
|
958
958
|
clientVersion: "${context.versionNumber}",
|
|
959
|
+
options: options ?? this._options,
|
|
959
960
|
});
|
|
960
961
|
}`;
|
|
961
962
|
}
|
|
@@ -1048,23 +1049,26 @@ function tsServiceFromDefinition(def, context) {
|
|
|
1048
1049
|
private readonly _baseUrl: string;
|
|
1049
1050
|
private readonly _fetch?: $Fetch;
|
|
1050
1051
|
private readonly _headers: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
|
|
1051
|
-
private readonly _onError?: (err: unknown) => void;
|
|
1052
|
+
private readonly _onError?: (err: unknown) => void;
|
|
1053
|
+
private readonly _options?: ArriRequestOptions;
|
|
1052
1054
|
${subServices.map((service) => ` ${service.key}: ${service.name};`).join("\n")}
|
|
1053
1055
|
constructor(
|
|
1054
|
-
|
|
1056
|
+
config: {
|
|
1055
1057
|
baseUrl?: string;
|
|
1056
1058
|
fetch?: Fetch;
|
|
1057
1059
|
headers?: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
|
|
1058
1060
|
onError?: (err: unknown) => void;
|
|
1061
|
+
options?: ArriRequestOptions;
|
|
1059
1062
|
} = {},
|
|
1060
1063
|
) {
|
|
1061
|
-
this._baseUrl =
|
|
1062
|
-
if (
|
|
1063
|
-
this._fetch = createFetch({ fetch:
|
|
1064
|
+
this._baseUrl = config.baseUrl ?? "";
|
|
1065
|
+
if (config.fetch) {
|
|
1066
|
+
this._fetch = createFetch({ fetch: config.fetch });
|
|
1064
1067
|
}
|
|
1065
|
-
this._headers =
|
|
1066
|
-
this._onError =
|
|
1067
|
-
|
|
1068
|
+
this._headers = config.headers ?? {};
|
|
1069
|
+
this._onError = config.onError;
|
|
1070
|
+
this._options = config.options;
|
|
1071
|
+
${subServices.map((service) => ` this.${service.key} = new ${service.name}(config);`).join("\n")}
|
|
1068
1072
|
}
|
|
1069
1073
|
${rpcParts.map((rpc) => ` ${rpc}`).join("\n")}
|
|
1070
1074
|
}
|
|
@@ -1153,6 +1157,7 @@ async function createTypescriptClient(def, options) {
|
|
|
1153
1157
|
import {
|
|
1154
1158
|
ArriEnumValidator,
|
|
1155
1159
|
ArriModelValidator,
|
|
1160
|
+
type ArriRequestOptions,
|
|
1156
1161
|
arriRequest,
|
|
1157
1162
|
${context.usedFeatures.sse ? "arriSseRequest," : ""}
|
|
1158
1163
|
${context.usedFeatures.ws ? "arriWsRequest," : ""}
|
package/dist/index.mjs
CHANGED
|
@@ -938,7 +938,7 @@ function httpRpcFromDefinition(def, context) {
|
|
|
938
938
|
return `${getJsDocComment({
|
|
939
939
|
description: def.description,
|
|
940
940
|
isDeprecated: def.isDeprecated
|
|
941
|
-
})} async ${key}(${params ? `params: ${params}` : ""}): Promise<${response ?? "undefined"}> {
|
|
941
|
+
})} async ${key}(${params ? `params: ${params}, ` : ""}options?: ArriRequestOptions): Promise<${response ?? "undefined"}> {
|
|
942
942
|
return arriRequest<${response ?? "undefined"}, ${params ?? "undefined"}>({
|
|
943
943
|
url: \`\${this._baseUrl}${def.path}\`,
|
|
944
944
|
method: "${def.method.toLowerCase()}",
|
|
@@ -950,6 +950,7 @@ function httpRpcFromDefinition(def, context) {
|
|
|
950
950
|
responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
|
|
951
951
|
serializer: ${params ? `$$${params}.${serializerMethod}` : "() => {}"},
|
|
952
952
|
clientVersion: "${context.versionNumber}",
|
|
953
|
+
options: options ?? this._options,
|
|
953
954
|
});
|
|
954
955
|
}`;
|
|
955
956
|
}
|
|
@@ -1042,23 +1043,26 @@ function tsServiceFromDefinition(def, context) {
|
|
|
1042
1043
|
private readonly _baseUrl: string;
|
|
1043
1044
|
private readonly _fetch?: $Fetch;
|
|
1044
1045
|
private readonly _headers: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
|
|
1045
|
-
private readonly _onError?: (err: unknown) => void;
|
|
1046
|
+
private readonly _onError?: (err: unknown) => void;
|
|
1047
|
+
private readonly _options?: ArriRequestOptions;
|
|
1046
1048
|
${subServices.map((service) => ` ${service.key}: ${service.name};`).join("\n")}
|
|
1047
1049
|
constructor(
|
|
1048
|
-
|
|
1050
|
+
config: {
|
|
1049
1051
|
baseUrl?: string;
|
|
1050
1052
|
fetch?: Fetch;
|
|
1051
1053
|
headers?: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
|
|
1052
1054
|
onError?: (err: unknown) => void;
|
|
1055
|
+
options?: ArriRequestOptions;
|
|
1053
1056
|
} = {},
|
|
1054
1057
|
) {
|
|
1055
|
-
this._baseUrl =
|
|
1056
|
-
if (
|
|
1057
|
-
this._fetch = createFetch({ fetch:
|
|
1058
|
+
this._baseUrl = config.baseUrl ?? "";
|
|
1059
|
+
if (config.fetch) {
|
|
1060
|
+
this._fetch = createFetch({ fetch: config.fetch });
|
|
1058
1061
|
}
|
|
1059
|
-
this._headers =
|
|
1060
|
-
this._onError =
|
|
1061
|
-
|
|
1062
|
+
this._headers = config.headers ?? {};
|
|
1063
|
+
this._onError = config.onError;
|
|
1064
|
+
this._options = config.options;
|
|
1065
|
+
${subServices.map((service) => ` this.${service.key} = new ${service.name}(config);`).join("\n")}
|
|
1062
1066
|
}
|
|
1063
1067
|
${rpcParts.map((rpc) => ` ${rpc}`).join("\n")}
|
|
1064
1068
|
}
|
|
@@ -1147,6 +1151,7 @@ async function createTypescriptClient(def, options) {
|
|
|
1147
1151
|
import {
|
|
1148
1152
|
ArriEnumValidator,
|
|
1149
1153
|
ArriModelValidator,
|
|
1154
|
+
type ArriRequestOptions,
|
|
1150
1155
|
arriRequest,
|
|
1151
1156
|
${context.usedFeatures.sse ? "arriSseRequest," : ""}
|
|
1152
1157
|
${context.usedFeatures.ws ? "arriWsRequest," : ""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/codegen-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"prettier": "^3.5.3",
|
|
26
|
-
"@arrirpc/codegen-utils": "0.
|
|
26
|
+
"@arrirpc/codegen-utils": "0.78.0"
|
|
27
27
|
}
|
|
28
28
|
}
|