sdnext 0.0.4 → 0.0.6

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.
@@ -56,8 +56,8 @@ export function use${upName}<TOnMutateResult = unknown>({ onMutate, onSuccess, o
56
56
  })
57
57
  }
58
58
  `;
59
- const getHook = `import { useQuery } from "@tanstack/react-query"
60
- import { createRequestFn, isNonNullable } from "deepsea-tools"
59
+ const getHook = `import { createRequestFn, isNonNullable } from "deepsea-tools"
60
+ import { createUseQuery } from "soda-tanstack-query"
61
61
 
62
62
  import { ${name}Action } from "@/actions/${join(dir, name)}"
63
63
  ${hasSchema ? `
@@ -66,41 +66,35 @@ ${match[0].replace(match[1], `${match[1].replace(/Schema$/, "Params").replace(/^
66
66
  export const ${name}Client = createRequestFn(${hasSchema ? `{
67
67
  fn: ${name}Action,
68
68
  schema: ${match[1]},
69
- }` : `${name}Action`})
70
-
71
- export interface Use${upName}Params {
72
- id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())} | ` : ""}undefined
73
- enabled?: boolean
74
- }
69
+ }` : `{
70
+ fn: ${name}Action,
71
+ }`})
75
72
 
76
- export function use${upName}(idOrParams?: Use${upName}Params | ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())} | ` : ""}undefined) {
77
- const { id, enabled = true } = typeof idOrParams === "object" ? idOrParams : { id: idOrParams, enabled: true }
73
+ export const ${name}ClientOptional = (id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())} | ` : ""}undefined) => (isNonNullable(id) ? ${name}Client(id) : null)
78
74
 
79
- return useQuery({
80
- queryKey: ["${key}", id],
81
- queryFn: () => (isNonNullable(id) ? ${name}Client(id) : null),
82
- enabled,
83
- })
84
- }
75
+ export const use${upName} = createUseQuery({
76
+ queryFn: ${name}Client,
77
+ queryKey: "${key}",
78
+ })
85
79
  `;
86
- const queryHook = `import { useQuery } from "@tanstack/react-query"
87
- import { createRequestFn } from "deepsea-tools"
80
+ const queryHook = `import { createRequestFn } from "deepsea-tools"
81
+ import { createUseQuery } from "soda-tanstack-query"
88
82
 
89
83
  import { ${name}Action } from "@/actions/${join(dir, name)}"
90
84
  ${hasSchema ? `
91
- ${match[0].replace(match[1], `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())}, ${match[1]}`)}
85
+ ${match[0]}
92
86
  ` : ""}
93
87
  export const ${name}Client = createRequestFn(${hasSchema ? `{
94
88
  fn: ${name}Action,
95
89
  schema: ${match[1]},
96
- }` : `${name}Action`})
90
+ }` : `{
91
+ fn: ${name}Action,
92
+ }`})
97
93
 
98
- export function use${upName}(${hasSchema ? `params: ${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())} = {}` : ""}) {
99
- return useQuery({
100
- queryKey: ["${key}", params],
101
- queryFn: () => ${name}Client(params),
102
- })
103
- }
94
+ export const use${upName} = createUseQuery({
95
+ queryFn: ${name}Client,
96
+ queryKey: "${key}",
97
+ })
104
98
  `;
105
99
  const map = {
106
100
  get: getHook,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdnext",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,33 +1,33 @@
1
- import { spawn } from "child_process"
2
- import { readdir, stat } from "fs/promises"
3
- import { join } from "path"
4
-
5
- import { Command } from "commander"
6
-
7
- import { createAction } from "./createAction"
8
- import { excludeActions } from "./excludeActions"
9
-
10
- export async function buildFolder(dir: string) {
11
- const content = await readdir(dir)
12
-
13
- for (const item of content) {
14
- const path = join(dir, item)
15
- const stats = await stat(path)
16
-
17
- if (stats.isDirectory()) await buildFolder(path)
18
- else await createAction(path)
19
- }
20
- }
21
-
22
- export async function build(options: Record<string, string>, { args }: Command) {
23
- await excludeActions()
24
-
25
- await buildFolder("shared")
26
-
27
- if (args.length === 0) return
28
-
29
- spawn(args.join(" "), {
30
- stdio: "inherit",
31
- shell: true,
32
- })
33
- }
1
+ import { spawn } from "child_process"
2
+ import { readdir, stat } from "fs/promises"
3
+ import { join } from "path"
4
+
5
+ import { Command } from "commander"
6
+
7
+ import { createAction } from "./createAction"
8
+ import { excludeActions } from "./excludeActions"
9
+
10
+ export async function buildFolder(dir: string) {
11
+ const content = await readdir(dir)
12
+
13
+ for (const item of content) {
14
+ const path = join(dir, item)
15
+ const stats = await stat(path)
16
+
17
+ if (stats.isDirectory()) await buildFolder(path)
18
+ else await createAction(path)
19
+ }
20
+ }
21
+
22
+ export async function build(options: Record<string, string>, { args }: Command) {
23
+ await excludeActions()
24
+
25
+ await buildFolder("shared")
26
+
27
+ if (args.length === 0) return
28
+
29
+ spawn(args.join(" "), {
30
+ stdio: "inherit",
31
+ shell: true,
32
+ })
33
+ }
package/src/utils/hook.ts CHANGED
@@ -81,8 +81,8 @@ export function use${upName}<TOnMutateResult = unknown>({ onMutate, onSuccess, o
81
81
  }
82
82
  `
83
83
 
84
- const getHook = `import { useQuery } from "@tanstack/react-query"
85
- import { createRequestFn, isNonNullable } from "deepsea-tools"
84
+ const getHook = `import { createRequestFn, isNonNullable } from "deepsea-tools"
85
+ import { createUseQuery } from "soda-tanstack-query"
86
86
 
87
87
  import { ${name}Action } from "@/actions/${join(dir, name)}"
88
88
  ${
@@ -98,33 +98,27 @@ export const ${name}Client = createRequestFn(${
98
98
  fn: ${name}Action,
99
99
  schema: ${match[1]},
100
100
  }`
101
- : `${name}Action`
101
+ : `{
102
+ fn: ${name}Action,
103
+ }`
102
104
  })
