startx 1.1.51 → 1.1.52

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.
@@ -223,4 +223,4 @@ export default extend(baseConfig);
223
223
  `),l&&await o.writeFile(t.join(a,`vitest.config.ts`),`import vitestConfig from "vitest-config/node";
224
224
 
225
225
  export default vitestConfig;
226
- `),Z_.info(`Created package ${r} at ${t.relative(i.workspace,a)}`),Z_.info("Run `pnpm install` to link the new package.")}static async resolveEslintPreference(e){if(e.eslint===!1)return!1;let n=Iy.getDirectory(),r=await this.readRootPackage(n.workspace);return this.hasDependency(r,`eslint`)?e.eslint??!0:e.eslint===!0||await Xx.confirm({message:`ESLint is not installed in this monorepo. Install and enable it?`,default:!0})?(r.devDependencies={...r.devDependencies,eslint:await this.resolveDependencyVersion(n.workspace,`eslint`)},await this.writeJson(t.join(n.workspace,`package.json`),r),Z_.info(`Added eslint to the root devDependencies.`),e.install!==!1&&await this.installRootDependencies(n.workspace),!0):!1}static async getInstallTags(e){let t=new Set([`common`,`node`]),n=await this.readRootPackage(e.workspace);e.eslintEnabled&&t.add(`eslint`),this.hasDependency(n,`@biomejs/biome`)&&t.add(`biome`),this.hasDependency(n,`prettier`)&&t.add(`prettier`),this.hasDependency(n,`vitest`)&&t.add(`vitest`),this.hasDependency(n,`tsdown`)&&t.add(`tsdown`);for(let n of e.packages)n.packageJson?.startx?.tags?.forEach(e=>t.add(e)),n.packageJson?.startx?.iTags?.forEach(e=>t.add(e)),n.packageJson?.startx?.gTags?.forEach(e=>t.add(e)),(n.type===`apps`||n.packageJson?.startx?.mode===`standalone`)&&t.add(`runnable`);return Array.from(t)}static resolvePackageClosure(e){let t=new Map,n=[e.selectedPackage],r=r=>{let i=this.findPackage(e.packages,r);i&&!t.has(i.name)&&n.push(i)};for(e.includeEslintConfig&&r(`eslint-config`);n.length>0;){let e=n.shift();if(!t.has(e.name)){t.set(e.name,e);for(let t of[...e.packageJson?.startx?.requiredDeps??[],...e.packageJson?.startx?.requiredDevDeps??[]])r(t)}}return Array.from(t.values())}static async ensureTemplatePackage(e){let t=this.findPackage(e.packages,e.name);if(!t){Z_.warn(`Could not find template package ${e.name}; skipping.`);return}await this.installTemplatePackage({pkg:t,directory:e.directory,tags:e.tags})}static async installTemplatePackage(e){if(!e.pkg.packageJson)throw Error(`Missing package.json for ${e.pkg.name}`);let n=e.overrideRelativePath??e.pkg.relativePath,r=t.join(e.directory.workspace,n);if(await this.pathExists(t.join(r,`package.json`))&&!await Xx.confirm({message:`"${n}" already exists. Overwrite?`,default:!1})){Z_.info(`Skipping ${e.pkg.name}.`);return}let i=new Set([...e.tags,...e.pkg.packageJson.startx?.tags??[]]),a=e.pkg.packageJson.startx?.ignore??[];a.includes(`eslint-config`)&&i.delete(`eslint`),a.includes(`vitest-config`)&&i.delete(`vitest`);let{packageJson:o,isWorkspace:s}=By.handlePackageJson({app:e.pkg.packageJson,tags:Array.from(i),name:e.overrideName??e.pkg.packageJson.name??e.pkg.name});if(s)throw Error(`Cannot install workspace as a package: ${e.pkg.name}`);await this.syncDepsWithCatalog({workspace:e.directory.workspace,templateDir:e.directory.template,packageJson:o}),await Ny.writeJSONFile({dir:r,file:`package`,content:o}),await this.copyValidatedFilesFromFolder(e.pkg.path,r,i),await Ny.copyDirectory({from:t.join(e.pkg.path,`src`),to:t.join(r,`src`),exclude:i.has(`vitest`)?void 0:/\.test\.tsx?$/}),Z_.info(`Installed ${e.overrideName??e.pkg.name} at ${n}`)}static async copyValidatedFilesFromFolder(e,n,r){let i=await Ny.listFiles({dir:e}).catch(()=>[]);for(let a of i){let i=Py[a];i&&!i.tags.every(e=>r.has(e))||a!==`package.json`&&await Ny.copyFile({from:t.join(e,a),to:t.join(n,a)})}}static createPackageJson(e){let t={typecheck:`tsc --noEmit`,clean:`rimraf dist .turbo`},n={"typescript-config":`workspace:*`},r=[];return e.eslintEnabled?(t.lint=`eslint .`,t[`lint:fix`]=`eslint . --fix`,n[`eslint-config`]=`workspace:*`):r.push(`eslint-config`),e.vitestEnabled?(t.test=`vitest run`,n[`vitest-config`]=`workspace:*`):r.push(`vitest-config`),{name:e.name,version:`1.0.0`,type:`module`,scripts:t,exports:`./src/index.ts`,devDependencies:n,startx:{iTags:[`node`],requiredDevDeps:[`typescript-config`],...r.length>0?{ignore:r}:{}}}}static async checkAndInstallMissingDeps(e){let n=await this.readRootPackage(e.directory.workspace),r=await Iy.parsePnpmWorkspace({dir:e.directory.workspace}),i=[],a=[];for(let[t,o]of Object.entries(Ly))if(o.tags.every(t=>e.tags.includes(t))&&!o.tags.includes(`root`))if(o.version.startsWith(`workspace:`))await this.workspacePackageExists(e.directory.workspace,t)||a.push(t);else{if(this.hasDependency(n,t))continue;let e=r?.catalog?.[t]?`catalog:`:o.version;i.push({name:t,version:e,isDev:o.isDevDependency??!0})}if(a.length>0){Z_.warn(`The following workspace packages are missing from this monorepo:`);for(let e of a)Z_.warn(` - ${e} → run: startx package add ${e}`)}if(i.length!==0){Z_.warn(`The following npm dependencies are required but not installed:`);for(let e of i)Z_.warn(` - ${e.name}`);if(!await Xx.confirm({message:`Add them to the workspace root package.json?`,default:!0})){Z_.warn(`Skipping. Some features may not work correctly without these dependencies.`);return}n.devDependencies??={},n.dependencies??={};for(let e of i)e.isDev?n.devDependencies[e.name]=e.version:n.dependencies[e.name]=e.version;await this.writeJson(t.join(e.directory.workspace,`package.json`),n),Z_.info(`Added missing dependencies to root package.json.`),e.install!==!1&&await this.installRootDependencies(e.directory.workspace)}}static async workspacePackageExists(e,n){let r=n.startsWith(`@`)?t.join(...n.split(`/`)):n,i=[t.join(e,`configs`,r,`package.json`),t.join(e,`packages`,r,`package.json`),t.join(e,`apps`,r,`package.json`)];for(let e of i)if(await this.pathExists(e))return!0;return!1}static getDestinationPath(e,n){let r=t.dirname(e),i=n.includes(`/`)?n.split(`/`).pop():n;return t.join(r,i)}static getDefaultPackagePath(e){if(e.startsWith(`@`)){let[n,r]=e.split(`/`);return t.join(`packages`,n,r)}return t.join(`packages`,e)}static findPackage(e,t){return e.find(e=>e.name===t||e.packageJson?.name===t)}static hasDependency(e,t){return!!(e.dependencies?.[t]||e.devDependencies?.[t]||e.peerDependencies?.[t])}static async readRootPackage(e){let n=await o.readFile(t.join(e,`package.json`),`utf-8`);return JSON.parse(n)}static async resolveDependencyVersion(e,t){return(await Iy.parsePnpmWorkspace({dir:e}))?.catalog?.[t]?`catalog:`:t===`eslint`?`^9.0.0`:`latest`}static async installRootDependencies(e){let t=(await this.readRootPackage(e)).packageManager?.split(`@`)[0]||`pnpm`,r=t===`yarn`?`yarn`:t,i=[`install`];Z_.info(`Running ${r} ${i.join(` `)} to install ESLint...`),await new Promise((t,a)=>{let o=n(r,i,{cwd:e,stdio:`inherit`,shell:process.platform===`win32`});o.on(`error`,a),o.on(`close`,e=>{if(e===0){t();return}a(Error(`${r} ${i.join(` `)} exited with code ${e}`))})}).catch(t=>{Z_.warn(`Could not install dependencies automatically: ${t instanceof Error?t.message:t}`),Z_.warn(`Run "${r} ${i.join(` `)}" manually in ${e}.`)})}static async syncDepsWithCatalog(e){let n=t.join(e.workspace,`pnpm-workspace.yaml`),r;try{r=await o.readFile(n,`utf-8`)}catch{Z_.warn(`Could not find pnpm workspace file at ${n}.`);return}let i=jy.parseDocument(r);i.has(`catalog`)||i.set(`catalog`,{});let a=await this.loadTemplateCatalog(e.templateDir),s=e.packageJson.dependencies,c=e.packageJson.devDependencies,l={},u=e=>{if(e)for(let[t,n]of Object.entries(e)){if(n.startsWith(`workspace:`))continue;let r=i.hasIn([`catalog`,t]);if(n===`catalog:`){if(!r){let e=a[t];e&&(l[t]=e)}}else e[t]=`catalog:`,r||(l[t]=n)}};if(u(s),u(c),Object.keys(l).length!==0){for(let[e,t]of Object.entries(l))i.setIn([`catalog`,e],t);await o.writeFile(n,i.toString()),Z_.info(`Added to pnpm-workspace.yaml catalog:`);for(let[e,t]of Object.entries(l))Z_.info(` + ${e}: ${t}`)}}static async loadTemplateCatalog(e){try{let n=await o.readFile(t.join(e,`pnpm-workspace.yaml`),`utf-8`),r=jy.parseDocument(n).get(`catalog`);return r?r.toJSON():{}}catch{return Z_.warn(`Could not find pnpm-workspace.yaml template in ${e}.`),{}}}static async writeJson(e,t){await o.writeFile(e,`${JSON.stringify(t,null,2)}\n`)}static async pathExists(e){try{return await o.access(e),!0}catch{return!1}}},eS=`1.1.51`;const tS=new dv;tS.name(`startx`).description(`StartX CLI - Your all in one monorepo startup tool.`).version(eS),tS.command(`ping`).action(()=>{Z_.info(`pong`)}),tS.addCommand(Zx.command),tS.addCommand($x.command),tS.parse(process.argv);export{};
226
+ `),Z_.info(`Created package ${r} at ${t.relative(i.workspace,a)}`),Z_.info("Run `pnpm install` to link the new package.")}static async resolveEslintPreference(e){if(e.eslint===!1)return!1;let n=Iy.getDirectory(),r=await this.readRootPackage(n.workspace);return this.hasDependency(r,`eslint`)?e.eslint??!0:e.eslint===!0||await Xx.confirm({message:`ESLint is not installed in this monorepo. Install and enable it?`,default:!0})?(r.devDependencies={...r.devDependencies,eslint:await this.resolveDependencyVersion(n.workspace,`eslint`)},await this.writeJson(t.join(n.workspace,`package.json`),r),Z_.info(`Added eslint to the root devDependencies.`),e.install!==!1&&await this.installRootDependencies(n.workspace),!0):!1}static async getInstallTags(e){let t=new Set([`common`,`node`]),n=await this.readRootPackage(e.workspace);e.eslintEnabled&&t.add(`eslint`),this.hasDependency(n,`@biomejs/biome`)&&t.add(`biome`),this.hasDependency(n,`prettier`)&&t.add(`prettier`),this.hasDependency(n,`vitest`)&&t.add(`vitest`),this.hasDependency(n,`tsdown`)&&t.add(`tsdown`);for(let n of e.packages)n.packageJson?.startx?.tags?.forEach(e=>t.add(e)),n.packageJson?.startx?.iTags?.forEach(e=>t.add(e)),n.packageJson?.startx?.gTags?.forEach(e=>t.add(e)),(n.type===`apps`||n.packageJson?.startx?.mode===`standalone`)&&t.add(`runnable`);return Array.from(t)}static resolvePackageClosure(e){let t=new Map,n=[e.selectedPackage],r=r=>{let i=this.findPackage(e.packages,r);i&&!t.has(i.name)&&n.push(i)};for(e.includeEslintConfig&&r(`eslint-config`);n.length>0;){let e=n.shift();if(!t.has(e.name)){t.set(e.name,e);for(let t of[...e.packageJson?.startx?.requiredDeps??[],...e.packageJson?.startx?.requiredDevDeps??[]])r(t)}}return Array.from(t.values())}static async ensureTemplatePackage(e){let t=this.findPackage(e.packages,e.name);if(!t){Z_.warn(`Could not find template package ${e.name}; skipping.`);return}await this.installTemplatePackage({pkg:t,directory:e.directory,tags:e.tags})}static async installTemplatePackage(e){if(!e.pkg.packageJson)throw Error(`Missing package.json for ${e.pkg.name}`);let n=e.overrideRelativePath??e.pkg.relativePath,r=t.join(e.directory.workspace,n);if(await this.pathExists(t.join(r,`package.json`))&&!await Xx.confirm({message:`"${n}" already exists. Overwrite?`,default:!1})){Z_.info(`Skipping ${e.pkg.name}.`);return}let i=new Set([...e.tags,...e.pkg.packageJson.startx?.tags??[]]),a=e.pkg.packageJson.startx?.ignore??[];a.includes(`eslint-config`)&&i.delete(`eslint`),a.includes(`vitest-config`)&&i.delete(`vitest`);let{packageJson:o,isWorkspace:s}=By.handlePackageJson({app:e.pkg.packageJson,tags:Array.from(i),name:e.overrideName??e.pkg.packageJson.name??e.pkg.name});if(s)throw Error(`Cannot install workspace as a package: ${e.pkg.name}`);await this.syncDepsWithCatalog({workspace:e.directory.workspace,templateDir:e.directory.template,packageJson:o}),await Ny.writeJSONFile({dir:r,file:`package`,content:o}),await this.copyValidatedFilesFromFolder(e.pkg.path,r,i),await Ny.copyDirectory({from:t.join(e.pkg.path,`src`),to:t.join(r,`src`),exclude:i.has(`vitest`)?void 0:/\.test\.tsx?$/}),Z_.info(`Installed ${e.overrideName??e.pkg.name} at ${n}`)}static async copyValidatedFilesFromFolder(e,n,r){let i=await Ny.listFiles({dir:e}).catch(()=>[]);for(let a of i){let i=Py[a];i&&!i.tags.every(e=>r.has(e))||a!==`package.json`&&await Ny.copyFile({from:t.join(e,a),to:t.join(n,a)})}}static createPackageJson(e){let t={typecheck:`tsc --noEmit`,clean:`rimraf dist .turbo`},n={"typescript-config":`workspace:*`},r=[];return e.eslintEnabled?(t.lint=`eslint .`,t[`lint:fix`]=`eslint . --fix`,n[`eslint-config`]=`workspace:*`):r.push(`eslint-config`),e.vitestEnabled?(t.test=`vitest run`,n[`vitest-config`]=`workspace:*`):r.push(`vitest-config`),{name:e.name,version:`1.0.0`,type:`module`,scripts:t,exports:`./src/index.ts`,devDependencies:n,startx:{iTags:[`node`],requiredDevDeps:[`typescript-config`],...r.length>0?{ignore:r}:{}}}}static async checkAndInstallMissingDeps(e){let n=await this.readRootPackage(e.directory.workspace),r=await Iy.parsePnpmWorkspace({dir:e.directory.workspace}),i=[],a=[];for(let[t,o]of Object.entries(Ly))if(o.tags.every(t=>e.tags.includes(t))&&!o.tags.includes(`root`))if(o.version.startsWith(`workspace:`))await this.workspacePackageExists(e.directory.workspace,t)||a.push(t);else{if(this.hasDependency(n,t))continue;let e=r?.catalog?.[t]?`catalog:`:o.version;i.push({name:t,version:e,isDev:o.isDevDependency??!0})}if(a.length>0){Z_.warn(`The following workspace packages are missing from this monorepo:`);for(let e of a)Z_.warn(` - ${e} → run: startx package add ${e}`)}if(i.length!==0){Z_.warn(`The following npm dependencies are required but not installed:`);for(let e of i)Z_.warn(` - ${e.name}`);if(!await Xx.confirm({message:`Add them to the workspace root package.json?`,default:!0})){Z_.warn(`Skipping. Some features may not work correctly without these dependencies.`);return}n.devDependencies??={},n.dependencies??={};for(let e of i)e.isDev?n.devDependencies[e.name]=e.version:n.dependencies[e.name]=e.version;await this.writeJson(t.join(e.directory.workspace,`package.json`),n),Z_.info(`Added missing dependencies to root package.json.`),e.install!==!1&&await this.installRootDependencies(e.directory.workspace)}}static async workspacePackageExists(e,n){let r=n.startsWith(`@`)?t.join(...n.split(`/`)):n,i=[t.join(e,`configs`,r,`package.json`),t.join(e,`packages`,r,`package.json`),t.join(e,`apps`,r,`package.json`)];for(let e of i)if(await this.pathExists(e))return!0;return!1}static getDestinationPath(e,n){let r=t.dirname(e),i=n.includes(`/`)?n.split(`/`).pop():n;return t.join(r,i)}static getDefaultPackagePath(e){if(e.startsWith(`@`)){let[n,r]=e.split(`/`);return t.join(`packages`,n,r)}return t.join(`packages`,e)}static findPackage(e,t){return e.find(e=>e.name===t||e.packageJson?.name===t)}static hasDependency(e,t){return!!(e.dependencies?.[t]||e.devDependencies?.[t]||e.peerDependencies?.[t])}static async readRootPackage(e){let n=await o.readFile(t.join(e,`package.json`),`utf-8`);return JSON.parse(n)}static async resolveDependencyVersion(e,t){return(await Iy.parsePnpmWorkspace({dir:e}))?.catalog?.[t]?`catalog:`:t===`eslint`?`^9.0.0`:`latest`}static async installRootDependencies(e){let t=(await this.readRootPackage(e)).packageManager?.split(`@`)[0]||`pnpm`,r=t===`yarn`?`yarn`:t,i=[`install`];Z_.info(`Running ${r} ${i.join(` `)} to install ESLint...`),await new Promise((t,a)=>{let o=n(r,i,{cwd:e,stdio:`inherit`,shell:process.platform===`win32`});o.on(`error`,a),o.on(`close`,e=>{if(e===0){t();return}a(Error(`${r} ${i.join(` `)} exited with code ${e}`))})}).catch(t=>{Z_.warn(`Could not install dependencies automatically: ${t instanceof Error?t.message:t}`),Z_.warn(`Run "${r} ${i.join(` `)}" manually in ${e}.`)})}static async syncDepsWithCatalog(e){let n=t.join(e.workspace,`pnpm-workspace.yaml`),r;try{r=await o.readFile(n,`utf-8`)}catch{Z_.warn(`Could not find pnpm workspace file at ${n}.`);return}let i=jy.parseDocument(r);i.has(`catalog`)||i.set(`catalog`,{});let a=await this.loadTemplateCatalog(e.templateDir),s=e.packageJson.dependencies,c=e.packageJson.devDependencies,l={},u=e=>{if(e)for(let[t,n]of Object.entries(e)){if(n.startsWith(`workspace:`))continue;let r=i.hasIn([`catalog`,t]);if(n===`catalog:`){if(!r){let e=a[t];e&&(l[t]=e)}}else e[t]=`catalog:`,r||(l[t]=n)}};if(u(s),u(c),Object.keys(l).length!==0){for(let[e,t]of Object.entries(l))i.setIn([`catalog`,e],t);await o.writeFile(n,i.toString()),Z_.info(`Added to pnpm-workspace.yaml catalog:`);for(let[e,t]of Object.entries(l))Z_.info(` + ${e}: ${t}`)}}static async loadTemplateCatalog(e){try{let n=await o.readFile(t.join(e,`pnpm-workspace.yaml`),`utf-8`),r=jy.parseDocument(n).get(`catalog`);return r?r.toJSON():{}}catch{return Z_.warn(`Could not find pnpm-workspace.yaml template in ${e}.`),{}}}static async writeJson(e,t){await o.writeFile(e,`${JSON.stringify(t,null,2)}\n`)}static async pathExists(e){try{return await o.access(e),!0}catch{return!1}}},eS=`1.1.52`;const tS=new dv;tS.name(`startx`).description(`StartX CLI - Your all in one monorepo startup tool.`).version(eS),tS.command(`ping`).action(()=>{Z_.info(`pong`)}),tS.addCommand(Zx.command),tS.addCommand($x.command),tS.parse(process.argv);export{};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "startx",
3
3
  "description": "",
