routesync 1.0.6 → 1.0.8
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 +33 -26
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8722,7 +8722,7 @@ var TypeGenerator = class {
|
|
|
8722
8722
|
}
|
|
8723
8723
|
}
|
|
8724
8724
|
}
|
|
8725
|
-
await import_fs_extra4.default.writeFile(import_path3.default.join(outputDir, "types.ts"), lines.join("
|
|
8725
|
+
await import_fs_extra4.default.writeFile(import_path3.default.join(outputDir, "types.ts"), lines.join("\n"));
|
|
8726
8726
|
}
|
|
8727
8727
|
};
|
|
8728
8728
|
|
|
@@ -8755,7 +8755,7 @@ var HookGenerator = class _HookGenerator {
|
|
|
8755
8755
|
lines.push(`export function ${hookName}() {`);
|
|
8756
8756
|
lines.push(` const queryClient = useQueryClient()`);
|
|
8757
8757
|
lines.push(` return useMutation({`);
|
|
8758
|
-
lines.push(` mutationFn: (data: unknown) => api.${group}.${route.actionName}({ body: data }),`);
|
|
8758
|
+
lines.push(` mutationFn: (data: Record<string, unknown>) => api.${group}.${route.actionName}({ body: data }),`);
|
|
8759
8759
|
lines.push(` onSuccess: () => {`);
|
|
8760
8760
|
lines.push(` queryClient.invalidateQueries({ queryKey: ['${group}'] })`);
|
|
8761
8761
|
lines.push(` }`);
|
|
@@ -8791,27 +8791,30 @@ var NextActionGenerator = class {
|
|
|
8791
8791
|
lines.push(` return token ? { Authorization: \`Bearer \${token}\` } : {}`);
|
|
8792
8792
|
lines.push(`}`);
|
|
8793
8793
|
lines.push(``);
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
args
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8794
|
+
const grouped = buildGeneratedRoutes(manifest.routes);
|
|
8795
|
+
for (const [groupName, routes] of Object.entries(grouped)) {
|
|
8796
|
+
for (const route of routes) {
|
|
8797
|
+
const actionName = `${groupName}${toTypeName(route.actionName)}`;
|
|
8798
|
+
lines.push(`export async function ${actionName}Action(payload?: Record<string, unknown>) {`);
|
|
8799
|
+
const args = [];
|
|
8800
|
+
if (route.method === "GET") {
|
|
8801
|
+
args.push(`query: payload`);
|
|
8802
|
+
} else {
|
|
8803
|
+
args.push(`body: payload`);
|
|
8804
|
+
}
|
|
8805
|
+
if (route.auth) {
|
|
8806
|
+
args.push(`headers: await getAuthHeaders()`);
|
|
8807
|
+
}
|
|
8808
|
+
const apiCall = `await api.${groupName}.${route.actionName}({ ${args.join(", ")} })`;
|
|
8809
|
+
lines.push(` try {`);
|
|
8810
|
+
lines.push(` const response = ${apiCall}`);
|
|
8811
|
+
lines.push(` return { success: true, data: response.data }`);
|
|
8812
|
+
lines.push(` } catch (error: unknown) {`);
|
|
8813
|
+
lines.push(` return { success: false, error: error instanceof Error ? error.message : String(error) }`);
|
|
8814
|
+
lines.push(` }`);
|
|
8815
|
+
lines.push(`}`);
|
|
8816
|
+
lines.push(``);
|
|
8817
|
+
}
|
|
8815
8818
|
}
|
|
8816
8819
|
await import_fs_extra6.default.writeFile(import_path5.default.join(outputDir, "actions.ts"), lines.join("\n"));
|
|
8817
8820
|
}
|
|
@@ -8831,12 +8834,16 @@ var MswGenerator = class {
|
|
|
8831
8834
|
const mswMethod = route.method.toLowerCase();
|
|
8832
8835
|
const mswPath = manifest.baseURL + route.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
8833
8836
|
const actionName = toMethodName(route);
|
|
8834
|
-
lines.push(" http." + mswMethod + "('" + mswPath + "', async ({ request
|
|
8837
|
+
lines.push(" http." + mswMethod + "('" + mswPath + "', async ({ request, params }) => {");
|
|
8835
8838
|
lines.push(` await delay(300) // Simulated network latency`);
|
|
8839
|
+
lines.push(` const url = new URL(request.url)`);
|
|
8836
8840
|
lines.push(` return HttpResponse.json({`);
|
|
8837
8841
|
lines.push(` success: true,`);
|
|
8838
|
-
lines.push(` message: 'Mocked response for ${actionName}',`);
|
|
8839
|
-
lines.push(` data: {
|
|
8842
|
+
lines.push(` message: 'Mocked response for ${actionName} at ' + url.pathname,`);
|
|
8843
|
+
lines.push(` data: {`);
|
|
8844
|
+
lines.push(` params,`);
|
|
8845
|
+
lines.push(` // TODO: Add mock data based on your schema`);
|
|
8846
|
+
lines.push(` }`);
|
|
8840
8847
|
lines.push(` })`);
|
|
8841
8848
|
lines.push(` }),`);
|
|
8842
8849
|
}
|