@arrirpc/client 0.77.0 → 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/dist/index.cjs +19 -17
- package/dist/index.d.cts +18 -6
- package/dist/index.d.mts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.mjs +19 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -78,35 +78,37 @@ async function getHeaders(input) {
|
|
|
78
78
|
return input ?? {};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
async function arriRequest(
|
|
82
|
-
let url =
|
|
81
|
+
async function arriRequest(config) {
|
|
82
|
+
let url = config.url;
|
|
83
83
|
let body;
|
|
84
84
|
let contentType;
|
|
85
|
-
switch (
|
|
85
|
+
switch (config.method) {
|
|
86
86
|
case "get":
|
|
87
87
|
case "head":
|
|
88
|
-
if (
|
|
89
|
-
url = `${
|
|
88
|
+
if (config.params && typeof config.params === "object") {
|
|
89
|
+
url = `${config.url}?${config.serializer(config.params)}`;
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
92
|
default:
|
|
93
|
-
if (
|
|
94
|
-
body =
|
|
93
|
+
if (config.params && typeof config.params === "object") {
|
|
94
|
+
body = config.serializer(config.params);
|
|
95
95
|
contentType = "application/json";
|
|
96
96
|
}
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
|
-
const headers = await getHeaders(
|
|
100
|
+
const headers = await getHeaders(config.headers) ?? {};
|
|
101
101
|
if (contentType) headers["Content-Type"] = contentType;
|
|
102
|
-
if (
|
|
103
|
-
|
|
102
|
+
if (config.clientVersion)
|
|
103
|
+
headers["client-version"] = config.clientVersion;
|
|
104
|
+
const fetchInstance = config.ofetch ?? ofetch.ofetch;
|
|
104
105
|
const result = await fetchInstance(url, {
|
|
105
|
-
method:
|
|
106
|
+
method: config.method,
|
|
106
107
|
body,
|
|
107
|
-
headers
|
|
108
|
+
headers,
|
|
109
|
+
...config.options ?? {}
|
|
108
110
|
});
|
|
109
|
-
return
|
|
111
|
+
return config.responseFromJson(result);
|
|
110
112
|
} catch (err) {
|
|
111
113
|
const error = err;
|
|
112
114
|
let arriError;
|
|
@@ -120,13 +122,13 @@ async function arriRequest(opts) {
|
|
|
120
122
|
stack: error.stack
|
|
121
123
|
});
|
|
122
124
|
}
|
|
123
|
-
if (
|
|
125
|
+
if (config.onError) config.onError(arriError);
|
|
124
126
|
throw arriError;
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
|
-
async function arriSafeRequest(
|
|
129
|
+
async function arriSafeRequest(config) {
|
|
128
130
|
try {
|
|
129
|
-
const result = await arriRequest(
|
|
131
|
+
const result = await arriRequest(config);
|
|
130
132
|
return {
|
|
131
133
|
success: true,
|
|
132
134
|
value: result
|
|
@@ -153,7 +155,7 @@ async function arriSafeRequest(opts) {
|
|
|
153
155
|
success: false,
|
|
154
156
|
error: new ArriErrorInstance({
|
|
155
157
|
code: 500,
|
|
156
|
-
message: `Unknown error connecting to ${
|
|
158
|
+
message: `Unknown error connecting to ${config.url}`,
|
|
157
159
|
data: err
|
|
158
160
|
})
|
|
159
161
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, EventSourcePlusOptions, OnRequestContext, OnRequestErrorContext, OnResponseContext, OnResponseErrorContext, EventSourceController } from 'event-source-plus';
|
|
2
2
|
export * from 'event-source-plus';
|
|
3
|
-
import { $Fetch } from 'ofetch';
|
|
3
|
+
import { FetchOptions, $Fetch } from 'ofetch';
|
|
4
4
|
export { $Fetch, Fetch, createFetch, ofetch } from 'ofetch';
|
|
5
5
|
|
|
6
6
|
interface ArriError {
|
|
@@ -30,7 +30,18 @@ declare class ArriErrorInstance extends Error implements ArriError {
|
|
|
30
30
|
static fromJson(json: unknown): ArriErrorInstance;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
interface
|
|
33
|
+
interface ArriRequestOptions {
|
|
34
|
+
retry?: FetchOptions['retry'];
|
|
35
|
+
retryDelay?: FetchOptions['retryDelay'];
|
|
36
|
+
retryStatusCodes?: FetchOptions['retryStatusCodes'];
|
|
37
|
+
onRequest?: FetchOptions['onRequest'];
|
|
38
|
+
onRequestError?: FetchOptions['onRequestError'];
|
|
39
|
+
onResponse?: FetchOptions['onResponse'];
|
|
40
|
+
onResponseError?: FetchOptions['onResponseError'];
|
|
41
|
+
timeout?: FetchOptions['timeout'];
|
|
42
|
+
signal?: FetchOptions['signal'];
|
|
43
|
+
}
|
|
44
|
+
interface ArriRequestConfig<TType, TParams extends Record<any, any> | undefined = undefined> {
|
|
34
45
|
url: string;
|
|
35
46
|
method: HttpMethod;
|
|
36
47
|
headers: EventSourcePlusOptions['headers'];
|
|
@@ -44,9 +55,10 @@ interface ArriRequestOpts<TType, TParams extends Record<any, any> | undefined =
|
|
|
44
55
|
ofetch?: $Fetch;
|
|
45
56
|
serializer: (input: TParams) => TParams extends undefined ? undefined : string;
|
|
46
57
|
clientVersion: string;
|
|
58
|
+
options?: ArriRequestOptions;
|
|
47
59
|
}
|
|
48
|
-
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
49
|
-
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
60
|
+
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<TType>;
|
|
61
|
+
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<SafeResponse<TType>>;
|
|
50
62
|
type SafeResponse<T> = {
|
|
51
63
|
success: true;
|
|
52
64
|
value: T;
|
|
@@ -102,7 +114,7 @@ interface SseOptions<TData> {
|
|
|
102
114
|
maxRetryCount?: number;
|
|
103
115
|
maxRetryInterval?: number;
|
|
104
116
|
}
|
|
105
|
-
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts:
|
|
117
|
+
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts: ArriRequestConfig<TType, TParams>, options: SseOptions<TType>): EventSourceController;
|
|
106
118
|
|
|
107
119
|
interface WsControllerOptions<TParams, TResponse> {
|
|
108
120
|
url: string;
|
|
@@ -162,4 +174,4 @@ declare function parsedWsResponse(input: string): {
|
|
|
162
174
|
};
|
|
163
175
|
|
|
164
176
|
export { ArriErrorInstance, INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN, INT64_MAX, INT64_MIN, INT8_MAX, INT8_MIN, UINT16_MAX, UINT32_MAX, UINT64_MAX, UINT8_MAX, WsController, arriRequest, arriSafeRequest, arriSseRequest, arriWsRequest, isArriError, isObject, parsedWsResponse, serializeString };
|
|
165
|
-
export type { ArriEnumValidator, ArriError, ArriModelValidator,
|
|
177
|
+
export type { ArriEnumValidator, ArriError, ArriModelValidator, ArriRequestConfig, ArriRequestOptions, SafeResponse, SseEvent, SseOptions, WsOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, EventSourcePlusOptions, OnRequestContext, OnRequestErrorContext, OnResponseContext, OnResponseErrorContext, EventSourceController } from 'event-source-plus';
|
|
2
2
|
export * from 'event-source-plus';
|
|
3
|
-
import { $Fetch } from 'ofetch';
|
|
3
|
+
import { FetchOptions, $Fetch } from 'ofetch';
|
|
4
4
|
export { $Fetch, Fetch, createFetch, ofetch } from 'ofetch';
|
|
5
5
|
|
|
6
6
|
interface ArriError {
|
|
@@ -30,7 +30,18 @@ declare class ArriErrorInstance extends Error implements ArriError {
|
|
|
30
30
|
static fromJson(json: unknown): ArriErrorInstance;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
interface
|
|
33
|
+
interface ArriRequestOptions {
|
|
34
|
+
retry?: FetchOptions['retry'];
|
|
35
|
+
retryDelay?: FetchOptions['retryDelay'];
|
|
36
|
+
retryStatusCodes?: FetchOptions['retryStatusCodes'];
|
|
37
|
+
onRequest?: FetchOptions['onRequest'];
|
|
38
|
+
onRequestError?: FetchOptions['onRequestError'];
|
|
39
|
+
onResponse?: FetchOptions['onResponse'];
|
|
40
|
+
onResponseError?: FetchOptions['onResponseError'];
|
|
41
|
+
timeout?: FetchOptions['timeout'];
|
|
42
|
+
signal?: FetchOptions['signal'];
|
|
43
|
+
}
|
|
44
|
+
interface ArriRequestConfig<TType, TParams extends Record<any, any> | undefined = undefined> {
|
|
34
45
|
url: string;
|
|
35
46
|
method: HttpMethod;
|
|
36
47
|
headers: EventSourcePlusOptions['headers'];
|
|
@@ -44,9 +55,10 @@ interface ArriRequestOpts<TType, TParams extends Record<any, any> | undefined =
|
|
|
44
55
|
ofetch?: $Fetch;
|
|
45
56
|
serializer: (input: TParams) => TParams extends undefined ? undefined : string;
|
|
46
57
|
clientVersion: string;
|
|
58
|
+
options?: ArriRequestOptions;
|
|
47
59
|
}
|
|
48
|
-
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
49
|
-
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
60
|
+
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<TType>;
|
|
61
|
+
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<SafeResponse<TType>>;
|
|
50
62
|
type SafeResponse<T> = {
|
|
51
63
|
success: true;
|
|
52
64
|
value: T;
|
|
@@ -102,7 +114,7 @@ interface SseOptions<TData> {
|
|
|
102
114
|
maxRetryCount?: number;
|
|
103
115
|
maxRetryInterval?: number;
|
|
104
116
|
}
|
|
105
|
-
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts:
|
|
117
|
+
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts: ArriRequestConfig<TType, TParams>, options: SseOptions<TType>): EventSourceController;
|
|
106
118
|
|
|
107
119
|
interface WsControllerOptions<TParams, TResponse> {
|
|
108
120
|
url: string;
|
|
@@ -162,4 +174,4 @@ declare function parsedWsResponse(input: string): {
|
|
|
162
174
|
};
|
|
163
175
|
|
|
164
176
|
export { ArriErrorInstance, INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN, INT64_MAX, INT64_MIN, INT8_MAX, INT8_MIN, UINT16_MAX, UINT32_MAX, UINT64_MAX, UINT8_MAX, WsController, arriRequest, arriSafeRequest, arriSseRequest, arriWsRequest, isArriError, isObject, parsedWsResponse, serializeString };
|
|
165
|
-
export type { ArriEnumValidator, ArriError, ArriModelValidator,
|
|
177
|
+
export type { ArriEnumValidator, ArriError, ArriModelValidator, ArriRequestConfig, ArriRequestOptions, SafeResponse, SseEvent, SseOptions, WsOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, EventSourcePlusOptions, OnRequestContext, OnRequestErrorContext, OnResponseContext, OnResponseErrorContext, EventSourceController } from 'event-source-plus';
|
|
2
2
|
export * from 'event-source-plus';
|
|
3
|
-
import { $Fetch } from 'ofetch';
|
|
3
|
+
import { FetchOptions, $Fetch } from 'ofetch';
|
|
4
4
|
export { $Fetch, Fetch, createFetch, ofetch } from 'ofetch';
|
|
5
5
|
|
|
6
6
|
interface ArriError {
|
|
@@ -30,7 +30,18 @@ declare class ArriErrorInstance extends Error implements ArriError {
|
|
|
30
30
|
static fromJson(json: unknown): ArriErrorInstance;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
interface
|
|
33
|
+
interface ArriRequestOptions {
|
|
34
|
+
retry?: FetchOptions['retry'];
|
|
35
|
+
retryDelay?: FetchOptions['retryDelay'];
|
|
36
|
+
retryStatusCodes?: FetchOptions['retryStatusCodes'];
|
|
37
|
+
onRequest?: FetchOptions['onRequest'];
|
|
38
|
+
onRequestError?: FetchOptions['onRequestError'];
|
|
39
|
+
onResponse?: FetchOptions['onResponse'];
|
|
40
|
+
onResponseError?: FetchOptions['onResponseError'];
|
|
41
|
+
timeout?: FetchOptions['timeout'];
|
|
42
|
+
signal?: FetchOptions['signal'];
|
|
43
|
+
}
|
|
44
|
+
interface ArriRequestConfig<TType, TParams extends Record<any, any> | undefined = undefined> {
|
|
34
45
|
url: string;
|
|
35
46
|
method: HttpMethod;
|
|
36
47
|
headers: EventSourcePlusOptions['headers'];
|
|
@@ -44,9 +55,10 @@ interface ArriRequestOpts<TType, TParams extends Record<any, any> | undefined =
|
|
|
44
55
|
ofetch?: $Fetch;
|
|
45
56
|
serializer: (input: TParams) => TParams extends undefined ? undefined : string;
|
|
46
57
|
clientVersion: string;
|
|
58
|
+
options?: ArriRequestOptions;
|
|
47
59
|
}
|
|
48
|
-
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
49
|
-
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(
|
|
60
|
+
declare function arriRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<TType>;
|
|
61
|
+
declare function arriSafeRequest<TType, TParams extends Record<any, any> | undefined = undefined>(config: ArriRequestConfig<TType, TParams>): Promise<SafeResponse<TType>>;
|
|
50
62
|
type SafeResponse<T> = {
|
|
51
63
|
success: true;
|
|
52
64
|
value: T;
|
|
@@ -102,7 +114,7 @@ interface SseOptions<TData> {
|
|
|
102
114
|
maxRetryCount?: number;
|
|
103
115
|
maxRetryInterval?: number;
|
|
104
116
|
}
|
|
105
|
-
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts:
|
|
117
|
+
declare function arriSseRequest<TType, TParams extends Record<any, any> | undefined = undefined>(opts: ArriRequestConfig<TType, TParams>, options: SseOptions<TType>): EventSourceController;
|
|
106
118
|
|
|
107
119
|
interface WsControllerOptions<TParams, TResponse> {
|
|
108
120
|
url: string;
|
|
@@ -162,4 +174,4 @@ declare function parsedWsResponse(input: string): {
|
|
|
162
174
|
};
|
|
163
175
|
|
|
164
176
|
export { ArriErrorInstance, INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN, INT64_MAX, INT64_MIN, INT8_MAX, INT8_MIN, UINT16_MAX, UINT32_MAX, UINT64_MAX, UINT8_MAX, WsController, arriRequest, arriSafeRequest, arriSseRequest, arriWsRequest, isArriError, isObject, parsedWsResponse, serializeString };
|
|
165
|
-
export type { ArriEnumValidator, ArriError, ArriModelValidator,
|
|
177
|
+
export type { ArriEnumValidator, ArriError, ArriModelValidator, ArriRequestConfig, ArriRequestOptions, SafeResponse, SseEvent, SseOptions, WsOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -74,35 +74,37 @@ async function getHeaders(input) {
|
|
|
74
74
|
return input ?? {};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
async function arriRequest(
|
|
78
|
-
let url =
|
|
77
|
+
async function arriRequest(config) {
|
|
78
|
+
let url = config.url;
|
|
79
79
|
let body;
|
|
80
80
|
let contentType;
|
|
81
|
-
switch (
|
|
81
|
+
switch (config.method) {
|
|
82
82
|
case "get":
|
|
83
83
|
case "head":
|
|
84
|
-
if (
|
|
85
|
-
url = `${
|
|
84
|
+
if (config.params && typeof config.params === "object") {
|
|
85
|
+
url = `${config.url}?${config.serializer(config.params)}`;
|
|
86
86
|
}
|
|
87
87
|
break;
|
|
88
88
|
default:
|
|
89
|
-
if (
|
|
90
|
-
body =
|
|
89
|
+
if (config.params && typeof config.params === "object") {
|
|
90
|
+
body = config.serializer(config.params);
|
|
91
91
|
contentType = "application/json";
|
|
92
92
|
}
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
95
|
try {
|
|
96
|
-
const headers = await getHeaders(
|
|
96
|
+
const headers = await getHeaders(config.headers) ?? {};
|
|
97
97
|
if (contentType) headers["Content-Type"] = contentType;
|
|
98
|
-
if (
|
|
99
|
-
|
|
98
|
+
if (config.clientVersion)
|
|
99
|
+
headers["client-version"] = config.clientVersion;
|
|
100
|
+
const fetchInstance = config.ofetch ?? ofetch;
|
|
100
101
|
const result = await fetchInstance(url, {
|
|
101
|
-
method:
|
|
102
|
+
method: config.method,
|
|
102
103
|
body,
|
|
103
|
-
headers
|
|
104
|
+
headers,
|
|
105
|
+
...config.options ?? {}
|
|
104
106
|
});
|
|
105
|
-
return
|
|
107
|
+
return config.responseFromJson(result);
|
|
106
108
|
} catch (err) {
|
|
107
109
|
const error = err;
|
|
108
110
|
let arriError;
|
|
@@ -116,13 +118,13 @@ async function arriRequest(opts) {
|
|
|
116
118
|
stack: error.stack
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
|
-
if (
|
|
121
|
+
if (config.onError) config.onError(arriError);
|
|
120
122
|
throw arriError;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
async function arriSafeRequest(
|
|
125
|
+
async function arriSafeRequest(config) {
|
|
124
126
|
try {
|
|
125
|
-
const result = await arriRequest(
|
|
127
|
+
const result = await arriRequest(config);
|
|
126
128
|
return {
|
|
127
129
|
success: true,
|
|
128
130
|
value: result
|
|
@@ -149,7 +151,7 @@ async function arriSafeRequest(opts) {
|
|
|
149
151
|
success: false,
|
|
150
152
|
error: new ArriErrorInstance({
|
|
151
153
|
code: 500,
|
|
152
|
-
message: `Unknown error connecting to ${
|
|
154
|
+
message: `Unknown error connecting to ${config.url}`,
|
|
153
155
|
data: err
|
|
154
156
|
})
|
|
155
157
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"event-source-plus": "^0.1.8",
|
|
26
26
|
"ofetch": "^1.4.1",
|
|
27
27
|
"ws": "^8.18.1",
|
|
28
|
-
"@arrirpc/schema": "0.
|
|
28
|
+
"@arrirpc/schema": "0.78.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/ws": "^8.18.0"
|