4
- "version": "1.1.51",
4
+ "version": "1.1.52",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/avinashid/startx.git"
@@ -1,62 +1,26 @@
1
- import {
2
- useQuery,
3
- useMutation,
4
- useQueryClient,
5
- type UseQueryOptions,
6
- type UseQueryResult,
7
- type UseMutationResult,
8
- } from "@tanstack/react-query";
1
+ import { useQuery, useMutation, useQueryClient, type UseQueryOptions, type UseQueryResult, type UseMutationResult } from "@tanstack/react-query";
9
2
  import { type AxiosError, type AxiosInstance, type AxiosRequestConfig } from "axios";
10
3
  import { useMemo, useRef } from "react";
11
- import { toast } from "sonner";
12
4
  import { z } from "zod";
13
5
  import { FormUtils } from "@repo/ui/lib/utils";
6
+ import { toast } from "@repo/ui/sonner";
14
7
  import { ApiHelper } from "../api-helpers";
15
- import type {
16
- IFetchOptions,
17
- IPaginatedFetchOptions,
18
- IFetchMutationOptions,
19
- IPaginatedData,
20
- QueryEvent,
21
- CbAction,
22
- RawSchema,
23
- QueryKey,
24
- ZQuery,
25
- ZParams,
26
- } from "../api-types";
8
+ import type { IFetchOptions, IPaginatedFetchOptions, IFetchMutationOptions, IPaginatedData, QueryEvent, CbAction, RawSchema, QueryKey, ZQuery, ZParams } from "../api-types";
27
9
  import { createQueryKeysProxy } from "../query-factory";
