@synchjs/ewb 1.0.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.
Files changed (41) hide show
  1. package/README.md +292 -0
  2. package/dist/Components/ServeMemoryStore.d.ts +14 -0
  3. package/dist/Components/ServeMemoryStore.d.ts.map +1 -0
  4. package/dist/Components/ServeMemoryStore.js +77 -0
  5. package/dist/Components/Server.d.ts +48 -0
  6. package/dist/Components/Server.d.ts.map +1 -0
  7. package/dist/Components/Server.js +441 -0
  8. package/dist/Decorations/Authorized.d.ts +8 -0
  9. package/dist/Decorations/Authorized.d.ts.map +1 -0
  10. package/dist/Decorations/Authorized.js +20 -0
  11. package/dist/Decorations/Controller.d.ts +8 -0
  12. package/dist/Decorations/Controller.d.ts.map +1 -0
  13. package/dist/Decorations/Controller.js +21 -0
  14. package/dist/Decorations/Metadata.d.ts +30 -0
  15. package/dist/Decorations/Metadata.d.ts.map +1 -0
  16. package/dist/Decorations/Metadata.js +32 -0
  17. package/dist/Decorations/Methods.d.ts +8 -0
  18. package/dist/Decorations/Methods.d.ts.map +1 -0
  19. package/dist/Decorations/Methods.js +52 -0
  20. package/dist/Decorations/Middleware.d.ts +5 -0
  21. package/dist/Decorations/Middleware.d.ts.map +1 -0
  22. package/dist/Decorations/Middleware.js +19 -0
  23. package/dist/Decorations/Security.d.ts +9 -0
  24. package/dist/Decorations/Security.d.ts.map +1 -0
  25. package/dist/Decorations/Security.js +24 -0
  26. package/dist/Decorations/Serve.d.ts +2 -0
  27. package/dist/Decorations/Serve.d.ts.map +1 -0
  28. package/dist/Decorations/Serve.js +31 -0
  29. package/dist/Decorations/Tailwind.d.ts +7 -0
  30. package/dist/Decorations/Tailwind.d.ts.map +1 -0
  31. package/dist/Decorations/Tailwind.js +8 -0
  32. package/dist/Decorations/index.d.ts +9 -0
  33. package/dist/Decorations/index.d.ts.map +1 -0
  34. package/dist/Decorations/index.js +8 -0
  35. package/dist/globals.d.ts +6 -0
  36. package/dist/globals.d.ts.map +1 -0
  37. package/dist/globals.js +0 -0
  38. package/dist/index.d.ts +5 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +5 -0
  41. package/package.json +51 -0