103
105
 
104
- export interface Use${upName}Params {
105
- id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())} | ` : ""}undefined
106
- enabled?: boolean
107
- }
108
-
109
- export function use${upName}(idOrParams?: Use${upName}Params | ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())} | ` : ""}undefined) {
110
- const { id, enabled = true } = typeof idOrParams === "object" ? idOrParams : { id: idOrParams, enabled: true }
106
+ export const ${name}ClientOptional = (id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())} | ` : ""}undefined) => (isNonNullable(id) ? ${name}Client(id) : null)
111
107
 
112
- return useQuery({
113
- queryKey: ["${key}", id],
114
- queryFn: () => (isNonNullable(id) ? ${name}Client(id) : null),
115
- enabled,
116
- })
117
- }
108
+ export const use${upName} = createUseQuery({
109
+ queryFn: ${name}Client,
110
+ queryKey: "${key}",
111
+ })
118
112
  `
119
113
 
120
- const queryHook = `import { useQuery } from "@tanstack/react-query"
121
- import { createRequestFn } from "deepsea-tools"
114
+ const queryHook = `import { createRequestFn } from "deepsea-tools"
115
+ import { createUseQuery } from "soda-tanstack-query"
122
116
 
123
117
  import { ${name}Action } from "@/actions/${join(dir, name)}"
124
118
  ${
125
119
  hasSchema
126
120
  ? `
127
- ${match[0].replace(match[1], `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())}, ${match[1]}`)}
121
+ ${match[0]}
128
122
  `
129
123
  : ""
130
124
  }
@@ -134,15 +128,15 @@ export const ${name}Client = createRequestFn(${
134
128
  fn: ${name}Action,
135
129
  schema: ${match[1]},
136
130
  }`
137
- : `${name}Action`
131
+ : `{
132
+ fn: ${name}Action,
133
+ }`
138
134
  })
139
135
 
140
- export function use${upName}(${hasSchema ? `params: ${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())} = {}` : ""}) {
141
- return useQuery({
142
- queryKey: ["${key}", params],
143
- queryFn: () => ${name}Client(params),
144
- })
145
- }
136
+ export const use${upName} = createUseQuery({
137
+ queryFn: ${name}Client,
138
+ queryKey: "${key}",
139
+ })
146
140
  `
147
141
 
148
142
  const map: HookContentMap = {
@@ -1,27 +1,27 @@
1
- import { rm } from "fs/promises"
2
- import { join, relative } from "path"
3
-
4
- import { watch } from "chokidar"
5
-
6
- import { createAction } from "./createAction"
7
-
8
- const watcher = watch("shared", {
9
- awaitWriteFinish: true,
10
- persistent: true,
11
- })
12
-
13
- watcher.on("add", createAction)
14
-
15
- watcher.on("change", createAction)
16
-
17
- watcher.on("unlink", async path => {
18
- path = relative("shared", path).replace(/\\/g, "/")
19
- const actionPath = join("actions", path)
20
- await rm(actionPath, { recursive: true, force: true })
21
- })
22
-
23
- watcher.on("unlinkDir", async path => {
24
- path = relative("shared", path).replace(/\\/g, "/")
25
- const actionPath = join("actions", path)
26
- await rm(actionPath, { recursive: true, force: true })
27
- })
1
+ import { rm } from "fs/promises"
2
+ import { join, relative } from "path"
3
+
4
+ import { watch } from "chokidar"
5
+
6
+ import { createAction } from "./createAction"
7
+
8
+ const watcher = watch("shared", {
9
+ awaitWriteFinish: true,
10
+ persistent: true,
11
+ })
12
+
13
+ watcher.on("add", createAction)
14
+
15
+ watcher.on("change", createAction)
16
+
17
+ watcher.on("unlink", async path => {
18
+ path = relative("shared", path).replace(/\\/g, "/")
19
+ const actionPath = join("actions", path)
20
+ await rm(actionPath, { recursive: true, force: true })
21
+ })
22
+
23
+ watcher.on("unlinkDir", async path => {
24
+ path = relative("shared", path).replace(/\\/g, "/")
25
+ const actionPath = join("actions", path)
26
+ await rm(actionPath, { recursive: true, force: true })
27
+ })