28
10
 
29
- import type {
30
- UseApiOptions,
31
- UseApiReturn,
32
- MutationVariables,
33
- ExtractData,
34
- FetchOptions,
35
- PaginatedFetchOptions,
36
- MutationOptions,
37
- } from "./types";
11
+ import type { UseApiOptions, UseApiReturn, MutationVariables, ExtractData, FetchOptions, PaginatedFetchOptions, MutationOptions } from "./types";
38
12
 
39
- async function processEvents<
40
- Schema extends RawSchema,
41
- IK extends string,
42
- IQ extends z.output<ZQuery>,
43
- IP extends z.output<ZParams>,
44
- IB,
45
- ID,
46
- >(
13
+ async function processEvents<Schema extends RawSchema, IK extends string, IQ extends z.output<ZQuery>, IP extends z.output<ZParams>, IB, ID>(
47
14
  events: QueryEvent<IK, IQ, IP, IB, ID, Schema> | undefined,
48
15
  data: ID,
49
16
  variables: { query?: IQ; params?: IP; body?: IB } | undefined,
50
17
  schemaProxy: ReturnType<typeof createQueryKeysProxy<Schema>>,
51
18
  queryClient: ReturnType<typeof useQueryClient>,
52
- override?: boolean
19
+ override?: boolean,
53
20
  ) {
54
21
  if (!events) return;
55
22
  const payload = { data, ...variables };
56
- const runAction = async (
57
- action: CbAction<Schema, IP, IQ, IB, ID, IK, Array<QueryKey<IK>>> | undefined,
58
- exec: (key: QueryKey<IK>) => Promise<void>
59
- ) => {
23
+ const runAction = async (action: CbAction<Schema, IP, IQ, IB, ID, IK, Array<QueryKey<IK>>> | undefined, exec: (key: QueryKey<IK>) => Promise<void>) => {
60
24
  if (!action) return;
61
25
  const keys: Array<QueryKey<IK>> = typeof action === "function" ? action(payload, schemaProxy) : action;
62
26
  for (const key of keys) {
@@ -64,9 +28,9 @@ async function processEvents<
64
28
  }
65
29
  };
66
30
 
67
- await runAction(events.invalidateQuery, key => queryClient.invalidateQueries({ queryKey: key }));
68
- await runAction(events.refetchQuery, key => queryClient.refetchQueries({ queryKey: key }));
69
- await runAction(events.clearQuery, key => queryClient.resetQueries({ queryKey: key }));
31
+ await runAction(events.invalidateQuery, (key) => queryClient.invalidateQueries({ queryKey: key }));
32
+ await runAction(events.refetchQuery, (key) => queryClient.refetchQueries({ queryKey: key }));
33
+ await runAction(events.clearQuery, (key) => queryClient.resetQueries({ queryKey: key }));
70
34
 
71
35
  if (!override) {
72
36
  if (typeof events.fn === "function") await events.fn?.(payload, schemaProxy);
@@ -82,7 +46,7 @@ function useFetchApi<ID, ZQ extends ZQuery, ZP extends ZParams>(
82
46
  params?: z.output<ZP>;
83
47
  staleTime?: number;
84
48
  enabled?: boolean;
85
- }
49
+ },
86
50
  ): UseQueryResult<ID> & { abort: () => void } {
87
51
  const queryClient = useQueryClient();
88
52
  const queryKey = useMemo(
@@ -91,7 +55,7 @@ function useFetchApi<ID, ZQ extends ZQuery, ZP extends ZParams>(
91
55
  params: options.params,
92
56
  query: options.query,
93
57
  }),
94
- [options.query, options.params]
58
+ [options.query, options.params],
95
59
  );
96
60
  const staleTime = ApiHelper.parseTime(ApiHelper.merge(options.staleTime, endpoint.staleTime));
97
61
 
@@ -105,7 +69,6 @@ function useFetchApi<ID, ZQ extends ZQuery, ZP extends ZParams>(
105
69
  params: options.params,
106
70
  searchParams: options.query,
107
71
  }),
108
- params: options.query,
109
72
  signal,
110
73
  };
