sdnext 0.0.19 → 0.0.21

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.
@@ -1,27 +1,16 @@
1
1
  import { mkdir, readFile, writeFile } from "fs/promises";
2
2
  import { join, parse, relative } from "path";
3
- import { isNonNullable } from "deepsea-tools";
4
3
  async function createAction(path) {
5
4
  path = relative("shared", path).replace(/\\/g, "/");
6
5
  const { dir, name, ext } = parse(path);
7
6
  if (".ts" !== ext && ".tsx" !== ext && ".js" !== ext && ".jsx" !== ext) return;
8
- const serverContent = await readFile(join("shared", path), "utf-8");
9
- const match = serverContent.match(new RegExp(`export async function ${name}\\(.+?: (.+?)Params\\)`, "s"));
10
- const schema = match?.[1].replace(/^./, (char)=>char.toLowerCase());
11
- const hasSchema = isNonNullable(schema) && serverContent.includes(`from "@/schemas/${schema}"`);
12
7
  const content = `"use server"
13
- ${hasSchema ? `
14
- import { ${schema}Schema } from "@/schemas/${schema}"
15
- ` : ""}
8
+
16
9
  import { createResponseFn } from "@/server/createResponseFn"
17
10
 
18
11
  import { ${name} } from "@/shared/${join(dir, name)}"
19
12
 
20
- export const ${name}Action = createResponseFn({
21
- fn: ${name},${hasSchema ? `
22
- schema: ${schema}Schema,` : ""}
23
- name: "${name}",
24
- })
13
+ export const ${name}Action = createResponseFn(${name})
25
14
  `;
26
15
  const actionPath = join("actions", path);
27
16
  try {
@@ -26,8 +26,8 @@ async function createHook(path, hookMap) {
26
26
  path = relative("actions", path).replace(/\\/g, "/");
27
27
  const { dir, name, ext, base } = parse(path);
28
28
  if (".ts" !== ext && ".tsx" !== ext && ".js" !== ext && ".jsx" !== ext) return;
29
- const actionContent = await readFile(join("actions", path), "utf-8");
30
- const match = actionContent.match(/^import { (.+Schema) } from "@\/schemas\/.+"$/m);
29
+ const serverContent = await readFile(join("shared", path), "utf-8");
30
+ const match = serverContent.match(new RegExp(`export async function ${name}\\(.+?: (.+?)Params\\)`, "s"));
31
31
  const hasSchema = !!match;
32
32
  const upName = name.replace(/^./, (char)=>char.toUpperCase());
33
33
  const key = name.replace(/[A-Z]/g, (char)=>`-${char.toLowerCase()}`);
@@ -37,15 +37,8 @@ import { useMutation, UseMutationOptions } from "@tanstack/react-query"
37
37
  import { createRequestFn } from "deepsea-tools"
38
38
 
39
39
  import { ${name}Action } from "@/actions/${join(dir, name)}"
40
- ${hasSchema ? `
41
- ${match[0]}
42
- ` : ""}
43
- export const ${name}Client = createRequestFn(${hasSchema ? `{
44
- fn: ${name}Action,
45
- schema: ${match[1]},
46
- }` : `{
47
- fn: ${name}Action,
48
- }`})
40
+
41
+ export const ${name}Client = createRequestFn(${name}Action)
49
42
 
50
43
  export interface Use${upName}Params<TOnMutateResult = unknown> extends Omit<
51
44
  UseMutationOptions<Awaited<ReturnType<typeof ${name}Client>>, Error, Parameters<typeof ${name}Client>[0], TOnMutateResult>,
@@ -95,15 +88,8 @@ export function use${upName}<TOnMutateResult = unknown>({ onMutate, onSuccess, o
95
88
  import { createUseQuery } from "soda-tanstack-query"
96
89
 
97
90
  import { ${name}Action } from "@/actions/${join(dir, name)}"
98
- ${hasSchema ? `
99
- ${match[0].replace(match[1], `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())}, ${match[1]}`)}
100
- ` : ""}
101
- export const ${name}Client = createRequestFn(${hasSchema ? `{
102
- fn: ${name}Action,
103
- schema: ${match[1]},
104
- }` : `{
105
- fn: ${name}Action,
106
- }`})
91
+
92
+ export const ${name}Client = createRequestFn(${name}Action)
107
93
 
108
94
  export function ${name}ClientOptional(id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, (char)=>char.toUpperCase())} | ` : ""}undefined | null) {
109
95
  return isNonNullable(id) ? ${name}Client(id) : null
@@ -118,15 +104,8 @@ export const use${upName} = createUseQuery({
118
104
  import { createUseQuery } from "soda-tanstack-query"
119
105
 
120
106
  import { ${name}Action } from "@/actions/${join(dir, name)}"
121
- ${hasSchema ? `
122
- ${match[0]}
123
- ` : ""}
124
- export const ${name}Client = createRequestFn(${hasSchema ? `{
125
- fn: ${name}Action,
126
- schema: ${match[1]},
127
- }` : `{
128
- fn: ${name}Action,
129
- }`})
107
+
108
+ export const ${name}Client = createRequestFn(${name}Action)
130
109
 
131
110
  export const use${upName} = createUseQuery({
132
111
  queryKey: "${key}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdnext",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -41,10 +41,10 @@
41
41
  "@inquirer/prompts": "^8.1.0",
42
42
  "chokidar": "^5.0.0",
43
43
  "commander": "^14.0.2",
44
- "deepsea-tools": "5.47.4"
44
+ "deepsea-tools": "5.47.5"
45
45
  },
46
46
  "devDependencies": {
47
- "@types/node": "^24.10.2",
47
+ "@types/node": "^24.10.14",
48
48
  "typescript": ">=5.8.3"
49
49
  },
50
50
  "scripts": {
@@ -1,38 +1,18 @@
1
1
  import { mkdir, readFile, writeFile } from "fs/promises"
2
2
  import { join, parse, relative } from "path"
3
3
 
4
- import { isNonNullable } from "deepsea-tools"
5
-
6
4
  export async function createAction(path: string) {
7
5
  path = relative("shared", path).replace(/\\/g, "/")
8
6
  const { dir, name, ext } = parse(path)
9
7
  if (ext !== ".ts" && ext !== ".tsx" && ext !== ".js" && ext !== ".jsx") return
10
- const serverContent = await readFile(join("shared", path), "utf-8")
11
- const match = serverContent.match(new RegExp(`export async function ${name}\\(.+?: (.+?)Params\\)`, "s"))
12
- const schema = match?.[1].replace(/^./, char => char.toLowerCase())
13
- const hasSchema = isNonNullable(schema) && serverContent.includes(`from "@/schemas/${schema}"`)
14
8
 
15
9
  const content = `"use server"
16
- ${
17
- hasSchema
18
- ? `
19
- import { ${schema}Schema } from "@/schemas/${schema}"
20
- `
21
- : ""
22
- }
10
+
23
11
  import { createResponseFn } from "@/server/createResponseFn"
24
12
 
25
13
  import { ${name} } from "@/shared/${join(dir, name)}"
26
14
 
27
- export const ${name}Action = createResponseFn({
28
- fn: ${name},${
29
- hasSchema
30
- ? `
31
- schema: ${schema}Schema,`
32
- : ""
33
- }
34
- name: "${name}",
35
- })
15
+ export const ${name}Action = createResponseFn(${name})
36
16
  `
37
17
 
38
18
  const actionPath = join("actions", path)
package/src/utils/hook.ts CHANGED
@@ -46,8 +46,8 @@ export async function createHook(path: string, hookMap: Record<string, HookData>
46
46
  path = relative("actions", path).replace(/\\/g, "/")
47
47
  const { dir, name, ext, base } = parse(path)
48
48
  if (ext !== ".ts" && ext !== ".tsx" && ext !== ".js" && ext !== ".jsx") return
49
- const actionContent = await readFile(join("actions", path), "utf-8")
50
- const match = actionContent.match(/^import { (.+Schema) } from "@\/schemas\/.+"$/m)
49
+ const serverContent = await readFile(join("shared", path), "utf-8")
50
+ const match = serverContent.match(new RegExp(`export async function ${name}\\(.+?: (.+?)Params\\)`, "s"))
51
51
  const hasSchema = !!match
52
52
  const upName = name.replace(/^./, char => char.toUpperCase())
53
53
  const key = name.replace(/[A-Z]/g, char => `-${char.toLowerCase()}`)
@@ -58,23 +58,8 @@ import { useMutation, UseMutationOptions } from "@tanstack/react-query"
58
58
  import { createRequestFn } from "deepsea-tools"
59
59
 
60
60
  import { ${name}Action } from "@/actions/${join(dir, name)}"
61
- ${
62
- hasSchema
63
- ? `
64
- ${match[0]}
65
- `
66
- : ""
67
- }
68
- export const ${name}Client = createRequestFn(${
69
- hasSchema
70
- ? `{
71
- fn: ${name}Action,
72
- schema: ${match[1]},
73
- }`
74
- : `{
75
- fn: ${name}Action,
76
- }`
77
- })
61
+
62
+ export const ${name}Client = createRequestFn(${name}Action)
78
63
 
79
64
  export interface Use${upName}Params<TOnMutateResult = unknown> extends Omit<
80
65
  UseMutationOptions<Awaited<ReturnType<typeof ${name}Client>>, Error, Parameters<typeof ${name}Client>[0], TOnMutateResult>,
@@ -125,23 +110,8 @@ export function use${upName}<TOnMutateResult = unknown>({ onMutate, onSuccess, o
125
110
  import { createUseQuery } from "soda-tanstack-query"
126
111
 
127
112
  import { ${name}Action } from "@/actions/${join(dir, name)}"
128
- ${
129
- hasSchema
130
- ? `
131
- ${match[0].replace(match[1], `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())}, ${match[1]}`)}
132
- `
133
- : ""
134
- }
135
- export const ${name}Client = createRequestFn(${
136
- hasSchema
137
- ? `{
138
- fn: ${name}Action,
139
- schema: ${match[1]},
140
- }`
141
- : `{
142
- fn: ${name}Action,
143
- }`
144
- })
113
+
114
+ export const ${name}Client = createRequestFn(${name}Action)
145
115
 
146
116
  export function ${name}ClientOptional(id?: ${hasSchema ? `${match[1].replace(/Schema$/, "Params").replace(/^./, char => char.toUpperCase())} | ` : ""}undefined | null) {
147
117
  return isNonNullable(id) ? ${name}Client(id) : null
@@ -157,23 +127,8 @@ export const use${upName} = createUseQuery({
157
127
  import { createUseQuery } from "soda-tanstack-query"
158
128
 
159
129
  import { ${name}Action } from "@/actions/${join(dir, name)}"
160
- ${
161
- hasSchema
162
- ? `
163
- ${match[0]}
164
- `
165
- : ""
166
- }
167
- export const ${name}Client = createRequestFn(${
168
- hasSchema
169
- ? `{
170
- fn: ${name}Action,
171
- schema: ${match[1]},
172
- }`
173
- : `{
174
- fn: ${name}Action,
175
- }`
176
- })
130
+
131
+ export const ${name}Client = createRequestFn(${name}Action)
177
132
 
178
133
  export const use${upName} = createUseQuery({
179
134
  queryKey: "${key}",