vovk 0.2.3-beta.82 → 0.2.3-beta.83

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.
@@ -42,7 +42,7 @@ async function generateClient({ ...env }) {
42
42
  }
43
43
 
44
44
  const controllersPath = path.join(returnDir, env.VOVK_ROUTE).replace(/\.ts$/, '');
45
- let ts = `// auto-generated
45
+ let dts = `// auto-generated
46
46
  /* eslint-disable */
47
47
  import type { Controllers, Workers } from "${controllersPath}";
48
48
  import type { clientizeController } from 'vovk/client';
@@ -59,11 +59,22 @@ const { promisifyWorker } = require('vovk/worker');
59
59
  const metadata = require('${jsonPath}');
60
60
  const { default: fetcher } = require('${fetcherPath}');
61
61
  const prefix = '${env.VOVK_PREFIX ?? '/api'}';
62
- const { default: validateOnClient = null } = ${
63
- env.VOVK_VALIDATE_ON_CLIENT ? `require('${env.VOVK_VALIDATE_ON_CLIENT}')` : '{}'
64
- };
62
+ const { default: validateOnClient = null } = ${validatePath ? `require('${validatePath}')` : '{}'};
65
63
 
66
64
  `;
65
+ let ts = `// auto-generated
66
+ /* eslint-disable */
67
+ import type { Controllers, Workers } from "${controllersPath}";
68
+ import { clientizeController } from 'vovk/client';
69
+ import { promisifyWorker } from 'vovk/worker';
70
+ import type { VovkClientFetcher } from 'vovk/client';
71
+ import fetcher from '${fetcherPath}';
72
+ import metadata from '${jsonPath}';
73
+ import type { Options } from '${fetcherPath}';
74
+ import type { ValidateOnClient } from '${validatePath}';
75
+ ${validatePath ? `import validateOnClient from '${validatePath}';\n` : '\nconst validateOnClient = null;'}
76
+ const prefix = '${env.VOVK_PREFIX ?? '/api'}';
77
+ `;
67
78
  const metadataJson = await fs.readFile(localJsonPath, 'utf-8').catch(() => null);
68
79
 
69
80
  if (!metadataJson) console.warn(` 🐺 No .vovk.json file found in ${localJsonPath}`);
@@ -72,14 +83,16 @@ const { default: validateOnClient = null } = ${
72
83
 
73
84
  for (const key of Object.keys(metadata)) {
74
85
  if (key !== 'workers') {
75
- ts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>>;\n`;
86
+ dts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>>;\n`;
76
87
  js += `exports.${key} = clientizeController(metadata.${key}, { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
88
+ ts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>> = clientizeController(metadata.${key}, { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
77
89
  }
78
90
  }
79
91
 
80
92
  for (const key of Object.keys(metadata.workers ?? {})) {
81
- ts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>;\n`;
93
+ dts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>;\n`;
82
94
  js += `exports.${key} = promisifyWorker(null, metadata.workers.${key});\n`;
95
+ ts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>; = promisifyWorker(null, metadata.workers.${key});\n`;
83
96
  }
84
97
 
85
98
  /* js += `
@@ -87,16 +100,18 @@ const { default: validateOnClient = null } = ${
87
100
  `; */
88
101
 
89
102
  const localJsPath = path.join(outDir, 'index.js');
90
- const localTsPath = path.join(outDir, 'index.d.ts');
91
- const localEntryPath = path.join(outDir, 'entry.ts');
103
+ const localDtsPath = path.join(outDir, 'index.d.ts');
104
+ const localTsPath = path.join(outDir, 'entry.ts');
92
105
  const existingJs = await fs.readFile(localJsPath, 'utf-8').catch(() => '');
106
+ const existingDts = await fs.readFile(localDtsPath, 'utf-8').catch(() => '');
93
107
  const existingTs = await fs.readFile(localTsPath, 'utf-8').catch(() => '');
94
- if (existingJs === js && existingTs === ts) return { written: false, path: outDir };
108
+
109
+ if (existingJs === js && existingDts === dts && existingTs === ts) return { written: false, path: outDir };
95
110
 
96
111
  await fs.mkdir(outDir, { recursive: true });
97
112
  await fs.writeFile(localJsPath, js);
113
+ await fs.writeFile(localDtsPath, dts);
98
114
  await fs.writeFile(localTsPath, ts);
99
- await fs.writeFile(localEntryPath, `export * from '.';`);
100
115
 
101
116
  return { written: true, path: outDir };
102
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "0.2.3-beta.82",
3
+ "version": "0.2.3-beta.83",
4
4
  "description": "Structural add-on for Next.js",
5
5
  "bin": "./cli/index.js",
6
6
  "scripts": {