@buenojs/bueno 0.8.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/.env.example +109 -0
- package/.github/workflows/ci.yml +31 -0
- package/LICENSE +21 -0
- package/README.md +892 -0
- package/architecture.md +652 -0
- package/bun.lock +70 -0
- package/dist/cli/index.js +3233 -0
- package/dist/index.js +9014 -0
- package/package.json +77 -0
- package/src/cache/index.ts +795 -0
- package/src/cli/ARCHITECTURE.md +837 -0
- package/src/cli/bin.ts +10 -0
- package/src/cli/commands/build.ts +425 -0
- package/src/cli/commands/dev.ts +248 -0
- package/src/cli/commands/generate.ts +541 -0
- package/src/cli/commands/help.ts +55 -0
- package/src/cli/commands/index.ts +112 -0
- package/src/cli/commands/migration.ts +355 -0
- package/src/cli/commands/new.ts +804 -0
- package/src/cli/commands/start.ts +208 -0
- package/src/cli/core/args.ts +283 -0
- package/src/cli/core/console.ts +349 -0
- package/src/cli/core/index.ts +60 -0
- package/src/cli/core/prompt.ts +424 -0
- package/src/cli/core/spinner.ts +265 -0
- package/src/cli/index.ts +135 -0
- package/src/cli/templates/deploy.ts +295 -0
- package/src/cli/templates/docker.ts +307 -0
- package/src/cli/templates/index.ts +24 -0
- package/src/cli/utils/fs.ts +428 -0
- package/src/cli/utils/index.ts +8 -0
- package/src/cli/utils/strings.ts +197 -0
- package/src/config/env.ts +408 -0
- package/src/config/index.ts +506 -0
- package/src/config/loader.ts +329 -0
- package/src/config/merge.ts +285 -0
- package/src/config/types.ts +320 -0
- package/src/config/validation.ts +441 -0
- package/src/container/forward-ref.ts +143 -0
- package/src/container/index.ts +386 -0
- package/src/context/index.ts +360 -0
- package/src/database/index.ts +1142 -0
- package/src/database/migrations/index.ts +371 -0
- package/src/database/schema/index.ts +619 -0
- package/src/frontend/api-routes.ts +640 -0
- package/src/frontend/bundler.ts +643 -0
- package/src/frontend/console-client.ts +419 -0
- package/src/frontend/console-stream.ts +587 -0
- package/src/frontend/dev-server.ts +846 -0
- package/src/frontend/file-router.ts +611 -0
- package/src/frontend/frameworks/index.ts +106 -0
- package/src/frontend/frameworks/react.ts +85 -0
- package/src/frontend/frameworks/solid.ts +104 -0
- package/src/frontend/frameworks/svelte.ts +110 -0
- package/src/frontend/frameworks/vue.ts +92 -0
- package/src/frontend/hmr-client.ts +663 -0
- package/src/frontend/hmr.ts +728 -0
- package/src/frontend/index.ts +342 -0
- package/src/frontend/islands.ts +552 -0
- package/src/frontend/isr.ts +555 -0
- package/src/frontend/layout.ts +475 -0
- package/src/frontend/ssr/react.ts +446 -0
- package/src/frontend/ssr/solid.ts +523 -0
- package/src/frontend/ssr/svelte.ts +546 -0
- package/src/frontend/ssr/vue.ts +504 -0
- package/src/frontend/ssr.ts +699 -0
- package/src/frontend/types.ts +2274 -0
- package/src/health/index.ts +604 -0
- package/src/index.ts +410 -0
- package/src/lock/index.ts +587 -0
- package/src/logger/index.ts +444 -0
- package/src/logger/transports/index.ts +969 -0
- package/src/metrics/index.ts +494 -0
- package/src/middleware/built-in.ts +360 -0
- package/src/middleware/index.ts +94 -0
- package/src/modules/filters.ts +458 -0
- package/src/modules/guards.ts +405 -0
- package/src/modules/index.ts +1256 -0
- package/src/modules/interceptors.ts +574 -0
- package/src/modules/lazy.ts +418 -0
- package/src/modules/lifecycle.ts +478 -0
- package/src/modules/metadata.ts +90 -0
- package/src/modules/pipes.ts +626 -0
- package/src/router/index.ts +339 -0
- package/src/router/linear.ts +371 -0
- package/src/router/regex.ts +292 -0
- package/src/router/tree.ts +562 -0
- package/src/rpc/index.ts +1263 -0
- package/src/security/index.ts +436 -0
- package/src/ssg/index.ts +631 -0
- package/src/storage/index.ts +456 -0
- package/src/telemetry/index.ts +1097 -0
- package/src/testing/index.ts +1586 -0
- package/src/types/index.ts +236 -0
- package/src/types/optional-deps.d.ts +219 -0
- package/src/validation/index.ts +276 -0
- package/src/websocket/index.ts +1004 -0
- package/tests/integration/cli.test.ts +1016 -0
- package/tests/integration/fullstack.test.ts +234 -0
- package/tests/unit/cache.test.ts +174 -0
- package/tests/unit/cli-commands.test.ts +892 -0
- package/tests/unit/cli.test.ts +1258 -0
- package/tests/unit/container.test.ts +279 -0
- package/tests/unit/context.test.ts +221 -0
- package/tests/unit/database.test.ts +183 -0
- package/tests/unit/linear-router.test.ts +280 -0
- package/tests/unit/lock.test.ts +336 -0
- package/tests/unit/middleware.test.ts +184 -0
- package/tests/unit/modules.test.ts +142 -0
- package/tests/unit/pubsub.test.ts +257 -0
- package/tests/unit/regex-router.test.ts +265 -0
- package/tests/unit/router.test.ts +373 -0
- package/tests/unit/rpc.test.ts +1248 -0
- package/tests/unit/security.test.ts +174 -0
- package/tests/unit/telemetry.test.ts +371 -0
- package/tests/unit/test-cache.test.ts +110 -0
- package/tests/unit/test-database.test.ts +282 -0
- package/tests/unit/tree-router.test.ts +325 -0
- package/tests/unit/validation.test.ts +794 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration type definitions for Bueno Framework
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { StandardSchema } from "../types";
|
|
6
|
+
|
|
7
|
+
// ============= Server Configuration =============
|
|
8
|
+
|
|
9
|
+
export interface ServerConfig {
|
|
10
|
+
/** Server port (default: 3000) */
|
|
11
|
+
port?: number;
|
|
12
|
+
/** Server host (default: 'localhost') */
|
|
13
|
+
host?: string;
|
|
14
|
+
/** Enable development mode */
|
|
15
|
+
development?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ============= Database Configuration =============
|
|
19
|
+
|
|
20
|
+
export interface DatabaseConfig {
|
|
21
|
+
/** Database connection URL */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** Connection pool size */
|
|
24
|
+
poolSize?: number;
|
|
25
|
+
/** Enable database metrics */
|
|
26
|
+
enableMetrics?: boolean;
|
|
27
|
+
/** Slow query threshold in milliseconds */
|
|
28
|
+
slowQueryThreshold?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ============= Cache Configuration =============
|
|
32
|
+
|
|
33
|
+
export interface CacheConfig {
|
|
34
|
+
/** Cache driver type */
|
|
35
|
+
driver?: "redis" | "memory";
|
|
36
|
+
/** Redis connection URL */
|
|
37
|
+
url?: string;
|
|
38
|
+
/** Default TTL in seconds */
|
|
39
|
+
ttl?: number;
|
|
40
|
+
/** Key prefix for namespacing */
|
|
41
|
+
keyPrefix?: string;
|
|
42
|
+
/** Enable cache metrics */
|
|
43
|
+
enableMetrics?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ============= Logger Configuration =============
|
|
47
|
+
|
|
48
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "fatal";
|
|
49
|
+
|
|
50
|
+
export interface LoggerConfig {
|
|
51
|
+
/** Log level (default: 'info') */
|
|
52
|
+
level?: LogLevel;
|
|
53
|
+
/** Pretty print logs (default: true in development) */
|
|
54
|
+
pretty?: boolean;
|
|
55
|
+
/** Output destination */
|
|
56
|
+
output?: "console" | "stdout";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ============= Health Check Configuration =============
|
|
60
|
+
|
|
61
|
+
export interface HealthConfig {
|
|
62
|
+
/** Enable health check endpoints */
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
/** Health check endpoint path (default: '/health') */
|
|
65
|
+
healthPath?: string;
|
|
66
|
+
/** Readiness check endpoint path (default: '/ready') */
|
|
67
|
+
readyPath?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ============= Metrics Configuration =============
|
|
71
|
+
|
|
72
|
+
export interface MetricsConfig {
|
|
73
|
+
/** Enable metrics collection */
|
|
74
|
+
enabled?: boolean;
|
|
75
|
+
/** Collection interval in milliseconds */
|
|
76
|
+
collectInterval?: number;
|
|
77
|
+
/** Maximum history size */
|
|
78
|
+
maxHistorySize?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ============= Telemetry Configuration =============
|
|
82
|
+
|
|
83
|
+
export interface TelemetryConfig {
|
|
84
|
+
/** Enable OpenTelemetry tracing */
|
|
85
|
+
enabled?: boolean;
|
|
86
|
+
/** Service name for tracing */
|
|
87
|
+
serviceName?: string;
|
|
88
|
+
/** OTLP endpoint URL */
|
|
89
|
+
endpoint?: string;
|
|
90
|
+
/** Sampling rate (0.0 to 1.0) */
|
|
91
|
+
sampleRate?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ============= Frontend Configuration =============
|
|
95
|
+
|
|
96
|
+
export interface FrontendConfig {
|
|
97
|
+
/** Enable development server */
|
|
98
|
+
devServer?: boolean;
|
|
99
|
+
/** Enable Hot Module Replacement */
|
|
100
|
+
hmr?: boolean;
|
|
101
|
+
/** Frontend dev server port */
|
|
102
|
+
port?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ============= Main Configuration Interface =============
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Main configuration interface for Bueno Framework
|
|
109
|
+
*/
|
|
110
|
+
export interface BuenoConfig {
|
|
111
|
+
/** Server configuration */
|
|
112
|
+
server?: ServerConfig;
|
|
113
|
+
/** Database configuration */
|
|
114
|
+
database?: DatabaseConfig;
|
|
115
|
+
/** Cache configuration */
|
|
116
|
+
cache?: CacheConfig;
|
|
117
|
+
/** Logger configuration */
|
|
118
|
+
logger?: LoggerConfig;
|
|
119
|
+
/** Health check configuration */
|
|
120
|
+
health?: HealthConfig;
|
|
121
|
+
/** Metrics configuration */
|
|
122
|
+
metrics?: MetricsConfig;
|
|
123
|
+
/** Telemetry configuration */
|
|
124
|
+
telemetry?: TelemetryConfig;
|
|
125
|
+
/** Frontend configuration */
|
|
126
|
+
frontend?: FrontendConfig;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ============= Configuration Manager Options =============
|
|
130
|
+
|
|
131
|
+
export interface ConfigManagerOptions {
|
|
132
|
+
/** Path to config file (default: auto-detect) */
|
|
133
|
+
configPath?: string;
|
|
134
|
+
/** Whether to load environment variables (default: true) */
|
|
135
|
+
loadEnv?: boolean;
|
|
136
|
+
/** Whether to validate config (default: true) */
|
|
137
|
+
validate?: boolean;
|
|
138
|
+
/** Custom validation schema */
|
|
139
|
+
schema?: StandardSchema<BuenoConfig>;
|
|
140
|
+
/** Environment to load (.env.{NODE_ENV}) */
|
|
141
|
+
env?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ============= Configuration Source =============
|
|
145
|
+
|
|
146
|
+
export type ConfigSource = "default" | "file" | "env" | "cli" | "runtime";
|
|
147
|
+
|
|
148
|
+
export interface ConfigSourceInfo {
|
|
149
|
+
/** Source of the configuration value */
|
|
150
|
+
source: ConfigSource;
|
|
151
|
+
/** File path if from file */
|
|
152
|
+
filePath?: string;
|
|
153
|
+
/** Environment variable name if from env */
|
|
154
|
+
envVar?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ============= Configuration Change Event =============
|
|
158
|
+
|
|
159
|
+
export interface ConfigChangeEvent {
|
|
160
|
+
/** Key that changed (dot notation) */
|
|
161
|
+
key: string;
|
|
162
|
+
/** Previous value */
|
|
163
|
+
oldValue: unknown;
|
|
164
|
+
/** New value */
|
|
165
|
+
newValue: unknown;
|
|
166
|
+
/** Source of the change */
|
|
167
|
+
source: ConfigSource;
|
|
168
|
+
/** Timestamp of the change */
|
|
169
|
+
timestamp: Date;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ============= Configuration Watch Callback =============
|
|
173
|
+
|
|
174
|
+
export type ConfigWatchCallback = (event: ConfigChangeEvent) => void;
|
|
175
|
+
|
|
176
|
+
// ============= Type Utilities =============
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Infer configuration type from a schema
|
|
180
|
+
*/
|
|
181
|
+
export type InferConfig<T extends StandardSchema<BuenoConfig>> = NonNullable<
|
|
182
|
+
T["~standard"]["types"]
|
|
183
|
+
>["output"];
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Deep partial type for configuration
|
|
187
|
+
*/
|
|
188
|
+
export type DeepPartial<T> = {
|
|
189
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* User configuration type (alias for DeepPartial<BuenoConfig>)
|
|
194
|
+
*/
|
|
195
|
+
export type UserConfig<T extends BuenoConfig = BuenoConfig> = DeepPartial<T>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* User configuration function type
|
|
199
|
+
*/
|
|
200
|
+
export type UserConfigFn<T extends BuenoConfig = BuenoConfig> = (env: string) => UserConfig<T> | Promise<UserConfig<T>>;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Configuration value type for a given key path
|
|
204
|
+
*/
|
|
205
|
+
export type ConfigValueForKey<TKey extends string> = TKey extends `${infer T}.${infer Rest}`
|
|
206
|
+
? T extends keyof BuenoConfig
|
|
207
|
+
? Rest extends string
|
|
208
|
+
? ConfigValueForKey<Rest>
|
|
209
|
+
: BuenoConfig[T]
|
|
210
|
+
: unknown
|
|
211
|
+
: TKey extends keyof BuenoConfig
|
|
212
|
+
? BuenoConfig[TKey]
|
|
213
|
+
: unknown;
|
|
214
|
+
|
|
215
|
+
// ============= Default Configuration =============
|
|
216
|
+
|
|
217
|
+
export const DEFAULT_CONFIG: Required<BuenoConfig> = {
|
|
218
|
+
server: {
|
|
219
|
+
port: 3000,
|
|
220
|
+
host: "localhost",
|
|
221
|
+
development: false,
|
|
222
|
+
},
|
|
223
|
+
database: {
|
|
224
|
+
url: undefined,
|
|
225
|
+
poolSize: 10,
|
|
226
|
+
enableMetrics: true,
|
|
227
|
+
slowQueryThreshold: 100,
|
|
228
|
+
},
|
|
229
|
+
cache: {
|
|
230
|
+
driver: "memory",
|
|
231
|
+
url: undefined,
|
|
232
|
+
ttl: 3600,
|
|
233
|
+
keyPrefix: "",
|
|
234
|
+
enableMetrics: true,
|
|
235
|
+
},
|
|
236
|
+
logger: {
|
|
237
|
+
level: "info",
|
|
238
|
+
pretty: true,
|
|
239
|
+
output: "console",
|
|
240
|
+
},
|
|
241
|
+
health: {
|
|
242
|
+
enabled: true,
|
|
243
|
+
healthPath: "/health",
|
|
244
|
+
readyPath: "/ready",
|
|
245
|
+
},
|
|
246
|
+
metrics: {
|
|
247
|
+
enabled: true,
|
|
248
|
+
collectInterval: 60000,
|
|
249
|
+
maxHistorySize: 100,
|
|
250
|
+
},
|
|
251
|
+
telemetry: {
|
|
252
|
+
enabled: false,
|
|
253
|
+
serviceName: "bueno-app",
|
|
254
|
+
endpoint: undefined,
|
|
255
|
+
sampleRate: 1.0,
|
|
256
|
+
},
|
|
257
|
+
frontend: {
|
|
258
|
+
devServer: false,
|
|
259
|
+
hmr: true,
|
|
260
|
+
port: 3001,
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// ============= Environment Variable Mappings =============
|
|
265
|
+
|
|
266
|
+
export interface EnvMapping {
|
|
267
|
+
/** Environment variable name */
|
|
268
|
+
envVar: string;
|
|
269
|
+
/** Config key path (dot notation) */
|
|
270
|
+
configKey: string;
|
|
271
|
+
/** Optional transformer function */
|
|
272
|
+
transform?: (value: string) => unknown;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export const ENV_MAPPINGS: EnvMapping[] = [
|
|
276
|
+
// Server
|
|
277
|
+
{ envVar: "BUENO_PORT", configKey: "server.port", transform: (v) => parseInt(v, 10) },
|
|
278
|
+
{ envVar: "BUENO_HOST", configKey: "server.host" },
|
|
279
|
+
{ envVar: "BUENO_DEV", configKey: "server.development", transform: (v) => v === "true" },
|
|
280
|
+
{ envVar: "PORT", configKey: "server.port", transform: (v) => parseInt(v, 10) },
|
|
281
|
+
{ envVar: "HOST", configKey: "server.host" },
|
|
282
|
+
|
|
283
|
+
// Database
|
|
284
|
+
{ envVar: "DATABASE_URL", configKey: "database.url" },
|
|
285
|
+
{ envVar: "BUENO_DATABASE_URL", configKey: "database.url" },
|
|
286
|
+
{ envVar: "BUENO_DB_POOL_SIZE", configKey: "database.poolSize", transform: (v) => parseInt(v, 10) },
|
|
287
|
+
{ envVar: "BUENO_DB_METRICS", configKey: "database.enableMetrics", transform: (v) => v === "true" },
|
|
288
|
+
{ envVar: "BUENO_DB_SLOW_QUERY", configKey: "database.slowQueryThreshold", transform: (v) => parseInt(v, 10) },
|
|
289
|
+
|
|
290
|
+
// Cache
|
|
291
|
+
{ envVar: "REDIS_URL", configKey: "cache.url" },
|
|
292
|
+
{ envVar: "BUENO_REDIS_URL", configKey: "cache.url" },
|
|
293
|
+
{ envVar: "BUENO_CACHE_DRIVER", configKey: "cache.driver" },
|
|
294
|
+
{ envVar: "BUENO_CACHE_TTL", configKey: "cache.ttl", transform: (v) => parseInt(v, 10) },
|
|
295
|
+
{ envVar: "BUENO_CACHE_PREFIX", configKey: "cache.keyPrefix" },
|
|
296
|
+
|
|
297
|
+
// Logger
|
|
298
|
+
{ envVar: "LOG_LEVEL", configKey: "logger.level" },
|
|
299
|
+
{ envVar: "BUENO_LOG_LEVEL", configKey: "logger.level" },
|
|
300
|
+
{ envVar: "BUENO_LOG_PRETTY", configKey: "logger.pretty", transform: (v) => v === "true" },
|
|
301
|
+
|
|
302
|
+
// Health
|
|
303
|
+
{ envVar: "BUENO_HEALTH_ENABLED", configKey: "health.enabled", transform: (v) => v === "true" },
|
|
304
|
+
{ envVar: "BUENO_HEALTH_PATH", configKey: "health.healthPath" },
|
|
305
|
+
{ envVar: "BUENO_READY_PATH", configKey: "health.readyPath" },
|
|
306
|
+
|
|
307
|
+
// Metrics
|
|
308
|
+
{ envVar: "BUENO_METRICS_ENABLED", configKey: "metrics.enabled", transform: (v) => v === "true" },
|
|
309
|
+
{ envVar: "BUENO_METRICS_INTERVAL", configKey: "metrics.collectInterval", transform: (v) => parseInt(v, 10) },
|
|
310
|
+
|
|
311
|
+
// Telemetry
|
|
312
|
+
{ envVar: "BUENO_TELEMETRY_ENABLED", configKey: "telemetry.enabled", transform: (v) => v === "true" },
|
|
313
|
+
{ envVar: "BUENO_SERVICE_NAME", configKey: "telemetry.serviceName" },
|
|
314
|
+
{ envVar: "BUENO_OTEL_ENDPOINT", configKey: "telemetry.endpoint" },
|
|
315
|
+
{ envVar: "OTEL_EXPORTER_OTLP_ENDPOINT", configKey: "telemetry.endpoint" },
|
|
316
|
+
|
|
317
|
+
// Frontend
|
|
318
|
+
{ envVar: "BUENO_FRONTEND_PORT", configKey: "frontend.port", transform: (v) => parseInt(v, 10) },
|
|
319
|
+
{ envVar: "BUENO_HMR", configKey: "frontend.hmr", transform: (v) => v === "true" },
|
|
320
|
+
];
|