sdnext 0.0.19 → 0.0.20

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()}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdnext",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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()}`)