111
74
  const resp = await axiosClient.request<ID>(config);
@@ -127,6 +90,7 @@ function useFetchApi<ID, ZQ extends ZQuery, ZP extends ZParams>(
127
90
  abort: () => queryClient.cancelQueries({ queryKey }),
128
91
  };
129
92
  }
93
+
130
94
  function usePaginatedFetchApi<ID, IO, ZQ extends ZQuery, ZP extends ZParams>(
131
95
  key: keyof RawSchema,
132
96
  endpoint: IPaginatedFetchOptions<ID, IO, ZQ, ZP>,
@@ -138,7 +102,7 @@ function usePaginatedFetchApi<ID, IO, ZQ extends ZQuery, ZP extends ZParams>(
138
102
  limit?: number;
139
103
  staleTime?: number;
140
104
  enabled?: boolean;
141
- }
105
+ },
142
106
  ): UseQueryResult<IPaginatedData<ID, IO>> & { abort: () => void } {
143
107
  const queryClient = useQueryClient();
144
108
  const mergedQuery = useMemo(
@@ -147,7 +111,7 @@ function usePaginatedFetchApi<ID, IO, ZQ extends ZQuery, ZP extends ZParams>(
147
111
  page: options.page,
148
112
  limit: options.limit,
149
113
  }),
150
- [options.query, options.page, options.limit]
114
+ [options.query, options.page, options.limit],
151
115
  );
