@voltx/server 0.4.3 → 0.4.5
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.
- package/LICENSE +21 -0
- package/dist/index.cjs +87 -3
- package/dist/index.d.cts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +85 -2
- package/package.json +38 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Promptly AI Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
filePathToUrlPath: () => filePathToUrlPath,
|
|
41
41
|
registerSSR: () => registerSSR,
|
|
42
42
|
registerStaticFiles: () => registerStaticFiles,
|
|
43
|
-
scanAndRegisterRoutes: () => scanAndRegisterRoutes
|
|
43
|
+
scanAndRegisterRoutes: () => scanAndRegisterRoutes,
|
|
44
|
+
voltxRouter: () => voltxRouter
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(index_exports);
|
|
46
47
|
|
|
@@ -309,6 +310,88 @@ function createViteDevConfig(options = {}) {
|
|
|
309
310
|
};
|
|
310
311
|
}
|
|
311
312
|
|
|
313
|
+
// src/vite-plugin.ts
|
|
314
|
+
function voltxRouter(options = {}) {
|
|
315
|
+
const pagesDir = options.pagesDir ?? "src/pages";
|
|
316
|
+
const PUBLIC_ID = "voltx/router";
|
|
317
|
+
const LEGACY_ID = "virtual:voltx-routes";
|
|
318
|
+
const RESOLVED_ID = "\0voltx/router";
|
|
319
|
+
return {
|
|
320
|
+
name: "voltx-router",
|
|
321
|
+
enforce: "pre",
|
|
322
|
+
config() {
|
|
323
|
+
return {
|
|
324
|
+
ssr: {
|
|
325
|
+
noExternal: ["react-router"]
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
resolveId(id) {
|
|
330
|
+
if (id === PUBLIC_ID || id === LEGACY_ID) {
|
|
331
|
+
return RESOLVED_ID;
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
load(id) {
|
|
335
|
+
if (id === RESOLVED_ID) {
|
|
336
|
+
return `
|
|
337
|
+
import { createElement } from "react";
|
|
338
|
+
import { Routes, Route } from "react-router";
|
|
339
|
+
|
|
340
|
+
const pages = import.meta.glob("/${pagesDir}/**/*.tsx", { eager: true });
|
|
341
|
+
|
|
342
|
+
function buildRoutes() {
|
|
343
|
+
const routes = [];
|
|
344
|
+
for (const [filePath, mod] of Object.entries(pages)) {
|
|
345
|
+
const Component = mod.default;
|
|
346
|
+
if (!Component) continue;
|
|
347
|
+
|
|
348
|
+
let routePath = filePath
|
|
349
|
+
.replace("/${pagesDir}", "")
|
|
350
|
+
.replace(/\\.tsx$/, "")
|
|
351
|
+
.replace(/\\/index$/, "/")
|
|
352
|
+
.replace(/\\[([^\\]]+)\\]/g, ":$1");
|
|
353
|
+
|
|
354
|
+
if (!routePath.startsWith("/")) routePath = "/" + routePath;
|
|
355
|
+
if (routePath !== "/" && routePath.endsWith("/")) {
|
|
356
|
+
routePath = routePath.slice(0, -1);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
routes.push({ path: routePath, Component });
|
|
360
|
+
}
|
|
361
|
+
return routes;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const routes = buildRoutes();
|
|
365
|
+
|
|
366
|
+
export function VoltxRoutes() {
|
|
367
|
+
return createElement(
|
|
368
|
+
Routes,
|
|
369
|
+
null,
|
|
370
|
+
routes.map(({ path, Component }) =>
|
|
371
|
+
createElement(Route, { key: path, path, element: createElement(Component) })
|
|
372
|
+
)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export { routes };
|
|
377
|
+
|
|
378
|
+
// Navigation primitives \u2014 single import source
|
|
379
|
+
export { Link, NavLink, useNavigate, useParams, useLocation, useSearchParams } from "react-router";
|
|
380
|
+
`;
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
handleHotUpdate({ file, server }) {
|
|
384
|
+
if (file.includes(pagesDir.replace(/\//g, "/"))) {
|
|
385
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
386
|
+
if (mod) {
|
|
387
|
+
server.moduleGraph.invalidateModule(mod);
|
|
388
|
+
server.ws.send({ type: "full-reload" });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
312
395
|
// src/ssr.ts
|
|
313
396
|
var import_node_path3 = require("path");
|
|
314
397
|
var import_node_fs = require("fs");
|
|
@@ -449,7 +532,7 @@ ${cssLinks}
|
|
|
449
532
|
}
|
|
450
533
|
|
|
451
534
|
// src/index.ts
|
|
452
|
-
var VERSION = "0.4.
|
|
535
|
+
var VERSION = "0.4.5";
|
|
453
536
|
// Annotate the CommonJS export names for ESM import in node:
|
|
454
537
|
0 && (module.exports = {
|
|
455
538
|
Hono,
|
|
@@ -462,5 +545,6 @@ var VERSION = "0.4.3";
|
|
|
462
545
|
filePathToUrlPath,
|
|
463
546
|
registerSSR,
|
|
464
547
|
registerStaticFiles,
|
|
465
|
-
scanAndRegisterRoutes
|
|
548
|
+
scanAndRegisterRoutes,
|
|
549
|
+
voltxRouter
|
|
466
550
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
2
|
import { Context, Hono } from 'hono';
|
|
3
3
|
export { Context, Hono } from 'hono';
|
|
4
|
+
import { Plugin } from 'vite';
|
|
4
5
|
|
|
5
6
|
interface ServerConfig {
|
|
6
7
|
/** Port to listen on (default: 3000) */
|
|
@@ -176,6 +177,27 @@ declare function createViteDevConfig(options?: ViteDevOptions): {
|
|
|
176
177
|
entry: string;
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
interface VoltxRouterOptions {
|
|
181
|
+
/** Directory to scan for page files (default: "src/pages") */
|
|
182
|
+
pagesDir?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* VoltX file-based router plugin for Vite.
|
|
186
|
+
*
|
|
187
|
+
* Scans `src/pages/` and generates a virtual module that maps
|
|
188
|
+
* file paths to routes — just like Next.js.
|
|
189
|
+
*
|
|
190
|
+
* Usage:
|
|
191
|
+
* import { Link, VoltxRoutes, useNavigate } from "voltx/router";
|
|
192
|
+
*
|
|
193
|
+
* Convention:
|
|
194
|
+
* src/pages/index.tsx → /
|
|
195
|
+
* src/pages/about.tsx → /about
|
|
196
|
+
* src/pages/blog/index.tsx → /blog
|
|
197
|
+
* src/pages/blog/[slug].tsx → /blog/:slug
|
|
198
|
+
*/
|
|
199
|
+
declare function voltxRouter(options?: VoltxRouterOptions): Plugin;
|
|
200
|
+
|
|
179
201
|
interface SSROptions {
|
|
180
202
|
/** Path to entry-server module (default: src/entry-server.tsx) */
|
|
181
203
|
entryServer?: string;
|
|
@@ -223,6 +245,6 @@ interface ViteDevServer {
|
|
|
223
245
|
*/
|
|
224
246
|
declare function registerSSR(app: Hono, vite: ViteDevServer | null, options?: SSROptions): void;
|
|
225
247
|
|
|
226
|
-
declare const VERSION = "0.4.
|
|
248
|
+
declare const VERSION = "0.4.5";
|
|
227
249
|
|
|
228
|
-
export { type CorsConfig, type HttpMethod, type MiddlewareHandler, type RouteEntry, type RouteHandler, type RouteModule, type SSROptions, type ServerConfig, type ServerInfo, VERSION, type ViteDevOptions, type VoltxServer, createCorsMiddleware, createErrorHandler, createLoggerMiddleware, createServer, createViteDevConfig, filePathToUrlPath, registerSSR, registerStaticFiles, scanAndRegisterRoutes };
|
|
250
|
+
export { type CorsConfig, type HttpMethod, type MiddlewareHandler, type RouteEntry, type RouteHandler, type RouteModule, type SSROptions, type ServerConfig, type ServerInfo, VERSION, type ViteDevOptions, type VoltxRouterOptions, type VoltxServer, createCorsMiddleware, createErrorHandler, createLoggerMiddleware, createServer, createViteDevConfig, filePathToUrlPath, registerSSR, registerStaticFiles, scanAndRegisterRoutes, voltxRouter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
2
|
import { Context, Hono } from 'hono';
|
|
3
3
|
export { Context, Hono } from 'hono';
|
|
4
|
+
import { Plugin } from 'vite';
|
|
4
5
|
|
|
5
6
|
interface ServerConfig {
|
|
6
7
|
/** Port to listen on (default: 3000) */
|
|
@@ -176,6 +177,27 @@ declare function createViteDevConfig(options?: ViteDevOptions): {
|
|
|
176
177
|
entry: string;
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
interface VoltxRouterOptions {
|
|
181
|
+
/** Directory to scan for page files (default: "src/pages") */
|
|
182
|
+
pagesDir?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* VoltX file-based router plugin for Vite.
|
|
186
|
+
*
|
|
187
|
+
* Scans `src/pages/` and generates a virtual module that maps
|
|
188
|
+
* file paths to routes — just like Next.js.
|
|
189
|
+
*
|
|
190
|
+
* Usage:
|
|
191
|
+
* import { Link, VoltxRoutes, useNavigate } from "voltx/router";
|
|
192
|
+
*
|
|
193
|
+
* Convention:
|
|
194
|
+
* src/pages/index.tsx → /
|
|
195
|
+
* src/pages/about.tsx → /about
|
|
196
|
+
* src/pages/blog/index.tsx → /blog
|
|
197
|
+
* src/pages/blog/[slug].tsx → /blog/:slug
|
|
198
|
+
*/
|
|
199
|
+
declare function voltxRouter(options?: VoltxRouterOptions): Plugin;
|
|
200
|
+
|
|
179
201
|
interface SSROptions {
|
|
180
202
|
/** Path to entry-server module (default: src/entry-server.tsx) */
|
|
181
203
|
entryServer?: string;
|
|
@@ -223,6 +245,6 @@ interface ViteDevServer {
|
|
|
223
245
|
*/
|
|
224
246
|
declare function registerSSR(app: Hono, vite: ViteDevServer | null, options?: SSROptions): void;
|
|
225
247
|
|
|
226
|
-
declare const VERSION = "0.4.
|
|
248
|
+
declare const VERSION = "0.4.5";
|
|
227
249
|
|
|
228
|
-
export { type CorsConfig, type HttpMethod, type MiddlewareHandler, type RouteEntry, type RouteHandler, type RouteModule, type SSROptions, type ServerConfig, type ServerInfo, VERSION, type ViteDevOptions, type VoltxServer, createCorsMiddleware, createErrorHandler, createLoggerMiddleware, createServer, createViteDevConfig, filePathToUrlPath, registerSSR, registerStaticFiles, scanAndRegisterRoutes };
|
|
250
|
+
export { type CorsConfig, type HttpMethod, type MiddlewareHandler, type RouteEntry, type RouteHandler, type RouteModule, type SSROptions, type ServerConfig, type ServerInfo, VERSION, type ViteDevOptions, type VoltxRouterOptions, type VoltxServer, createCorsMiddleware, createErrorHandler, createLoggerMiddleware, createServer, createViteDevConfig, filePathToUrlPath, registerSSR, registerStaticFiles, scanAndRegisterRoutes, voltxRouter };
|
package/dist/index.js
CHANGED
|
@@ -263,6 +263,88 @@ function createViteDevConfig(options = {}) {
|
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
// src/vite-plugin.ts
|
|
267
|
+
function voltxRouter(options = {}) {
|
|
268
|
+
const pagesDir = options.pagesDir ?? "src/pages";
|
|
269
|
+
const PUBLIC_ID = "voltx/router";
|
|
270
|
+
const LEGACY_ID = "virtual:voltx-routes";
|
|
271
|
+
const RESOLVED_ID = "\0voltx/router";
|
|
272
|
+
return {
|
|
273
|
+
name: "voltx-router",
|
|
274
|
+
enforce: "pre",
|
|
275
|
+
config() {
|
|
276
|
+
return {
|
|
277
|
+
ssr: {
|
|
278
|
+
noExternal: ["react-router"]
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
resolveId(id) {
|
|
283
|
+
if (id === PUBLIC_ID || id === LEGACY_ID) {
|
|
284
|
+
return RESOLVED_ID;
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
load(id) {
|
|
288
|
+
if (id === RESOLVED_ID) {
|
|
289
|
+
return `
|
|
290
|
+
import { createElement } from "react";
|
|
291
|
+
import { Routes, Route } from "react-router";
|
|
292
|
+
|
|
293
|
+
const pages = import.meta.glob("/${pagesDir}/**/*.tsx", { eager: true });
|
|
294
|
+
|
|
295
|
+
function buildRoutes() {
|
|
296
|
+
const routes = [];
|
|
297
|
+
for (const [filePath, mod] of Object.entries(pages)) {
|
|
298
|
+
const Component = mod.default;
|
|
299
|
+
if (!Component) continue;
|
|
300
|
+
|
|
301
|
+
let routePath = filePath
|
|
302
|
+
.replace("/${pagesDir}", "")
|
|
303
|
+
.replace(/\\.tsx$/, "")
|
|
304
|
+
.replace(/\\/index$/, "/")
|
|
305
|
+
.replace(/\\[([^\\]]+)\\]/g, ":$1");
|
|
306
|
+
|
|
307
|
+
if (!routePath.startsWith("/")) routePath = "/" + routePath;
|
|
308
|
+
if (routePath !== "/" && routePath.endsWith("/")) {
|
|
309
|
+
routePath = routePath.slice(0, -1);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
routes.push({ path: routePath, Component });
|
|
313
|
+
}
|
|
314
|
+
return routes;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const routes = buildRoutes();
|
|
318
|
+
|
|
319
|
+
export function VoltxRoutes() {
|
|
320
|
+
return createElement(
|
|
321
|
+
Routes,
|
|
322
|
+
null,
|
|
323
|
+
routes.map(({ path, Component }) =>
|
|
324
|
+
createElement(Route, { key: path, path, element: createElement(Component) })
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export { routes };
|
|
330
|
+
|
|
331
|
+
// Navigation primitives \u2014 single import source
|
|
332
|
+
export { Link, NavLink, useNavigate, useParams, useLocation, useSearchParams } from "react-router";
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
handleHotUpdate({ file, server }) {
|
|
337
|
+
if (file.includes(pagesDir.replace(/\//g, "/"))) {
|
|
338
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
339
|
+
if (mod) {
|
|
340
|
+
server.moduleGraph.invalidateModule(mod);
|
|
341
|
+
server.ws.send({ type: "full-reload" });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
266
348
|
// src/ssr.ts
|
|
267
349
|
import { resolve as resolve2 } from "path";
|
|
268
350
|
import { readFileSync, existsSync } from "fs";
|
|
@@ -403,7 +485,7 @@ ${cssLinks}
|
|
|
403
485
|
}
|
|
404
486
|
|
|
405
487
|
// src/index.ts
|
|
406
|
-
var VERSION = "0.4.
|
|
488
|
+
var VERSION = "0.4.5";
|
|
407
489
|
export {
|
|
408
490
|
Hono2 as Hono,
|
|
409
491
|
VERSION,
|
|
@@ -415,5 +497,6 @@ export {
|
|
|
415
497
|
filePathToUrlPath,
|
|
416
498
|
registerSSR,
|
|
417
499
|
registerStaticFiles,
|
|
418
|
-
scanAndRegisterRoutes
|
|
500
|
+
scanAndRegisterRoutes,
|
|
501
|
+
voltxRouter
|
|
419
502
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltx/server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "VoltX Server — Hono-based HTTP server with file-based routing, SSE streaming, and static file serving",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -13,31 +13,47 @@
|
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
20
|
-
"clean": "rm -rf dist"
|
|
21
|
-
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
22
19
|
"dependencies": {
|
|
23
|
-
"hono": "^
|
|
24
|
-
"
|
|
20
|
+
"@hono/node-server": "^1.14.0",
|
|
21
|
+
"hono": "^4.7.0"
|
|
25
22
|
},
|
|
26
23
|
"peerDependencies": {
|
|
27
24
|
"react": ">=18.0.0",
|
|
28
|
-
"react-dom": ">=18.0.0"
|
|
25
|
+
"react-dom": ">=18.0.0",
|
|
26
|
+
"vite": ">=5.0.0"
|
|
29
27
|
},
|
|
30
28
|
"peerDependenciesMeta": {
|
|
31
|
-
"react": {
|
|
32
|
-
|
|
29
|
+
"react": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"react-dom": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"vite": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
40
|
+
"@types/react": "^19.0.0",
|
|
41
|
+
"@types/react-dom": "^19.0.0",
|
|
35
42
|
"tsup": "^8.0.0",
|
|
36
43
|
"typescript": "^5.7.0",
|
|
37
|
-
"
|
|
38
|
-
"@types/react-dom": "^19.0.0"
|
|
44
|
+
"vite": "^8.0.1"
|
|
39
45
|
},
|
|
40
|
-
"keywords": [
|
|
46
|
+
"keywords": [
|
|
47
|
+
"voltx",
|
|
48
|
+
"server",
|
|
49
|
+
"hono",
|
|
50
|
+
"http",
|
|
51
|
+
"routing",
|
|
52
|
+
"file-based",
|
|
53
|
+
"sse",
|
|
54
|
+
"streaming",
|
|
55
|
+
"middleware"
|
|
56
|
+
],
|
|
41
57
|
"license": "MIT",
|
|
42
58
|
"repository": {
|
|
43
59
|
"type": "git",
|
|
@@ -45,5 +61,10 @@
|
|
|
45
61
|
"directory": "packages/server"
|
|
46
62
|
},
|
|
47
63
|
"homepage": "https://voltx.co.in",
|
|
48
|
-
"author": "Promptly AI Team"
|
|
49
|
-
|
|
64
|
+
"author": "Promptly AI Team",
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --external vite",
|
|
67
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
68
|
+
"clean": "rm -rf dist"
|
|
69
|
+
}
|
|
70
|
+
}
|