@forgedevstack/harbor 1.0.0 → 1.5.0
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/CHANGELOG.md +82 -101
- package/README.md +210 -794
- package/dist/auth/apiKey.d.ts +6 -0
- package/dist/auth/apiKey.d.ts.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/jwt.d.ts +21 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/password.d.ts +6 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/rbac.d.ts +6 -0
- package/dist/auth/rbac.d.ts.map +1 -0
- package/dist/auth/signing.d.ts +5 -0
- package/dist/auth/signing.d.ts.map +1 -0
- package/dist/auth/types/apiKey.types.d.ts +9 -0
- package/dist/auth/types/apiKey.types.d.ts.map +1 -0
- package/dist/auth/types/index.d.ts +5 -0
- package/dist/auth/types/index.d.ts.map +1 -0
- package/dist/auth/types/jwt.types.d.ts +17 -0
- package/dist/auth/types/jwt.types.d.ts.map +1 -0
- package/dist/auth/types/rbac.types.d.ts +8 -0
- package/dist/auth/types/rbac.types.d.ts.map +1 -0
- package/dist/auth/types/signing.types.d.ts +8 -0
- package/dist/auth/types/signing.types.d.ts.map +1 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/manager.d.ts +24 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/stores.d.ts +28 -0
- package/dist/cache/stores.d.ts.map +1 -0
- package/dist/cache/types.d.ts +23 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cli/index.js +21 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/router.d.ts +40 -2
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/database/connection.d.ts +1 -2
- package/dist/database/connection.d.ts.map +1 -1
- package/dist/database/index.js +2 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/model.d.ts +1 -4
- package/dist/database/model.d.ts.map +1 -1
- package/dist/docker/index.js +1 -1
- package/dist/http.const-BKHG1Lsj.mjs +62 -0
- package/dist/http.const-BKHG1Lsj.mjs.map +1 -0
- package/dist/http.const-Ckcy7OFp.js +2 -0
- package/dist/http.const-Ckcy7OFp.js.map +1 -0
- package/dist/index-Ca4WpLvw.js +2 -0
- package/dist/index-Ca4WpLvw.js.map +1 -0
- package/dist/index-DIVHd6rO.mjs +1054 -0
- package/dist/index-DIVHd6rO.mjs.map +1 -0
- package/dist/index.cjs.js +16 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +676 -1691
- package/dist/index.es.js.map +1 -1
- package/dist/logger-CZn7QxCl.mjs +102 -0
- package/dist/{logger-D7aJSi62.mjs.map → logger-CZn7QxCl.mjs.map} +1 -1
- package/dist/logger-D-lfaRWQ.js +3 -0
- package/dist/{logger-DEnWXtpk.js.map → logger-D-lfaRWQ.js.map} +1 -1
- package/dist/manager-CjcKb4P9.mjs +149 -0
- package/dist/{manager-B6vqJgEn.mjs.map → manager-CjcKb4P9.mjs.map} +1 -1
- package/dist/manager-DrF1vbJg.js +4 -0
- package/dist/{manager-B1UKMjXW.js.map → manager-DrF1vbJg.js.map} +1 -1
- package/dist/middleware/health.d.ts +65 -0
- package/dist/middleware/health.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/metrics.d.ts +68 -0
- package/dist/middleware/metrics.d.ts.map +1 -0
- package/dist/middleware/rateLimit.d.ts +52 -0
- package/dist/middleware/rateLimit.d.ts.map +1 -0
- package/dist/middleware/upload.d.ts +59 -0
- package/dist/middleware/upload.d.ts.map +1 -0
- package/dist/password-BXBkKbv3.js +2 -0
- package/dist/password-BXBkKbv3.js.map +1 -0
- package/dist/password-y4m307oa.mjs +223 -0
- package/dist/password-y4m307oa.mjs.map +1 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +30 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/types.d.ts +25 -0
- package/dist/scheduler/types.d.ts.map +1 -0
- package/dist/types/server.types.d.ts +7 -0
- package/dist/types/server.types.d.ts.map +1 -1
- package/dist/upload-9lCNnKK_.js +5 -0
- package/dist/upload-9lCNnKK_.js.map +1 -0
- package/dist/upload-DUjQiuq7.mjs +619 -0
- package/dist/upload-DUjQiuq7.mjs.map +1 -0
- package/dist/validation/index.js +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +2 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/manager.d.ts +30 -0
- package/dist/websocket/manager.d.ts.map +1 -0
- package/dist/websocket/types.d.ts +27 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/package.json +58 -18
- package/templates/default/controllers/user.controller.ts +44 -64
- package/templates/default/package.json +9 -33
- package/templates/default/routes/index.ts +2 -12
- package/templates/default/routes/user.routes.ts +26 -19
- package/templates/default/server.ts +16 -35
- package/dist/logger-D7aJSi62.mjs +0 -102
- package/dist/logger-DEnWXtpk.js +0 -3
- package/dist/manager-B1UKMjXW.js +0 -4
- package/dist/manager-B6vqJgEn.mjs +0 -152
- package/dist/portal.d.ts +0 -13
- package/dist/portal.d.ts.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { ApiKeyOptions } from './types';
|
|
3
|
+
|
|
4
|
+
export declare function apiKeyAuth(options: ApiKeyOptions): RequestHandler;
|
|
5
|
+
export declare function generateApiKey(length?: number): string;
|
|
6
|
+
//# sourceMappingURL=apiKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKey.d.ts","sourceRoot":"","sources":["../../src/auth/apiKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,wBAAgB,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,CAwCjE;AAED,wBAAgB,cAAc,CAAC,MAAM,SAAK,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { JWT, jwtAuth, createJwt } from './jwt';
|
|
2
|
+
export { apiKeyAuth, generateApiKey } from './apiKey';
|
|
3
|
+
export { requireRole, requirePermission } from './rbac';
|
|
4
|
+
export { verifySignature } from './signing';
|
|
5
|
+
export { hashPassword, verifyPassword } from './password';
|
|
6
|
+
export type { JwtOptions, JwtPayload, ApiKeyOptions, Role, Permission, RbacOptions, SigningOptions, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE1D,YAAY,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,IAAI,EACJ,UAAU,EACV,WAAW,EACX,cAAc,GACf,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../password-BXBkKbv3.js");exports.JWT=e.JWT;exports.apiKeyAuth=e.apiKeyAuth;exports.createJwt=e.createJwt;exports.generateApiKey=e.generateApiKey;exports.hashPassword=e.hashPassword;exports.jwtAuth=e.jwtAuth;exports.requirePermission=e.requirePermission;exports.requireRole=e.requireRole;exports.verifyPassword=e.verifyPassword;exports.verifySignature=e.verifySignature;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { JwtOptions, JwtPayload } from './types';
|
|
3
|
+
|
|
4
|
+
export declare class JWT {
|
|
5
|
+
private secret;
|
|
6
|
+
private algorithm;
|
|
7
|
+
private defaultExpiry;
|
|
8
|
+
private issuer?;
|
|
9
|
+
private audience?;
|
|
10
|
+
constructor(options: JwtOptions);
|
|
11
|
+
sign(payload: JwtPayload, expiresIn?: number): string;
|
|
12
|
+
verify(token: string): JwtPayload;
|
|
13
|
+
decode(token: string): JwtPayload | null;
|
|
14
|
+
private createSignature;
|
|
15
|
+
private safeCompare;
|
|
16
|
+
}
|
|
17
|
+
export declare function jwtAuth(jwt: JWT, options?: {
|
|
18
|
+
optional?: boolean;
|
|
19
|
+
}): RequestHandler;
|
|
20
|
+
export declare function createJwt(options: JwtOptions): JWT;
|
|
21
|
+
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/auth/jwt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA6BtD,qBAAa,GAAG;IACd,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,CAAS;gBAEd,OAAO,EAAE,UAAU;IAQ/B,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAoBrD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAmCjC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAUxC,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,WAAW;CAIpB;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,cAAc,CAqCtF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,GAAG,CAElD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/auth/password.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,SAAkC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAGrH;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { Role, Permission, RbacOptions } from './types';
|
|
3
|
+
|
|
4
|
+
export declare function requireRole(roles: Role | Role[], options?: RbacOptions): RequestHandler;
|
|
5
|
+
export declare function requirePermission(permissions: Permission | Permission[], options?: RbacOptions): RequestHandler;
|
|
6
|
+
//# sourceMappingURL=rbac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac.d.ts","sourceRoot":"","sources":["../../src/auth/rbac.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE7D,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,OAAO,GAAE,WAAgB,GAAG,cAAc,CAyB3F;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,EAAE,EAAE,OAAO,GAAE,WAAgB,GAAG,cAAc,CA+BnH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/auth/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,wBAAgB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAkDvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKey.types.d.ts","sourceRoot":"","sources":["../../../src/auth/types/apiKey.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC7F"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { JwtOptions, JwtPayload } from './jwt.types';
|
|
2
|
+
export type { ApiKeyOptions } from './apiKey.types';
|
|
3
|
+
export type { Role, Permission, RbacOptions } from './rbac.types';
|
|
4
|
+
export type { SigningOptions } from './signing.types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface JwtOptions {
|
|
2
|
+
secret: string;
|
|
3
|
+
algorithm?: 'HS256' | 'HS384' | 'HS512';
|
|
4
|
+
expiresIn?: number;
|
|
5
|
+
issuer?: string;
|
|
6
|
+
audience?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface JwtPayload {
|
|
9
|
+
sub?: string;
|
|
10
|
+
iss?: string;
|
|
11
|
+
aud?: string;
|
|
12
|
+
exp?: number;
|
|
13
|
+
iat?: number;
|
|
14
|
+
nbf?: number;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=jwt.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.types.d.ts","sourceRoot":"","sources":["../../../src/auth/types/jwt.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac.types.d.ts","sourceRoot":"","sources":["../../../src/auth/types/rbac.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.types.d.ts","sourceRoot":"","sources":["../../../src/auth/types/signing.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../logger-D-lfaRWQ.js");class p{cache=new Map;maxSize;constructor(e=1e3){this.maxSize=e}async get(e){const t=this.cache.get(e);return t?t.expires&&t.expires<Date.now()?(this.cache.delete(e),null):t.value:null}async set(e,t,s){if(this.cache.size>=this.maxSize){const i=this.cache.keys().next().value;i&&this.cache.delete(i)}const a={value:t,expires:s?Date.now()+s:0,createdAt:Date.now()};this.cache.set(e,a)}async del(e){this.cache.delete(e)}async clear(){this.cache.clear()}async has(e){return await this.get(e)!==null}async keys(){return Array.from(this.cache.keys())}async size(){return this.cache.size}}class C{client;prefix;defaultTtl;constructor(e,t="cache:",s=3600){this.client=e,this.prefix=t,this.defaultTtl=s}async get(e){const t=await this.client.get(this.prefix+e);if(!t)return null;try{return JSON.parse(t)}catch{return t}}async set(e,t,s){const a=typeof t=="string"?t:JSON.stringify(t),i=s||this.defaultTtl;await this.client.setex(this.prefix+e,Math.ceil(i/1e3),a)}async del(e){await this.client.del(this.prefix+e)}async clear(){const e=await this.client.keys(this.prefix+"*");e.length>0&&await this.client.del(...e)}async has(e){return await this.client.exists(this.prefix+e)===1}async keys(){return(await this.client.keys(this.prefix+"*")).map(t=>t.slice(this.prefix.length))}async size(){return(await this.client.keys(this.prefix+"*")).length}}const f=m.createLogger("cache");class g{store;defaultTtl;constructor(e=new p,t=36e5){this.store=e,this.defaultTtl=t}async get(e){return this.store.get(e)}async set(e,t,s){return this.store.set(e,t,s||this.defaultTtl)}async del(e){return this.store.del(e)}async getOrSet(e,t,s){const a=await this.get(e);if(a!==null)return a;const i=await t();return await this.set(e,i,s),i}async wrap(e,t,s){return this.getOrSet(e,t,s)}async invalidate(e){const s=(await this.store.keys()).filter(a=>new RegExp(e).test(a));await Promise.all(s.map(a=>this.store.del(a)))}async clear(){return this.store.clear()}async stats(){return{size:await this.store.size(),keys:await this.store.keys()}}}const y=new g;function S(n={}){const{ttl:e=6e4,keyGenerator:t=r=>`${r.method}:${r.originalUrl}`,shouldCache:s=(r,c)=>r.method==="GET"&&c.statusCode===200,onHit:a,onMiss:i}=n;return async(r,c,x)=>{const h=t(r),d=await y.get(h);if(d)return f.debug(`Cache hit: ${h}`),a?.(h),Object.entries(d.headers).forEach(([o,l])=>{c.setHeader(o,l)}),c.setHeader("X-Cache","HIT"),c.json(d.body);f.debug(`Cache miss: ${h}`),i?.(h);const k=c.json.bind(c);c.json=o=>{if(s(r,c)){const l={};c.getHeaderNames().forEach(u=>{const w=c.getHeader(u);w&&(l[u]=String(w))}),y.set(h,{body:o,headers:l},e).catch(u=>{f.error(`Failed to cache response: ${u}`)})}return c.setHeader("X-Cache","MISS"),k(o)},x()}}function z(n,e,t){return async(...s)=>{const a=e(...s);return y.getOrSet(a,()=>n(...s),t)}}function M(n,e){return new g(n,e)}exports.CacheManager=g;exports.MemoryCache=p;exports.RedisCache=C;exports.cache=y;exports.cacheResponse=S;exports.cached=z;exports.createCache=M;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/cache/stores.ts","../../src/cache/manager.ts"],"sourcesContent":["import type { CacheStore, CacheEntry } from './types';\n\nexport class MemoryCache implements CacheStore {\n private cache: Map<string, CacheEntry> = new Map();\n private maxSize: number;\n\n constructor(maxSize = 1000) {\n this.maxSize = maxSize;\n }\n\n async get<T>(key: string): Promise<T | null> {\n const entry = this.cache.get(key);\n \n if (!entry) {\n return null;\n }\n\n if (entry.expires && entry.expires < Date.now()) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value as T;\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n if (this.cache.size >= this.maxSize) {\n const oldest = this.cache.keys().next().value;\n if (oldest) {\n this.cache.delete(oldest);\n }\n }\n\n const entry: CacheEntry = {\n value,\n expires: ttl ? Date.now() + ttl : 0,\n createdAt: Date.now(),\n };\n\n this.cache.set(key, entry);\n }\n\n async del(key: string): Promise<void> {\n this.cache.delete(key);\n }\n\n async clear(): Promise<void> {\n this.cache.clear();\n }\n\n async has(key: string): Promise<boolean> {\n const value = await this.get(key);\n return value !== null;\n }\n\n async keys(): Promise<string[]> {\n return Array.from(this.cache.keys());\n }\n\n async size(): Promise<number> {\n return this.cache.size;\n }\n}\n\nexport class RedisCache implements CacheStore {\n private client: any;\n private prefix: string;\n private defaultTtl: number;\n\n constructor(client: any, prefix = 'cache:', defaultTtl = 3600) {\n this.client = client;\n this.prefix = prefix;\n this.defaultTtl = defaultTtl;\n }\n\n async get<T>(key: string): Promise<T | null> {\n const data = await this.client.get(this.prefix + key);\n if (!data) return null;\n \n try {\n return JSON.parse(data);\n } catch {\n return data as T;\n }\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n const data = typeof value === 'string' ? value : JSON.stringify(value);\n const expiry = ttl || this.defaultTtl;\n \n await this.client.setex(this.prefix + key, Math.ceil(expiry / 1000), data);\n }\n\n async del(key: string): Promise<void> {\n await this.client.del(this.prefix + key);\n }\n\n async clear(): Promise<void> {\n const keys = await this.client.keys(this.prefix + '*');\n if (keys.length > 0) {\n await this.client.del(...keys);\n }\n }\n\n async has(key: string): Promise<boolean> {\n return (await this.client.exists(this.prefix + key)) === 1;\n }\n\n async keys(): Promise<string[]> {\n const keys = await this.client.keys(this.prefix + '*');\n return keys.map((k: string) => k.slice(this.prefix.length));\n }\n\n async size(): Promise<number> {\n const keys = await this.client.keys(this.prefix + '*');\n return keys.length;\n }\n}\n\n","import { RequestHandler } from 'express';\nimport { createLogger } from '../utils/logger';\nimport { MemoryCache } from './stores';\nimport type { CacheStore, CacheOptions } from './types';\n\nconst logger = createLogger('cache');\n\nexport class CacheManager {\n private store: CacheStore;\n private defaultTtl: number;\n\n constructor(store: CacheStore = new MemoryCache(), defaultTtl = 3600000) {\n this.store = store;\n this.defaultTtl = defaultTtl;\n }\n\n async get<T>(key: string): Promise<T | null> {\n return this.store.get<T>(key);\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n return this.store.set(key, value, ttl || this.defaultTtl);\n }\n\n async del(key: string): Promise<void> {\n return this.store.del(key);\n }\n\n async getOrSet<T>(key: string, factory: () => T | Promise<T>, ttl?: number): Promise<T> {\n const cached = await this.get<T>(key);\n if (cached !== null) {\n return cached;\n }\n\n const value = await factory();\n await this.set(key, value, ttl);\n return value;\n }\n\n async wrap<T>(key: string, fn: () => T | Promise<T>, ttl?: number): Promise<T> {\n return this.getOrSet(key, fn, ttl);\n }\n\n async invalidate(pattern: string): Promise<void> {\n const keys = await this.store.keys();\n const matching = keys.filter((k) => new RegExp(pattern).test(k));\n await Promise.all(matching.map((k) => this.store.del(k)));\n }\n\n async clear(): Promise<void> {\n return this.store.clear();\n }\n\n async stats(): Promise<{ size: number; keys: string[] }> {\n return {\n size: await this.store.size(),\n keys: await this.store.keys(),\n };\n }\n}\n\nexport const cache = new CacheManager();\n\nexport function cacheResponse(options: CacheOptions = {}): RequestHandler {\n const {\n ttl = 60000,\n keyGenerator = (req: any) => `${req.method}:${req.originalUrl}`,\n shouldCache = (req: any, res: any) => req.method === 'GET' && res.statusCode === 200,\n onHit,\n onMiss,\n } = options;\n\n return async (req, res, next) => {\n const key = keyGenerator(req);\n\n const cached = await cache.get<{ body: any; headers: Record<string, string> }>(key);\n \n if (cached) {\n logger.debug(`Cache hit: ${key}`);\n onHit?.(key);\n \n Object.entries(cached.headers).forEach(([k, v]) => {\n res.setHeader(k, v);\n });\n res.setHeader('X-Cache', 'HIT');\n \n return res.json(cached.body);\n }\n\n logger.debug(`Cache miss: ${key}`);\n onMiss?.(key);\n\n const originalJson = res.json.bind(res);\n res.json = (body: any) => {\n if (shouldCache(req, res)) {\n const headers: Record<string, string> = {};\n res.getHeaderNames().forEach((name) => {\n const value = res.getHeader(name);\n if (value) {\n headers[name] = String(value);\n }\n });\n\n cache.set(key, { body, headers }, ttl).catch((err) => {\n logger.error(`Failed to cache response: ${err}`);\n });\n }\n\n res.setHeader('X-Cache', 'MISS');\n return originalJson(body);\n };\n\n next();\n };\n}\n\nexport function cached<T extends (...args: any[]) => Promise<any>>(\n fn: T,\n keyGenerator: (...args: Parameters<T>) => string,\n ttl?: number\n): T {\n return (async (...args: Parameters<T>) => {\n const key = keyGenerator(...args);\n return cache.getOrSet(key, () => fn(...args), ttl);\n }) as T;\n}\n\nexport function createCache(store?: CacheStore, defaultTtl?: number): CacheManager {\n return new CacheManager(store, defaultTtl);\n}\n\n"],"names":["MemoryCache","maxSize","key","entry","value","ttl","oldest","RedisCache","client","prefix","defaultTtl","data","expiry","keys","k","logger","createLogger","CacheManager","store","factory","cached","fn","pattern","matching","cache","cacheResponse","options","keyGenerator","req","shouldCache","res","onHit","onMiss","next","v","originalJson","body","headers","name","err","args","createCache"],"mappings":"yHAEO,MAAMA,CAAkC,CACrC,UAAqC,IACrC,QAER,YAAYC,EAAU,IAAM,CAC1B,KAAK,QAAUA,CACjB,CAEA,MAAM,IAAOC,EAAgC,CAC3C,MAAMC,EAAQ,KAAK,MAAM,IAAID,CAAG,EAEhC,OAAKC,EAIDA,EAAM,SAAWA,EAAM,QAAU,KAAK,OACxC,KAAK,MAAM,OAAOD,CAAG,EACd,MAGFC,EAAM,MARJ,IASX,CAEA,MAAM,IAAOD,EAAaE,EAAUC,EAA6B,CAC/D,GAAI,KAAK,MAAM,MAAQ,KAAK,QAAS,CACnC,MAAMC,EAAS,KAAK,MAAM,KAAA,EAAO,OAAO,MACpC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UAAUQ,CAAI,EAC5BlC,IACFiC,EAAQC,CAAI,EAAI,OAAOlC,CAAK,EAEhC,CAAC,EAEDoB,EAAM,IAAItB,EAAK,CAAE,KAAAkC,EAAM,QAAAC,CAAA,EAAWhC,CAAG,EAAE,MAAOkC,GAAQ,CACpDxB,EAAO,MAAM,6BAA6BwB,CAAG,EAAE,CACjD,CAAC,CACH,CAEA,OAAAT,EAAI,UAAU,UAAW,MAAM,EACxBK,EAAaC,CAAI,CAC1B,EAEAH,EAAA,CACF,CACF,CAEO,SAASb,EACdC,EACAM,EACAtB,EACG,CACH,MAAQ,UAAUmC,IAAwB,CACxC,MAAMtC,EAAMyB,EAAa,GAAGa,CAAI,EAChC,OAAOhB,EAAM,SAAStB,EAAK,IAAMmB,EAAG,GAAGmB,CAAI,EAAGnC,CAAG,CACnD,CACF,CAEO,SAASoC,EAAYvB,EAAoBR,EAAmC,CACjF,OAAO,IAAIO,EAAaC,EAAOR,CAAU,CAC3C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { CacheStore, CacheOptions } from './types';
|
|
3
|
+
|
|
4
|
+
export declare class CacheManager {
|
|
5
|
+
private store;
|
|
6
|
+
private defaultTtl;
|
|
7
|
+
constructor(store?: CacheStore, defaultTtl?: number);
|
|
8
|
+
get<T>(key: string): Promise<T | null>;
|
|
9
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
|
+
del(key: string): Promise<void>;
|
|
11
|
+
getOrSet<T>(key: string, factory: () => T | Promise<T>, ttl?: number): Promise<T>;
|
|
12
|
+
wrap<T>(key: string, fn: () => T | Promise<T>, ttl?: number): Promise<T>;
|
|
13
|
+
invalidate(pattern: string): Promise<void>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
stats(): Promise<{
|
|
16
|
+
size: number;
|
|
17
|
+
keys: string[];
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare const cache: CacheManager;
|
|
21
|
+
export declare function cacheResponse(options?: CacheOptions): RequestHandler;
|
|
22
|
+
export declare function cached<T extends (...args: any[]) => Promise<any>>(fn: T, keyGenerator: (...args: Parameters<T>) => string, ttl?: number): T;
|
|
23
|
+
export declare function createCache(store?: CacheStore, defaultTtl?: number): CacheManager;
|
|
24
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/cache/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIxD,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAEf,KAAK,GAAE,UAA8B,EAAE,UAAU,SAAU;IAKjE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAItC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/B,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAWjF,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxE,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,KAAK,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAMzD;AAED,eAAO,MAAM,KAAK,cAAqB,CAAC;AAExC,wBAAgB,aAAa,CAAC,OAAO,GAAE,YAAiB,GAAG,cAAc,CAmDxE;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC/D,EAAE,EAAE,CAAC,EACL,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,EAChD,GAAG,CAAC,EAAE,MAAM,GACX,CAAC,CAKH;AAED,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAEjF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CacheStore } from './types';
|
|
2
|
+
|
|
3
|
+
export declare class MemoryCache implements CacheStore {
|
|
4
|
+
private cache;
|
|
5
|
+
private maxSize;
|
|
6
|
+
constructor(maxSize?: number);
|
|
7
|
+
get<T>(key: string): Promise<T | null>;
|
|
8
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
del(key: string): Promise<void>;
|
|
10
|
+
clear(): Promise<void>;
|
|
11
|
+
has(key: string): Promise<boolean>;
|
|
12
|
+
keys(): Promise<string[]>;
|
|
13
|
+
size(): Promise<number>;
|
|
14
|
+
}
|
|
15
|
+
export declare class RedisCache implements CacheStore {
|
|
16
|
+
private client;
|
|
17
|
+
private prefix;
|
|
18
|
+
private defaultTtl;
|
|
19
|
+
constructor(client: any, prefix?: string, defaultTtl?: number);
|
|
20
|
+
get<T>(key: string): Promise<T | null>;
|
|
21
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
22
|
+
del(key: string): Promise<void>;
|
|
23
|
+
clear(): Promise<void>;
|
|
24
|
+
has(key: string): Promise<boolean>;
|
|
25
|
+
keys(): Promise<string[]>;
|
|
26
|
+
size(): Promise<number>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../../src/cache/stores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,SAAS,CAAC;AAEtD,qBAAa,WAAY,YAAW,UAAU;IAC5C,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,SAAO;IAIpB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAetC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB1D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKlC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIzB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAG9B;AAED,qBAAa,UAAW,YAAW,UAAU;IAC3C,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,GAAG,EAAE,MAAM,SAAW,EAAE,UAAU,SAAO;IAMvD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAWtC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAI9B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface CacheOptions {
|
|
2
|
+
ttl?: number;
|
|
3
|
+
maxSize?: number;
|
|
4
|
+
keyGenerator?: (req: unknown) => string;
|
|
5
|
+
shouldCache?: (req: unknown, res: unknown) => boolean;
|
|
6
|
+
onHit?: (key: string) => void;
|
|
7
|
+
onMiss?: (key: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface CacheEntry<T = unknown> {
|
|
10
|
+
value: T;
|
|
11
|
+
expires: number;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
}
|
|
14
|
+
export interface CacheStore {
|
|
15
|
+
get<T>(key: string): Promise<T | null>;
|
|
16
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
17
|
+
del(key: string): Promise<void>;
|
|
18
|
+
clear(): Promise<void>;
|
|
19
|
+
has(key: string): Promise<boolean>;
|
|
20
|
+
keys(): Promise<string[]>;
|
|
21
|
+
size(): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cache/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IACxC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IACtD,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACvC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const n=require("path"),o=require("fs"),
|
|
2
|
+
"use strict";const n=require("path"),o=require("fs"),v=require("../logger-D-lfaRWQ.js"),b=v.createLogger("cli"),f=[{name:"create",description:"Create a new Harbor project with full boilerplate",action:j},{name:"init",description:"Initialize Harbor config in existing project",action:S},{name:"generate",description:"Generate server file from config",action:x},{name:"docs",description:"Generate API documentation",action:w},{name:"version",description:"Show Harbor version",action:P},{name:"help",description:"Show help information",action:d}];async function y(){const t=process.argv.slice(2),e=t[0]??"help",l=t.slice(1),r=f.find(s=>s.name===e);r||(console.error(`Unknown command: ${e}`),d(),process.exit(1));try{await r.action(l)}catch(s){b.error("Command failed",s),process.exit(1)}}function u(t,e,l={}){o.existsSync(e)||o.mkdirSync(e,{recursive:!0});const r=o.readdirSync(t);for(const s of r){const i=n.join(t,s),a=n.join(e,s);if(o.statSync(i).isDirectory())u(i,a,l);else{let c=o.readFileSync(i,"utf-8");for(const[m,h]of Object.entries(l))c=c.replace(new RegExp(`\\{\\{${m}\\}\\}`,"g"),h);const p=s==="env.example"?n.join(n.dirname(a),".env.example"):a;o.writeFileSync(p,c,"utf-8")}}}async function j(t){const e=t[0];e||(console.error("Please provide a project name: harbor create <project-name>"),process.exit(1));const l=n.resolve(process.cwd(),e);o.existsSync(l)&&(console.error(`Directory "${e}" already exists`),process.exit(1)),console.log(`
|
|
3
3
|
🚢 Creating Harbor project: ${e}
|
|
4
|
-
`);let r=n.resolve(__dirname,"../../templates/default");o.existsSync(r)||(r=n.resolve(__dirname,"../../../templates/default")),o.existsSync(r)||(console.error("Templates not found. Please reinstall Harbor."),process.exit(1));const s={PROJECT_NAME:e,PROJECT_DESCRIPTION:"A Node.js backend built with Harbor",CREATED_AT:new Date().toISOString()};console.log("📁 Copying project files..."),u(r,l,s);const
|
|
4
|
+
`);let r=n.resolve(__dirname,"../../templates/default");o.existsSync(r)||(r=n.resolve(__dirname,"../../../templates/default")),o.existsSync(r)||(console.error("Templates not found. Please reinstall Harbor."),process.exit(1));const s={PROJECT_NAME:e,PROJECT_DESCRIPTION:"A Node.js backend built with Harbor",CREATED_AT:new Date().toISOString()};console.log("📁 Copying project files..."),u(r,l,s);const i={server:{port:3e3,host:"localhost",cors:{enabled:!0,origin:"*"}},database:{type:"mongodb",uri:"",name:e.toLowerCase().replace(/[^a-z0-9]/g,"_")},routes:{prefix:"/api",timeout:3e4},errors:{404:{message:"Not Found",json:!0},500:{message:"Internal Server Error",json:!0,log:!0}},logger:{enabled:!0,level:"info",format:"text"}};o.writeFileSync(n.join(l,"harbor.config.json"),JSON.stringify(i,null,2),"utf-8"),console.log(`✅ Project created successfully!
|
|
5
5
|
`),console.log(`📂 Project structure:
|
|
6
6
|
`),console.log(` ${e}/`),console.log(" ├── server.ts # Application entry point"),console.log(" ├── routes/ # Route definitions"),console.log(" ├── controllers/ # Request handlers"),console.log(" ├── services/ # Business logic"),console.log(" ├── models/ # Database models"),console.log(" ├── types/ # TypeScript definitions"),console.log(" ├── utils/ # Utility functions"),console.log(" ├── constants/ # App constants & config"),console.log(" ├── package.json"),console.log(" ├── tsconfig.json"),console.log(" ├── .eslintrc.json"),console.log(" └── harbor.config.json"),console.log(`
|
|
7
7
|
🚀 Next steps:
|
|
8
8
|
`),console.log(` cd ${e}`),console.log(" npm install"),console.log(" cp .env.example .env"),console.log(` npm run dev
|
|
9
|
-
`),console.log(`📚 Documentation: https://
|
|
9
|
+
`),console.log(`📚 Documentation: https://forgestack.dev/harbor
|
|
10
10
|
`)}function S(t){const e=process.cwd(),l=t.includes("--template")||t.includes("-t"),r=e.split("/").pop()||"my-app";if(l){console.log(`
|
|
11
11
|
🚢 Initializing with template...
|
|
12
|
-
`);let
|
|
12
|
+
`);let c=n.resolve(__dirname,"../../templates/default");o.existsSync(c)||(c=n.resolve(__dirname,"../../../templates/default")),o.existsSync(c)||(console.error("Templates not found. Please reinstall Harbor."),process.exit(1));const p={PROJECT_NAME:r,PROJECT_DESCRIPTION:"A Node.js backend built with Harbor"};console.log("📁 Copying project files..."),u(c,e,p);const m={server:{port:3e3,host:"localhost",cors:{enabled:!0,origin:"*"}},database:{type:"mongodb",uri:"",name:r.toLowerCase().replace(/[^a-z0-9]/g,"_")},routes:{prefix:"/api",timeout:3e4},errors:{404:{message:"Not Found",json:!0},500:{message:"Internal Server Error",json:!0,log:!0}},logger:{enabled:!0,level:"info",format:"text"}};o.writeFileSync(n.join(e,"harbor.config.json"),JSON.stringify(m,null,2),"utf-8"),console.log(`✅ Project initialized with template!
|
|
13
13
|
`),console.log(`🚀 Next steps:
|
|
14
14
|
`),console.log(" npm install"),console.log(" cp .env.example .env"),console.log(` npm run dev
|
|
15
|
-
`);return}const s=n.resolve(e,"harbor.config.json");if(o.existsSync(s)){console.log("harbor.config.json already exists");return}const
|
|
15
|
+
`);return}const s=n.resolve(e,"harbor.config.json");if(o.existsSync(s)){console.log("harbor.config.json already exists");return}const i={server:{port:3e3,host:"localhost",cors:{enabled:!0,origin:"*"},bodyParser:{json:!0,urlencoded:!0,limit:"10mb"}},routes:{prefix:"/api",timeout:3e4},validation:{adapter:"mongoose",strictMode:!0,sanitize:!0},errors:{404:{message:"Not Found",json:!0},500:{message:"Internal Server Error",json:!0,log:!0}},logger:{enabled:!0,level:"info",format:"text",output:"console"}};o.writeFileSync(s,JSON.stringify(i,null,2),"utf-8"),console.log("Created harbor.config.json");const a=n.resolve(e,"src");o.existsSync(a)||o.mkdirSync(a,{recursive:!0});const g=n.resolve(a,"server.ts");o.existsSync(g)||(o.writeFileSync(g,`import { createServer, router, GET } from '@forgestack/harbor';
|
|
16
16
|
|
|
17
|
-
const server = createServer({
|
|
18
|
-
port: 3000,
|
|
19
|
-
});
|
|
17
|
+
const server = createServer({ port: 3000 });
|
|
20
18
|
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
// Define routes
|
|
20
|
+
const healthRoutes = router('/health', [
|
|
21
|
+
GET('/', async () => ({
|
|
22
|
+
status: 'ok',
|
|
23
|
+
timestamp: new Date().toISOString()
|
|
24
|
+
})),
|
|
25
|
+
]);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
27
|
+
server.use(healthRoutes);
|
|
28
|
+
|
|
29
|
+
console.log('Server running at http://localhost:3000');
|
|
31
30
|
`,"utf-8"),console.log("Created src/server.ts")),console.log(`
|
|
32
|
-
Harbor project initialized!`),console.log("Run: npm install harbor"),console.log("Then: npm run dev"),console.log(`
|
|
33
|
-
Tip: Use --template flag for full boilerplate`)}function x(){console.log("Generating server from config..."),console.log("This feature is coming soon!")}function w(){console.log("Generating API documentation..."),console.log("This feature is coming soon!")}function P(){console.log("
|
|
34
|
-
🚢 Harbor -
|
|
31
|
+
Harbor project initialized!`),console.log("Run: npm install @forgestack/harbor"),console.log("Then: npm run dev"),console.log(`
|
|
32
|
+
Tip: Use --template flag for full boilerplate`)}function x(){console.log("Generating server from config..."),console.log("This feature is coming soon!")}function w(){console.log("Generating API documentation..."),console.log("This feature is coming soon!")}function P(){console.log("@forgestack/harbor v1.4.0")}function d(){console.log(`
|
|
33
|
+
🚢 ForgeStack Harbor - Node.js Backend Framework
|
|
35
34
|
`),console.log(`Usage: harbor <command> [options]
|
|
36
35
|
`),console.log(`Commands:
|
|
37
36
|
`);for(const t of f)console.log(` ${t.name.padEnd(12)} ${t.description}`);console.log(`
|
|
38
37
|
Options:
|
|
39
38
|
`),console.log(" --template, -t Use full boilerplate template (for init command)"),console.log(`
|
|
40
39
|
Examples:
|
|
41
|
-
`),console.log(" harbor create my-app
|
|
42
|
-
Documentation: https://
|
|
40
|
+
`),console.log(" npx @forgestack/harbor create my-app Create new project"),console.log(" harbor create my-app Create new project"),console.log(" harbor init Initialize config"),console.log(" harbor init --template Initialize with full boilerplate"),console.log(" harbor version Show version"),console.log(`
|
|
41
|
+
Documentation: https://forgestack.dev/harbor`)}y();
|
|
43
42
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { resolve, join, dirname } from 'path';\nimport { existsSync, writeFileSync, mkdirSync, readFileSync, readdirSync, statSync } from 'fs';\nimport { createLogger } from '../utils/logger';\n\nconst logger = createLogger('cli');\n\ninterface CliCommand {\n name: string;\n description: string;\n action: (args: string[]) => Promise<void> | void;\n}\n\nconst commands: CliCommand[] = [\n {\n name: 'create',\n description: 'Create a new Harbor project with full boilerplate',\n action: createProject,\n },\n {\n name: 'init',\n description: 'Initialize Harbor config in existing project',\n action: initProject,\n },\n {\n name: 'generate',\n description: 'Generate server file from config',\n action: generateServer,\n },\n {\n name: 'docs',\n description: 'Generate API documentation',\n action: generateDocs,\n },\n {\n name: 'version',\n description: 'Show Harbor version',\n action: showVersion,\n },\n {\n name: 'help',\n description: 'Show help information',\n action: showHelp,\n },\n];\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n const commandName = args[0] ?? 'help';\n const commandArgs = args.slice(1);\n\n const command = commands.find((c) => c.name === commandName);\n\n if (!command) {\n console.error(`Unknown command: ${commandName}`);\n showHelp();\n process.exit(1);\n }\n\n try {\n await command.action(commandArgs);\n } catch (error) {\n logger.error('Command failed', error as Error);\n process.exit(1);\n }\n}\n\n/**\n * Copy directory recursively\n */\nfunction copyDirectory(src: string, dest: string, replacements: Record<string, string> = {}): void {\n if (!existsSync(dest)) {\n mkdirSync(dest, { recursive: true });\n }\n\n const entries = readdirSync(src);\n\n for (const entry of entries) {\n const srcPath = join(src, entry);\n const destPath = join(dest, entry);\n const stats = statSync(srcPath);\n\n if (stats.isDirectory()) {\n copyDirectory(srcPath, destPath, replacements);\n } else {\n // Read file content\n let content = readFileSync(srcPath, 'utf-8');\n\n // Apply replacements for template variables\n for (const [key, value] of Object.entries(replacements)) {\n content = content.replace(new RegExp(`\\\\{\\\\{${key}\\\\}\\\\}`, 'g'), value);\n }\n\n // Handle env.example -> .env.example rename\n const finalDestPath = entry === 'env.example' \n ? join(dirname(destPath), '.env.example')\n : destPath;\n\n writeFileSync(finalDestPath, content, 'utf-8');\n }\n }\n}\n\n/**\n * Create a new project with full boilerplate\n */\nasync function createProject(args: string[]): Promise<void> {\n const projectName = args[0];\n\n if (!projectName) {\n console.error('Please provide a project name: harbor create <project-name>');\n process.exit(1);\n }\n\n const projectPath = resolve(process.cwd(), projectName);\n\n if (existsSync(projectPath)) {\n console.error(`Directory \"${projectName}\" already exists`);\n process.exit(1);\n }\n\n console.log(`\\n🚢 Creating Harbor project: ${projectName}\\n`);\n\n // Find templates directory\n // When installed from npm, templates are in the package root\n // When running locally, they're in the project root\n let templatesPath = resolve(__dirname, '../../templates/default');\n \n if (!existsSync(templatesPath)) {\n // Try relative to src for development\n templatesPath = resolve(__dirname, '../../../templates/default');\n }\n\n if (!existsSync(templatesPath)) {\n console.error('Templates not found. Please reinstall Harbor.');\n process.exit(1);\n }\n\n // Template replacements\n const replacements: Record<string, string> = {\n PROJECT_NAME: projectName,\n PROJECT_DESCRIPTION: `A Node.js backend built with Harbor`,\n CREATED_AT: new Date().toISOString(),\n };\n\n // Copy template files\n console.log('📁 Copying project files...');\n copyDirectory(templatesPath, projectPath, replacements);\n\n // Create harbor.config.json\n const harborConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: {\n enabled: true,\n origin: '*',\n },\n },\n database: {\n type: 'mongodb',\n uri: '',\n name: projectName.toLowerCase().replace(/[^a-z0-9]/g, '_'),\n },\n routes: {\n prefix: '/api',\n timeout: 30000,\n },\n errors: {\n 404: { message: 'Not Found', json: true },\n 500: { message: 'Internal Server Error', json: true, log: true },\n },\n logger: {\n enabled: true,\n level: 'info',\n format: 'text',\n },\n };\n\n writeFileSync(\n join(projectPath, 'harbor.config.json'),\n JSON.stringify(harborConfig, null, 2),\n 'utf-8'\n );\n\n console.log('✅ Project created successfully!\\n');\n console.log('📂 Project structure:\\n');\n console.log(` ${projectName}/`);\n console.log(' ├── server.ts # Application entry point');\n console.log(' ├── routes/ # Route definitions');\n console.log(' ├── controllers/ # Request handlers');\n console.log(' ├── services/ # Business logic');\n console.log(' ├── models/ # Database models');\n console.log(' ├── types/ # TypeScript definitions');\n console.log(' ├── utils/ # Utility functions');\n console.log(' ├── constants/ # App constants & config');\n console.log(' ├── package.json');\n console.log(' ├── tsconfig.json');\n console.log(' ├── .eslintrc.json');\n console.log(' └── harbor.config.json');\n\n console.log('\\n🚀 Next steps:\\n');\n console.log(` cd ${projectName}`);\n console.log(' npm install');\n console.log(' cp .env.example .env');\n console.log(' npm run dev\\n');\n\n console.log('📚 Documentation: https://github.com/yaghobieh/Harbor\\n');\n}\n\nfunction initProject(args: string[]): void {\n const cwd = process.cwd();\n const useTemplate = args.includes('--template') || args.includes('-t');\n const projectName = cwd.split('/').pop() || 'my-app';\n \n if (useTemplate) {\n console.log('\\n🚢 Initializing with template...\\n');\n \n // Find templates directory\n let templatesPath = resolve(__dirname, '../../templates/default');\n if (!existsSync(templatesPath)) {\n templatesPath = resolve(__dirname, '../../../templates/default');\n }\n\n if (!existsSync(templatesPath)) {\n console.error('Templates not found. Please reinstall Harbor.');\n process.exit(1);\n }\n\n // Template replacements\n const replacements: Record<string, string> = {\n PROJECT_NAME: projectName,\n PROJECT_DESCRIPTION: `A Node.js backend built with Harbor`,\n };\n\n // Copy template files\n console.log('📁 Copying project files...');\n copyDirectory(templatesPath, cwd, replacements);\n\n // Create harbor.config.json\n const harborConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: { enabled: true, origin: '*' },\n },\n database: {\n type: 'mongodb',\n uri: '',\n name: projectName.toLowerCase().replace(/[^a-z0-9]/g, '_'),\n },\n routes: { prefix: '/api', timeout: 30000 },\n errors: {\n 404: { message: 'Not Found', json: true },\n 500: { message: 'Internal Server Error', json: true, log: true },\n },\n logger: { enabled: true, level: 'info', format: 'text' },\n };\n\n writeFileSync(\n join(cwd, 'harbor.config.json'),\n JSON.stringify(harborConfig, null, 2),\n 'utf-8'\n );\n\n console.log('✅ Project initialized with template!\\n');\n console.log('🚀 Next steps:\\n');\n console.log(' npm install');\n console.log(' cp .env.example .env');\n console.log(' npm run dev\\n');\n return;\n }\n\n // Simple init without template\n const configPath = resolve(cwd, 'harbor.config.json');\n if (existsSync(configPath)) {\n console.log('harbor.config.json already exists');\n return;\n }\n\n const defaultConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: {\n enabled: true,\n origin: '*',\n },\n bodyParser: {\n json: true,\n urlencoded: true,\n limit: '10mb',\n },\n },\n routes: {\n prefix: '/api',\n timeout: 30000,\n },\n validation: {\n adapter: 'mongoose',\n strictMode: true,\n sanitize: true,\n },\n errors: {\n 404: {\n message: 'Not Found',\n json: true,\n },\n 500: {\n message: 'Internal Server Error',\n json: true,\n log: true,\n },\n },\n logger: {\n enabled: true,\n level: 'info',\n format: 'text',\n output: 'console',\n },\n };\n\n writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), 'utf-8');\n console.log('Created harbor.config.json');\n\n const serverDir = resolve(cwd, 'src');\n if (!existsSync(serverDir)) {\n mkdirSync(serverDir, { recursive: true });\n }\n\n const serverPath = resolve(serverDir, 'server.ts');\n if (!existsSync(serverPath)) {\n const serverTemplate = `import { createServer, GET, POST } from 'harbor';\n\nconst server = createServer({\n port: 3000,\n});\n\n// Health check\nserver.get('/health', GET(async () => ({ \n status: 'ok', \n timestamp: new Date().toISOString() \n})));\n\n// Start the server\nserver.listen(3000, () => {\n console.log('Server running at http://localhost:3000');\n});\n`;\n\n writeFileSync(serverPath, serverTemplate, 'utf-8');\n console.log('Created src/server.ts');\n }\n\n console.log('\\nHarbor project initialized!');\n console.log('Run: npm install harbor');\n console.log('Then: npm run dev');\n console.log('\\nTip: Use --template flag for full boilerplate');\n}\n\nfunction generateServer(): void {\n console.log('Generating server from config...');\n console.log('This feature is coming soon!');\n}\n\nfunction generateDocs(): void {\n console.log('Generating API documentation...');\n console.log('This feature is coming soon!');\n}\n\nfunction showVersion(): void {\n console.log('Harbor v1.2.0');\n}\n\nfunction showHelp(): void {\n console.log('\\n🚢 Harbor - The pipeline for Node.js backends\\n');\n console.log('Usage: harbor <command> [options]\\n');\n console.log('Commands:\\n');\n\n for (const command of commands) {\n console.log(` ${command.name.padEnd(12)} ${command.description}`);\n }\n\n console.log('\\nOptions:\\n');\n console.log(' --template, -t Use full boilerplate template (for init command)');\n\n console.log('\\nExamples:\\n');\n console.log(' harbor create my-app Create new project with boilerplate');\n console.log(' harbor init Initialize config in existing project');\n console.log(' harbor init --template Initialize with full boilerplate');\n console.log(' harbor docs Generate API documentation');\n console.log(' harbor version Show version');\n console.log('\\nDocumentation: https://github.com/yaghobieh/Harbor');\n}\n\nmain();\n"],"names":["logger","createLogger","commands","createProject","initProject","generateServer","generateDocs","showVersion","showHelp","main","args","commandName","commandArgs","command","c","error","copyDirectory","src","dest","replacements","existsSync","mkdirSync","entries","readdirSync","entry","srcPath","join","destPath","statSync","content","readFileSync","key","value","finalDestPath","dirname","writeFileSync","projectName","projectPath","resolve","templatesPath","harborConfig","cwd","useTemplate","configPath","defaultConfig","serverDir","serverPath"],"mappings":";wFAMMA,EAASC,EAAAA,aAAa,KAAK,EAQ3BC,EAAyB,CAC7B,CACE,KAAM,SACN,YAAa,oDACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,+CACb,OAAQC,CAAA,EAEV,CACE,KAAM,WACN,YAAa,mCACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,6BACb,OAAQC,CAAA,EAEV,CACE,KAAM,UACN,YAAa,sBACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,wBACb,OAAQC,CAAA,CAEZ,EAEA,eAAeC,GAAsB,CACnC,MAAMC,EAAO,QAAQ,KAAK,MAAM,CAAC,EAC3BC,EAAcD,EAAK,CAAC,GAAK,OACzBE,EAAcF,EAAK,MAAM,CAAC,EAE1BG,EAAUX,EAAS,KAAMY,GAAMA,EAAE,OAASH,CAAW,EAEtDE,IACH,QAAQ,MAAM,oBAAoBF,CAAW,EAAE,EAC/CH,EAAA,E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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBmB,OAAO,EACjD,QAAQ,IAAI,uBAAuB,GAGrC,QAAQ,IAAI;AAAA,4BAA+B,EAC3C,QAAQ,IAAI,yBAAyB,EACrC,QAAQ,IAAI,mBAAmB,EAC/B,QAAQ,IAAI;AAAA,8CAAiD,CAC/D,CAEA,SAASzC,GAAuB,CAC9B,QAAQ,IAAI,kCAAkC,EAC9C,QAAQ,IAAI,8BAA8B,CAC5C,CAEA,SAASC,GAAqB,CAC5B,QAAQ,IAAI,iCAAiC,EAC7C,QAAQ,IAAI,8BAA8B,CAC5C,CAEA,SAASC,GAAoB,CAC3B,QAAQ,IAAI,eAAe,CAC7B,CAEA,SAASC,GAAiB,CACxB,QAAQ,IAAI;AAAA;AAAA,CAAmD,EAC/D,QAAQ,IAAI;AAAA,CAAqC,EACjD,QAAQ,IAAI;AAAA,CAAa,EAEzB,UAAWK,KAAWX,EACpB,QAAQ,IAAI,KAAKW,EAAQ,KAAK,OAAO,EAAE,CAAC,IAAIA,EAAQ,WAAW,EAAE,EAGnE,QAAQ,IAAI;AAAA;AAAA,CAAc,EAC1B,QAAQ,IAAI,uEAAuE,EAEnF,QAAQ,IAAI;AAAA;AAAA,CAAe,EAC3B,QAAQ,IAAI,gEAAgE,EAC5E,QAAQ,IAAI,kEAAkE,EAC9E,QAAQ,IAAI,6DAA6D,EACzE,QAAQ,IAAI,uDAAuD,EACnE,QAAQ,IAAI,yCAAyC,EACrD,QAAQ,IAAI;AAAA,mDAAsD,CACpE,CAEAJ,EAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { resolve, join, dirname } from 'path';\nimport { existsSync, writeFileSync, mkdirSync, readFileSync, readdirSync, statSync } from 'fs';\nimport { createLogger } from '../utils/logger';\n\nconst logger = createLogger('cli');\n\ninterface CliCommand {\n name: string;\n description: string;\n action: (args: string[]) => Promise<void> | void;\n}\n\nconst commands: CliCommand[] = [\n {\n name: 'create',\n description: 'Create a new Harbor project with full boilerplate',\n action: createProject,\n },\n {\n name: 'init',\n description: 'Initialize Harbor config in existing project',\n action: initProject,\n },\n {\n name: 'generate',\n description: 'Generate server file from config',\n action: generateServer,\n },\n {\n name: 'docs',\n description: 'Generate API documentation',\n action: generateDocs,\n },\n {\n name: 'version',\n description: 'Show Harbor version',\n action: showVersion,\n },\n {\n name: 'help',\n description: 'Show help information',\n action: showHelp,\n },\n];\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n const commandName = args[0] ?? 'help';\n const commandArgs = args.slice(1);\n\n const command = commands.find((c) => c.name === commandName);\n\n if (!command) {\n console.error(`Unknown command: ${commandName}`);\n showHelp();\n process.exit(1);\n }\n\n try {\n await command.action(commandArgs);\n } catch (error) {\n logger.error('Command failed', error as Error);\n process.exit(1);\n }\n}\n\n/**\n * Copy directory recursively\n */\nfunction copyDirectory(src: string, dest: string, replacements: Record<string, string> = {}): void {\n if (!existsSync(dest)) {\n mkdirSync(dest, { recursive: true });\n }\n\n const entries = readdirSync(src);\n\n for (const entry of entries) {\n const srcPath = join(src, entry);\n const destPath = join(dest, entry);\n const stats = statSync(srcPath);\n\n if (stats.isDirectory()) {\n copyDirectory(srcPath, destPath, replacements);\n } else {\n // Read file content\n let content = readFileSync(srcPath, 'utf-8');\n\n // Apply replacements for template variables\n for (const [key, value] of Object.entries(replacements)) {\n content = content.replace(new RegExp(`\\\\{\\\\{${key}\\\\}\\\\}`, 'g'), value);\n }\n\n // Handle env.example -> .env.example rename\n const finalDestPath = entry === 'env.example' \n ? join(dirname(destPath), '.env.example')\n : destPath;\n\n writeFileSync(finalDestPath, content, 'utf-8');\n }\n }\n}\n\n/**\n * Create a new project with full boilerplate\n */\nasync function createProject(args: string[]): Promise<void> {\n const projectName = args[0];\n\n if (!projectName) {\n console.error('Please provide a project name: harbor create <project-name>');\n process.exit(1);\n }\n\n const projectPath = resolve(process.cwd(), projectName);\n\n if (existsSync(projectPath)) {\n console.error(`Directory \"${projectName}\" already exists`);\n process.exit(1);\n }\n\n console.log(`\\n🚢 Creating Harbor project: ${projectName}\\n`);\n\n // Find templates directory\n // When installed from npm, templates are in the package root\n // When running locally, they're in the project root\n let templatesPath = resolve(__dirname, '../../templates/default');\n \n if (!existsSync(templatesPath)) {\n // Try relative to src for development\n templatesPath = resolve(__dirname, '../../../templates/default');\n }\n\n if (!existsSync(templatesPath)) {\n console.error('Templates not found. Please reinstall Harbor.');\n process.exit(1);\n }\n\n // Template replacements\n const replacements: Record<string, string> = {\n PROJECT_NAME: projectName,\n PROJECT_DESCRIPTION: `A Node.js backend built with Harbor`,\n CREATED_AT: new Date().toISOString(),\n };\n\n // Copy template files\n console.log('📁 Copying project files...');\n copyDirectory(templatesPath, projectPath, replacements);\n\n // Create harbor.config.json\n const harborConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: {\n enabled: true,\n origin: '*',\n },\n },\n database: {\n type: 'mongodb',\n uri: '',\n name: projectName.toLowerCase().replace(/[^a-z0-9]/g, '_'),\n },\n routes: {\n prefix: '/api',\n timeout: 30000,\n },\n errors: {\n 404: { message: 'Not Found', json: true },\n 500: { message: 'Internal Server Error', json: true, log: true },\n },\n logger: {\n enabled: true,\n level: 'info',\n format: 'text',\n },\n };\n\n writeFileSync(\n join(projectPath, 'harbor.config.json'),\n JSON.stringify(harborConfig, null, 2),\n 'utf-8'\n );\n\n console.log('✅ Project created successfully!\\n');\n console.log('📂 Project structure:\\n');\n console.log(` ${projectName}/`);\n console.log(' ├── server.ts # Application entry point');\n console.log(' ├── routes/ # Route definitions');\n console.log(' ├── controllers/ # Request handlers');\n console.log(' ├── services/ # Business logic');\n console.log(' ├── models/ # Database models');\n console.log(' ├── types/ # TypeScript definitions');\n console.log(' ├── utils/ # Utility functions');\n console.log(' ├── constants/ # App constants & config');\n console.log(' ├── package.json');\n console.log(' ├── tsconfig.json');\n console.log(' ├── .eslintrc.json');\n console.log(' └── harbor.config.json');\n\n console.log('\\n🚀 Next steps:\\n');\n console.log(` cd ${projectName}`);\n console.log(' npm install');\n console.log(' cp .env.example .env');\n console.log(' npm run dev\\n');\n\n console.log('📚 Documentation: https://forgestack.dev/harbor\\n');\n}\n\nfunction initProject(args: string[]): void {\n const cwd = process.cwd();\n const useTemplate = args.includes('--template') || args.includes('-t');\n const projectName = cwd.split('/').pop() || 'my-app';\n \n if (useTemplate) {\n console.log('\\n🚢 Initializing with template...\\n');\n \n // Find templates directory\n let templatesPath = resolve(__dirname, '../../templates/default');\n if (!existsSync(templatesPath)) {\n templatesPath = resolve(__dirname, '../../../templates/default');\n }\n\n if (!existsSync(templatesPath)) {\n console.error('Templates not found. Please reinstall Harbor.');\n process.exit(1);\n }\n\n // Template replacements\n const replacements: Record<string, string> = {\n PROJECT_NAME: projectName,\n PROJECT_DESCRIPTION: `A Node.js backend built with Harbor`,\n };\n\n // Copy template files\n console.log('📁 Copying project files...');\n copyDirectory(templatesPath, cwd, replacements);\n\n // Create harbor.config.json\n const harborConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: { enabled: true, origin: '*' },\n },\n database: {\n type: 'mongodb',\n uri: '',\n name: projectName.toLowerCase().replace(/[^a-z0-9]/g, '_'),\n },\n routes: { prefix: '/api', timeout: 30000 },\n errors: {\n 404: { message: 'Not Found', json: true },\n 500: { message: 'Internal Server Error', json: true, log: true },\n },\n logger: { enabled: true, level: 'info', format: 'text' },\n };\n\n writeFileSync(\n join(cwd, 'harbor.config.json'),\n JSON.stringify(harborConfig, null, 2),\n 'utf-8'\n );\n\n console.log('✅ Project initialized with template!\\n');\n console.log('🚀 Next steps:\\n');\n console.log(' npm install');\n console.log(' cp .env.example .env');\n console.log(' npm run dev\\n');\n return;\n }\n\n // Simple init without template\n const configPath = resolve(cwd, 'harbor.config.json');\n if (existsSync(configPath)) {\n console.log('harbor.config.json already exists');\n return;\n }\n\n const defaultConfig = {\n server: {\n port: 3000,\n host: 'localhost',\n cors: {\n enabled: true,\n origin: '*',\n },\n bodyParser: {\n json: true,\n urlencoded: true,\n limit: '10mb',\n },\n },\n routes: {\n prefix: '/api',\n timeout: 30000,\n },\n validation: {\n adapter: 'mongoose',\n strictMode: true,\n sanitize: true,\n },\n errors: {\n 404: {\n message: 'Not Found',\n json: true,\n },\n 500: {\n message: 'Internal Server Error',\n json: true,\n log: true,\n },\n },\n logger: {\n enabled: true,\n level: 'info',\n format: 'text',\n output: 'console',\n },\n };\n\n writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), 'utf-8');\n console.log('Created harbor.config.json');\n\n const serverDir = resolve(cwd, 'src');\n if (!existsSync(serverDir)) {\n mkdirSync(serverDir, { recursive: true });\n }\n\n const serverPath = resolve(serverDir, 'server.ts');\n if (!existsSync(serverPath)) {\n const serverTemplate = `import { createServer, router, GET } from '@forgestack/harbor';\n\nconst server = createServer({ port: 3000 });\n\n// Define routes\nconst healthRoutes = router('/health', [\n GET('/', async () => ({ \n status: 'ok', \n timestamp: new Date().toISOString() \n })),\n]);\n\nserver.use(healthRoutes);\n\nconsole.log('Server running at http://localhost:3000');\n`;\n\n writeFileSync(serverPath, serverTemplate, 'utf-8');\n console.log('Created src/server.ts');\n }\n\n console.log('\\nHarbor project initialized!');\n console.log('Run: npm install @forgestack/harbor');\n console.log('Then: npm run dev');\n console.log('\\nTip: Use --template flag for full boilerplate');\n}\n\nfunction generateServer(): void {\n console.log('Generating server from config...');\n console.log('This feature is coming soon!');\n}\n\nfunction generateDocs(): void {\n console.log('Generating API documentation...');\n console.log('This feature is coming soon!');\n}\n\nfunction showVersion(): void {\n console.log('@forgestack/harbor v1.4.0');\n}\n\nfunction showHelp(): void {\n console.log('\\n🚢 ForgeStack Harbor - Node.js Backend Framework\\n');\n console.log('Usage: harbor <command> [options]\\n');\n console.log('Commands:\\n');\n\n for (const command of commands) {\n console.log(` ${command.name.padEnd(12)} ${command.description}`);\n }\n\n console.log('\\nOptions:\\n');\n console.log(' --template, -t Use full boilerplate template (for init command)');\n\n console.log('\\nExamples:\\n');\n console.log(' npx @forgestack/harbor create my-app Create new project');\n console.log(' harbor create my-app Create new project');\n console.log(' harbor init Initialize config');\n console.log(' harbor init --template Initialize with full boilerplate');\n console.log(' harbor version Show version');\n console.log('\\nDocumentation: https://forgestack.dev/harbor');\n}\n\nmain();\n"],"names":["logger","createLogger","commands","createProject","initProject","generateServer","generateDocs","showVersion","showHelp","main","args","commandName","commandArgs","command","c","error","copyDirectory","src","dest","replacements","existsSync","mkdirSync","entries","readdirSync","entry","srcPath","join","destPath","statSync","content","readFileSync","key","value","finalDestPath","dirname","writeFileSync","projectName","projectPath","resolve","templatesPath","harborConfig","cwd","useTemplate","configPath","defaultConfig","serverDir","serverPath"],"mappings":";wFAMMA,EAASC,EAAAA,aAAa,KAAK,EAQ3BC,EAAyB,CAC7B,CACE,KAAM,SACN,YAAa,oDACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,+CACb,OAAQC,CAAA,EAEV,CACE,KAAM,WACN,YAAa,mCACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,6BACb,OAAQC,CAAA,EAEV,CACE,KAAM,UACN,YAAa,sBACb,OAAQC,CAAA,EAEV,CACE,KAAM,OACN,YAAa,wBACb,OAAQC,CAAA,CAEZ,EAEA,eAAeC,GAAsB,CACnC,MAAMC,EAAO,QAAQ,KAAK,MAAM,CAAC,EAC3BC,EAAcD,EAAK,CAAC,GAAK,OACzBE,EAAcF,EAAK,MAAM,CAAC,EAE1BG,EAAUX,EAAS,KAAMY,GAAMA,EAAE,OAASH,CAAW,EAEtDE,IACH,QAAQ,MAAM,oBAAoBF,CAAW,EAAE,EAC/CH,EAAA,EACA,QAAQ,KAAK,CAAC,GAGhB,GAAI,CACF,MAAMK,EAAQ,OAAOD,CAAW,CAClC,OAASG,EAAO,CACdf,EAAO,MAAM,iBAAkBe,CAAc,EAC7C,QAAQ,KAAK,CAAC,CAChB,CACF,CAKA,SAASC,EAAcC,EAAaC,EAAcC,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AAAA,8CAAiD,CAC/D,CAEA,SAASzC,GAAuB,CAC9B,QAAQ,IAAI,kCAAkC,EAC9C,QAAQ,IAAI,8BAA8B,CAC5C,CAEA,SAASC,GAAqB,CAC5B,QAAQ,IAAI,iCAAiC,EAC7C,QAAQ,IAAI,8BAA8B,CAC5C,CAEA,SAASC,GAAoB,CAC3B,QAAQ,IAAI,2BAA2B,CACzC,CAEA,SAASC,GAAiB,CACxB,QAAQ,IAAI;AAAA;AAAA,CAAsD,EAClE,QAAQ,IAAI;AAAA,CAAqC,EACjD,QAAQ,IAAI;AAAA,CAAa,EAEzB,UAAWK,KAAWX,EACpB,QAAQ,IAAI,KAAKW,EAAQ,KAAK,OAAO,EAAE,CAAC,IAAIA,EAAQ,WAAW,EAAE,EAGnE,QAAQ,IAAI;AAAA;AAAA,CAAc,EAC1B,QAAQ,IAAI,uEAAuE,EAEnF,QAAQ,IAAI;AAAA;AAAA,CAAe,EAC3B,QAAQ,IAAI,8DAA8D,EAC1E,QAAQ,IAAI,8DAA8D,EAC1E,QAAQ,IAAI,6DAA6D,EACzE,QAAQ,IAAI,4EAA4E,EACxF,QAAQ,IAAI,wDAAwD,EACpE,QAAQ,IAAI;AAAA,6CAAgD,CAC9D,CAEAJ,EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAmB5D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAExE;AA8ED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAYnF"}
|
package/dist/core/router.d.ts
CHANGED
|
@@ -19,6 +19,28 @@ export interface SimpleRouteOptions {
|
|
|
19
19
|
};
|
|
20
20
|
timeout?: number;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a router with routes - no express import needed!
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Style 1: Using GET, POST helpers
|
|
27
|
+
* const userRoutes = router('/api/users', [
|
|
28
|
+
* GET('/', async () => ({ users: [] })),
|
|
29
|
+
* GET('/:id', async (req) => ({ user: req.params.id })),
|
|
30
|
+
* POST('/', async (req) => ({ id: '123', ...req.body })),
|
|
31
|
+
* ]);
|
|
32
|
+
*
|
|
33
|
+
* // Style 2: Using route.get, route.post
|
|
34
|
+
* const userRoutes = router('/api/users', [
|
|
35
|
+
* route.get('/', async () => ({ users: [] })),
|
|
36
|
+
* route.post('/', async (req) => ({ ...req.body })),
|
|
37
|
+
* ]);
|
|
38
|
+
*
|
|
39
|
+
* server.use(userRoutes);
|
|
40
|
+
*/
|
|
41
|
+
export declare function router(basePath: string, routes: RouteDefinition[], options?: {
|
|
42
|
+
middleware?: RequestHandler[];
|
|
43
|
+
}): Router;
|
|
22
44
|
/**
|
|
23
45
|
* Define a GET route
|
|
24
46
|
*/
|
|
@@ -40,9 +62,25 @@ export declare function PATCH(path: string, handler: RouteHandlerFn, options?: S
|
|
|
40
62
|
*/
|
|
41
63
|
export declare function DELETE(path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions): RouteDefinition;
|
|
42
64
|
/**
|
|
43
|
-
*
|
|
65
|
+
* Route helper object - alternative syntax
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const userRoutes = router('/api/users', [
|
|
69
|
+
* route.get('/', async () => ({ users: [] })),
|
|
70
|
+
* route.post('/', async (req) => ({ ...req.body })),
|
|
71
|
+
* route.put('/:id', async (req) => ({ id: req.params.id })),
|
|
72
|
+
* route.delete('/:id', async (req) => ({ deleted: true })),
|
|
73
|
+
* ]);
|
|
44
74
|
*/
|
|
45
|
-
export declare
|
|
75
|
+
export declare const route: {
|
|
76
|
+
get: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
77
|
+
post: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
78
|
+
put: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
79
|
+
patch: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
80
|
+
delete: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
81
|
+
options: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
82
|
+
head: (path: string, handler: RouteHandlerFn, options?: SimpleRouteOptions) => RouteDefinition;
|
|
83
|
+
};
|
|
46
84
|
export declare class RouteBuilder {
|
|
47
85
|
private _route;
|
|
48
86
|
private _options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAQlB,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED,wBAAgB,Y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IAAI,YAAY;IAI7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKxB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIvB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIvB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIzB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe;IAe/C,GAAG,CAAC,GAAG,GAAG,EAAE,WAAW,EAAE,GAAG,IAAI;IAKhC,MAAM,CAAC,GAAG,GAAG,EAAE,YAAY,EAAE,GAAG,IAAI;IAKpC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,IAAI;IAKtD,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,IAAI;IAKlD,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,IAAI;IAKxC,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI;IAK1C,KAAK,IAAI,eAAe;CAYzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAEZ,mBAAmB,EAKpB,MAAM,UAAU,CAAC;AASlB,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAEZ,mBAAmB,EAKpB,MAAM,UAAU,CAAC;AASlB,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAkL5E"}
|
|
@@ -4,8 +4,8 @@ import { ConnectionOptions, ConnectionState } from './types';
|
|
|
4
4
|
type EventCallback = (...args: unknown[]) => void;
|
|
5
5
|
declare class HarborConnection extends EventEmitter {
|
|
6
6
|
private _state;
|
|
7
|
+
private _uri;
|
|
7
8
|
private _options;
|
|
8
|
-
private _connectionUri;
|
|
9
9
|
private _mongoClient;
|
|
10
10
|
private _db;
|
|
11
11
|
private _models;
|
|
@@ -16,7 +16,6 @@ declare class HarborConnection extends EventEmitter {
|
|
|
16
16
|
get db(): unknown;
|
|
17
17
|
get client(): unknown;
|
|
18
18
|
get models(): Map<string, unknown>;
|
|
19
|
-
get uri(): string;
|
|
20
19
|
connect(uri: string, options?: ConnectionOptions): Promise<this>;
|
|
21
20
|
disconnect(): Promise<void>;
|
|
22
21
|
close(): Promise<void>;
|