create-fluxstack 1.16.0 → 1.17.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.
- package/CHANGELOG.md +80 -0
- package/app/client/src/App.tsx +8 -0
- package/app/client/src/live/AuthDemo.tsx +4 -4
- package/core/build/bundler.ts +40 -26
- package/core/build/flux-plugins-generator.ts +325 -325
- package/core/build/index.ts +92 -21
- package/core/cli/command-registry.ts +44 -46
- package/core/cli/commands/build.ts +11 -6
- package/core/cli/commands/create.ts +7 -5
- package/core/cli/commands/dev.ts +6 -5
- package/core/cli/commands/help.ts +3 -2
- package/core/cli/commands/make-plugin.ts +8 -7
- package/core/cli/commands/plugin-add.ts +60 -43
- package/core/cli/commands/plugin-deps.ts +73 -57
- package/core/cli/commands/plugin-list.ts +44 -41
- package/core/cli/commands/plugin-remove.ts +33 -22
- package/core/cli/generators/component.ts +770 -769
- package/core/cli/generators/controller.ts +9 -8
- package/core/cli/generators/index.ts +148 -146
- package/core/cli/generators/interactive.ts +228 -227
- package/core/cli/generators/plugin.ts +11 -10
- package/core/cli/generators/prompts.ts +83 -82
- package/core/cli/generators/route.ts +7 -6
- package/core/cli/generators/service.ts +10 -9
- package/core/cli/generators/template-engine.ts +2 -1
- package/core/cli/generators/types.ts +7 -7
- package/core/cli/generators/utils.ts +191 -191
- package/core/cli/index.ts +9 -8
- package/core/cli/plugin-discovery.ts +2 -2
- package/core/client/hooks/useAuth.ts +48 -48
- package/core/client/standalone.ts +18 -17
- package/core/client/state/createStore.ts +192 -192
- package/core/client/state/index.ts +14 -14
- package/core/config/index.ts +1 -0
- package/core/framework/client.ts +131 -131
- package/core/framework/index.ts +7 -7
- package/core/framework/server.ts +73 -113
- package/core/framework/types.ts +2 -2
- package/core/plugins/built-in/live-components/commands/create-live-component.ts +6 -3
- package/core/plugins/built-in/monitoring/index.ts +110 -68
- package/core/plugins/built-in/static/index.ts +2 -2
- package/core/plugins/built-in/swagger/index.ts +9 -9
- package/core/plugins/built-in/vite/index.ts +3 -3
- package/core/plugins/built-in/vite/vite-dev.ts +3 -3
- package/core/plugins/config.ts +50 -47
- package/core/plugins/discovery.ts +10 -4
- package/core/plugins/executor.ts +2 -2
- package/core/plugins/index.ts +206 -203
- package/core/plugins/manager.ts +21 -20
- package/core/plugins/registry.ts +76 -12
- package/core/plugins/types.ts +14 -14
- package/core/server/framework.ts +3 -189
- package/core/server/live/auto-generated-components.ts +11 -29
- package/core/server/live/index.ts +41 -31
- package/core/server/live/websocket-plugin.ts +11 -1
- package/core/server/middleware/elysia-helpers.ts +16 -15
- package/core/server/middleware/errorHandling.ts +14 -14
- package/core/server/middleware/index.ts +31 -31
- package/core/server/plugins/database.ts +181 -180
- package/core/server/plugins/static-files-plugin.ts +4 -3
- package/core/server/plugins/swagger.ts +11 -8
- package/core/server/rooms/RoomBroadcaster.ts +11 -10
- package/core/server/rooms/RoomSystem.ts +14 -11
- package/core/server/services/BaseService.ts +7 -7
- package/core/server/services/ServiceContainer.ts +5 -5
- package/core/server/services/index.ts +8 -8
- package/core/templates/create-project.ts +28 -27
- package/core/testing/index.ts +9 -9
- package/core/testing/setup.ts +73 -73
- package/core/types/api.ts +168 -168
- package/core/types/config.ts +5 -5
- package/core/types/index.ts +1 -1
- package/core/types/plugin.ts +2 -2
- package/core/types/types.ts +3 -3
- package/core/utils/build-logger.ts +324 -324
- package/core/utils/config-schema.ts +480 -480
- package/core/utils/env.ts +10 -8
- package/core/utils/errors/codes.ts +114 -114
- package/core/utils/errors/handlers.ts +30 -20
- package/core/utils/errors/index.ts +54 -46
- package/core/utils/errors/middleware.ts +113 -113
- package/core/utils/helpers.ts +19 -16
- package/core/utils/logger/colors.ts +114 -114
- package/core/utils/logger/config.ts +2 -2
- package/core/utils/logger/formatter.ts +82 -82
- package/core/utils/logger/group-logger.ts +101 -101
- package/core/utils/logger/index.ts +13 -3
- package/core/utils/logger/startup-banner.ts +2 -2
- package/core/utils/logger/winston-logger.ts +152 -152
- package/core/utils/monitoring/index.ts +211 -211
- package/core/utils/sync-version.ts +67 -66
- package/core/utils/version.ts +1 -1
- package/package.json +104 -100
- package/playwright-report/index.html +85 -0
- package/playwright.config.ts +31 -0
- package/plugins/crypto-auth/client/CryptoAuthClient.ts +302 -302
- package/plugins/crypto-auth/client/components/index.ts +11 -11
- package/plugins/crypto-auth/client/index.ts +11 -11
- package/plugins/crypto-auth/package.json +65 -65
- package/plugins/crypto-auth/server/CryptoAuthService.ts +185 -185
- package/plugins/crypto-auth/server/middlewares/cryptoAuthAdmin.ts +6 -5
- package/plugins/crypto-auth/server/middlewares/cryptoAuthPermissions.ts +6 -5
- package/plugins/crypto-auth/server/middlewares/cryptoAuthRequired.ts +3 -3
- package/plugins/crypto-auth/server/middlewares/index.ts +22 -22
- package/plugins/crypto-auth/server/middlewares.ts +19 -19
- package/vite.config.ts +13 -0
- package/app/client/.live-stubs/LiveAdminPanel.js +0 -5
- package/app/client/.live-stubs/LiveCounter.js +0 -9
- package/app/client/.live-stubs/LiveForm.js +0 -11
- package/app/client/.live-stubs/LiveLocalCounter.js +0 -8
- package/app/client/.live-stubs/LivePingPong.js +0 -10
- package/app/client/.live-stubs/LiveRoomChat.js +0 -11
- package/app/client/.live-stubs/LiveSharedCounter.js +0 -10
- package/app/client/.live-stubs/LiveUpload.js +0 -15
- package/app/server/live/register-components.ts +0 -19
- package/core/build/live-components-generator.ts +0 -321
- package/core/live/ComponentRegistry.ts +0 -403
- package/core/live/types.ts +0 -241
- package/workspace.json +0 -6
package/core/plugins/index.ts
CHANGED
|
@@ -1,204 +1,207 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enhanced Plugin System
|
|
3
|
-
* Comprehensive plugin system with lifecycle hooks, dependency management, and configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Core plugin types and interfaces
|
|
7
|
-
export type {
|
|
8
|
-
FluxStack,
|
|
9
|
-
PluginContext,
|
|
10
|
-
PluginHook,
|
|
11
|
-
PluginPriority,
|
|
12
|
-
PluginManifest,
|
|
13
|
-
PluginLoadResult,
|
|
14
|
-
PluginRegistryState,
|
|
15
|
-
PluginHookResult,
|
|
16
|
-
PluginMetrics,
|
|
17
|
-
PluginDiscoveryOptions,
|
|
18
|
-
PluginInstallOptions,
|
|
19
|
-
PluginExecutionContext,
|
|
20
|
-
PluginValidationResult,
|
|
21
|
-
HookExecutionOptions,
|
|
22
|
-
PluginLifecycleEvent,
|
|
23
|
-
PluginConfigSchema,
|
|
24
|
-
RequestContext,
|
|
25
|
-
ResponseContext,
|
|
26
|
-
ErrorContext,
|
|
27
|
-
BuildContext
|
|
28
|
-
} from './types'
|
|
29
|
-
|
|
30
|
-
export type Plugin = FluxStack.Plugin
|
|
31
|
-
|
|
32
|
-
// Plugin registry
|
|
33
|
-
export { PluginRegistry } from './registry'
|
|
34
|
-
export type { PluginRegistryConfig } from './registry'
|
|
35
|
-
|
|
36
|
-
// Plugin discovery
|
|
37
|
-
export { PluginDiscovery, pluginDiscovery } from './discovery'
|
|
38
|
-
export type { PluginDiscoveryConfig } from './discovery'
|
|
39
|
-
|
|
40
|
-
// Plugin configuration management
|
|
41
|
-
export {
|
|
42
|
-
DefaultPluginConfigManager,
|
|
43
|
-
createPluginUtils
|
|
44
|
-
} from './config'
|
|
45
|
-
export type { PluginConfigManager } from './config'
|
|
46
|
-
|
|
47
|
-
// Plugin manager
|
|
48
|
-
export {
|
|
49
|
-
PluginManager,
|
|
50
|
-
createRequestContext,
|
|
51
|
-
createResponseContext,
|
|
52
|
-
createErrorContext,
|
|
53
|
-
createBuildContext
|
|
54
|
-
} from './manager'
|
|
55
|
-
export type { PluginManagerConfig } from './manager'
|
|
56
|
-
|
|
57
|
-
// Module resolver for plugins
|
|
58
|
-
export { PluginModuleResolver } from './module-resolver'
|
|
59
|
-
export type { ModuleResolverConfig } from './module-resolver'
|
|
60
|
-
|
|
61
|
-
// Plugin executor
|
|
62
|
-
export {
|
|
63
|
-
PluginExecutor,
|
|
64
|
-
calculateExecutionStats
|
|
65
|
-
} from './executor'
|
|
66
|
-
export type {
|
|
67
|
-
PluginExecutionPlan,
|
|
68
|
-
PluginExecutionStep,
|
|
69
|
-
PluginExecutionStats
|
|
70
|
-
} from './executor'
|
|
71
|
-
|
|
72
|
-
// Utility functions for plugin development
|
|
73
|
-
export const PluginUtils = {
|
|
74
|
-
/**
|
|
75
|
-
* Create a simple plugin
|
|
76
|
-
*/
|
|
77
|
-
createPlugin: (config: {
|
|
78
|
-
name: string
|
|
79
|
-
version?: string
|
|
80
|
-
description?: string
|
|
81
|
-
dependencies?: string[]
|
|
82
|
-
priority?: number | PluginPriority
|
|
83
|
-
setup?: (context: PluginContext) => void | Promise<void>
|
|
84
|
-
onServerStart?: (context: PluginContext) => void | Promise<void>
|
|
85
|
-
onServerStop?: (context: PluginContext) => void | Promise<void>
|
|
86
|
-
onRequest?: (context: RequestContext) => void | Promise<void>
|
|
87
|
-
onBeforeRoute?: (context: RequestContext) => void | Promise<void>
|
|
88
|
-
onResponse?: (context: ResponseContext) => void | Promise<void>
|
|
89
|
-
onError?: (context: ErrorContext) => void | Promise<void>
|
|
90
|
-
configSchema?:
|
|
91
|
-
defaultConfig?:
|
|
92
|
-
}): Plugin => {
|
|
93
|
-
const plugin = {
|
|
94
|
-
name: config.name,
|
|
95
|
-
...(config.version && { version: config.version }),
|
|
96
|
-
...(config.description && { description: config.description }),
|
|
97
|
-
...(config.dependencies && { dependencies: config.dependencies }),
|
|
98
|
-
...(config.priority !== undefined && { priority: config.priority }),
|
|
99
|
-
...(config.setup && { setup: config.setup }),
|
|
100
|
-
...(config.onServerStart && { onServerStart: config.onServerStart }),
|
|
101
|
-
...(config.onServerStop && { onServerStop: config.onServerStop }),
|
|
102
|
-
...(config.onRequest && { onRequest: config.onRequest }),
|
|
103
|
-
...(config.onBeforeRoute && { onBeforeRoute: config.onBeforeRoute }),
|
|
104
|
-
...(config.onResponse && { onResponse: config.onResponse }),
|
|
105
|
-
...(config.onError && { onError: config.onError }),
|
|
106
|
-
...(config.configSchema && { configSchema: config.configSchema }),
|
|
107
|
-
...(config.defaultConfig
|
|
108
|
-
} as Plugin
|
|
109
|
-
return plugin
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Create a plugin manifest
|
|
114
|
-
*/
|
|
115
|
-
createManifest: (config: {
|
|
116
|
-
name: string
|
|
117
|
-
version: string
|
|
118
|
-
description: string
|
|
119
|
-
author: string
|
|
120
|
-
license: string
|
|
121
|
-
homepage?: string
|
|
122
|
-
repository?: string
|
|
123
|
-
keywords?: string[]
|
|
124
|
-
dependencies?: Record<string, string>
|
|
125
|
-
peerDependencies?: Record<string, string>
|
|
126
|
-
fluxstack: {
|
|
127
|
-
version: string
|
|
128
|
-
hooks: PluginHook[]
|
|
129
|
-
config?:
|
|
130
|
-
category?: string
|
|
131
|
-
tags?: string[]
|
|
132
|
-
}
|
|
133
|
-
}):
|
|
134
|
-
return {
|
|
135
|
-
name: config.name,
|
|
136
|
-
version: config.version || '1.0.0',
|
|
137
|
-
description: config.description,
|
|
138
|
-
author: config.author,
|
|
139
|
-
license: config.license,
|
|
140
|
-
homepage: config.homepage,
|
|
141
|
-
repository: config.repository,
|
|
142
|
-
keywords: config.keywords || [],
|
|
143
|
-
dependencies: config.dependencies || {},
|
|
144
|
-
peerDependencies: config.peerDependencies,
|
|
145
|
-
fluxstack: config.fluxstack
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Validate plugin structure
|
|
151
|
-
*/
|
|
152
|
-
validatePlugin: (plugin:
|
|
153
|
-
return (
|
|
154
|
-
plugin &&
|
|
155
|
-
typeof plugin === 'object' &&
|
|
156
|
-
|
|
157
|
-
plugin.name
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
'
|
|
177
|
-
'
|
|
178
|
-
'
|
|
179
|
-
'
|
|
180
|
-
'
|
|
181
|
-
'
|
|
182
|
-
'
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Plugin System
|
|
3
|
+
* Comprehensive plugin system with lifecycle hooks, dependency management, and configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Core plugin types and interfaces
|
|
7
|
+
export type {
|
|
8
|
+
FluxStack,
|
|
9
|
+
PluginContext,
|
|
10
|
+
PluginHook,
|
|
11
|
+
PluginPriority,
|
|
12
|
+
PluginManifest,
|
|
13
|
+
PluginLoadResult,
|
|
14
|
+
PluginRegistryState,
|
|
15
|
+
PluginHookResult,
|
|
16
|
+
PluginMetrics,
|
|
17
|
+
PluginDiscoveryOptions,
|
|
18
|
+
PluginInstallOptions,
|
|
19
|
+
PluginExecutionContext,
|
|
20
|
+
PluginValidationResult,
|
|
21
|
+
HookExecutionOptions,
|
|
22
|
+
PluginLifecycleEvent,
|
|
23
|
+
PluginConfigSchema,
|
|
24
|
+
RequestContext,
|
|
25
|
+
ResponseContext,
|
|
26
|
+
ErrorContext,
|
|
27
|
+
BuildContext
|
|
28
|
+
} from './types'
|
|
29
|
+
|
|
30
|
+
export type Plugin = FluxStack.Plugin
|
|
31
|
+
|
|
32
|
+
// Plugin registry
|
|
33
|
+
export { PluginRegistry } from './registry'
|
|
34
|
+
export type { PluginRegistryConfig } from './registry'
|
|
35
|
+
|
|
36
|
+
// Plugin discovery
|
|
37
|
+
export { PluginDiscovery, pluginDiscovery } from './discovery'
|
|
38
|
+
export type { PluginDiscoveryConfig } from './discovery'
|
|
39
|
+
|
|
40
|
+
// Plugin configuration management
|
|
41
|
+
export {
|
|
42
|
+
DefaultPluginConfigManager,
|
|
43
|
+
createPluginUtils
|
|
44
|
+
} from './config'
|
|
45
|
+
export type { PluginConfigManager } from './config'
|
|
46
|
+
|
|
47
|
+
// Plugin manager
|
|
48
|
+
export {
|
|
49
|
+
PluginManager,
|
|
50
|
+
createRequestContext,
|
|
51
|
+
createResponseContext,
|
|
52
|
+
createErrorContext,
|
|
53
|
+
createBuildContext
|
|
54
|
+
} from './manager'
|
|
55
|
+
export type { PluginManagerConfig } from './manager'
|
|
56
|
+
|
|
57
|
+
// Module resolver for plugins
|
|
58
|
+
export { PluginModuleResolver } from './module-resolver'
|
|
59
|
+
export type { ModuleResolverConfig } from './module-resolver'
|
|
60
|
+
|
|
61
|
+
// Plugin executor
|
|
62
|
+
export {
|
|
63
|
+
PluginExecutor,
|
|
64
|
+
calculateExecutionStats
|
|
65
|
+
} from './executor'
|
|
66
|
+
export type {
|
|
67
|
+
PluginExecutionPlan,
|
|
68
|
+
PluginExecutionStep,
|
|
69
|
+
PluginExecutionStats
|
|
70
|
+
} from './executor'
|
|
71
|
+
|
|
72
|
+
// Utility functions for plugin development
|
|
73
|
+
export const PluginUtils = {
|
|
74
|
+
/**
|
|
75
|
+
* Create a simple plugin
|
|
76
|
+
*/
|
|
77
|
+
createPlugin: (config: {
|
|
78
|
+
name: string
|
|
79
|
+
version?: string
|
|
80
|
+
description?: string
|
|
81
|
+
dependencies?: string[]
|
|
82
|
+
priority?: number | PluginPriority
|
|
83
|
+
setup?: (context: PluginContext) => void | Promise<void>
|
|
84
|
+
onServerStart?: (context: PluginContext) => void | Promise<void>
|
|
85
|
+
onServerStop?: (context: PluginContext) => void | Promise<void>
|
|
86
|
+
onRequest?: (context: RequestContext) => void | Promise<void>
|
|
87
|
+
onBeforeRoute?: (context: RequestContext) => void | Promise<void>
|
|
88
|
+
onResponse?: (context: ResponseContext) => void | Promise<void>
|
|
89
|
+
onError?: (context: ErrorContext) => void | Promise<void>
|
|
90
|
+
configSchema?: PluginConfigSchema
|
|
91
|
+
defaultConfig?: unknown
|
|
92
|
+
}): Plugin => {
|
|
93
|
+
const plugin = {
|
|
94
|
+
name: config.name,
|
|
95
|
+
...(config.version && { version: config.version }),
|
|
96
|
+
...(config.description && { description: config.description }),
|
|
97
|
+
...(config.dependencies && { dependencies: config.dependencies }),
|
|
98
|
+
...(config.priority !== undefined && { priority: config.priority }),
|
|
99
|
+
...(config.setup && { setup: config.setup }),
|
|
100
|
+
...(config.onServerStart && { onServerStart: config.onServerStart }),
|
|
101
|
+
...(config.onServerStop && { onServerStop: config.onServerStop }),
|
|
102
|
+
...(config.onRequest && { onRequest: config.onRequest }),
|
|
103
|
+
...(config.onBeforeRoute && { onBeforeRoute: config.onBeforeRoute }),
|
|
104
|
+
...(config.onResponse && { onResponse: config.onResponse }),
|
|
105
|
+
...(config.onError && { onError: config.onError }),
|
|
106
|
+
...(config.configSchema && { configSchema: config.configSchema }),
|
|
107
|
+
...(config.defaultConfig !== undefined ? { defaultConfig: config.defaultConfig } : {})
|
|
108
|
+
} as Plugin
|
|
109
|
+
return plugin
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Create a plugin manifest
|
|
114
|
+
*/
|
|
115
|
+
createManifest: (config: {
|
|
116
|
+
name: string
|
|
117
|
+
version: string
|
|
118
|
+
description: string
|
|
119
|
+
author: string
|
|
120
|
+
license: string
|
|
121
|
+
homepage?: string
|
|
122
|
+
repository?: string
|
|
123
|
+
keywords?: string[]
|
|
124
|
+
dependencies?: Record<string, string>
|
|
125
|
+
peerDependencies?: Record<string, string>
|
|
126
|
+
fluxstack: {
|
|
127
|
+
version: string
|
|
128
|
+
hooks: PluginHook[]
|
|
129
|
+
config?: PluginConfigSchema
|
|
130
|
+
category?: string
|
|
131
|
+
tags?: string[]
|
|
132
|
+
}
|
|
133
|
+
}): PluginManifest => {
|
|
134
|
+
return {
|
|
135
|
+
name: config.name,
|
|
136
|
+
version: config.version || '1.0.0',
|
|
137
|
+
description: config.description,
|
|
138
|
+
author: config.author,
|
|
139
|
+
license: config.license,
|
|
140
|
+
homepage: config.homepage,
|
|
141
|
+
repository: config.repository,
|
|
142
|
+
keywords: config.keywords || [],
|
|
143
|
+
dependencies: config.dependencies || {},
|
|
144
|
+
peerDependencies: config.peerDependencies,
|
|
145
|
+
fluxstack: config.fluxstack
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Validate plugin structure
|
|
151
|
+
*/
|
|
152
|
+
validatePlugin: (plugin: unknown): plugin is Plugin => {
|
|
153
|
+
return (
|
|
154
|
+
!!plugin &&
|
|
155
|
+
typeof plugin === 'object' &&
|
|
156
|
+
'name' in plugin &&
|
|
157
|
+
typeof (plugin as Record<string, unknown>).name === 'string' &&
|
|
158
|
+
((plugin as Record<string, unknown>).name as string).length > 0
|
|
159
|
+
)
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Check if plugin implements hook
|
|
164
|
+
*/
|
|
165
|
+
implementsHook: (plugin: Plugin, hook: PluginHook): boolean => {
|
|
166
|
+
const hookFunction = plugin[hook]
|
|
167
|
+
return !!hookFunction && typeof hookFunction === 'function'
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get plugin hooks
|
|
172
|
+
*/
|
|
173
|
+
getPluginHooks: (plugin: Plugin): PluginHook[] => {
|
|
174
|
+
const hooks: PluginHook[] = []
|
|
175
|
+
const possibleHooks: PluginHook[] = [
|
|
176
|
+
'setup',
|
|
177
|
+
'onServerStart',
|
|
178
|
+
'onServerStop',
|
|
179
|
+
'onRequest',
|
|
180
|
+
'onResponse',
|
|
181
|
+
'onError',
|
|
182
|
+
'onBuild',
|
|
183
|
+
'onBuildComplete'
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
for (const hook of possibleHooks) {
|
|
187
|
+
if (PluginUtils.implementsHook(plugin, hook)) {
|
|
188
|
+
hooks.push(hook)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return hooks
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Re-export types for convenience
|
|
197
|
+
import type {
|
|
198
|
+
PluginContext,
|
|
199
|
+
PluginConfigSchema,
|
|
200
|
+
PluginHook,
|
|
201
|
+
PluginManifest,
|
|
202
|
+
PluginPriority,
|
|
203
|
+
RequestContext,
|
|
204
|
+
ResponseContext,
|
|
205
|
+
ErrorContext,
|
|
206
|
+
FluxStack
|
|
204
207
|
} from './types'
|
package/core/plugins/manager.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* Handles plugin lifecycle, execution, and context management
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
7
|
FluxStack,
|
|
8
|
-
PluginContext,
|
|
9
|
-
PluginHook,
|
|
10
|
-
PluginHookResult,
|
|
8
|
+
PluginContext,
|
|
9
|
+
PluginHook,
|
|
10
|
+
PluginHookResult,
|
|
11
|
+
PluginLoadResult,
|
|
11
12
|
PluginMetrics,
|
|
12
13
|
PluginExecutionContext,
|
|
13
14
|
HookExecutionOptions,
|
|
@@ -43,14 +44,14 @@ function parseRequestURL(request: Request): URL {
|
|
|
43
44
|
export interface PluginManagerConfig {
|
|
44
45
|
config: FluxStackConfig
|
|
45
46
|
logger: Logger
|
|
46
|
-
app?:
|
|
47
|
+
app?: unknown
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export class PluginManager extends EventEmitter {
|
|
50
51
|
private registry: PluginRegistry
|
|
51
52
|
private config: FluxStackConfig
|
|
52
53
|
private logger: Logger
|
|
53
|
-
private app?:
|
|
54
|
+
private app?: unknown
|
|
54
55
|
private metrics: Map<string, PluginMetrics> = new Map()
|
|
55
56
|
private contexts: Map<string, PluginContext> = new Map()
|
|
56
57
|
private initialized = false
|
|
@@ -163,8 +164,8 @@ export class PluginManager extends EventEmitter {
|
|
|
163
164
|
* Execute a hook on all plugins
|
|
164
165
|
*/
|
|
165
166
|
async executeHook(
|
|
166
|
-
hook: PluginHook,
|
|
167
|
-
context?:
|
|
167
|
+
hook: PluginHook,
|
|
168
|
+
context?: unknown,
|
|
168
169
|
options: HookExecutionOptions = {}
|
|
169
170
|
): Promise<PluginHookResult[]> {
|
|
170
171
|
const {
|
|
@@ -259,7 +260,7 @@ export class PluginManager extends EventEmitter {
|
|
|
259
260
|
async executePluginHook(
|
|
260
261
|
plugin: Plugin,
|
|
261
262
|
hook: PluginHook,
|
|
262
|
-
context?:
|
|
263
|
+
context?: unknown,
|
|
263
264
|
options: { timeout?: number; retries?: number } = {}
|
|
264
265
|
): Promise<PluginHookResult> {
|
|
265
266
|
const { timeout = 30000, retries = 0 } = options
|
|
@@ -305,25 +306,25 @@ export class PluginManager extends EventEmitter {
|
|
|
305
306
|
})
|
|
306
307
|
|
|
307
308
|
// Execute the hook with appropriate context
|
|
308
|
-
let hookPromise: Promise<
|
|
309
|
+
let hookPromise: Promise<unknown>
|
|
309
310
|
|
|
310
311
|
switch (hook) {
|
|
311
312
|
case 'setup':
|
|
312
313
|
case 'onServerStart':
|
|
313
314
|
case 'onServerStop':
|
|
314
|
-
hookPromise = Promise.resolve(hookFunction
|
|
315
|
+
hookPromise = Promise.resolve((hookFunction as Function)(pluginContext))
|
|
315
316
|
break
|
|
316
317
|
case 'onRequest':
|
|
317
318
|
case 'onResponse':
|
|
318
319
|
case 'onError':
|
|
319
|
-
hookPromise = Promise.resolve(hookFunction
|
|
320
|
+
hookPromise = Promise.resolve((hookFunction as Function)(context))
|
|
320
321
|
break
|
|
321
322
|
case 'onBuild':
|
|
322
323
|
case 'onBuildComplete':
|
|
323
|
-
hookPromise = Promise.resolve(hookFunction
|
|
324
|
+
hookPromise = Promise.resolve((hookFunction as Function)(context))
|
|
324
325
|
break
|
|
325
326
|
default:
|
|
326
|
-
hookPromise = Promise.resolve(hookFunction(context || pluginContext))
|
|
327
|
+
hookPromise = Promise.resolve((hookFunction as Function)(context || pluginContext))
|
|
327
328
|
}
|
|
328
329
|
|
|
329
330
|
// Race between hook execution and timeout
|
|
@@ -408,8 +409,8 @@ export class PluginManager extends EventEmitter {
|
|
|
408
409
|
*/
|
|
409
410
|
private getEnabledPlugins(): Plugin[] {
|
|
410
411
|
const allPlugins = this.registry.getAll()
|
|
411
|
-
const enabledNames = this.config.plugins.enabled ?? []
|
|
412
|
-
const disabledNames = this.config.plugins.disabled ?? []
|
|
412
|
+
const enabledNames = (this.config.plugins.enabled ?? []) as string[]
|
|
413
|
+
const disabledNames = (this.config.plugins.disabled ?? []) as string[]
|
|
413
414
|
|
|
414
415
|
return allPlugins.filter(plugin => {
|
|
415
416
|
// If explicitly disabled, exclude
|
|
@@ -435,7 +436,7 @@ export class PluginManager extends EventEmitter {
|
|
|
435
436
|
// ⚠️ Built-in plugins are now registered manually via .use()
|
|
436
437
|
// No auto-discovery for core/plugins/built-in - developer chooses which to use
|
|
437
438
|
|
|
438
|
-
const results:
|
|
439
|
+
const results: PluginLoadResult[] = []
|
|
439
440
|
|
|
440
441
|
// 1. Discover project plugins (plugins/ directory)
|
|
441
442
|
this.logger.debug('Discovering project plugins in directory: plugins')
|
|
@@ -566,7 +567,7 @@ export class PluginManager extends EventEmitter {
|
|
|
566
567
|
/**
|
|
567
568
|
* Create request context from HTTP request
|
|
568
569
|
*/
|
|
569
|
-
export function createRequestContext(request: Request, additionalData:
|
|
570
|
+
export function createRequestContext(request: Request, additionalData: Record<string, unknown> = {}): RequestContext {
|
|
570
571
|
const url = parseRequestURL(request)
|
|
571
572
|
|
|
572
573
|
return {
|
|
@@ -593,7 +594,7 @@ export function createRequestContext(request: Request, additionalData: any = {})
|
|
|
593
594
|
export function createResponseContext(
|
|
594
595
|
requestContext: RequestContext,
|
|
595
596
|
response: Response,
|
|
596
|
-
additionalData:
|
|
597
|
+
additionalData: Record<string, unknown> = {}
|
|
597
598
|
): ResponseContext {
|
|
598
599
|
return {
|
|
599
600
|
...requestContext,
|
|
@@ -611,7 +612,7 @@ export function createResponseContext(
|
|
|
611
612
|
export function createErrorContext(
|
|
612
613
|
requestContext: RequestContext,
|
|
613
614
|
error: Error,
|
|
614
|
-
additionalData:
|
|
615
|
+
additionalData: Record<string, unknown> = {}
|
|
615
616
|
): ErrorContext {
|
|
616
617
|
return {
|
|
617
618
|
...requestContext,
|