Skip to content

Commit e097935

Browse files
committed
chore: wip
1 parent bee080d commit e097935

File tree

4 files changed

+146
-93
lines changed

4 files changed

+146
-93
lines changed

storage/framework/core/config/src/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import type { StacksOptions } from '@stacksjs/types'
2-
import { defaults } from './defaults'
32
import { overrides } from './overrides'
3+
import { defaults } from './defaults'
4+
import { initializeDbConfig } from '../../database/src/utils'
45

56
// merged defaults and overrides
67
export const config: StacksOptions = {
78
...defaults,
89
...overrides,
910
}
1011

12+
// Initialize the database config to avoid circular dependencies
13+
initializeDbConfig(config)
14+
1115
export function getConfig(): StacksOptions {
12-
return {
13-
...defaults,
14-
...overrides,
15-
}
16+
return config
1617
}
1718

1819
export const ai: StacksOptions['ai'] = config.ai
@@ -43,6 +44,7 @@ export const team: StacksOptions['team'] = config.team
4344
export const ui: StacksOptions['ui'] = config.ui
4445

4546
export * from './helpers'
47+
export { defaults, overrides }
4648

4749
type AppEnv = 'dev' | 'stage' | 'prod' | string
4850

@@ -61,5 +63,3 @@ export function determineAppEnv(): AppEnv {
6163

6264
return app.env
6365
}
64-
65-
export { defaults, overrides }

storage/framework/core/config/src/defaults.ts

Lines changed: 82 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,53 @@ export const defaults: StacksOptions = {
7676
},
7777

