vovk 2.0.0-beta.7 → 2.0.0-beta.9

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.
Files changed (2) hide show
  1. package/cli/server.cjs +19 -4
  2. package/package.json +1 -1
package/cli/server.cjs CHANGED
@@ -63,7 +63,7 @@ const showDiff = ({ addedKeys, removedKeys, constantName }) => {
63
63
  let is404Reported = false;
64
64
 
65
65
  /** @type {() => Promise<void>} */
66
- const ping = async () => {
66
+ const pingNoDebounce = async () => {
67
67
  const env = await getVars();
68
68
  let prefix = env.VOVK_PREFIX;
69
69
  prefix = prefix.startsWith('http://')
@@ -84,6 +84,14 @@ const ping = async () => {
84
84
  });
85
85
  };
86
86
 
87
+ /** @type {NodeJS.Timeout} */
88
+ let timer;
89
+ /** @type {() => void} */
90
+ const ping = () => {
91
+ clearTimeout(timer);
92
+ timer = setTimeout(() => void pingNoDebounce(), 1000);
93
+ };
94
+
87
95
  const server = http.createServer((req, res) => {
88
96
  if (req.method === 'POST' && req.url === '/__metadata') {
89
97
  let body = '';
@@ -161,9 +169,16 @@ async function startVovkServer(env) {
161
169
  for await (const info of fs.watch(srcRoot, { recursive: true })) {
162
170
  if (info.filename) {
163
171
  const filename = path.join(srcRoot, info.filename);
164
- const importRegex = /import\s*{[^}]*\b(get|post|put|del|head|options)\b[^}]*}\s*from\s*['"]vovk['"]/;
165
- const fileContent = await fs.readFile(filename, 'utf-8');
166
- if (importRegex.test(fileContent)) await ping(); // TODO: Debounce this
172
+ try {
173
+ const stats = await fs.lstat(filename);
174
+ if (stats.isFile()) {
175
+ const fileContent = await fs.readFile(filename, 'utf-8');
176
+ const importRegex = /import\s*{[^}]*\b(get|post|put|del|head|options)\b[^}]*}\s*from\s*['"]vovk['"]/;
177
+ if (importRegex.test(fileContent)) void ping();
178
+ }
179
+ } catch (error) {
180
+ console.error(' 🐺 Error reading file:', error);
181
+ }
167
182
  }
168
183
  }
169
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "REST for Next - Transforms Next.js into a powerful and extensible REST API platform",
5
5
  "bin": "./cli/index.cjs",
6
6
  "scripts": {