152
116
 
153
117
  const queryKey = useMemo(
@@ -156,7 +120,7 @@ function usePaginatedFetchApi<ID, IO, ZQ extends ZQuery, ZP extends ZParams>(
156
120
  params: options.params,
157
121
  query: mergedQuery,
158
122
  }),
159
- [key, endpoint.key, options.params, mergedQuery]
123
+ [key, endpoint.key, options.params, mergedQuery],
160
124
  );
161
125
 
162
126
  const staleTime = ApiHelper.parseTime(ApiHelper.merge(options.staleTime, endpoint.staleTime));
@@ -199,7 +163,7 @@ function useMutationApi<Schema extends RawSchema, K extends keyof Schema & strin
199
163
  endpoint: IFetchMutationOptions<K>,
200
164
  axiosClient: AxiosInstance,
201
165
  proxy: ReturnType<typeof createQueryKeysProxy<Schema>>,
202
- options?: MutationOptions<Schema[K]>
166
+ options?: MutationOptions<Schema[K]>,
203
167
  ): UseMutationResult<ExtractData<Schema[K]>, Error, MutationVariables<Schema[K]>> & { abort: () => void } {
204
168
  const queryClient = useQueryClient();
205
169
  const abortControllerRef = useRef<AbortController | null>(null);
@@ -222,10 +186,9 @@ function useMutationApi<Schema extends RawSchema, K extends keyof Schema & strin
222
186
  url: ApiHelper.buildUrl(
223
187
  ApiHelper.merge(
224
188
  { route: endpoint.route, params: variables.params, searchParams: variables.query },
225
- { route: endpoint.route, params: options?.params, searchParams: options?.query }
226
- )
189
+ { route: endpoint.route, params: options?.params, searchParams: options?.query },
190
+ ),
227
191
  ),
