routesync 1.0.30 → 1.0.32
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 +14 -9
- package/dist/react.d.mts +7 -13
- package/dist/react.d.ts +7 -13
- package/dist/react.js +3 -9
- package/dist/react.mjs +3 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8976,11 +8976,7 @@ var SchemaGenerator = class {
|
|
|
8976
8976
|
lines.push(`export const ${schemaName} = z.object({`);
|
|
8977
8977
|
for (const [field, rules] of Object.entries(route.schema.rules)) {
|
|
8978
8978
|
const ruleStr = Array.isArray(rules) ? rules.join("|") : String(rules);
|
|
8979
|
-
let zodRule =
|
|
8980
|
-
if (ruleStr.includes("string")) zodRule = "z.string()";
|
|
8981
|
-
if (ruleStr.includes("numeric") || ruleStr.includes("integer") || ruleStr.includes("int")) zodRule = "z.number()";
|
|
8982
|
-
if (ruleStr.includes("boolean") || ruleStr.includes("bool")) zodRule = "z.boolean()";
|
|
8983
|
-
if (ruleStr.includes("array")) zodRule = "z.array(z.unknown())";
|
|
8979
|
+
let zodRule = this.mapRulesToZod(ruleStr);
|
|
8984
8980
|
if (!ruleStr.includes("required")) {
|
|
8985
8981
|
zodRule += ".optional()";
|
|
8986
8982
|
}
|
|
@@ -8998,6 +8994,16 @@ var SchemaGenerator = class {
|
|
|
8998
8994
|
}
|
|
8999
8995
|
await import_fs_extra5.default.writeFile(import_path4.default.join(outputDir, "schemas.ts"), lines.join("\n"));
|
|
9000
8996
|
}
|
|
8997
|
+
/**
|
|
8998
|
+
* Map a Laravel validation rule string to a Zod type.
|
|
8999
|
+
* Default is z.string() — HTTP inputs are strings unless explicitly typed.
|
|
9000
|
+
*/
|
|
9001
|
+
static mapRulesToZod(ruleStr) {
|
|
9002
|
+
if (ruleStr.includes("array")) return "z.array(z.unknown())";
|
|
9003
|
+
if (ruleStr.includes("integer") || ruleStr.includes("numeric") || ruleStr.includes("digits")) return "z.number()";
|
|
9004
|
+
if (ruleStr.includes("boolean") || ruleStr.includes("bool")) return "z.boolean()";
|
|
9005
|
+
return "z.string()";
|
|
9006
|
+
}
|
|
9001
9007
|
static mapSqlTypeToZod(sqlType) {
|
|
9002
9008
|
const type = sqlType.toLowerCase();
|
|
9003
9009
|
if (type.includes("int") || type.includes("float") || type.includes("double") || type.includes("decimal") || type.includes("numeric")) {
|
|
@@ -9051,19 +9057,18 @@ var HookGenerator = class _HookGenerator {
|
|
|
9051
9057
|
for (const route of routes) {
|
|
9052
9058
|
const method = route.method.toUpperCase();
|
|
9053
9059
|
const hookName = _HookGenerator.toHookName(group, route.actionName);
|
|
9054
|
-
const queryKey = `['${group}', '${route.actionName}']`;
|
|
9055
9060
|
const contractName = `${toTypeName(group)}${toTypeName(route.actionName)}Contract`;
|
|
9056
9061
|
const hasParams = route.path.includes(":") || route.path.includes("{");
|
|
9057
|
-
const hasQuery = route.schema?.query || route.method.toUpperCase() === "GET";
|
|
9058
9062
|
const hasBody = route.schema?.body;
|
|
9059
|
-
const requiresOptions = hasParams || hasBody
|
|
9063
|
+
const requiresOptions = hasParams || hasBody;
|
|
9060
9064
|
if (method === "GET") {
|
|
9061
9065
|
lines.push(`/**`);
|
|
9062
9066
|
lines.push(` * @deprecated Generated hooks will become optional in v2.`);
|
|
9063
9067
|
lines.push(` * Prefer \`useApiQuery(api.${group}.${route.actionName}, ...args)\` for future compatibility.`);
|
|
9064
9068
|
lines.push(` */`);
|
|
9065
9069
|
lines.push(`export function ${hookName}(...args: [options${requiresOptions ? "" : "?"}: import('./api').${contractName}['request'], queryOptions?: import('routesync/react').ApiQueryOptions<import('./api').${contractName}['response'], import('./types').ApiError>]) {`);
|
|
9066
|
-
lines.push(`
|
|
9070
|
+
lines.push(` const [options, queryOptions] = args`);
|
|
9071
|
+
lines.push(` return useApiQuery<import('./api').${contractName}['response'], import('./api').${contractName}['request']['params'], import('./api').${contractName}['request']['body'], import('./types').ApiError>(api.${group}.${route.actionName}, options, queryOptions)`);
|
|
9067
9072
|
lines.push(`}`);
|
|
9068
9073
|
lines.push(``);
|
|
9069
9074
|
} else {
|
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import { UseQueryOptions, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, useQuery, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
5
|
type RouteTransform = (value: unknown) => unknown;
|
|
@@ -83,18 +83,12 @@ interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unkno
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
86
|
-
declare function useApiQuery<TResponse
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
93
|
-
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
94
|
-
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
95
|
-
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
96
|
-
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
97
|
-
]): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
86
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
87
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
88
|
+
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
89
|
+
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'> & {
|
|
90
|
+
getNextPageParam: UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>['getNextPageParam'];
|
|
91
|
+
}): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* useApiMutation — accepts an endpoint callable directly.
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import { UseQueryOptions, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, useQuery, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
5
|
type RouteTransform = (value: unknown) => unknown;
|
|
@@ -83,18 +83,12 @@ interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unkno
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
86
|
-
declare function useApiQuery<TResponse
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
93
|
-
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
94
|
-
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
95
|
-
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
96
|
-
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
97
|
-
]): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
86
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
87
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
88
|
+
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
89
|
+
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'> & {
|
|
90
|
+
getNextPageParam: UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>['getNextPageParam'];
|
|
91
|
+
}): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* useApiMutation — accepts an endpoint callable directly.
|
package/dist/react.js
CHANGED
|
@@ -32,9 +32,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
32
32
|
|
|
33
33
|
// packages/react/src/hooks/useQuery.ts
|
|
34
34
|
var import_react_query = require("@tanstack/react-query");
|
|
35
|
-
function useApiQuery(endpoint,
|
|
36
|
-
const options = args[0];
|
|
37
|
-
const queryOptions = args[1];
|
|
35
|
+
function useApiQuery(endpoint, options, queryOptions) {
|
|
38
36
|
const queryKey = endpoint.$queryKey(options);
|
|
39
37
|
return (0, import_react_query.useQuery)({
|
|
40
38
|
queryKey,
|
|
@@ -42,9 +40,7 @@ function useApiQuery(endpoint, ...args) {
|
|
|
42
40
|
...queryOptions
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
|
-
function useApiSuspenseQuery(endpoint,
|
|
46
|
-
const options = args[0];
|
|
47
|
-
const queryOptions = args[1];
|
|
43
|
+
function useApiSuspenseQuery(endpoint, options, queryOptions) {
|
|
48
44
|
const queryKey = endpoint.$queryKey(options);
|
|
49
45
|
return (0, import_react_query.useSuspenseQuery)({
|
|
50
46
|
queryKey,
|
|
@@ -52,9 +48,7 @@ function useApiSuspenseQuery(endpoint, ...args) {
|
|
|
52
48
|
...queryOptions
|
|
53
49
|
});
|
|
54
50
|
}
|
|
55
|
-
function useApiInfiniteQuery(endpoint,
|
|
56
|
-
const options = args[0];
|
|
57
|
-
const queryOptions = args.length > 1 ? args[1] : args[0];
|
|
51
|
+
function useApiInfiniteQuery(endpoint, options, queryOptions) {
|
|
58
52
|
const queryKey = endpoint.$queryKey(options);
|
|
59
53
|
return (0, import_react_query.useInfiniteQuery)({
|
|
60
54
|
queryKey,
|
package/dist/react.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// packages/react/src/hooks/useQuery.ts
|
|
2
2
|
import { useQuery, useSuspenseQuery, useInfiniteQuery } from "@tanstack/react-query";
|
|
3
|
-
function useApiQuery(endpoint,
|
|
4
|
-
const options = args[0];
|
|
5
|
-
const queryOptions = args[1];
|
|
3
|
+
function useApiQuery(endpoint, options, queryOptions) {
|
|
6
4
|
const queryKey = endpoint.$queryKey(options);
|
|
7
5
|
return useQuery({
|
|
8
6
|
queryKey,
|
|
@@ -10,9 +8,7 @@ function useApiQuery(endpoint, ...args) {
|
|
|
10
8
|
...queryOptions
|
|
11
9
|
});
|
|
12
10
|
}
|
|
13
|
-
function useApiSuspenseQuery(endpoint,
|
|
14
|
-
const options = args[0];
|
|
15
|
-
const queryOptions = args[1];
|
|
11
|
+
function useApiSuspenseQuery(endpoint, options, queryOptions) {
|
|
16
12
|
const queryKey = endpoint.$queryKey(options);
|
|
17
13
|
return useSuspenseQuery({
|
|
18
14
|
queryKey,
|
|
@@ -20,9 +16,7 @@ function useApiSuspenseQuery(endpoint, ...args) {
|
|
|
20
16
|
...queryOptions
|
|
21
17
|
});
|
|
22
18
|
}
|
|
23
|
-
function useApiInfiniteQuery(endpoint,
|
|
24
|
-
const options = args[0];
|
|
25
|
-
const queryOptions = args.length > 1 ? args[1] : args[0];
|
|
19
|
+
function useApiInfiniteQuery(endpoint, options, queryOptions) {
|
|
26
20
|
const queryKey = endpoint.$queryKey(options);
|
|
27
21
|
return useInfiniteQuery({
|
|
28
22
|
queryKey,
|