routesync 1.0.18 → 1.0.20
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/cli.js +704 -584
- package/dist/core.d.mts +23 -3
- package/dist/core.d.ts +23 -3
- package/dist/core.js +1 -0
- package/dist/core.mjs +1 -0
- package/dist/react.d.mts +31 -11
- package/dist/react.d.ts +31 -11
- package/dist/react.js +4 -2
- package/dist/react.mjs +4 -2
- package/dist/sdk.d.mts +44 -12
- package/dist/sdk.d.ts +44 -12
- package/dist/sdk.js +23 -1
- package/dist/sdk.mjs +23 -1
- package/dist/vue.d.mts +9 -0
- package/dist/vue.d.ts +9 -0
- package/package.json +3 -2
package/dist/sdk.mjs
CHANGED
|
@@ -45,6 +45,7 @@ function snakeCaseKeys(obj) {
|
|
|
45
45
|
import axios from "axios";
|
|
46
46
|
var HttpClient = class {
|
|
47
47
|
constructor(config) {
|
|
48
|
+
this.config = config;
|
|
48
49
|
this.client = axios.create({
|
|
49
50
|
baseURL: config.baseURL,
|
|
50
51
|
timeout: config.timeout ?? 1e4,
|
|
@@ -302,14 +303,35 @@ function defineApi(definition, config) {
|
|
|
302
303
|
} else {
|
|
303
304
|
response = await client[method](resolvedPath, body, requestConfig);
|
|
304
305
|
}
|
|
306
|
+
if (client.config.validateResponse && route.responseSchema) {
|
|
307
|
+
try {
|
|
308
|
+
response = route.responseSchema.parse(response);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (client.config.onValidationError) {
|
|
311
|
+
client.config.onValidationError(error, {
|
|
312
|
+
endpoint: action,
|
|
313
|
+
method: route.method,
|
|
314
|
+
path: resolvedPath,
|
|
315
|
+
request: { params, query, body, headers: requestConfig.headers },
|
|
316
|
+
response
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
} else if (client.config.validateResponse) {
|
|
322
|
+
response = parseRouteSchema(route, "response", response);
|
|
323
|
+
}
|
|
305
324
|
return applyMapper(
|
|
306
325
|
route,
|
|
307
326
|
"response",
|
|
308
|
-
|
|
327
|
+
response
|
|
309
328
|
);
|
|
310
329
|
};
|
|
311
330
|
callable.$def = route;
|
|
312
331
|
callable.$key = [group, action];
|
|
332
|
+
callable.$queryKey = (options) => {
|
|
333
|
+
return options ? [group, action, options] : [group, action];
|
|
334
|
+
};
|
|
313
335
|
groupProxy[action] = callable;
|
|
314
336
|
}
|
|
315
337
|
;
|
package/dist/vue.d.mts
CHANGED
|
@@ -9,6 +9,14 @@ interface ServiceConfig {
|
|
|
9
9
|
timeout?: number;
|
|
10
10
|
retry?: RetryConfig;
|
|
11
11
|
cache?: boolean;
|
|
12
|
+
validateResponse?: boolean;
|
|
13
|
+
onValidationError?: (error: unknown, context: {
|
|
14
|
+
endpoint: string;
|
|
15
|
+
method: string;
|
|
16
|
+
path: string;
|
|
17
|
+
request: unknown;
|
|
18
|
+
response: unknown;
|
|
19
|
+
}) => void;
|
|
12
20
|
}
|
|
13
21
|
interface RetryConfig {
|
|
14
22
|
attempts: number;
|
|
@@ -18,6 +26,7 @@ interface RetryConfig {
|
|
|
18
26
|
|
|
19
27
|
declare class HttpClient {
|
|
20
28
|
private client;
|
|
29
|
+
readonly config: ServiceConfig;
|
|
21
30
|
constructor(config: ServiceConfig);
|
|
22
31
|
private setupInterceptors;
|
|
23
32
|
setToken(token: string): void;
|
package/dist/vue.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ interface ServiceConfig {
|
|
|
9
9
|
timeout?: number;
|
|
10
10
|
retry?: RetryConfig;
|
|
11
11
|
cache?: boolean;
|
|
12
|
+
validateResponse?: boolean;
|
|
13
|
+
onValidationError?: (error: unknown, context: {
|
|
14
|
+
endpoint: string;
|
|
15
|
+
method: string;
|
|
16
|
+
path: string;
|
|
17
|
+
request: unknown;
|
|
18
|
+
response: unknown;
|
|
19
|
+
}) => void;
|
|
12
20
|
}
|
|
13
21
|
interface RetryConfig {
|
|
14
22
|
attempts: number;
|
|
@@ -18,6 +26,7 @@ interface RetryConfig {
|
|
|
18
26
|
|
|
19
27
|
declare class HttpClient {
|
|
20
28
|
private client;
|
|
29
|
+
readonly config: ServiceConfig;
|
|
21
30
|
constructor(config: ServiceConfig);
|
|
22
31
|
private setupInterceptors;
|
|
23
32
|
setToken(token: string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "routesync",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Laravel routes to typed frontend SDKs.",
|
|
5
5
|
"main": "./dist/sdk.js",
|
|
6
6
|
"module": "./dist/sdk.mjs",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"@types/node": "^20.0.0",
|
|
62
62
|
"tsup": "^8.0.0",
|
|
63
63
|
"turbo": "^2.9.16",
|
|
64
|
-
"typescript": "^5.4.0"
|
|
64
|
+
"typescript": "^5.4.0",
|
|
65
|
+
"vitest": "^4.1.7"
|
|
65
66
|
},
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": ">=20.0.0"
|