routesync 1.0.21 → 1.0.23

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.
Files changed (2) hide show
  1. package/dist/cli.js +26 -10
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -8767,7 +8767,7 @@ var SDKGenerator = class {
8767
8767
  const TitleCaseAction = route.actionName.charAt(0).toUpperCase() + route.actionName.slice(1);
8768
8768
  const ContractName = `${TitleCaseGroup}${TitleCaseAction}Contract`;
8769
8769
  const pathParams = Array.from(route.runtimePath.matchAll(/:([a-zA-Z0-9_]+)/g)).map((m) => m[1]);
8770
- const paramsType = pathParams.length > 0 ? `{ ${pathParams.map((p) => `${p}: string`).join(", ")} }` : `Record<string, never>`;
8770
+ const paramsType = pathParams.length > 0 ? `{ ${pathParams.map((p) => `${p}: string`).join(", ")} }` : `unknown`;
8771
8771
  const methodActionName = TitleCaseGroup + TitleCaseAction;
8772
8772
  const bodyType = route.schema?.rules && usesZod ? `z.infer<typeof Schemas.${methodActionName}Schema>` : `unknown`;
8773
8773
  const responseType = route.response ? `Types.${route.response.type}${route.response.collection ? "[]" : ""}` : `unknown`;
@@ -8798,7 +8798,7 @@ var SDKGenerator = class {
8798
8798
  lines.push(` body: Schemas.${ContractName.replace("Contract", "Schema")}`);
8799
8799
  lines.push(` },`);
8800
8800
  }
8801
- if (options.zod && route.response) {
8801
+ if (options.zod && route.response && options.models) {
8802
8802
  lines.push(` responseSchema: Schemas.${route.response.type}Schema${route.response.collection ? ".array()" : ""},`);
8803
8803
  }
8804
8804
  lines.push(` }),`);
@@ -9042,7 +9042,7 @@ var HookGenerator = class _HookGenerator {
9042
9042
  const lines = [];
9043
9043
  lines.push(`// Auto-generated by routesync. Do not edit manually.`);
9044
9044
  lines.push(``);
9045
- lines.push(`import { useApiQuery, useApiMutation } from '@routesync/react'`);
9045
+ lines.push(`import { useApiQuery, useApiMutation } from 'routesync/react'`);
9046
9046
  lines.push(`import { api } from './api'`);
9047
9047
  lines.push(``);
9048
9048
  const grouped = buildGeneratedRoutes(manifest.routes);
@@ -9103,23 +9103,35 @@ var NextActionGenerator = class {
9103
9103
  for (const [groupName, routes] of Object.entries(grouped)) {
9104
9104
  for (const route of routes) {
9105
9105
  const actionName = `${groupName}${toTypeName(route.actionName)}`;
9106
- lines.push(`export async function ${actionName}Action(payload?: Record<string, unknown>) {`);
9106
+ const TitleCaseGroup = groupName.charAt(0).toUpperCase() + groupName.slice(1);
9107
+ const TitleCaseAction = route.actionName.charAt(0).toUpperCase() + route.actionName.slice(1);
9108
+ const ContractName = `${TitleCaseGroup}${TitleCaseAction}Contract`;
9109
+ const hasBody = route.schema && route.schema.rules && Object.keys(route.schema.rules).length > 0;
9110
+ const hasQuery = route.method === "GET";
9111
+ const hasParams = route.path.includes(":");
9112
+ let payloadType = "never";
9113
+ if (hasBody) payloadType = `${ContractName}['request']['body']`;
9114
+ else if (hasQuery) payloadType = `${ContractName}['request']['query']`;
9115
+ else if (hasParams) payloadType = `${ContractName}['request']['params']`;
9116
+ const payloadParam = hasBody || hasQuery || hasParams ? `payload: ${payloadType}` : `payload?: unknown`;
9117
+ lines.push(`export async function ${actionName}Action(${payloadParam}) {`);
9107
9118
  const args = [];
9108
- if (route.path.includes(":")) {
9109
- args.push(`params: payload as any`);
9119
+ if (hasParams) {
9120
+ args.push(`params: payload`);
9110
9121
  }
9111
- if (route.method === "GET") {
9122
+ if (hasQuery) {
9112
9123
  args.push(`query: payload`);
9113
- } else {
9124
+ } else if (hasBody) {
9114
9125
  args.push(`body: payload`);
9115
9126
  }
9116
9127
  if (route.auth) {
9117
9128
  args.push(`headers: await getAuthHeaders()`);
9118
9129
  }
9119
- const apiCall = `await api.${groupName}.${route.actionName}({ ${args.join(", ")} })`;
9130
+ const argsString = args.length > 0 ? `{ ${args.join(", ")} }` : "";
9131
+ const apiCall = `await api.${groupName}.${route.actionName}(${argsString})`;
9120
9132
  lines.push(` try {`);
9121
9133
  lines.push(` const response = ${apiCall}`);
9122
- lines.push(` return { success: true, data: response.data }`);
9134
+ lines.push(` return { success: true, data: response }`);
9123
9135
  lines.push(` } catch (error: unknown) {`);
9124
9136
  lines.push(` return { success: false, error: error instanceof Error ? error.message : String(error) }`);
9125
9137
  lines.push(` }`);
@@ -9127,6 +9139,10 @@ var NextActionGenerator = class {
9127
9139
  lines.push(``);
9128
9140
  }
9129
9141
  }
9142
+ lines.splice(3, 1, `import { api, type ${Object.values(grouped).flatMap((routes) => routes.map((r) => {
9143
+ const g = r.groupName || Object.keys(grouped).find((k) => grouped[k] === routes) || "";
9144
+ return g.charAt(0).toUpperCase() + g.slice(1) + r.actionName.charAt(0).toUpperCase() + r.actionName.slice(1) + "Contract";
9145
+ })).join(", type ")} } from './api'`);
9130
9146
  await import_fs_extra7.default.writeFile(import_path6.default.join(outputDir, "actions.ts"), lines.join("\n"));
9131
9147
  }
9132
9148
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routesync",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "Laravel routes to typed frontend SDKs.",
5
5
  "main": "./dist/sdk.js",
6
6
  "module": "./dist/sdk.mjs",