Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions core/cli/command-registry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { CliCommand, CliContext, CliArgument, CliOption } from "../plugins/types"
import type { CliCommand, CliContext, CliArgument, CliOption, PluginConfigSchema } from "../plugins/types"
import { fluxStackConfig } from "@config"
import { logger } from "@core/utils/logger"
import { createTimer, formatBytes, isProduction, isDevelopment } from "../utils/helpers"
import { createHash } from "crypto"
import { createPluginUtils } from "../plugins/config"

export class CliCommandRegistry {
private commands = new Map<string, CliCommand>()
Expand Down Expand Up @@ -35,12 +36,8 @@ export class CliCommandRegistry {
}
return result
},
validateSchema: (_data: unknown, _schema: unknown) => {
try {
return { valid: true, errors: [] }
} catch (error) {
return { valid: false, errors: [error instanceof Error ? error.message : 'Validation failed'] }
}
validateSchema: (data: Record<string, unknown>, schema: PluginConfigSchema) => {
return createPluginUtils(logger).validateSchema(data, schema)
}
},
workingDir: process.cwd(),
Expand Down
4 changes: 2 additions & 2 deletions core/cli/generators/__tests__/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('Code Generators', () => {
createHash: (data: string) => {
return createHash('sha256').update(data).digest('hex')
},
deepMerge: (target: any, source: any) => {
deepMerge: (target: Record<string, unknown>, source: Record<string, unknown>) => {
const result = { ...target }
for (const key in source) {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
result[key] = context.utils.deepMerge(result[key] || {}, source[key])
result[key] = context.utils.deepMerge(result[key] as Record<string, unknown> || {}, source[key] as Record<string, unknown>)
} else {
result[key] = source[key]
}
Expand Down
17 changes: 6 additions & 11 deletions core/framework/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Elysia } from "elysia"
import type { FluxStackConfig, FluxStackContext } from "@core/types"
import type { FluxStack, PluginContext, PluginUtils } from "@core/plugins/types"
import type { FluxStack, PluginContext, PluginUtils, PluginConfigSchema } from "@core/plugins/types"
import { PluginRegistry } from "@core/plugins/registry"
import { PluginManager } from "@core/plugins/manager"
import { fluxStackConfig } from "@config"
Expand All @@ -11,6 +11,7 @@ import { componentRegistry } from "@core/server/live"
import { FluxStackError } from "@core/utils/errors"
import { createTimer, formatBytes, isProduction, isDevelopment } from "@core/utils/helpers"
import { createHash } from "crypto"
import { createPluginUtils } from "@core/plugins/config"
import type { Plugin } from "@core/plugins"

export class FluxStackFramework {
Expand Down Expand Up @@ -99,25 +100,19 @@ export class FluxStackFramework {
createHash: (data: string) => {
return createHash('sha256').update(data).digest('hex')
},
deepMerge: (target: any, source: any) => {
deepMerge: (target: Record<string, unknown>, source: Record<string, unknown>) => {
const result = { ...target }
for (const key in source) {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
result[key] = pluginUtils.deepMerge(result[key] || {}, source[key])
result[key] = pluginUtils.deepMerge(result[key] as Record<string, unknown> || {}, source[key] as Record<string, unknown>)
} else {
result[key] = source[key]
}
}
return result
},
validateSchema: (_data: any, _schema: any) => {
// Simple validation - in a real implementation you'd use a proper schema validator
try {
// Basic validation logic
return { valid: true, errors: [] }
} catch (error) {
return { valid: false, errors: [error instanceof Error ? error.message : 'Validation failed'] }
}
validateSchema: (data: Record<string, unknown>, schema: PluginConfigSchema) => {
return createPluginUtils(logger).validateSchema(data, schema)
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class DefaultPluginConfigManager implements PluginConfigManager {
/**
* Deep merge two objects
*/
private deepMerge(target: any, source: any): any {
deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {
if (source === null || source === undefined) {
return target
}
Expand All @@ -274,7 +274,7 @@ export class DefaultPluginConfigManager implements PluginConfigManager {
for (const key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] === 'object' && !Array.isArray(source[key]) && source[key] !== null) {
result[key] = this.deepMerge(target[key], source[key])
result[key] = this.deepMerge(target[key] as Record<string, unknown>, source[key] as Record<string, unknown>)
} else {
result[key] = source[key]
}
Expand Down Expand Up @@ -335,11 +335,11 @@ export function createPluginUtils(logger?: Logger): PluginUtils {
return hash.toString(36)
},

deepMerge: (target: any, source: any): any => {
return (sharedConfigManager as any).deepMerge(target, source)
deepMerge: (target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> => {
return sharedConfigManager.deepMerge(target, source)
},

validateSchema: (data: any, schema: any): { valid: boolean; errors: string[] } => {
validateSchema: (data: Record<string, unknown>, schema: PluginConfigSchema): { valid: boolean; errors: string[] } => {
const result = sharedConfigManager.validatePluginConfig({ name: 'temp', configSchema: schema }, data)
return {
valid: result.valid,
Expand Down
4 changes: 2 additions & 2 deletions core/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export interface PluginUtils {
isDevelopment: () => boolean
getEnvironment: () => string
createHash: (data: string) => string
deepMerge: (target: any, source: any) => any
validateSchema: (data: any, schema: any) => { valid: boolean; errors: string[] }
deepMerge: (target: Record<string, unknown>, source: Record<string, unknown>) => Record<string, unknown>
validateSchema: (data: Record<string, unknown>, schema: PluginConfigSchema) => { valid: boolean; errors: string[] }
}

export interface RequestContext {
Expand Down
Loading
Loading