228
- params: ApiHelper.merge(variables.query, options?.query),
229
192
  data: isFormData ? FormUtils.getFormData(body!) : body,
230
193
  ...(isFormData && { headers: { "Content-Type": "multipart/form-data" } }),
231
194
  signal: abortControllerRef.current.signal,
@@ -243,20 +206,9 @@ function useMutationApi<Schema extends RawSchema, K extends keyof Schema & strin
243
206
  },
244
207
  onError: async (error: Error, variables) => {
245
208
  options?.onError?.(error, variables);
246
- await processEvents(
247
- endpoint.onError,
248
- error as AxiosError<any>,
249
- variables,
250
- proxy,
251
- queryClient,
252
- options?.overwriteEvents
253
- );
209
+ await processEvents(endpoint.onError, error as AxiosError<any>, variables, proxy, queryClient, options?.overwriteEvents);
254
210
  if (!options?.onError && !endpoint.onError) {
255
- try {
256
- toast.error((error as any)?.response?.data?.message ?? error.message);
257
- } catch (error) {
258
- console.error(error);
259
- }
211
+ toast.error((error as any)?.response?.data?.message ?? error.message);
260
212
  }
261
213
  },
262
214
  onMutate: options?.onMutate,
@@ -267,6 +219,7 @@ function useMutationApi<Schema extends RawSchema, K extends keyof Schema & strin
267
219
  abort: () => abortControllerRef.current?.abort(),
268
220
  };
269
221
  }
222
+
270
223
  export function useApi<Schema extends RawSchema>(schema: Schema, axiosClient: AxiosInstance) {
271
224
  return <K extends keyof Schema & string>(key: K, options?: UseApiOptions<Schema, K>): UseApiReturn<Schema, K> => {
272
225
  const endpoint = schema[key];