baraqex 1.0.8 → 1.0.10
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/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/renderComponent.d.ts +9 -0
- package/dist/renderComponent.d.ts.map +1 -0
- package/dist/renderComponent.js +39 -0
- package/dist/renderComponent.js.map +1 -0
- package/dist/server/api-router.d.ts +16 -0
- package/dist/server/api-router.d.ts.map +1 -0
- package/dist/server/api-router.js +93 -0
- package/dist/server/api-router.js.map +1 -0
- package/dist/server/auth.d.ts +33 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +74 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/database.d.ts +25 -0
- package/dist/server/database.d.ts.map +1 -0
- package/dist/server/database.js +109 -0
- package/dist/server/database.js.map +1 -0
- package/dist/server/index.d.ts +117 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +465 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/middleware.d.ts +12 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/middleware.js +46 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +81 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/templates.d.ts +31 -0
- package/dist/server/templates.d.ts.map +1 -0
- package/dist/server/templates.js +208 -0
- package/dist/server/templates.js.map +1 -0
- package/dist/server/types.d.ts +39 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +4 -0
- package/dist/server/types.js.map +1 -0
- package/dist/server/utils.d.ts +71 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/server/utils.js +156 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/server/wasm.d.ts +10 -0
- package/dist/server/wasm.d.ts.map +1 -0
- package/dist/server/wasm.js +117 -0
- package/dist/server/wasm.js.map +1 -0
- package/dist/server-renderer.d.ts +6 -0
- package/dist/server-renderer.d.ts.map +1 -0
- package/dist/server-renderer.js +39 -0
- package/dist/server-renderer.js.map +1 -0
- package/dist/wasm.d.ts +17 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +48 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +15 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import * as frontendHamroun from 'frontend-hamroun';
|
|
2
1
|
export * from 'frontend-hamroun';
|
|
3
|
-
export
|
|
2
|
+
export { generateDocument, generateErrorPage, generateLoadingPage } from './server/templates.js';
|
|
3
|
+
export { safeJsonParse, generateToken, hashString, getPagination, sendSuccess, sendError, validateFields, validateFileUpload, getEnvironmentInfo, isDirectoryEmpty, ensureDirectory, writeJsonFile, readJsonFile } from './server/utils.js';
|
|
4
|
+
export type { ServerConfig, User, DbConfig, MiddlewareFunction } from './server/types.js';
|
|
5
|
+
export { renderToString as baraqexRenderToString, hydrate as baraqexHydrate } from './server-renderer.js';
|
|
6
|
+
export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './server/middleware.js';
|
|
7
|
+
export { initNodeWasm, loadGoWasmFromFile } from './server/wasm.js';
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AAKjC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EACb,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG1F,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG1G,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGjG,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
import * as frontendHamroun from 'frontend-hamroun';
|
|
3
|
-
// Re-export everything as named exports
|
|
1
|
+
// Re-export everything from frontend-hamroun
|
|
4
2
|
export * from 'frontend-hamroun';
|
|
5
3
|
// Also export as default for compatibility
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
// Export server functionality that actually exists and compiles
|
|
5
|
+
export { generateDocument, generateErrorPage, generateLoadingPage } from './server/templates.js';
|
|
6
|
+
export { safeJsonParse, generateToken, hashString, getPagination, sendSuccess, sendError, validateFields, validateFileUpload, getEnvironmentInfo, isDirectoryEmpty, ensureDirectory, writeJsonFile, readJsonFile } from './server/utils.js';
|
|
7
|
+
// Export server-renderer functions
|
|
8
|
+
export { renderToString as baraqexRenderToString, hydrate as baraqexHydrate } from './server-renderer.js';
|
|
9
|
+
// Export middleware functions
|
|
10
|
+
export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './server/middleware.js';
|
|
11
|
+
// Export WASM utilities
|
|
12
|
+
export { initNodeWasm, loadGoWasmFromFile } from './server/wasm.js';
|
|
13
|
+
console.log('Baraqex - powered by Frontend Hamroun Framework with additional utilities');
|
|
8
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,cAAc,kBAAkB,CAAC;AAEjC,2CAA2C;AAE3C,gEAAgE;AAChE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EACb,MAAM,mBAAmB,CAAC;AAK3B,mCAAmC;AACnC,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE1G,8BAA8B;AAC9B,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEjG,wBAAwB;AACxB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderComponent.d.ts","sourceRoot":"","sources":["../src/renderComponent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAsB,eAAe,CACnC,SAAS,EAAE,GAAG,EACd,KAAK,GAAE,GAAQ,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,CAiC5D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component rendering utilities
|
|
3
|
+
*/
|
|
4
|
+
export async function renderComponent(Component, props = {}) {
|
|
5
|
+
try {
|
|
6
|
+
// Simple component rendering
|
|
7
|
+
let html = '';
|
|
8
|
+
if (typeof Component === 'function') {
|
|
9
|
+
const result = Component(props);
|
|
10
|
+
if (typeof result === 'string') {
|
|
11
|
+
html = result;
|
|
12
|
+
}
|
|
13
|
+
else if (result && typeof result.then === 'function') {
|
|
14
|
+
// Handle async components
|
|
15
|
+
const asyncResult = await result;
|
|
16
|
+
html = typeof asyncResult === 'string' ? asyncResult : String(asyncResult || '');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
html = String(result || '');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
html = String(Component || '');
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
html,
|
|
27
|
+
success: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Error rendering component:', error);
|
|
32
|
+
return {
|
|
33
|
+
html: '<div>Error rendering component</div>',
|
|
34
|
+
success: false,
|
|
35
|
+
error: error instanceof Error ? error : new Error('Unknown error')
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=renderComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderComponent.js","sourceRoot":"","sources":["../src/renderComponent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAc,EACd,QAAa,EAAE;IAEf,IAAI,CAAC;QACH,6BAA6B;QAC7B,IAAI,IAAI,GAAG,EAAE,CAAC;QAEd,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAEhC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC/B,IAAI,GAAG,MAAM,CAAC;YAChB,CAAC;iBAAM,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACvD,0BAA0B;gBAC1B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;gBACjC,IAAI,GAAG,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;YACnF,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC;QAED,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO;YACL,IAAI,EAAE,sCAAsC;YAC5C,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC;SACnE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { AuthService } from './auth.js';
|
|
3
|
+
export declare class ApiRouter {
|
|
4
|
+
router: Router;
|
|
5
|
+
private apiDir;
|
|
6
|
+
private auth;
|
|
7
|
+
constructor(apiDir: string, auth?: AuthService | null);
|
|
8
|
+
private setupRoutes;
|
|
9
|
+
private scanDirectory;
|
|
10
|
+
private isRouteFile;
|
|
11
|
+
private getRoutePath;
|
|
12
|
+
private registerRoute;
|
|
13
|
+
private isValidRouteModule;
|
|
14
|
+
private wrapHandler;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=api-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../../src/server/api-router.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAkBxC,qBAAa,SAAS;IACb,MAAM,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAqB;gBAErB,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,WAAW,GAAG,IAAW;IAQ3D,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,YAAY;YAiBN,aAAa;IAgC3B,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,WAAW;CASpB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
export class ApiRouter {
|
|
5
|
+
constructor(apiDir, auth = null) {
|
|
6
|
+
this.router = express.Router();
|
|
7
|
+
this.apiDir = path.resolve(process.cwd(), apiDir);
|
|
8
|
+
this.auth = auth;
|
|
9
|
+
this.setupRoutes();
|
|
10
|
+
}
|
|
11
|
+
setupRoutes() {
|
|
12
|
+
if (!fs.existsSync(this.apiDir)) {
|
|
13
|
+
console.log(`API directory not found: ${this.apiDir}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.scanDirectory(this.apiDir, '');
|
|
17
|
+
}
|
|
18
|
+
scanDirectory(dirPath, routePrefix) {
|
|
19
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
22
|
+
if (entry.isDirectory()) {
|
|
23
|
+
// Recursively scan subdirectories
|
|
24
|
+
this.scanDirectory(fullPath, `${routePrefix}/${entry.name}`);
|
|
25
|
+
}
|
|
26
|
+
else if (this.isRouteFile(entry.name)) {
|
|
27
|
+
// Process route file
|
|
28
|
+
const routePath = this.getRoutePath(entry.name, routePrefix);
|
|
29
|
+
this.registerRoute(fullPath, routePath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
isRouteFile(filename) {
|
|
34
|
+
return filename.endsWith('.js') ||
|
|
35
|
+
filename.endsWith('.ts') ||
|
|
36
|
+
filename.endsWith('.mjs');
|
|
37
|
+
}
|
|
38
|
+
getRoutePath(filename, routePrefix) {
|
|
39
|
+
// Remove extension and handle special names
|
|
40
|
+
const baseName = path.basename(filename, path.extname(filename));
|
|
41
|
+
if (baseName === 'index') {
|
|
42
|
+
return routePrefix || '/';
|
|
43
|
+
}
|
|
44
|
+
// Handle dynamic routes [param]
|
|
45
|
+
const paramMatch = baseName.match(/^\[(.+)\]$/);
|
|
46
|
+
if (paramMatch) {
|
|
47
|
+
return `${routePrefix}/:${paramMatch[1]}`;
|
|
48
|
+
}
|
|
49
|
+
return `${routePrefix}/${baseName}`;
|
|
50
|
+
}
|
|
51
|
+
async registerRoute(filePath, routePath) {
|
|
52
|
+
try {
|
|
53
|
+
// Dynamic import the route file
|
|
54
|
+
const routeModule = await import(filePath);
|
|
55
|
+
if (!this.isValidRouteModule(routeModule)) {
|
|
56
|
+
console.warn(`Invalid route module: ${filePath}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log(`Registering API route: ${routePath}`);
|
|
60
|
+
// Register middleware if any
|
|
61
|
+
const middleware = routeModule.middleware || [];
|
|
62
|
+
// Register HTTP methods
|
|
63
|
+
for (const method of ['get', 'post', 'put', 'delete', 'patch', 'options']) {
|
|
64
|
+
const handler = routeModule[method];
|
|
65
|
+
if (typeof handler === 'function') {
|
|
66
|
+
const routerMethod = this.router[method];
|
|
67
|
+
routerMethod(routePath, ...middleware, this.wrapHandler(handler));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(`Error registering route (${filePath}):`, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
isValidRouteModule(module) {
|
|
76
|
+
if (!module)
|
|
77
|
+
return false;
|
|
78
|
+
// Check if at least one HTTP method handler is defined
|
|
79
|
+
return ['get', 'post', 'put', 'delete', 'patch', 'options']
|
|
80
|
+
.some(method => typeof module[method] === 'function');
|
|
81
|
+
}
|
|
82
|
+
wrapHandler(handler) {
|
|
83
|
+
return async (req, res, next) => {
|
|
84
|
+
try {
|
|
85
|
+
await handler(req, res, next);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
next(error);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=api-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-router.js","sourceRoot":"","sources":["../../src/server/api-router.ts"],"names":[],"mappings":"AAAA,OAAO,OAAoD,MAAM,SAAS,CAAC;AAC3E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAmBpB,MAAM,OAAO,SAAS;IAKpB,YAAY,MAAc,EAAE,OAA2B,IAAI;QACzD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAEO,WAAW;QACjB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC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C1B,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,QAAQ,IAAI,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,kBAAkB,CAAC,MAAW;QACpC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAE1B,uDAAuD;QACvD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;aACxD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,CAAC;IAC1D,CAAC;IAEO,WAAW,CAAC,OAAqB;QACvC,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;YAC/D,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAChC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SignOptions } from 'jsonwebtoken';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
export interface AuthConfig {
|
|
4
|
+
secret: string;
|
|
5
|
+
expiresIn?: SignOptions['expiresIn'];
|
|
6
|
+
}
|
|
7
|
+
export interface User {
|
|
8
|
+
id: string | number;
|
|
9
|
+
username: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
roles?: string[];
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export declare class AuthService {
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: AuthConfig);
|
|
18
|
+
hashPassword(password: string): Promise<string>;
|
|
19
|
+
comparePasswords(password: string, hashedPassword: string): Promise<boolean>;
|
|
20
|
+
generateToken(user: Omit<User, 'password'>): string;
|
|
21
|
+
verifyToken(token: string): any;
|
|
22
|
+
initialize(): (req: Request & {
|
|
23
|
+
user?: any;
|
|
24
|
+
}, res: Response, next: NextFunction) => void;
|
|
25
|
+
requireAuth(): (req: Request & {
|
|
26
|
+
user?: any;
|
|
27
|
+
}, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
28
|
+
requireRoles(roles: string[]): (req: Request & {
|
|
29
|
+
user?: any;
|
|
30
|
+
}, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
31
|
+
private extractToken;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,UAAU;IAOxB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlF,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,MAAM;IAcnD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAS/B,UAAU,KACA,KAAK,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;IAa1E,WAAW,KACD,KAAK,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;IAS1E,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAClB,KAAK,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;IAgB1E,OAAO,CAAC,YAAY;CAMrB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import bcrypt from 'bcryptjs';
|
|
3
|
+
export class AuthService {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = {
|
|
6
|
+
expiresIn: '24h',
|
|
7
|
+
...config
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
async hashPassword(password) {
|
|
11
|
+
return bcrypt.hash(password, 10);
|
|
12
|
+
}
|
|
13
|
+
async comparePasswords(password, hashedPassword) {
|
|
14
|
+
return bcrypt.compare(password, hashedPassword);
|
|
15
|
+
}
|
|
16
|
+
generateToken(user) {
|
|
17
|
+
const options = {};
|
|
18
|
+
if (this.config.expiresIn) {
|
|
19
|
+
options.expiresIn = this.config.expiresIn;
|
|
20
|
+
}
|
|
21
|
+
return jwt.sign({ id: user.id, username: user.username, roles: user.roles || [] }, this.config.secret, options);
|
|
22
|
+
}
|
|
23
|
+
verifyToken(token) {
|
|
24
|
+
try {
|
|
25
|
+
return jwt.verify(token, this.config.secret);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Express middleware for authentication
|
|
32
|
+
initialize() {
|
|
33
|
+
return (req, res, next) => {
|
|
34
|
+
const token = this.extractToken(req);
|
|
35
|
+
if (token) {
|
|
36
|
+
const decoded = this.verifyToken(token);
|
|
37
|
+
if (decoded) {
|
|
38
|
+
req.user = decoded;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
next();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Express middleware for requiring authentication
|
|
45
|
+
requireAuth() {
|
|
46
|
+
return (req, res, next) => {
|
|
47
|
+
if (!req.user) {
|
|
48
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
49
|
+
}
|
|
50
|
+
return next();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Express middleware for requiring specific roles
|
|
54
|
+
requireRoles(roles) {
|
|
55
|
+
return (req, res, next) => {
|
|
56
|
+
if (!req.user) {
|
|
57
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
58
|
+
}
|
|
59
|
+
const userRoles = req.user.roles || [];
|
|
60
|
+
const hasRequiredRole = roles.some(role => userRoles.includes(role));
|
|
61
|
+
if (!hasRequiredRole) {
|
|
62
|
+
return res.status(403).json({ message: 'Forbidden' });
|
|
63
|
+
}
|
|
64
|
+
return next();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
extractToken(req) {
|
|
68
|
+
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) {
|
|
69
|
+
return req.headers.authorization.substring(7);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/server/auth.ts"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C;YAED,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,GAAY;QAC/B,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACjF,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import mysql from 'mysql2/promise';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
export interface DbConfig {
|
|
5
|
+
url: string;
|
|
6
|
+
type: 'mongodb' | 'mysql' | 'postgres';
|
|
7
|
+
}
|
|
8
|
+
export declare class Database {
|
|
9
|
+
private config;
|
|
10
|
+
private mongoClient;
|
|
11
|
+
private mongoDb;
|
|
12
|
+
private mysqlPool;
|
|
13
|
+
private pgPool;
|
|
14
|
+
constructor(config: DbConfig);
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
private connectMongo;
|
|
17
|
+
private connectMysql;
|
|
18
|
+
private connectPostgres;
|
|
19
|
+
disconnect(): Promise<void>;
|
|
20
|
+
getMongoDb(): Db | null;
|
|
21
|
+
getMysqlPool(): mysql.Pool | null;
|
|
22
|
+
getPgPool(): pg.Pool | null;
|
|
23
|
+
query(sql: string, values?: any[]): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/server/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;CACxC;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,MAAM,CAAwB;gBAE1B,MAAM,EAAE,QAAQ;IAItB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAgBhB,YAAY;YAYZ,YAAY;YAYZ,eAAe;IAavB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBjC,UAAU,IAAI,EAAE,GAAG,IAAI;IAIvB,YAAY,IAAI,KAAK,CAAC,IAAI,GAAG,IAAI;IAIjC,SAAS,IAAI,EAAE,CAAC,IAAI,GAAG,IAAI;IAKrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAgBvD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
import mysql from 'mysql2/promise';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
export class Database {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.mongoClient = null;
|
|
7
|
+
this.mongoDb = null;
|
|
8
|
+
this.mysqlPool = null;
|
|
9
|
+
this.pgPool = null;
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async connect() {
|
|
13
|
+
switch (this.config.type) {
|
|
14
|
+
case 'mongodb':
|
|
15
|
+
await this.connectMongo();
|
|
16
|
+
break;
|
|
17
|
+
case 'mysql':
|
|
18
|
+
await this.connectMysql();
|
|
19
|
+
break;
|
|
20
|
+
case 'postgres':
|
|
21
|
+
await this.connectPostgres();
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`Unsupported database type: ${this.config.type}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async connectMongo() {
|
|
28
|
+
try {
|
|
29
|
+
this.mongoClient = new MongoClient(this.config.url);
|
|
30
|
+
await this.mongoClient.connect();
|
|
31
|
+
this.mongoDb = this.mongoClient.db();
|
|
32
|
+
console.log('Connected to MongoDB');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error('MongoDB connection error:', error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async connectMysql() {
|
|
40
|
+
try {
|
|
41
|
+
this.mysqlPool = mysql.createPool(this.config.url);
|
|
42
|
+
// Test connection
|
|
43
|
+
await this.mysqlPool.getConnection();
|
|
44
|
+
console.log('Connected to MySQL');
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error('MySQL connection error:', error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async connectPostgres() {
|
|
52
|
+
try {
|
|
53
|
+
this.pgPool = new pg.Pool({ connectionString: this.config.url });
|
|
54
|
+
// Test connection
|
|
55
|
+
const client = await this.pgPool.connect();
|
|
56
|
+
client.release();
|
|
57
|
+
console.log('Connected to PostgreSQL');
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('PostgreSQL connection error:', error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async disconnect() {
|
|
65
|
+
if (this.mongoClient) {
|
|
66
|
+
await this.mongoClient.close();
|
|
67
|
+
this.mongoClient = null;
|
|
68
|
+
this.mongoDb = null;
|
|
69
|
+
}
|
|
70
|
+
if (this.mysqlPool) {
|
|
71
|
+
await this.mysqlPool.end();
|
|
72
|
+
this.mysqlPool = null;
|
|
73
|
+
}
|
|
74
|
+
if (this.pgPool) {
|
|
75
|
+
await this.pgPool.end();
|
|
76
|
+
this.pgPool = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Database-specific methods
|
|
80
|
+
getMongoDb() {
|
|
81
|
+
return this.mongoDb;
|
|
82
|
+
}
|
|
83
|
+
getMysqlPool() {
|
|
84
|
+
return this.mysqlPool;
|
|
85
|
+
}
|
|
86
|
+
getPgPool() {
|
|
87
|
+
return this.pgPool;
|
|
88
|
+
}
|
|
89
|
+
// Generic query method
|
|
90
|
+
async query(sql, values) {
|
|
91
|
+
switch (this.config.type) {
|
|
92
|
+
case 'mongodb':
|
|
93
|
+
throw new Error('For MongoDB, use getMongoDb() instead of query()');
|
|
94
|
+
case 'mysql':
|
|
95
|
+
if (!this.mysqlPool)
|
|
96
|
+
throw new Error('MySQL not connected');
|
|
97
|
+
const [rows] = await this.mysqlPool.execute(sql, values || []);
|
|
98
|
+
return rows;
|
|
99
|
+
case 'postgres':
|
|
100
|
+
if (!this.pgPool)
|
|
101
|
+
throw new Error('PostgreSQL not connected');
|
|
102
|
+
const result = await this.pgPool.query(sql, values || []);
|
|
103
|
+
return result.rows;
|
|
104
|
+
default:
|
|
105
|
+
throw new Error(`Unsupported database type: ${this.config.type}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/server/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAM,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,CAAC;AAOpB,MAAM,OAAO,QAAQ;IAOnB,YAAY,MAAgB;QALpB,gBAAW,GAAuB,IAAI,CAAC;QACvC,YAAO,GAAc,IAAI,CAAC;QAC1B,cAAS,GAAsB,IAAI,CAAC;QACpC,WAAM,GAAmB,IAAI,CAAC;QAGpC,IAAI,CAAC,MAAM,GAAG,MAAM,C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O,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,uBAAuB;IACvB,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,MAAc;QACrC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,SAAS;gBACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,KAAK,OAAO;gBACV,IAAI,CAAC,IAAI,CAAC,SAAS;oBAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;gBAC5D,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;gBAC/D,OAAO,IAAI,CAAC;YACd,KAAK,UAAU;gBACb,IAAI,CAAC,IAAI,CAAC,MAAM;oBAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAC9D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;gBAC1D,OAAO,MAAM,CAAC,IAAI,CAAC;YACrB;gBACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Express, Request, Response, NextFunction } from 'express';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import { SignOptions } from 'jsonwebtoken';
|
|
4
|
+
import { renderToString } from 'frontend-hamroun';
|
|
5
|
+
import { Database } from './database.js';
|
|
6
|
+
import { AuthService } from './auth.js';
|
|
7
|
+
import { ApiRouter } from './api-router.js';
|
|
8
|
+
import { rateLimit } from './middleware.js';
|
|
9
|
+
import * as utils from './utils.js';
|
|
10
|
+
import * as templates from './templates.js';
|
|
11
|
+
import { loadGoWasmFromFile } from './wasm.js';
|
|
12
|
+
export interface ServerConfig {
|
|
13
|
+
port?: number;
|
|
14
|
+
apiDir?: string;
|
|
15
|
+
pagesDir?: string;
|
|
16
|
+
staticDir?: string;
|
|
17
|
+
enableCors?: boolean;
|
|
18
|
+
corsOptions?: cors.CorsOptions;
|
|
19
|
+
db?: {
|
|
20
|
+
url: string;
|
|
21
|
+
type: 'mongodb' | 'mysql' | 'postgres';
|
|
22
|
+
};
|
|
23
|
+
auth?: {
|
|
24
|
+
secret: string;
|
|
25
|
+
expiresIn?: SignOptions['expiresIn'];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare class Server {
|
|
29
|
+
private app;
|
|
30
|
+
private server;
|
|
31
|
+
private config;
|
|
32
|
+
private db;
|
|
33
|
+
private auth;
|
|
34
|
+
constructor(config?: ServerConfig);
|
|
35
|
+
private setupApiRoutes;
|
|
36
|
+
private generateApiDocs;
|
|
37
|
+
private scanApiDirectory;
|
|
38
|
+
private getRoutePath;
|
|
39
|
+
private detectApiMethods;
|
|
40
|
+
private setupPageRoutes;
|
|
41
|
+
private renderPage;
|
|
42
|
+
getExpressApp(): Express;
|
|
43
|
+
getDatabase(): Database | null;
|
|
44
|
+
getAuth(): AuthService | null;
|
|
45
|
+
start(): Promise<void>;
|
|
46
|
+
stop(): Promise<void>;
|
|
47
|
+
restart(): Promise<void>;
|
|
48
|
+
enableSSR(options?: {
|
|
49
|
+
hydratable?: boolean;
|
|
50
|
+
}): void;
|
|
51
|
+
registerPlugin(plugin: (server: Server) => void): void;
|
|
52
|
+
addShutdownHandler(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates and configures a new server instance
|
|
56
|
+
*/
|
|
57
|
+
export declare function createServer(config?: ServerConfig): Server;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new server with sensible defaults for development
|
|
60
|
+
*/
|
|
61
|
+
export declare function createDevServer(options?: {
|
|
62
|
+
port?: number;
|
|
63
|
+
enableCors?: boolean;
|
|
64
|
+
}): Server;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a production-ready server with optimized settings
|
|
67
|
+
*/
|
|
68
|
+
export declare function createProductionServer(config: ServerConfig): Server;
|
|
69
|
+
export declare function getRequestIp(req: Request): string;
|
|
70
|
+
export declare function parseCookies(req: Request): Record<string, string>;
|
|
71
|
+
export declare const renderComponent: (Component: any, props?: any) => Promise<{
|
|
72
|
+
html: string;
|
|
73
|
+
success: boolean;
|
|
74
|
+
error?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
html: string;
|
|
77
|
+
success: boolean;
|
|
78
|
+
error: unknown;
|
|
79
|
+
}>;
|
|
80
|
+
export { initNodeWasm, loadGoWasmFromFile } from './wasm.js';
|
|
81
|
+
export * from './utils.js';
|
|
82
|
+
export * from './templates.js';
|
|
83
|
+
export { Database } from './database.js';
|
|
84
|
+
export { AuthService } from './auth.js';
|
|
85
|
+
export { ApiRouter } from './api-router.js';
|
|
86
|
+
export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware.js';
|
|
87
|
+
export { renderToString };
|
|
88
|
+
declare const _default: {
|
|
89
|
+
Server: typeof Server;
|
|
90
|
+
createServer: typeof createServer;
|
|
91
|
+
createDevServer: typeof createDevServer;
|
|
92
|
+
createProductionServer: typeof createProductionServer;
|
|
93
|
+
rateLimit: typeof rateLimit;
|
|
94
|
+
requestLogger: import("./middleware.js").MiddlewareFunction;
|
|
95
|
+
errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
96
|
+
notFoundHandler: (req: Request, res: Response) => void;
|
|
97
|
+
loadGoWasmFromFile: typeof loadGoWasmFromFile;
|
|
98
|
+
templates: typeof templates;
|
|
99
|
+
utils: typeof utils;
|
|
100
|
+
renderComponent: (Component: any, props?: any) => Promise<{
|
|
101
|
+
html: string;
|
|
102
|
+
success: boolean;
|
|
103
|
+
error?: undefined;
|
|
104
|
+
} | {
|
|
105
|
+
html: string;
|
|
106
|
+
success: boolean;
|
|
107
|
+
error: unknown;
|
|
108
|
+
}>;
|
|
109
|
+
renderToString: typeof renderToString;
|
|
110
|
+
getRequestIp: typeof getRequestIp;
|
|
111
|
+
parseCookies: typeof parseCookies;
|
|
112
|
+
Database: typeof Database;
|
|
113
|
+
AuthService: typeof AuthService;
|
|
114
|
+
ApiRouter: typeof ApiRouter;
|
|
115
|
+
};
|
|
116
|
+
export default _default;
|
|
117
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK5E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAgD,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG1F,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAgB,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAkB7D,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC;IAC/B,EAAE,CAAC,EAAE;QACH,GAAG,EAAE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