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.
- package/dist/utils/hook.js +20 -26
- package/package.json +1 -1
- package/src/utils/build.ts +33 -33
- package/src/utils/hook.ts +20 -26
- package/src/utils/watch.ts +27 -27
package/dist/utils/hook.js
CHANGED
|
@@ -56,8 +56,8 @@ export function use${upName}<TOnMutateResult = unknown>({ onMutate, onSuccess, o
|
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
`;
|
|
59
|
-
const getHook = `import {
|
|
60
|
-
import {
|
|
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
|
-
}` :
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
}
|
|
75
|
+
export const use${upName} = createUseQuery({
|
|
76
|
+
queryFn: ${name}Client,
|
|
77
|
+
queryKey: "${key}",
|
|
78
|
+
})
|
|
85
79
|
`;
|
|
86
|
-
const queryHook = `import {
|
|
87
|
-
import {
|
|
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]
|
|
85
|
+
${match[0]}
|
|
92
86
|
` : ""}
|
|
93
87
|
export const ${name}Client = createRequestFn(${hasSchema ? `{
|
|
94
88
|
fn: ${name}Action,
|
|
95
89
|
schema: ${match[1]},
|
|
96
|
-
}` :
|
|
90
|
+
}` : `{
|
|
91
|
+
fn: ${name}Action,
|
|
92
|
+
}`})
|
|
97
93
|
|
|
98
|
-
export
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
package/src/utils/build.ts
CHANGED
|
@@ -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 {
|
|
85
|
-
import {
|
|
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
|
-
:
|
|
101
|
+
: `{
|
|
102
|
+
fn: ${name}Action,
|
|
103
|
+
}`
|
|
102
104
|
})
|
|
103
105
|
|
|
104
|
-
export
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
}
|
|
108
|
+
export const use${upName} = createUseQuery({
|
|
109
|
+
queryFn: ${name}Client,
|
|
110
|
+
queryKey: "${key}",
|
|
111
|
+
})
|
|
118
112
|
`
|
|
119
113
|
|
|
120
|
-
const queryHook = `import {
|
|
121
|
-
import {
|
|
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]
|
|
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
|
-
:
|
|
131
|
+
: `{
|
|
132
|
+
fn: ${name}Action,
|
|
133
|
+
}`
|
|
138
134
|
})
|
|
139
135
|
|
|
140
|
-
export
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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 = {
|
package/src/utils/watch.ts
CHANGED
|
@@ -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
|
+
})
|