@stacksjs/config 0.70.257 → 0.70.259
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/dist/capabilities.js +1 -42
- package/dist/config.js +1 -109
- package/dist/defaults.js +5 -628
- package/dist/features.js +1 -53
- package/dist/helpers.js +1 -156
- package/dist/index.js +1 -5
- package/dist/overrides.js +3 -120
- package/dist/validators.js +1 -135
- package/package.json +13 -6
package/dist/features.js
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import { config }
|
|
2
|
-
const FEATURE_NAMES = [
|
|
3
|
-
"auth",
|
|
4
|
-
"marketing",
|
|
5
|
-
"cms",
|
|
6
|
-
"commerce",
|
|
7
|
-
"dashboard",
|
|
8
|
-
"monitoring",
|
|
9
|
-
"realtime",
|
|
10
|
-
"queue"
|
|
11
|
-
], FEATURE_DEFAULTS = {
|
|
12
|
-
dashboard: !0
|
|
13
|
-
}, overrides = new Map;
|
|
14
|
-
function configFor(name) {
|
|
15
|
-
const raw = config[name];
|
|
16
|
-
return raw && typeof raw === "object" ? raw : void 0;
|
|
17
|
-
}
|
|
18
|
-
export function feature(name) {
|
|
19
|
-
if (overrides.has(name))
|
|
20
|
-
return overrides.get(name);
|
|
21
|
-
const cfg = configFor(name);
|
|
22
|
-
if (cfg) {
|
|
23
|
-
const enabledField = cfg.enabled;
|
|
24
|
-
if (enabledField === !1)
|
|
25
|
-
return !1;
|
|
26
|
-
if (Array.isArray(cfg.env) && cfg.env.length > 0) {
|
|
27
|
-
const currentEnv = (config.app?.env ?? "").toString();
|
|
28
|
-
if (!cfg.env.includes(currentEnv))
|
|
29
|
-
return !1;
|
|
30
|
-
}
|
|
31
|
-
if (enabledField !== void 0)
|
|
32
|
-
return !!enabledField;
|
|
33
|
-
return !0;
|
|
34
|
-
}
|
|
35
|
-
return FEATURE_DEFAULTS[name] ?? !1;
|
|
36
|
-
}
|
|
37
|
-
export function enableFeature(name) {
|
|
38
|
-
overrides.set(name, !0);
|
|
39
|
-
}
|
|
40
|
-
export function disableFeature(name) {
|
|
41
|
-
overrides.set(name, !1);
|
|
42
|
-
}
|
|
43
|
-
export function resetFeature(name) {
|
|
44
|
-
overrides.delete(name);
|
|
45
|
-
}
|
|
46
|
-
export function listFeatures() {
|
|
47
|
-
const out = {};
|
|
48
|
-
for (const name of FEATURE_NAMES)
|
|
49
|
-
out[name] = feature(name);
|
|
50
|
-
for (const name of overrides.keys())
|
|
51
|
-
out[name] = feature(name);
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
1
|
+
import{config}from"./config";const FEATURE_NAMES=["auth","marketing","cms","commerce","dashboard","monitoring","realtime","queue"],FEATURE_DEFAULTS={dashboard:!0},overrides=new Map;function configFor(name){const raw=config[name];return raw&&typeof raw==="object"?raw:void 0}export function feature(name){if(overrides.has(name))return overrides.get(name);const cfg=configFor(name);if(cfg){const enabledField=cfg.enabled;if(enabledField===!1)return!1;if(Array.isArray(cfg.env)&&cfg.env.length>0){const currentEnv=(config.app?.env??"").toString();if(!cfg.env.includes(currentEnv))return!1}if(enabledField!==void 0)return!!enabledField;return!0}return FEATURE_DEFAULTS[name]??!1}export function enableFeature(name){overrides.set(name,!0)}export function disableFeature(name){overrides.set(name,!1)}export function resetFeature(name){overrides.delete(name)}export function listFeatures(){const out={};for(const name of FEATURE_NAMES)out[name]=feature(name);for(const name of overrides.keys())out[name]=feature(name);return out}
|
package/dist/helpers.js
CHANGED
|
@@ -1,156 +1 @@
|
|
|
1
|
-
import { config }
|
|
2
|
-
export async function localUrl(options = {}) {
|
|
3
|
-
const domain = options.domain ?? config.app.url ?? "stacks", type = options.type ?? "frontend", localhost = options.localhost ?? !1, https = options.https, network = options.network;
|
|
4
|
-
let url = domain.replace(/\.[^.]+$/, ".localhost");
|
|
5
|
-
async function tunnel(port) {
|
|
6
|
-
const { createLocalTunnel } = await import("@stacksjs/tunnel");
|
|
7
|
-
return createLocalTunnel(port);
|
|
8
|
-
}
|
|
9
|
-
switch (type) {
|
|
10
|
-
case "frontend":
|
|
11
|
-
if (network)
|
|
12
|
-
return await tunnel(config.ports?.frontend || 3000);
|
|
13
|
-
if (localhost)
|
|
14
|
-
return `http://localhost:${config.ports?.frontend}`;
|
|
15
|
-
break;
|
|
16
|
-
case "backend":
|
|
17
|
-
if (network)
|
|
18
|
-
return await tunnel(config.ports?.backend || 3001);
|
|
19
|
-
if (localhost)
|
|
20
|
-
return `http://localhost:${config.ports?.backend}`;
|
|
21
|
-
url = `api.${url}`;
|
|
22
|
-
break;
|
|
23
|
-
case "admin":
|
|
24
|
-
if (network)
|
|
25
|
-
return await tunnel(config.ports?.admin || 3002);
|
|
26
|
-
if (localhost)
|
|
27
|
-
return `http://localhost:${config.ports?.admin}`;
|
|
28
|
-
url = `admin.${url}`;
|
|
29
|
-
break;
|
|
30
|
-
case "library":
|
|
31
|
-
if (network)
|
|
32
|
-
return await tunnel(config.ports?.library || 3003);
|
|
33
|
-
if (localhost)
|
|
34
|
-
return `http://localhost:${config.ports?.library}`;
|
|
35
|
-
url = `libs.${url}`;
|
|
36
|
-
break;
|
|
37
|
-
case "email":
|
|
38
|
-
if (network)
|
|
39
|
-
return await tunnel(config.ports?.email || 3005);
|
|
40
|
-
if (localhost)
|
|
41
|
-
return `http://localhost:${config.ports?.email}`;
|
|
42
|
-
url = `email.${url}`;
|
|
43
|
-
break;
|
|
44
|
-
case "desktop":
|
|
45
|
-
if (network)
|
|
46
|
-
return await tunnel(config.ports?.desktop || 3004);
|
|
47
|
-
if (localhost)
|
|
48
|
-
return `http://localhost:${config.ports?.desktop}`;
|
|
49
|
-
url = `desktop.${url}`;
|
|
50
|
-
break;
|
|
51
|
-
case "docs":
|
|
52
|
-
if (network)
|
|
53
|
-
return await tunnel(config.ports?.docs || 3006);
|
|
54
|
-
if (localhost)
|
|
55
|
-
return `http://localhost:${config.ports?.docs}`;
|
|
56
|
-
url = `docs.${url}`;
|
|
57
|
-
break;
|
|
58
|
-
case "inspect":
|
|
59
|
-
if (network)
|
|
60
|
-
return await tunnel(config.ports?.inspect || 3007);
|
|
61
|
-
if (localhost)
|
|
62
|
-
return `http://localhost:${config.ports?.inspect}`;
|
|
63
|
-
url = `inspect.${url}`;
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
if (localhost)
|
|
67
|
-
return `http://localhost:${config.ports?.frontend}`;
|
|
68
|
-
}
|
|
69
|
-
if (https)
|
|
70
|
-
return `https://${url}`;
|
|
71
|
-
return `http://${url}`;
|
|
72
|
-
}
|
|
73
|
-
export function defineStacksConfig(config) {
|
|
74
|
-
return config;
|
|
75
|
-
}
|
|
76
|
-
export function defineApp(config) {
|
|
77
|
-
return config;
|
|
78
|
-
}
|
|
79
|
-
export function defineCache(config) {
|
|
80
|
-
return config;
|
|
81
|
-
}
|
|
82
|
-
export function defineCdn(config) {
|
|
83
|
-
return config;
|
|
84
|
-
}
|
|
85
|
-
export function defineChat(config) {
|
|
86
|
-
return config;
|
|
87
|
-
}
|
|
88
|
-
export function defineCli(config) {
|
|
89
|
-
return config;
|
|
90
|
-
}
|
|
91
|
-
export function defineDatabase(config) {
|
|
92
|
-
return config;
|
|
93
|
-
}
|
|
94
|
-
export function defineDependencies(config) {
|
|
95
|
-
return config;
|
|
96
|
-
}
|
|
97
|
-
export function defineDns(config) {
|
|
98
|
-
return config;
|
|
99
|
-
}
|
|
100
|
-
export function defineEmailConfig(config) {
|
|
101
|
-
return config;
|
|
102
|
-
}
|
|
103
|
-
export function defineEmail(config) {
|
|
104
|
-
return config;
|
|
105
|
-
}
|
|
106
|
-
export function defineGit(config) {
|
|
107
|
-
return config;
|
|
108
|
-
}
|
|
109
|
-
export function defineHashing(config) {
|
|
110
|
-
return config;
|
|
111
|
-
}
|
|
112
|
-
export function defineImages(config) {
|
|
113
|
-
return config;
|
|
114
|
-
}
|
|
115
|
-
export function defineLibrary(config) {
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
export function defineNotification(config) {
|
|
119
|
-
return config;
|
|
120
|
-
}
|
|
121
|
-
export function definePayment(config) {
|
|
122
|
-
return config;
|
|
123
|
-
}
|
|
124
|
-
export function defineQueue(config) {
|
|
125
|
-
return config;
|
|
126
|
-
}
|
|
127
|
-
export function defineSearchEngine(config) {
|
|
128
|
-
return config;
|
|
129
|
-
}
|
|
130
|
-
export function defineSecurity(config) {
|
|
131
|
-
return config;
|
|
132
|
-
}
|
|
133
|
-
export function defineServices(config) {
|
|
134
|
-
return config;
|
|
135
|
-
}
|
|
136
|
-
export function defineSms(config) {
|
|
137
|
-
return config;
|
|
138
|
-
}
|
|
139
|
-
export function defineStorage(config) {
|
|
140
|
-
return config;
|
|
141
|
-
}
|
|
142
|
-
export function defineFilesystems(config) {
|
|
143
|
-
return config;
|
|
144
|
-
}
|
|
145
|
-
export function defineFeatureFlags(config) {
|
|
146
|
-
return config;
|
|
147
|
-
}
|
|
148
|
-
export function defineUi(config) {
|
|
149
|
-
return config;
|
|
150
|
-
}
|
|
151
|
-
export function defineModel(config) {
|
|
152
|
-
return config;
|
|
153
|
-
}
|
|
154
|
-
export function defineEvents(config) {
|
|
155
|
-
return config;
|
|
156
|
-
}
|
|
1
|
+
import{config}from".";export async function localUrl(options={}){const domain=options.domain??config.app.url??"stacks",type=options.type??"frontend",localhost=options.localhost??!1,https=options.https,network=options.network;let url=domain.replace(/\.[^.]+$/,".localhost");async function tunnel(port){const{createLocalTunnel}=await import("@stacksjs/tunnel");return createLocalTunnel(port)}switch(type){case"frontend":if(network)return await tunnel(config.ports?.frontend||3000);if(localhost)return`http://localhost:${config.ports?.frontend}`;break;case"backend":if(network)return await tunnel(config.ports?.backend||3001);if(localhost)return`http://localhost:${config.ports?.backend}`;url=`api.${url}`;break;case"admin":if(network)return await tunnel(config.ports?.admin||3002);if(localhost)return`http://localhost:${config.ports?.admin}`;url=`admin.${url}`;break;case"library":if(network)return await tunnel(config.ports?.library||3003);if(localhost)return`http://localhost:${config.ports?.library}`;url=`libs.${url}`;break;case"email":if(network)return await tunnel(config.ports?.email||3005);if(localhost)return`http://localhost:${config.ports?.email}`;url=`email.${url}`;break;case"desktop":if(network)return await tunnel(config.ports?.desktop||3004);if(localhost)return`http://localhost:${config.ports?.desktop}`;url=`desktop.${url}`;break;case"docs":if(network)return await tunnel(config.ports?.docs||3006);if(localhost)return`http://localhost:${config.ports?.docs}`;url=`docs.${url}`;break;case"inspect":if(network)return await tunnel(config.ports?.inspect||3007);if(localhost)return`http://localhost:${config.ports?.inspect}`;url=`inspect.${url}`;break;default:if(localhost)return`http://localhost:${config.ports?.frontend}`}if(https)return`https://${url}`;return`http://${url}`}export function defineStacksConfig(config){return config}export function defineApp(config){return config}export function defineCache(config){return config}export function defineCdn(config){return config}export function defineChat(config){return config}export function defineCli(config){return config}export function defineDatabase(config){return config}export function defineDependencies(config){return config}export function defineDns(config){return config}export function defineEmailConfig(config){return config}export function defineEmail(config){return config}export function defineGit(config){return config}export function defineHashing(config){return config}export function defineImages(config){return config}export function defineLibrary(config){return config}export function defineNotification(config){return config}export function definePayment(config){return config}export function defineQueue(config){return config}export function defineSearchEngine(config){return config}export function defineSecurity(config){return config}export function defineServices(config){return config}export function defineSms(config){return config}export function defineStorage(config){return config}export function defineFilesystems(config){return config}export function defineFeatureFlags(config){return config}export function defineUi(config){return config}export function defineModel(config){return config}export function defineEvents(config){return config}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { FRAMEWORK_DEFAULTS } from "./defaults";
|
|
3
|
-
export { validateConfig, reportConfigIssues } from "./validators";
|
|
4
|
-
export { feature, enableFeature, disableFeature, resetFeature, listFeatures } from "./features";
|
|
5
|
-
export * from "./capabilities";
|
|
1
|
+
export*from"./config";export{FRAMEWORK_DEFAULTS}from"./defaults";export{validateConfig,reportConfigIssues}from"./validators";export{feature,enableFeature,disableFeature,resetFeature,listFeatures}from"./features";export*from"./capabilities";
|
package/dist/overrides.js
CHANGED
|
@@ -1,121 +1,4 @@
|
|
|
1
|
-
import { resolve } from "
|
|
2
|
-
|
|
3
|
-
import { validateConfig } from "./validators";
|
|
4
|
-
const skipConfigLoading = process.env.SKIP_CONFIG_LOADING === "true", skipConfigValidation = process.env.SKIP_CONFIG_VALIDATION === "true", OVERRIDES_KEY = Symbol.for("@stacksjs/config:overrides"), READY_KEY = Symbol.for("@stacksjs/config:overridesReady");
|
|
5
|
-
function defaultsForOverrides() {
|
|
6
|
-
return {
|
|
7
|
-
ai: {},
|
|
8
|
-
analytics: {},
|
|
9
|
-
app: { name: process.env.APP_NAME || "Stacks", env: process.env.APP_ENV || "production" },
|
|
10
|
-
auth: {},
|
|
11
|
-
cache: {},
|
|
12
|
-
cli: {},
|
|
13
|
-
cloud: {},
|
|
14
|
-
cms: {},
|
|
15
|
-
commerce: {},
|
|
16
|
-
dashboard: {},
|
|
17
|
-
database: {},
|
|
18
|
-
dns: {},
|
|
19
|
-
realtime: {},
|
|
20
|
-
email: {},
|
|
21
|
-
errors: {},
|
|
22
|
-
featureFlags: {},
|
|
23
|
-
git: {},
|
|
24
|
-
hashing: {},
|
|
25
|
-
images: {},
|
|
26
|
-
library: {},
|
|
27
|
-
logging: {},
|
|
28
|
-
marketing: {},
|
|
29
|
-
monitoring: {},
|
|
30
|
-
notification: {},
|
|
31
|
-
queue: {},
|
|
32
|
-
payment: {},
|
|
33
|
-
ports: {},
|
|
34
|
-
saas: {},
|
|
35
|
-
searchEngine: {},
|
|
36
|
-
security: {},
|
|
37
|
-
services: {},
|
|
38
|
-
filesystems: {},
|
|
39
|
-
team: {},
|
|
40
|
-
ui: {}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const globalScope = globalThis, sharedOverrides = globalScope[OVERRIDES_KEY];
|
|
44
|
-
export const overrides = sharedOverrides ?? (() => {
|
|
45
|
-
const created = defaultsForOverrides();
|
|
46
|
-
globalScope[OVERRIDES_KEY] = created;
|
|
47
|
-
return created;
|
|
48
|
-
})();
|
|
49
|
-
const userConfigs = [
|
|
50
|
-
["ai", "ai"],
|
|
51
|
-
["analytics", "analytics"],
|
|
52
|
-
["app", "app"],
|
|
53
|
-
["auth", "auth"],
|
|
54
|
-
["cache", "cache"],
|
|
55
|
-
["cli", "cli"],
|
|
56
|
-
["cloud", "cloud"],
|
|
57
|
-
["cms", "cms"],
|
|
58
|
-
["commerce", "commerce"],
|
|
59
|
-
["dashboard", "dashboard"],
|
|
60
|
-
["database", "database"],
|
|
61
|
-
["dns", "dns"],
|
|
62
|
-
["docs", "docs"],
|
|
63
|
-
["email", "email"],
|
|
64
|
-
["errors", "errors"],
|
|
65
|
-
["featureFlags", "feature-flags"],
|
|
66
|
-
["git", "git"],
|
|
67
|
-
["hashing", "hashing"],
|
|
68
|
-
["images", "images"],
|
|
69
|
-
["library", "library"],
|
|
70
|
-
["logging", "logging"],
|
|
71
|
-
["marketing", "marketing"],
|
|
72
|
-
["monitoring", "monitoring"],
|
|
73
|
-
["notification", "notification"],
|
|
74
|
-
["payment", "payment"],
|
|
75
|
-
["ports", "ports"],
|
|
76
|
-
["queue", "queue"],
|
|
77
|
-
["realtime", "realtime"],
|
|
78
|
-
["saas", "saas"],
|
|
79
|
-
["searchEngine", "search-engine"],
|
|
80
|
-
["security", "security"],
|
|
81
|
-
["services", "services"],
|
|
82
|
-
["filesystems", "filesystems"],
|
|
83
|
-
["team", "team"],
|
|
84
|
-
["ui", "ui"]
|
|
85
|
-
];
|
|
86
|
-
export function userConfigUrl(name, cwd = process.cwd()) {
|
|
87
|
-
return pathToFileURL(resolve(cwd, "config", `${name}.ts`)).href;
|
|
88
|
-
}
|
|
89
|
-
const sharedReady = globalScope[READY_KEY];
|
|
90
|
-
export const overridesReady = sharedReady ?? (() => {
|
|
91
|
-
const promise = skipConfigLoading ? Promise.resolve(overrides) : Promise.all(userConfigs.map(async ([key, name]) => {
|
|
92
|
-
const modulePath = userConfigUrl(name);
|
|
93
|
-
try {
|
|
94
|
-
const mod = await import(modulePath);
|
|
95
|
-
if (mod?.default !== void 0)
|
|
96
|
-
overrides[key] = mod.default;
|
|
97
|
-
} catch (err) {
|
|
98
|
-
const code = err?.code, msg = err?.message ?? String(err);
|
|
99
|
-
if (!(code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || /Cannot find module/i.test(msg)))
|
|
100
|
-
console.warn(`[config] Failed to load ${String(key)} config from ${modulePath}: ${msg}`);
|
|
101
|
-
}
|
|
102
|
-
})).then(() => {
|
|
103
|
-
if (!skipConfigValidation) {
|
|
104
|
-
const issues = validateConfig(overrides);
|
|
105
|
-
if (issues.length > 0) {
|
|
106
|
-
console.error("[config] Configuration issues detected:");
|
|
107
|
-
for (const issue of issues)
|
|
108
|
-
console.error(` \u2022 ${issue.path}: ${issue.message}`);
|
|
109
|
-
const summary = issues.map((i) => ` \u2022 ${i.path}: ${i.message}`).join(`
|
|
110
|
-
`);
|
|
111
|
-
throw Error(`[config] ${issues.length} configuration issue(s) detected at boot:
|
|
1
|
+
import{resolve}from"node:path";import{pathToFileURL}from"node:url";import{validateConfig}from"./validators";const skipConfigLoading=process.env.SKIP_CONFIG_LOADING==="true",skipConfigValidation=process.env.SKIP_CONFIG_VALIDATION==="true",OVERRIDES_KEY=Symbol.for("@stacksjs/config:overrides"),READY_KEY=Symbol.for("@stacksjs/config:overridesReady");function defaultsForOverrides(){return{ai:{},analytics:{},app:{name:process.env.APP_NAME||"Stacks",env:process.env.APP_ENV||"production"},auth:{},cache:{},cli:{},cloud:{},cms:{},commerce:{},dashboard:{},database:{},dns:{},realtime:{},email:{},errors:{},featureFlags:{},git:{},hashing:{},images:{},library:{},logging:{},marketing:{},monitoring:{},notification:{},queue:{},payment:{},ports:{},saas:{},searchEngine:{},security:{},services:{},filesystems:{},team:{},ui:{}}}const globalScope=globalThis,sharedOverrides=globalScope[OVERRIDES_KEY];export const overrides=sharedOverrides??(()=>{const created=defaultsForOverrides();globalScope[OVERRIDES_KEY]=created;return created})();const userConfigs=[["ai","ai"],["analytics","analytics"],["app","app"],["auth","auth"],["cache","cache"],["cli","cli"],["cloud","cloud"],["cms","cms"],["commerce","commerce"],["dashboard","dashboard"],["database","database"],["dns","dns"],["docs","docs"],["email","email"],["errors","errors"],["featureFlags","feature-flags"],["git","git"],["hashing","hashing"],["images","images"],["library","library"],["logging","logging"],["marketing","marketing"],["monitoring","monitoring"],["notification","notification"],["payment","payment"],["ports","ports"],["queue","queue"],["realtime","realtime"],["saas","saas"],["searchEngine","search-engine"],["security","security"],["services","services"],["filesystems","filesystems"],["team","team"],["ui","ui"]];export function userConfigUrl(name,cwd=process.cwd()){return pathToFileURL(resolve(cwd,"config",`${name}.ts`)).href}const sharedReady=globalScope[READY_KEY];export const overridesReady=sharedReady??(()=>{const promise=skipConfigLoading?Promise.resolve(overrides):Promise.all(userConfigs.map(async([key,name])=>{const modulePath=userConfigUrl(name);try{const mod=await import(modulePath);if(mod?.default!==void 0)overrides[key]=mod.default}catch(err){const code=err?.code,msg=err?.message??String(err);if(!(code==="ERR_MODULE_NOT_FOUND"||code==="MODULE_NOT_FOUND"||/Cannot find module/i.test(msg)))console.warn(`[config] Failed to load ${String(key)} config from ${modulePath}: ${msg}`)}})).then(()=>{if(!skipConfigValidation){const issues=validateConfig(overrides);if(issues.length>0){console.error("[config] Configuration issues detected:");for(const issue of issues)console.error(` \u2022 ${issue.path}: ${issue.message}`);const summary=issues.map((i)=>` \u2022 ${i.path}: ${i.message}`).join(`
|
|
2
|
+
`);throw Error(`[config] ${issues.length} configuration issue(s) detected at boot:
|
|
112
3
|
${summary}
|
|
113
|
-
Set SKIP_CONFIG_VALIDATION=true to bypass (e.g. when running migrations against partial config).`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return overrides;
|
|
117
|
-
});
|
|
118
|
-
globalScope[READY_KEY] = promise;
|
|
119
|
-
return promise;
|
|
120
|
-
})();
|
|
121
|
-
export default overrides;
|
|
4
|
+
Set SKIP_CONFIG_VALIDATION=true to bypass (e.g. when running migrations against partial config).`)}}return overrides});globalScope[READY_KEY]=promise;return promise})();export default overrides;
|
package/dist/validators.js
CHANGED
|
@@ -1,135 +1 @@
|
|
|
1
|
-
import { capabilityDrivers, findCapability }
|
|
2
|
-
function isPlainObject(v) {
|
|
3
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4
|
-
}
|
|
5
|
-
function checkInteger(min, max) {
|
|
6
|
-
return (value, path) => {
|
|
7
|
-
if (value == null)
|
|
8
|
-
return [];
|
|
9
|
-
let num = null;
|
|
10
|
-
if (typeof value === "number" && Number.isInteger(value))
|
|
11
|
-
num = value;
|
|
12
|
-
else if (typeof value === "string" && /^-?\d+$/.test(value))
|
|
13
|
-
num = Number.parseInt(value, 10);
|
|
14
|
-
if (num === null)
|
|
15
|
-
return [{ path, message: `expected integer, got ${typeof value} (${JSON.stringify(value)})` }];
|
|
16
|
-
if (num < min || num > max)
|
|
17
|
-
return [{ path, message: `expected integer in [${min}, ${max}], got ${num}` }];
|
|
18
|
-
return [];
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function checkOneOf(values) {
|
|
22
|
-
return (value, path) => {
|
|
23
|
-
if (value == null)
|
|
24
|
-
return [];
|
|
25
|
-
if (typeof value !== "string" || !values.includes(value))
|
|
26
|
-
return [{ path, message: `expected one of [${values.join(", ")}], got ${JSON.stringify(value)}` }];
|
|
27
|
-
return [];
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function checkCapability(category) {
|
|
31
|
-
return (value, path) => {
|
|
32
|
-
if (value == null)
|
|
33
|
-
return [];
|
|
34
|
-
const drivers = capabilityDrivers(category);
|
|
35
|
-
if (typeof value !== "string")
|
|
36
|
-
return [{ path, message: `expected ${category} driver name, got ${typeof value}` }];
|
|
37
|
-
const capability = findCapability(category, value);
|
|
38
|
-
if (!capability)
|
|
39
|
-
return [{ path, message: `unknown ${category} driver ${JSON.stringify(value)}; known drivers: [${drivers.map((driver) => driver.name).join(", ")}]` }];
|
|
40
|
-
if (capability.status === "unsupported")
|
|
41
|
-
return [{ path, message: `${category} driver ${JSON.stringify(value)} is unsupported: ${capability.limitations.join(" ")}` }];
|
|
42
|
-
return [];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function checkString() {
|
|
46
|
-
return (value, path) => {
|
|
47
|
-
if (value == null)
|
|
48
|
-
return [];
|
|
49
|
-
return typeof value === "string" ? [] : [{ path, message: `expected string, got ${typeof value}` }];
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function checkBoolean() {
|
|
53
|
-
return (value, path) => {
|
|
54
|
-
if (value == null)
|
|
55
|
-
return [];
|
|
56
|
-
return typeof value === "boolean" ? [] : [{ path, message: `expected boolean, got ${typeof value}` }];
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const PORT_CHECK = checkInteger(1, 65535), SCHEMA = {
|
|
60
|
-
app: {
|
|
61
|
-
rules: {
|
|
62
|
-
name: checkString(),
|
|
63
|
-
env: checkOneOf(["local", "development", "staging", "production", "test"]),
|
|
64
|
-
debug: checkBoolean(),
|
|
65
|
-
url: checkString()
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
ports: {
|
|
69
|
-
rules: {
|
|
70
|
-
frontend: PORT_CHECK,
|
|
71
|
-
api: PORT_CHECK,
|
|
72
|
-
admin: PORT_CHECK,
|
|
73
|
-
docs: PORT_CHECK,
|
|
74
|
-
systemTray: PORT_CHECK,
|
|
75
|
-
desktop: PORT_CHECK
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
database: {
|
|
79
|
-
rules: {
|
|
80
|
-
default: checkCapability("database")
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
cache: {
|
|
84
|
-
rules: {
|
|
85
|
-
driver: checkCapability("cache")
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
featureFlags: {
|
|
89
|
-
rules: {
|
|
90
|
-
default: checkOneOf(["memory", "database"]),
|
|
91
|
-
missing: checkOneOf(["false", "throw"])
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
queue: {
|
|
95
|
-
rules: {
|
|
96
|
-
default: checkCapability("queue")
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
logging: {
|
|
100
|
-
rules: {
|
|
101
|
-
level: checkOneOf(["trace", "debug", "info", "warn", "error", "fatal"])
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
email: {
|
|
105
|
-
rules: {
|
|
106
|
-
default: checkCapability("mail")
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
export function validateConfig(config) {
|
|
111
|
-
const issues = [];
|
|
112
|
-
for (const [section, schema] of Object.entries(SCHEMA)) {
|
|
113
|
-
const sectionValue = config[section];
|
|
114
|
-
if (sectionValue == null)
|
|
115
|
-
continue;
|
|
116
|
-
if (!isPlainObject(sectionValue)) {
|
|
117
|
-
issues.push({ path: section, message: `expected object, got ${typeof sectionValue}` });
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
for (const [field, check] of Object.entries(schema.rules)) {
|
|
121
|
-
const v = sectionValue[field];
|
|
122
|
-
issues.push(...check(v, `${section}.${field}`));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return issues;
|
|
126
|
-
}
|
|
127
|
-
export function reportConfigIssues(config) {
|
|
128
|
-
const issues = validateConfig(config);
|
|
129
|
-
if (issues.length === 0)
|
|
130
|
-
return !0;
|
|
131
|
-
console.warn("[config] Configuration issues detected:");
|
|
132
|
-
for (const issue of issues)
|
|
133
|
-
console.warn(` \u2022 ${issue.path}: ${issue.message}`);
|
|
134
|
-
return !1;
|
|
135
|
-
}
|
|
1
|
+
import{capabilityDrivers,findCapability}from"./capabilities";function isPlainObject(v){return typeof v==="object"&&v!==null&&!Array.isArray(v)}function checkInteger(min,max){return(value,path)=>{if(value==null)return[];let num=null;if(typeof value==="number"&&Number.isInteger(value))num=value;else if(typeof value==="string"&&/^-?\d+$/.test(value))num=Number.parseInt(value,10);if(num===null)return[{path,message:`expected integer, got ${typeof value} (${JSON.stringify(value)})`}];if(num<min||num>max)return[{path,message:`expected integer in [${min}, ${max}], got ${num}`}];return[]}}function checkOneOf(values){return(value,path)=>{if(value==null)return[];if(typeof value!=="string"||!values.includes(value))return[{path,message:`expected one of [${values.join(", ")}], got ${JSON.stringify(value)}`}];return[]}}function checkCapability(category){return(value,path)=>{if(value==null)return[];const drivers=capabilityDrivers(category);if(typeof value!=="string")return[{path,message:`expected ${category} driver name, got ${typeof value}`}];const capability=findCapability(category,value);if(!capability)return[{path,message:`unknown ${category} driver ${JSON.stringify(value)}; known drivers: [${drivers.map((driver)=>driver.name).join(", ")}]`}];if(capability.status==="unsupported")return[{path,message:`${category} driver ${JSON.stringify(value)} is unsupported: ${capability.limitations.join(" ")}`}];return[]}}function checkString(){return(value,path)=>{if(value==null)return[];return typeof value==="string"?[]:[{path,message:`expected string, got ${typeof value}`}]}}function checkBoolean(){return(value,path)=>{if(value==null)return[];return typeof value==="boolean"?[]:[{path,message:`expected boolean, got ${typeof value}`}]}}const PORT_CHECK=checkInteger(1,65535),SCHEMA={app:{rules:{name:checkString(),env:checkOneOf(["local","development","staging","production","test"]),debug:checkBoolean(),url:checkString()}},ports:{rules:{frontend:PORT_CHECK,api:PORT_CHECK,admin:PORT_CHECK,docs:PORT_CHECK,systemTray:PORT_CHECK,desktop:PORT_CHECK}},database:{rules:{default:checkCapability("database")}},cache:{rules:{driver:checkCapability("cache")}},featureFlags:{rules:{default:checkOneOf(["memory","database"]),missing:checkOneOf(["false","throw"])}},queue:{rules:{default:checkCapability("queue")}},logging:{rules:{level:checkOneOf(["trace","debug","info","warn","error","fatal"])}},email:{rules:{default:checkCapability("mail")}}};export function validateConfig(config){const issues=[];for(const[section,schema]of Object.entries(SCHEMA)){const sectionValue=config[section];if(sectionValue==null)continue;if(!isPlainObject(sectionValue)){issues.push({path:section,message:`expected object, got ${typeof sectionValue}`});continue}for(const[field,check]of Object.entries(schema.rules)){const v=sectionValue[field];issues.push(...check(v,`${section}.${field}`))}}return issues}export function reportConfigIssues(config){const issues=validateConfig(config);if(issues.length===0)return!0;console.warn("[config] Configuration issues detected:");for(const issue of issues)console.warn(` \u2022 ${issue.path}: ${issue.message}`);return!1}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/config",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.70.
|
|
5
|
+
"version": "0.70.259",
|
|
6
6
|
"description": "The Stacks config helper methods.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -33,9 +33,16 @@
|
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
35
|
"./*": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
36
|
+
"types": "./dist/*.d.ts",
|
|
37
|
+
"bun": "./dist/*.js",
|
|
38
|
+
"import": "./dist/*.js",
|
|
39
|
+
"default": "./dist/*.js"
|
|
40
|
+
},
|
|
41
|
+
"./*.js": {
|
|
42
|
+
"types": "./dist/*.d.ts",
|
|
43
|
+
"bun": "./dist/*.js",
|
|
44
|
+
"import": "./dist/*.js",
|
|
45
|
+
"default": "./dist/*.js"
|
|
39
46
|
}
|
|
40
47
|
},
|
|
41
48
|
"files": [
|
|
@@ -51,8 +58,8 @@
|
|
|
51
58
|
"ts-pantry": "^0.11.0"
|
|
52
59
|
},
|
|
53
60
|
"devDependencies": {
|
|
54
|
-
"@stacksjs/alias": "0.70.
|
|
61
|
+
"@stacksjs/alias": "0.70.259",
|
|
55
62
|
"better-dx": "^0.2.17",
|
|
56
|
-
"@stacksjs/types": "0.70.
|
|
63
|
+
"@stacksjs/types": "0.70.259"
|
|
57
64
|
}
|
|
58
65
|
}
|