@stacksjs/config 0.75.316 → 0.75.318
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/validators.js +1 -1
- package/package.json +8 -8
package/dist/validators.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{capabilityDrivers,findCapability}from"./capabilities";import{isCiphertext}from"./plain-env";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:
|
|
1
|
+
import{capabilityDrivers,findCapability}from"./capabilities";import{isCiphertext}from"./plain-env";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:checkInteger(0,65535),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],path=`${section}.${field}`;if(isCiphertext(v)){issues.push({path,message:"value is still encrypted; no usable private key opened it, so config read the ciphertext. Set the matching DOTENV_PRIVATE_KEY_<ENV> or ship .env.keys, and read it through `env` from @stacksjs/env rather than process.env"});continue}issues.push(...check(v,path))}}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.75.
|
|
5
|
+
"version": "0.75.318",
|
|
6
6
|
"description": "The Stacks config helper methods.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"prepublishOnly": "bun run build"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@stacksjs/events": "0.75.
|
|
59
|
-
"@stacksjs/features": "0.75.
|
|
60
|
-
"@stacksjs/path": "0.75.
|
|
61
|
-
"@stacksjs/tunnel": "0.75.
|
|
58
|
+
"@stacksjs/events": "0.75.318",
|
|
59
|
+
"@stacksjs/features": "0.75.318",
|
|
60
|
+
"@stacksjs/path": "0.75.318",
|
|
61
|
+
"@stacksjs/tunnel": "0.75.318",
|
|
62
62
|
"ts-pantry": "^0.11.127"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@stacksjs/alias": "0.75.
|
|
66
|
-
"@stacksjs/env": "0.75.
|
|
67
|
-
"@stacksjs/types": "0.75.
|
|
65
|
+
"@stacksjs/alias": "0.75.318",
|
|
66
|
+
"@stacksjs/env": "0.75.318",
|
|
67
|
+
"@stacksjs/types": "0.75.318",
|
|
68
68
|
"better-dx": "^0.2.24"
|
|
69
69
|
}
|
|
70
70
|
}
|