@flexireact/core 1.0.2 → 2.0.1

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 (37) hide show
  1. package/README.md +112 -112
  2. package/bin/flexireact.js +23 -0
  3. package/cli/index.ts +9 -21
  4. package/core/cli/{logger.js → logger.ts} +8 -2
  5. package/core/client/{hydration.js → hydration.ts} +10 -0
  6. package/core/client/{islands.js → islands.ts} +6 -1
  7. package/core/client/{navigation.js → navigation.ts} +10 -2
  8. package/core/client/{runtime.js → runtime.ts} +16 -0
  9. package/core/{config.js → config.ts} +7 -4
  10. package/core/{index.js → index.ts} +6 -2
  11. package/core/islands/{index.js → index.ts} +16 -4
  12. package/core/{logger.js → logger.ts} +1 -1
  13. package/core/middleware/{index.js → index.ts} +32 -9
  14. package/core/plugins/{index.js → index.ts} +9 -6
  15. package/core/render/index.ts +1069 -0
  16. package/core/{render.js → render.ts} +7 -5
  17. package/core/router/index.ts +543 -0
  18. package/core/rsc/{index.js → index.ts} +6 -5
  19. package/core/server/{index.js → index.ts} +25 -6
  20. package/core/{server.js → server.ts} +8 -2
  21. package/core/ssg/{index.js → index.ts} +30 -5
  22. package/core/start-dev.ts +6 -0
  23. package/core/start-prod.ts +6 -0
  24. package/core/tsconfig.json +28 -0
  25. package/core/types.ts +239 -0
  26. package/package.json +20 -15
  27. package/cli/index.js +0 -992
  28. package/core/render/index.js +0 -773
  29. package/core/router/index.js +0 -296
  30. /package/core/{api.js → api.ts} +0 -0
  31. /package/core/build/{index.js → index.ts} +0 -0
  32. /package/core/client/{index.js → index.ts} +0 -0
  33. /package/core/{context.js → context.ts} +0 -0
  34. /package/core/{dev.js → dev.ts} +0 -0
  35. /package/core/{loader.js → loader.ts} +0 -0
  36. /package/core/{router.js → router.ts} +0 -0
  37. /package/core/{utils.js → utils.ts} +0 -0
@@ -29,8 +29,22 @@ import { pathToFileURL } from 'url';
29
29
  /**
30
30
  * Middleware response helpers
31
31
  */