@@ -0,0 +1,19 @@
1
+ import "reflect-metadata";
2
+ export function Use(...middlewares) {
3
+ return function (target, propertyKey, descriptor) {
4
+ if (propertyKey) {
5
+ // Method Level Decorator
6
+ const current = Reflect.getMetadata("middlewares", target, propertyKey) || [];
7
+ Reflect.defineMetadata("middlewares", [...current, ...middlewares], target, propertyKey);
8
+ }
9
+ else {
10
+ // Class Level Decorator
11
+ // Note: For constructor, target is the constructor itself
12
+ const current = Reflect.getMetadata("middlewares", target) || [];
13
+ Reflect.defineMetadata("middlewares", [...current, ...middlewares], target);
14
+ }
15
+ };
16
+ }
17
+ export function Middleware(...middlewares) {
18
+ return Use(...middlewares);
19
+ }
@@ -0,0 +1,9 @@
1
+ import "reflect-metadata";
2
+ export declare const SECURITY_METADATA_KEY: unique symbol;
3
+ export interface SecurityRequirement {
4
+ [name: string]: string[];
5
+ }
6
+ export declare function Security(name: string, scopes?: string[]): MethodDecorator & ClassDecorator;
7
+ export declare function OAuth(scopes?: string[]): MethodDecorator & ClassDecorator;
8
+ export declare function ApiKey(name: string): MethodDecorator & ClassDecorator;
9
+ //# sourceMappingURL=Security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Security.d.ts","sourceRoot":"","sources":["../../src/Decorations/Security.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,eAAO,MAAM,qBAAqB,eAAqB,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,EAAO,GACpB,eAAe,GAAG,cAAc,CAyBlC;AAED,wBAAgB,KAAK,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,eAAe,GAAG,cAAc,CAE7E;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,cAAc,CAErE"}
@@ -0,0 +1,24 @@
1
+ import "reflect-metadata";
2
+ export const SECURITY_METADATA_KEY = Symbol("security");
3
+ export function Security(name, scopes = []) {
4
+ return function (target, propertyKey, descriptor) {
5
+ if (propertyKey) {
6
+ // Method decorator
7
+ const existing = Reflect.getMetadata(SECURITY_METADATA_KEY, target, propertyKey) || [];
8
+ existing.push({ [name]: scopes });
9
+ Reflect.defineMetadata(SECURITY_METADATA_KEY, existing, target, propertyKey);
10
+ }
11
+ else {
12
+ // Class decorator
13
+ const existing = Reflect.getMetadata(SECURITY_METADATA_KEY, target) || [];
14
+ existing.push({ [name]: scopes });
15
+ Reflect.defineMetadata(SECURITY_METADATA_KEY, existing, target);
16
+ }
17
+ };
18
+ }
19
+ export function OAuth(scopes = []) {
20
+ return Security("oauth2", scopes);
21
+ }
22
+ export function ApiKey(name) {
23
+ return Security(name, []);
24
+ }
@@ -0,0 +1,2 @@
1
+ export declare function Serve(htmlPath: string): MethodDecorator;
2
+ //# sourceMappingURL=Serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serve.d.ts","sourceRoot":"","sources":["../../src/Decorations/Serve.ts"],"names":[],"mappings":"AAIA,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CA2CvD"}
@@ -0,0 +1,31 @@
1
+ import { ServeMemoryStore } from "../Components/ServeMemoryStore";
2
+ import { TAILWIND_METADATA_KEY } from "./Tailwind";
3
+ export function Serve(htmlPath) {
4
+ return function (target, propertyKey, descriptor) {
5
+ const originalMethod = descriptor.value;
6
+ descriptor.value = async function (req, res, next) {
7
+ try {
8
+ // Execute the original method
9
+ const result = await originalMethod.apply(this, [req, res, next]);
10
+ // Check if response has been sent or if result is not undefined/void
11
+ if (res.headersSent || result !== undefined) {
12
+ return result;
13
+ }
14
+ // Check if Tailwind is enabled for the controller
15
+ const tailwindOptions = Reflect.getMetadata(TAILWIND_METADATA_KEY, target.constructor) || {};
16
+ // If no response, build and serve the HTML
17
+ const html = await ServeMemoryStore.instance.buildAndCache(htmlPath, tailwindOptions);
18
+ if (html) {
19
+ res.type("html").send(html);
20
+ }
21
+ else {
22
+ next(); // No HTML found?
23
+ }
24
+ }
25
+ catch (error) {
26
+ next(error);
27
+ }
28
+ };
29
+ return descriptor;
30
+ };
31
+ }
@@ -0,0 +1,7 @@
1
+ export declare const TAILWIND_METADATA_KEY = "serve:tailwind";
2
+ export interface TailwindOptions {
3
+ enable?: boolean;
4
+ plugins?: any[];
5
+ }
6
+ export declare function Tailwindcss(options?: TailwindOptions): ClassDecorator;
7
+ //# sourceMappingURL=Tailwind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tailwind.d.ts","sourceRoot":"","sources":["../../src/Decorations/Tailwind.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,eAAoB,GAAG,cAAc,CAMzE"}
@@ -0,0 +1,8 @@
1
+ export const TAILWIND_METADATA_KEY = "serve:tailwind";
2
+ export function Tailwindcss(options = {}) {
3
+ return function (target) {
4
+ const defaultOptions = { enable: true, plugins: [] };
5
+ const finalOptions = { ...defaultOptions, ...options };
6
+ Reflect.defineMetadata(TAILWIND_METADATA_KEY, finalOptions, target);
7
+ };
8
+ }
@@ -0,0 +1,9 @@
1
+ export * from "./Controller";
2
+ export * from "./Methods";
3
+ export * from "./Metadata";
4
+ export * from "./Middleware";
5
+ export * from "./Authorized";
6
+ export * from "./Serve";
7
+ export * from "./Tailwind";
8
+ export * from "./Security";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Decorations/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from "./Controller";
2
+ export * from "./Methods";
3
+ export * from "./Metadata";
4
+ export * from "./Middleware";
5
+ export * from "./Authorized";
6
+ export * from "./Serve";
7
+ export * from "./Tailwind";
8
+ export * from "./Security";
@@ -0,0 +1,6 @@
1
+ import type { Express } from "express";
2
+ declare global {
3
+ var servers: Map<string, Express>;
4
+ }
5
+ export {};
6
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,OAAO,EAAE,CAAC"}
File without changes
@@ -0,0 +1,5 @@
1
+ import "./globals";
2
+ export * from "./Components/Server";
3
+ export * from "./Components/ServeMemoryStore";
4
+ export * from "./Decorations";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,WAAW,CAAC;AACnB,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ global.servers = new Map();
2
+ import "./globals";
3
+ export * from "./Components/Server";
4
+ export * from "./Components/ServeMemoryStore";
5
+ export * from "./Decorations";
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@synchjs/ewb",
3
+ "version": "1.0.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "type": "module",
14
+ "devDependencies": {
15
+ "@tailwindcss/postcss": "^4.1.18",
16
+ "@types/bun": "latest",
17
+ "autoprefixer": "^10.4.24",
18
+ "postcss": "^8.5.6"
19
+ },
20
+ "peerDependencies": {
21
+ "typescript": "^5"
22
+ },
23
+ "scripts": {
24
+ "build": "bun x tsc -p tsconfig.build.json",
25
+ "prepublishOnly": "bun run build",
26
+ "example": "bun run --watch example/index.ts"
27
+ },
28
+ "dependencies": {
29
+ "ajv": "^8.18.0",
30
+ "ajv-formats": "^3.0.1",
31
+ "boxen": "^8.0.1",
32
+ "bun-plugin-tailwind": "^0.1.2",
33
+ "cors": "^2.8.6",
34
+ "express": "^5.2.1",
35
+ "express-rate-limit": "^8.2.1",
36
+ "helmet": "^8.1.0",
37
+ "jsonwebtoken": "^9.0.3",
38
+ "picocolors": "^1.1.1",
39
+ "reflect-metadata": "^0.2.2",
40
+ "swagger-jsdoc": "^6.2.8",
41
+ "swagger-ui-express": "^5.0.1",
42
+ "tailwindcss": "^4.1.18",
43
+ "openapi-types": "^12.1.3",
44
+ "@types/express": "^5.0.6",
45
+ "@types/cors": "^2.8.19",
46
+ "@types/jsonwebtoken": "^9.0.10",
47
+ "@types/swagger-jsdoc": "^6.0.4",
48
+ "@types/swagger-ui-express": "^4.1.8",
49
+ "@types/express-serve-static-core": "^5.1.1"
50
+ }
51
+ }