7878
cloud: {
79-
type: 'serverless',
79+
infrastructure: {
80+
type: 'serverless',
81+
driver: 'aws',
82+
environments: ['production', 'staging', 'development'],
8083

81-
driver: 'aws',
82-
83-
storage: {},
84+
firewall: {
85+
enabled: true,
86+
countryCodes: [],
87+
ipAddresses: [],
88+
queryString: [],
89+
httpHeaders: [],
90+
// ipSets: [],
91+
rateLimitPerMinute: 1000,
92+
useIpReputationLists: true,
93+
useKnownBadInputsRuleSet: true,
94+
},
8495

85-
environments: ['production', 'staging', 'development'],
96+
cdn: {
97+
allowedMethods: 'GET_HEAD',
98+
cachedMethods: 'GET_HEAD',
99+
minTtl: 0,
100+
defaultTtl: 86400,
101+
maxTtl: 31536000,
102+
compress: true,
103+
priceClass: 'PriceClass_All',
104+
originShieldRegion: 'us-east-1',
105+
cookieBehavior: 'none',
106+
allowList: {
107+
cookies: [],
108+
headers: [],
109+
queryStrings: [],
110+
},
111+
realtimeLogs: {
112+
enabled: true,
113+
samplingRate: 2,
114+
},
115+
},
86116

87-
firewall: {
88-
enabled: true,
89-
countryCodes: [],
90-
ipAddresses: [],
91-
queryString: [],
92-
httpHeaders: [],
93-
// ipSets: [],
94-
rateLimitPerMinute: 1000,
95-
useIpReputationLists: true,
96-
useKnownBadInputsRuleSet: true,
117+
fileSystem: false,
118+
storage: {},
97119
},
98120

99-
cdn: {
100-
allowedMethods: 'GET_HEAD',
101-
cachedMethods: 'GET_HEAD',
102-
minTtl: 0,
103-
defaultTtl: 86400,
104-
maxTtl: 31536000,
105-
compress: true,
106-
priceClass: 'PriceClass_All',
107-
originShieldRegion: 'us-east-1',
108-
cookieBehavior: 'none',
109-
allowList: {
110-
cookies: [],
111-
headers: [],
112-
queryStrings: [],
113-
},
114-
realtimeLogs: {
115-
enabled: true,
116-
samplingRate: 2,
117-
},
121+
// Default site configuration
122+
sites: {
123+
root: '',
124+
path: '',
118125
},
119-
120-
fileSystem: false,
121126
},
122127

123128
database: {
@@ -322,69 +327,69 @@ export const defaults: StacksOptions = {
322327
],
323328

324329
messages: {
325-
type: 'Select the type of change that youre committing:',
326-
scope: 'Select the SCOPE of this change (optional):',
327-
customScope: 'Select the SCOPE of this change:',
328-
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
329-
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
330-
breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
331-
footerPrefixesSelect: 'Select the ISSUES type of the change list by this change (optional):',
332-
customFooterPrefixes: 'Input ISSUES prefix:',
333-
footer: 'List any ISSUES by this change. E.g.: #31, #34:\n',
334-
confirmCommit: 'Are you sure you want to proceed with the commit above?',
330+
type: "Select the type of change that you're committing:",
331+
scope: "Select the SCOPE of this change (optional):",
332+
customScope: "Select the SCOPE of this change:",
333+
subject: "Write a SHORT, IMPERATIVE tense description of the change:\n",
334+
body: "Provide a LONGER description of the change (optional). Use \"|\" to break new line:\n",
335+
breaking: "List any BREAKING CHANGES (optional). Use \"|\" to break new line:\n",
336+
footerPrefixesSelect: "Select the ISSUES type of the change list by this change (optional):",
337+
customFooterPrefixes: "Input ISSUES prefix:",
338+
footer: "List any ISSUES by this change. E.g.: #31, #34:\n",
339+
confirmCommit: "Are you sure you want to proceed with the commit above?",
335340
},
336341

337342
types: [
338343
{
339-
value: 'feat',
340-
name: 'feat: ✨ A new feature',
341-
emoji: ':sparkles:',
344+
value: "feat",
345+
name: "feat: ✨ A new feature",
346+
emoji: ":sparkles:",
342347
},
343-
{ value: 'fix', name: 'fix: 🐛 A bug fix', emoji: ':bug:' },
348+
{ value: "fix", name: "fix: 🐛 A bug fix", emoji: ":bug:" },
344349
{
345-
value: 'docs',
346-
name: 'docs: 📝 Documentation only changes',
347-
emoji: ':memo:',
350+
value: "docs",
351+
name: "docs: 📝 Documentation only changes",
352+
emoji: ":memo:",
348353
},
349354
{
350-
value: 'style',
351-
name: 'style: 💄 Changes that do not affect the meaning of the code',
352-
emoji: ':lipstick:',
355+
value: "style",
356+
name: "style: 💄 Changes that do not affect the meaning of the code",
357+
emoji: ":lipstick:",
353358
},
354359
{
355-
value: 'refactor',
356-
name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature',
357-
emoji: ':recycle:',
360+
value: "refactor",
361+
name: "refactor: ♻️ A code change that neither fixes a bug nor adds a feature",
362+
emoji: ":recycle:",
358363
},
359364
{
360-
value: 'perf',
361-
name: 'perf: ⚡️ A code change that improves performance',
362-
emoji: ':zap:',
365+
value: "perf",
366+
name: "perf: ⚡️ A code change that improves performance",
367+
emoji: ":zap:",
363368
},
364369
{
365-
value: 'test',
366-
name: 'test: ✅ Adding missing tests or adjusting existing tests',
367-
emoji: ':white_check_mark:',
370+
value: "test",
371+
name: "test: ✅ Adding missing tests or adjusting existing tests",
372+
emoji: ":white_check_mark:",
368373
},
369374
{
370-
value: 'build',
371-
name: 'build: 📦️ Changes that affect the build system or external dependencies',
372-
emoji: ':package:',
375+
value: "build",
376+
name: "build: 📦️ Changes that affect the build system or external dependencies",
377+
emoji: ":package:",
373378
},
374379
{
375-
value: 'ci',
376-
name: 'ci: 🎡 Changes to our CI configuration files and scripts',
377-
emoji: ':ferris_wheel:',
380+
value: "ci",
381+
name: "ci: 🎡 Changes to our CI configuration files and scripts",
382+
emoji: ":ferris_wheel:",
378383
},
379384
{
380-
value: 'chore',
381-
name: 'chore: 🔨 Other changes that dont modify src or test files',
382-
emoji: ':hammer:',
385+
value: "chore",
386+
name: "chore: 🔨 Other changes that don't modify src or test files",
387+
emoji: ":hammer:",
383388
},
384389
{
385-
value: 'revert',
386-
name: 'revert: ⏪️ Reverts a previous commit',
387-
emoji: ':rewind:',
390+
value: "revert",
391+
name: "revert: ⏪️ Reverts a previous commit",
392+
emoji: ":rewind:",
388393
},
389394
],
390395
},

storage/framework/core/database/src/utils.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,64 @@
11
import type { Database } from '@stacksjs/orm'
22
import type { RawBuilder } from 'kysely'
3-
import { getConfig } from '@stacksjs/config'
43
import { log } from '@stacksjs/logging'
54
import { projectPath } from '@stacksjs/path'
65
import { Kysely, MysqlDialect, PostgresDialect, sql } from 'kysely'
76
import { BunWorkerDialect } from 'kysely-bun-worker'
87
import { createPool } from 'mysql2'
9-
108
import { Pool } from 'pg'
119

12-
// Simple functions with defensive defaults in case the imports failed
10+
// Use default values to avoid circular dependencies initially
11+
// These can be overridden later once config is fully loaded
12+
let appEnv = 'local'
13+
let dbDriver = 'sqlite'
14+
let dbConfig = {
15+
connections: {
16+
sqlite: {
17+
database: 'database/stacks.sqlite',
18+
prefix: '',
19+
},
20+
mysql: {
21+
name: 'stacks',
22+
host: '127.0.0.1',
23+
username: 'root',
24+
password: '',
25+
port: 3306,
26+
prefix: '',
27+
},
28+
postgres: {
29+
name: 'stacks',
30+
host: '127.0.0.1',
31+
username: '',
32+
password: '',
33+
port: 5432,
34+
prefix: '',
35+
}
36+
}
37+
}
38+
39+
// Function to initialize the config when it's available
40+
export function initializeDbConfig(config: any): void {
41+
if (config?.app?.env)
42+
appEnv = config.app.env
43+
44+
if (config?.database?.default)
45+
dbDriver = config.database.default
46+
47+
if (config?.database)
48+
dbConfig = config.database
49+
}
50+
51+
// Simple functions with defensive defaults
1352
function getEnv(): string {
14-
return getConfig()?.app?.env || 'local'
53+
return appEnv
1554
}
1655

1756
function getDriver(): string {
18-
return getConfig()?.database?.default || 'sqlite'
57+
return dbDriver
1958
}
2059

2160
function getDatabaseConfig() {
22-
return getConfig()?.database || { connections: {} }
61+
return dbConfig
2362
}
2463

2564
export function getDialect(): MysqlDialect | PostgresDialect | BunWorkerDialect {

storage/framework/core/error-handling/src/handler.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { appendFile, mkdir } from 'node:fs/promises'
33
import { dirname } from 'node:path'
44
import process from 'node:process'
55
import { italic, stripAnsi } from '@stacksjs/cli'
6-
import { config } from '@stacksjs/config'
76
import * as path from '@stacksjs/path'
8-
import { fs } from '@stacksjs/storage'
97
import { ExitCode } from '@stacksjs/types'
108
import { isString } from '@stacksjs/validation'
9+
import fs from 'fs-extra'
1110

1211
type ErrorMessage = string
1312

@@ -102,10 +101,20 @@ interface WriteOptions {
102101
logFile?: string
103102
}
104103

104+
// Default log path that will be used if config isn't initialized yet
105+
let defaultLogPath = 'storage/logs/stacks.log'
106+
107+
// Function to update the default log path when config is available
108+
export function setLogPath(path: string): void {
109+
defaultLogPath = path
110+
}
111+
105112
export async function writeToLogFile(message: string, options?: WriteOptions): Promise<void> {
106113
const timestamp = new Date().toISOString()
107114
const formattedMessage = `[${timestamp}] ${message}\n`
108-
const logFile = options?.logFile ?? config.logging.logsPath ?? 'storage/logs/stacks.log'
115+
116+
// Use options or default path instead of config
117+
const logFile = options?.logFile ?? defaultLogPath
109118
const dirPath = dirname(logFile)
110119

111120
if (!fs.existsSync(dirPath)) {

0 commit comments

Comments
 (0)