32
+ interface MiddlewareResponseOptions {
33
+ type?: string;
34
+ status?: number;
35
+ headers?: Record<string, string>;
36
+ body?: any;
37
+ url?: string | null;
38
+ }
39
+
32
40
  export class MiddlewareResponse {
33
- constructor(options = {}) {
41
+ type: string;
42
+ status: number;
43
+ headers: Map<string, string>;
44
+ body: any;
45
+ url: string | null;
46
+
47
+ constructor(options: MiddlewareResponseOptions = {}) {
34
48
  this.type = options.type || 'next';
35
49
  this.status = options.status || 200;
36
50
  this.headers = new Map(Object.entries(options.headers || {}));
@@ -69,7 +83,7 @@ export class MiddlewareResponse {
69
83
  /**
70
84
  * Return a JSON response
71
85
  */
72
- static json(data, options = {}) {
86
+ static json(data: any, options: { status?: number; headers?: Record<string, string> } = {}) {
73
87
  return new MiddlewareResponse({
74
88
  type: 'response',
75
89
  status: options.status || 200,
@@ -81,7 +95,7 @@ export class MiddlewareResponse {
81
95
  /**
82
96
  * Return an HTML response
83
97
  */
84
- static html(content, options = {}) {
98
+ static html(content: string, options: { status?: number; headers?: Record<string, string> } = {}) {
85
99
  return new MiddlewareResponse({
86
100
  type: 'response',
87
101
  status: options.status || 200,
@@ -95,7 +109,16 @@ export class MiddlewareResponse {
95
109
  * Middleware request wrapper
96
110
  */
97
111
  export class MiddlewareRequest {
98
- constructor(req) {
112
+ raw: any;
113
+ method: string;
114
+ url: string;
115
+ headers: Map<string, string>;
116
+ pathname: string;
117
+ searchParams: URLSearchParams;
118
+ query: Record<string, string>;
119
+ cookies: Map<string, string>;
120
+
121
+ constructor(req: any) {
99
122
  this.raw = req;
100
123
  this.method = req.method;
101
124
  this.url = req.url;
@@ -105,7 +128,7 @@ export class MiddlewareRequest {
105
128
  const parsedUrl = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
106
129
  this.pathname = parsedUrl.pathname;
107
130
  this.searchParams = parsedUrl.searchParams;
108
- this.query = Object.fromEntries(parsedUrl.searchParams);
131
+ this.query = Object.fromEntries(parsedUrl.searchParams) as Record<string, string>;
109
132
 
110
133
  // Parse cookies
111
134
  this.cookies = this._parseCookies(req.headers.cookie || '');
@@ -274,7 +297,7 @@ export const middlewares = {
274
297
  /**
275
298
  * CORS middleware
276
299
  */
277
- cors(options = {}) {
300
+ cors(options: { origin?: string; methods?: string; headers?: string; credentials?: boolean } = {}) {
278
301
  const {
279
302
  origin = '*',
280
303
  methods = 'GET,HEAD,PUT,PATCH,POST,DELETE',
@@ -294,7 +317,7 @@ export const middlewares = {
294
317
 
295
318
  // Handle preflight
296
319
  if (request.method === 'OPTIONS') {
297
- return MiddlewareResponse.json({}, { status: 204, headers: response.headers });
320
+ return MiddlewareResponse.json({}, { status: 204, headers: Object.fromEntries(response.headers) });
298
321
  }
299
322
 
300
323
  return response;
@@ -330,7 +353,7 @@ export const middlewares = {
330
353
  /**
331
354
  * Rate limiting middleware
332
355
  */
333
- rateLimit(options = {}) {
356
+ rateLimit(options: { windowMs?: number; max?: number } = {}) {
334
357
  const { windowMs = 60000, max = 100 } = options;
335
358
  const requests = new Map();
336
359
 
@@ -369,7 +392,7 @@ export const middlewares = {
369
392
  /**
370
393
  * Logging middleware
371
394
  */
372
- logger(options = {}) {
395
+ logger(options: { format?: string } = {}) {
373
396
  const { format = 'combined' } = options;
374
397
 
375
398
  return (request) => {
@@ -65,13 +65,16 @@ export const PluginHooks = {
65
65
  * Plugin manager class
66
66
  */
67
67
  export class PluginManager {
68
+ plugins: any[];
69
+ hooks: Map<string, any[]>;
70
+
68
71
  constructor() {
69
72
  this.plugins = [];
70
73
  this.hooks = new Map();
71
74
 
72
75
  // Initialize hook arrays
73
76
  for (const hook of Object.values(PluginHooks)) {
74
- this.hooks.set(hook, []);
77
+ this.hooks.set(hook as string, []);
75
78
  }
76
79
  }
77
80
 
@@ -248,7 +251,7 @@ export const builtinPlugins = {
248
251
  /**
249
252
  * Analytics plugin
250
253
  */
251
- analytics(options = {}) {
254
+ analytics(options: { trackingId?: string } = {}) {
252
255
  const { trackingId } = options;
253
256
 
254
257
  return definePlugin({
@@ -275,7 +278,7 @@ export const builtinPlugins = {
275
278
  /**
276
279
  * PWA plugin
277
280
  */
278
- pwa(options = {}) {
281
+ pwa(options: { manifest?: string; serviceWorker?: string } = {}) {
279
282
  const { manifest = '/manifest.json', serviceWorker = '/sw.js' } = options;
280
283
 
281
284
  return definePlugin({
@@ -299,7 +302,7 @@ export const builtinPlugins = {
299
302
  /**
300
303
  * SEO plugin
301
304
  */
302
- seo(options = {}) {
305
+ seo(options: { defaultTitle?: string; titleTemplate?: string; defaultDescription?: string } = {}) {
303
306
  const { defaultTitle, titleTemplate = '%s', defaultDescription } = options;
304
307
 
305
308
  return definePlugin({
@@ -339,8 +342,8 @@ export const builtinPlugins = {
339
342
  /**
340
343
  * Security headers plugin
341
344
  */
342
- securityHeaders(options = {}) {
343
- const headers = {
345
+ securityHeaders(options: { headers?: Record<string, string> } = {}) {
346
+ const headers: Record<string, string> = {
344
347
  'X-Content-Type-Options': 'nosniff',
345
348
  'X-Frame-Options': 'DENY',
346
349
  'X-XSS-Protection': '1; mode=block',