vovk 0.2.3-beta.82 → 0.2.3-beta.84

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,21 @@ 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
+ ${validatePath ? `import validateOnClient from '${validatePath}';\n` : '\nconst validateOnClient = null;'}
74
+ const prefix = '${env.VOVK_PREFIX ?? '/api'}';
75
+ type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
76
+ `;
67
77
  const metadataJson = await fs.readFile(localJsonPath, 'utf-8').catch(() => null);
68
78
 
69
79
  if (!metadataJson) console.warn(` 🐺 No .vovk.json file found in ${localJsonPath}`);
@@ -72,14 +82,16 @@ const { default: validateOnClient = null } = ${
72
82
 
73
83
  for (const key of Object.keys(metadata)) {
74
84
  if (key !== 'workers') {
75
- ts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>>;\n`;
85
+ dts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>>;\n`;
76
86
  js += `exports.${key} = clientizeController(metadata.${key}, { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
87
+ ts += `export const ${key}: ReturnType<typeof clientizeController<Controllers["${key}"], Options>> = clientizeController(metadata.${key}, { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
77
88
  }
78
89
  }
79
90
 
80
91
  for (const key of Object.keys(metadata.workers ?? {})) {
81
- ts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>;\n`;
92
+ dts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>;\n`;
82
93
  js += `exports.${key} = promisifyWorker(null, metadata.workers.${key});\n`;
94
+ ts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers["${key}"]>>; = promisifyWorker(null, metadata.workers.${key});\n`;
83
95
  }
84
96
 
85
97
  /* js += `
@@ -87,16 +99,18 @@ const { default: validateOnClient = null } = ${
87
99
  `; */
88
100
 
89
101
  const localJsPath = path.join(outDir, 'index.js');
90
- const localTsPath = path.join(outDir, 'index.d.ts');
91
- const localEntryPath = path.join(outDir, 'entry.ts');
102
+ const localDtsPath = path.join(outDir, 'index.d.ts');
103
+ const localTsPath = path.join(outDir, 'entry.ts');
92
104
  const existingJs = await fs.readFile(localJsPath, 'utf-8').catch(() => '');
105
+ const existingDts = await fs.readFile(localDtsPath, 'utf-8').catch(() => '');
93
106
  const existingTs = await fs.readFile(localTsPath, 'utf-8').catch(() => '');
94
- if (existingJs === js && existingTs === ts) return { written: false, path: outDir };
107
+
108
+ if (existingJs === js && existingDts === dts && existingTs === ts) return { written: false, path: outDir };
95
109
 
96
110
  await fs.mkdir(outDir, { recursive: true });
97
111
  await fs.writeFile(localJsPath, js);
112
+ await fs.writeFile(localDtsPath, dts);
98
113
  await fs.writeFile(localTsPath, ts);
99
- await fs.writeFile(localEntryPath, `export * from '.';`);
100
114
 
101
115
  return { written: true, path: outDir };
102
116
  }
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.84",
4
4
  "description": "Structural add-on for Next.js",
5
5
  "bin": "./cli/index.js",
6
6
  "scripts": {