typed-settings 0.1.4 → 0.2.1
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/README.md +14 -7
- package/bin/typed-settings.mjs +5 -0
- package/dist/adapters/joi.cjs +1 -26
- package/dist/adapters/joi.d.cts +2 -1
- package/dist/adapters/joi.d.ts +2 -1
- package/dist/adapters/joi.js +1 -1
- package/dist/adapters/superstruct.cjs +1 -26
- package/dist/adapters/superstruct.js +1 -1
- package/dist/adapters/yup.cjs +1 -25
- package/dist/adapters/yup.js +1 -1
- package/dist/adapters/zod.cjs +3 -36
- package/dist/adapters/zod.js +1 -33
- package/dist/check-XVFZEVNV.js +1 -0
- package/dist/chunk-4EAMKDNK.js +3 -0
- package/dist/chunk-5D2AQWDG.js +1 -0
- package/dist/chunk-C6CG2D4B.js +2 -0
- package/dist/chunk-FQYD5ZKE.js +1 -0
- package/dist/chunk-NQDE3WLR.js +3 -0
- package/dist/chunk-RURPDXIJ.js +1 -0
- package/dist/cli/main.cjs +36 -2225
- package/dist/cli/main.js +32 -806
- package/dist/errors-JkkOM0u-.d.cts +25 -0
- package/dist/errors-JkkOM0u-.d.ts +25 -0
- package/dist/framework/next.cjs +5 -1158
- package/dist/framework/next.d.cts +3 -3
- package/dist/framework/next.d.ts +3 -3
- package/dist/framework/next.js +1 -15
- package/dist/framework/vite.cjs +5 -1156
- package/dist/framework/vite.d.cts +8 -3
- package/dist/framework/vite.d.ts +8 -3
- package/dist/framework/vite.js +1 -14
- package/dist/index.cjs +5 -1181
- package/dist/index.d.cts +38 -7
- package/dist/index.d.ts +38 -7
- package/dist/index.js +1 -6
- package/dist/node.cjs +6 -1241
- package/dist/node.d.cts +23 -9
- package/dist/node.d.ts +23 -9
- package/dist/node.js +1 -7
- package/dist/{types-B_Dc2L4T.d.cts → types-CcsYDAdO.d.cts} +23 -1
- package/dist/{types-B_Dc2L4T.d.ts → types-CcsYDAdO.d.ts} +23 -1
- package/dist/vault/aws.cjs +4 -217
- package/dist/vault/aws.d.cts +1 -1
- package/dist/vault/aws.d.ts +1 -1
- package/dist/vault/aws.js +2 -167
- package/dist/vault/hashicorp.cjs +4 -183
- package/dist/vault/hashicorp.d.cts +1 -1
- package/dist/vault/hashicorp.d.ts +1 -1
- package/dist/vault/hashicorp.js +2 -77
- package/dist/vault/http.cjs +4 -185
- package/dist/vault/http.d.cts +1 -1
- package/dist/vault/http.d.ts +1 -1
- package/dist/vault/http.js +2 -79
- package/package.json +2 -3
- package/dist/chunk-33M5GIKQ.js +0 -13
- package/dist/chunk-A5TCQJ7L.js +0 -65
- package/dist/chunk-DEP5SD4J.js +0 -233
- package/dist/chunk-EE6LXNJV.js +0 -34
- package/dist/chunk-F6DX3HXZ.js +0 -101
- package/dist/chunk-OVFMKC2O.js +0 -15
- package/dist/chunk-RQC6OMVV.js +0 -86
- package/dist/chunk-UFUHHR2J.js +0 -38
- package/dist/chunk-YVJEZPPZ.js +0 -989
- package/dist/errors-itGaU4Q8.d.cts +0 -17
- package/dist/errors-itGaU4Q8.d.ts +0 -17
- package/dist/formats/env.cjs +0 -103
- package/dist/formats/env.d.cts +0 -8
- package/dist/formats/env.d.ts +0 -8
- package/dist/formats/env.js +0 -1
- package/dist/formats/json.cjs +0 -15
- package/dist/formats/json.d.cts +0 -7
- package/dist/formats/json.d.ts +0 -7
- package/dist/formats/json.js +0 -1
- package/dist/formats/toml.cjs +0 -17
- package/dist/formats/toml.d.cts +0 -7
- package/dist/formats/toml.d.ts +0 -7
- package/dist/formats/toml.js +0 -1
- package/dist/formats/yaml.cjs +0 -40
- package/dist/formats/yaml.d.cts +0 -8
- package/dist/formats/yaml.d.ts +0 -8
- package/dist/formats/yaml.js +0 -1
package/README.md
CHANGED
|
@@ -145,12 +145,12 @@ The full list of spellings:
|
|
|
145
145
|
| `'config.yaml'` (any path) | structured file if the extension is `.json`/`.yaml`/`.yml`/`.toml`, dotenv format otherwise |
|
|
146
146
|
| `{ text: 'PORT=1' }` | dotenv text, inline |
|
|
147
147
|
| `{ file: 'path/to/x.yaml' }` | explicit file source |
|
|
148
|
-
| `{ dir: '/run/secrets' }` | secrets dir. Core
|
|
148
|
+
| `{ dir: '/run/secrets' }` | secrets dir. Core rejects this with `E_USAGE` on purpose (it never touches directories, so a `{ dir }` source would silently contribute nothing); read it with `loadSecretsDir()` from `typed-settings/node` and pass the result back as `{ map }` |
|
|
149
149
|
| `{ map: {...}, prefix?: 'X_' }` | inline values, with an optional per-source prefix |
|
|
150
150
|
| `{ provider, prefix? }` or bare provider | vault provider. Async ones require `settingsAsync()` |
|
|
151
151
|
| `{ PORT: 1 }` (plain object) | inline values. (An object with a non-function `load` key counts as data, not a provider) |
|
|
152
152
|
|
|
153
|
-
`prefix` strips case-insensitively and exactly once, so `APP_PORT` becomes `port` with `prefix: 'APP_'`. Double underscores nest (`APP_DB__URL` → `db.url`) and `ARR__0`, `ARR__1` fold into arrays. The edge cases are in [docs/syntax.md](docs/syntax.md); all the options in [docs/configuration.md](docs/configuration.md).
|
|
153
|
+
`prefix` strips case-insensitively and exactly once, so `APP_PORT` becomes `port` with `prefix: 'APP_'`. It only strips at a segment boundary: `prefix: 'APP'` strips `APP_FOO` but leaves `APPLE` alone (the key is dropped, never cut down to `le`). Double underscores nest (`APP_DB__URL` → `db.url`) and `ARR__0`, `ARR__1` fold into arrays. The edge cases are in [docs/syntax.md](docs/syntax.md); all the options in [docs/configuration.md](docs/configuration.md).
|
|
154
154
|
|
|
155
155
|
Node helpers (`typed-settings/node`):
|
|
156
156
|
|
|
@@ -194,8 +194,10 @@ Provider details: [docs/vault.md](docs/vault.md).
|
|
|
194
194
|
| `arrayStrategy` | `replace \| concat \| mergeIndex` | `'replace'` | how arrays merge across layers |
|
|
195
195
|
| `unknownKeys` | `strip \| preserve \| reject` | `'strip'` | `reject` throws `E_UNKNOWN_KEY` |
|
|
196
196
|
| `freeze` | `boolean` | `true` | deep-freeze the result |
|
|
197
|
-
| `timeoutMs` | `number` | `5000` | async only: provider
|
|
197
|
+
| `timeoutMs` | `number` | `5000` | async only: whole-collection provider deadline + async validation race |
|
|
198
198
|
| `maxBytes` | `number` | `2 MiB` | per-file read cap, counted in UTF-8 bytes |
|
|
199
|
+
| `secretKeys` | `(string\|RegExp)[]` | default pattern | extra secret matchers for error + `check --json` redaction |
|
|
200
|
+
| `fs` | `{ readFileSync, statSync? }` | node hook / require | injectable filesystem for file sources |
|
|
199
201
|
|
|
200
202
|
Full semantics for each: [docs/configuration.md](docs/configuration.md).
|
|
201
203
|
|
|
@@ -219,7 +221,7 @@ settings({ schema: yupAdapter(userSchema), sources: ['env'] });
|
|
|
219
221
|
|
|
220
222
|
## Secrets & redaction
|
|
221
223
|
|
|
222
|
-
Keys looking like secrets (`key`, `secret`, `token`, `password`, `private`, case-insensitive) get special treatment in errors: the value never appears, neither raw nor base64'd.
|
|
224
|
+
Keys looking like secrets (`key`, `secret`, `token`, `password`, `private`, case-insensitive) get special treatment in errors: the value never appears, neither raw nor base64'd — not even a three-character preview survives. Short values read `(redacted)`, longer ones `(redacted: N chars)`. More in [docs/errors.md](docs/errors.md).
|
|
223
225
|
|
|
224
226
|
## CLI
|
|
225
227
|
|
|
@@ -234,7 +236,7 @@ npx typed-settings watch -s src/settings.ts -c base.yaml -- node server.js
|
|
|
234
236
|
|---|---|---|
|
|
235
237
|
| `check` | validate config against a schema (`--strict`, `--no-expand`, `--array`, `--format human\|json`) | 0 valid · 1 invalid · 2 load/usage problem |
|
|
236
238
|
| `init` | scaffold `src/settings.ts` plus an example file (`--force`, `--dry-run`, `--check`) | 0 ok · 2 error or drift |
|
|
237
|
-
| `gen` | generate `.env.example` + `CONFIG.md` from a schema (`--force`) | 0 ok · 2 load problem
|
|
239
|
+
| `gen` | generate `.env.example` + `CONFIG.md` from a schema (`--force`) | 0 ok · 2 load problem, file exists, or symlink |
|
|
238
240
|
| `watch` | validate once (`--once`) or supervise and restart `-- cmd` | 0 ok · 1 invalid · 2 load/usage problem |
|
|
239
241
|
|
|
240
242
|
Flags and schema-export resolution: [docs/cli.md](docs/cli.md).
|
|
@@ -286,6 +288,7 @@ Things people actually hit, in rough order of frequency:
|
|
|
286
288
|
- **`E_UNKNOWN_KEY`.** Extra keys with `unknownKeys: 'reject'` (the CLI calls this `--strict`). Either drop the keys or switch to `strip` / `preserve`.
|
|
287
289
|
- **`SCHEMA_LOAD_ERROR`.** The CLI can't find your schema. Export it under the name `schema`, or point at it with `--schema-export NAME`.
|
|
288
290
|
- **`E_CIRCULAR`.** Two variables reference each other (`A=${B}`, `B=${A}`). Unwind the cycle.
|
|
291
|
+
- **`E_EXPAND` vs `E_PARSE`.** `E_EXPAND` is a malformed `${}` in a *value* (`A=${B` with no closing brace) — fix the value, and `check` exits `1`. `E_PARSE` is a *document* that wouldn't parse (a bad YAML/JSON/TOML/`.env` file, or a vault response body) — it carries the filename and `check` exits `2`.
|
|
289
292
|
|
|
290
293
|
Every code is listed with a fix in [docs/errors.md](docs/errors.md).
|
|
291
294
|
|
|
@@ -294,11 +297,15 @@ Every code is listed with a fix in [docs/errors.md](docs/errors.md).
|
|
|
294
297
|
```sh
|
|
295
298
|
npm install
|
|
296
299
|
npm run typecheck # tsc --noEmit
|
|
297
|
-
npm
|
|
298
|
-
npm
|
|
300
|
+
npm run build # tsup (ESM + CJS + DTS) - required before `npm test`
|
|
301
|
+
npm test # vitest - 441 tests, 100% lines/branches/functions/statements enforced
|
|
299
302
|
npm run size # bundle budgets (tracking only)
|
|
300
303
|
```
|
|
301
304
|
|
|
305
|
+
The `init`-template integration tests load a scaffolded project that imports
|
|
306
|
+
`typed-settings` by name, which resolves (via self-reference) to `dist/`, so run
|
|
307
|
+
`npm run build` before `npm test`.
|
|
308
|
+
|
|
302
309
|
The source is laid out by job: `src/index.ts` is the pipeline, `src/{expand,coerce,merge,adapter,errors}.ts` are the stages, then `src/formats/`, `src/node.ts`, `src/vault/`, `src/adapters/`, `src/cli/`, `src/framework/`. Tests live in `test/`, reference docs in `docs/`, runnable samples in `examples/`.
|
|
303
310
|
|
|
304
311
|
## License
|
package/bin/typed-settings.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import('../dist/cli/main.js').then((m) => m.main()).then((code) => {
|
|
3
3
|
process.exitCode = code;
|
|
4
|
+
}).catch((e) => {
|
|
5
|
+
// A failed import (missing dist/, broken install) must fail the CI gate,
|
|
6
|
+
// not pass it with exit 0 via an unhandled rejection.
|
|
7
|
+
console.error(e?.message ?? e);
|
|
8
|
+
process.exitCode = 2;
|
|
4
9
|
});
|
package/dist/adapters/joi.cjs
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/adapters/legacy.ts
|
|
4
|
-
function joiAdapter(schema) {
|
|
5
|
-
return {
|
|
6
|
-
"~standard": {
|
|
7
|
-
version: 1,
|
|
8
|
-
vendor: "typed-settings.joi",
|
|
9
|
-
validate: (input) => {
|
|
10
|
-
let res;
|
|
11
|
-
try {
|
|
12
|
-
res = schema.validate(input, { abortEarly: false, convert: true, allowUnknown: true, stripUnknown: true });
|
|
13
|
-
} catch (e) {
|
|
14
|
-
const err = e;
|
|
15
|
-
return { issues: [{ message: err?.message ?? String(e) }] };
|
|
16
|
-
}
|
|
17
|
-
if (!res.error) return { value: res.value };
|
|
18
|
-
const issues = (res.error.details ?? []).map((d) => ({ message: d.message, path: d.path.map(String) }));
|
|
19
|
-
if (issues.length === 0) return { issues: [{ message: res.error.message ?? "Invalid input" }] };
|
|
20
|
-
return { issues };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.joiAdapter = joiAdapter;
|
|
1
|
+
'use strict';function a(r){return {"~standard":{version:1,vendor:"typed-settings.joi",validate:s=>{let e;try{e=r.validate(s,{abortEarly:!1,convert:!0,allowUnknown:!0,stripUnknown:!0});}catch(n){return {issues:[{message:n?.message??String(n)}]}}if(e&&typeof e.then=="function")return {issues:[{message:"USE_ASYNC: Joi schema is async, which legacy bridges do not support"}]};if(!e.error)return {value:e.value};let t=(e.error.details??[]).map(n=>({message:n.message,path:n.path.map(String)}));return t.length===0?{issues:[{message:e.error.message??"Invalid input"}]}:{issues:t}}}}}exports.joiAdapter=a;
|
package/dist/adapters/joi.d.cts
CHANGED
|
@@ -12,7 +12,8 @@ declare function yupAdapter(schema: any): StandardSchemaV1;
|
|
|
12
12
|
/**
|
|
13
13
|
* Adapts a Joi schema (`validate` with convert + stripUnknown). `details[]`
|
|
14
14
|
* map to issues; a throwing `validate()` or empty details still yields a
|
|
15
|
-
* non-empty issues array, as Standard Schema requires.
|
|
15
|
+
* non-empty issues array, as Standard Schema requires. Sync only: an async
|
|
16
|
+
* `validate()` returning a promise is reported as failure, never validated.
|
|
16
17
|
*/
|
|
17
18
|
declare function joiAdapter(schema: AnySchema & {
|
|
18
19
|
validate?: (v: unknown, o?: unknown) => {
|
package/dist/adapters/joi.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ declare function yupAdapter(schema: any): StandardSchemaV1;
|
|
|
12
12
|
/**
|
|
13
13
|
* Adapts a Joi schema (`validate` with convert + stripUnknown). `details[]`
|
|
14
14
|
* map to issues; a throwing `validate()` or empty details still yields a
|
|
15
|
-
* non-empty issues array, as Standard Schema requires.
|
|
15
|
+
* non-empty issues array, as Standard Schema requires. Sync only: an async
|
|
16
|
+
* `validate()` returning a promise is reported as failure, never validated.
|
|
16
17
|
*/
|
|
17
18
|
declare function joiAdapter(schema: AnySchema & {
|
|
18
19
|
validate?: (v: unknown, o?: unknown) => {
|
package/dist/adapters/joi.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{b as joiAdapter}from'../chunk-RURPDXIJ.js';
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/adapters/legacy.ts
|
|
4
|
-
function superstructAdapter(schema) {
|
|
5
|
-
return {
|
|
6
|
-
"~standard": {
|
|
7
|
-
version: 1,
|
|
8
|
-
vendor: "typed-settings.superstruct",
|
|
9
|
-
validate: (input) => {
|
|
10
|
-
try {
|
|
11
|
-
const value = schema.create(input);
|
|
12
|
-
return { value };
|
|
13
|
-
} catch (e) {
|
|
14
|
-
const err = e;
|
|
15
|
-
if (typeof err.failures === "function") {
|
|
16
|
-
const issues = err.failures().map((f) => ({ message: f.message, path: f.path.map(String) }));
|
|
17
|
-
if (issues.length > 0) return { issues };
|
|
18
|
-
}
|
|
19
|
-
return { issues: [{ message: err.message ?? String(e) }] };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.superstructAdapter = superstructAdapter;
|
|
1
|
+
'use strict';function o(i){return {"~standard":{version:1,vendor:"typed-settings.superstruct",validate:u=>{let t;try{return t=i.create(u),{value:t}}catch(r){let e=r,n;try{if(typeof e.failures=="function"){let s=e.failures().map(a=>({message:a.message,path:a.path.map(String)}));s.length>0&&(n=s);}}catch{}return n?{issues:n}:{issues:[{message:e?.message??String(r)}]}}}}}}exports.superstructAdapter=o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{c as superstructAdapter}from'../chunk-RURPDXIJ.js';
|
package/dist/adapters/yup.cjs
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/adapters/legacy.ts
|
|
4
|
-
function yupAdapter(schema) {
|
|
5
|
-
return {
|
|
6
|
-
"~standard": {
|
|
7
|
-
version: 1,
|
|
8
|
-
vendor: "typed-settings.yup",
|
|
9
|
-
validate: (input) => {
|
|
10
|
-
try {
|
|
11
|
-
const value = schema.validateSync(input, { stripUnknown: true, abortEarly: false });
|
|
12
|
-
return { value };
|
|
13
|
-
} catch (e) {
|
|
14
|
-
const err = e;
|
|
15
|
-
const issues = (err.inner?.length ? err.inner : [{ path: "<root>", message: err.message ?? String(e) }]).map(
|
|
16
|
-
(i) => ({ message: String(i.message ?? String(e)), path: i.path ? [i.path] : void 0 })
|
|
17
|
-
);
|
|
18
|
-
return { issues };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.yupAdapter = yupAdapter;
|
|
1
|
+
'use strict';function a(r){return {"~standard":{version:1,vendor:"typed-settings.yup",validate:s=>{try{return {value:r.validateSync(s,{stripUnknown:!0,abortEarly:!1})}}catch(e){let n=e;return {issues:(n.inner?.length?n.inner:[{path:"<root>",message:n.message??String(e)}]).map(t=>({message:String(t.message??String(e)),path:t.path?[t.path]:void 0}))}}}}}}exports.yupAdapter=a;
|
package/dist/adapters/yup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{a as yupAdapter}from'../chunk-RURPDXIJ.js';
|
package/dist/adapters/zod.cjs
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function withPrefix(schema, prefix) {
|
|
5
|
-
if (!prefix) return schema;
|
|
6
|
-
const inner = schema;
|
|
7
|
-
const wrapped = {
|
|
8
|
-
"~standard": {
|
|
9
|
-
...inner["~standard"],
|
|
10
|
-
validate: (input) => {
|
|
11
|
-
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
12
|
-
const rec = input;
|
|
13
|
-
const stripped = {};
|
|
14
|
-
const low = prefix.toLowerCase();
|
|
15
|
-
for (const [k, v] of Object.entries(rec)) {
|
|
16
|
-
if (k.toLowerCase().startsWith(low)) {
|
|
17
|
-
const rest = k.slice(prefix.length);
|
|
18
|
-
stripped[rest ? rest.toLowerCase() : k] = v;
|
|
19
|
-
} else if (!(k.toLowerCase() in stripped)) {
|
|
20
|
-
stripped[k] = v;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return inner["~standard"].validate(stripped);
|
|
24
|
-
}
|
|
25
|
-
return inner["~standard"].validate(input);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
return wrapped;
|
|
30
|
-
}
|
|
31
|
-
function coerceEnv(value) {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
exports.coerceEnv = coerceEnv;
|
|
36
|
-
exports.withPrefix = withPrefix;
|
|
1
|
+
'use strict';var s=class extends Error{code="E_INVALID_CONFIG";issues;static[Symbol.hasInstance](n){return typeof n=="object"&&n!==null&&n.name==="ConfigError"&&typeof n.code=="string"&&Array.isArray(n.issues)}constructor(n=[],r="E_INVALID_CONFIG"){let f=n.map(t=>`- ${t.path} (from ${t.from}): ${t.message}`);super(n.length===0?"Invalid config: unknown error (no issues attached)":`Invalid config (${n.length} issue${n.length===1?"":"s"}):
|
|
2
|
+
${f.join(`
|
|
3
|
+
`)}`),this.name="ConfigError",this.code=r,this.issues=n;}};function a(e){return e.toLowerCase()==="__proto__"}function l(e,n){if(!n)return e;if(e.length<=n.length||e.slice(0,n.length).toLowerCase()!==n.toLowerCase())return null;let r=e.slice(n.length);return /[A-Za-z0-9]$/.test(n)&&/^[A-Za-z0-9]/.test(r)?null:r}function A(e,n){if(!n)return e;let r=e;return {"~standard":{...r["~standard"],validate:t=>{if(t&&typeof t=="object"&&!Array.isArray(t)){let d=t,i={};for(let[o,c]of Object.entries(d)){if(a(o))throw new s([{path:o,from:"withPrefix",message:"E_PROTO: forbidden key"}],"E_PROTO");let u=l(o,n);if(u===null){o.toLowerCase()in i||(i[o]=c);continue}let g=u.toLowerCase();if(a(g))throw new s([{path:o,from:"withPrefix",message:"E_PROTO: forbidden key"}],"E_PROTO");i[g]=c;}return r["~standard"].validate(i)}return r["~standard"].validate(t)}}}}function y(e){return e}exports.coerceEnv=y;exports.withPrefix=A;
|
package/dist/adapters/zod.js
CHANGED
|
@@ -1,33 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function withPrefix(schema, prefix) {
|
|
3
|
-
if (!prefix) return schema;
|
|
4
|
-
const inner = schema;
|
|
5
|
-
const wrapped = {
|
|
6
|
-
"~standard": {
|
|
7
|
-
...inner["~standard"],
|
|
8
|
-
validate: (input) => {
|
|
9
|
-
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
10
|
-
const rec = input;
|
|
11
|
-
const stripped = {};
|
|
12
|
-
const low = prefix.toLowerCase();
|
|
13
|
-
for (const [k, v] of Object.entries(rec)) {
|
|
14
|
-
if (k.toLowerCase().startsWith(low)) {
|
|
15
|
-
const rest = k.slice(prefix.length);
|
|
16
|
-
stripped[rest ? rest.toLowerCase() : k] = v;
|
|
17
|
-
} else if (!(k.toLowerCase() in stripped)) {
|
|
18
|
-
stripped[k] = v;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return inner["~standard"].validate(stripped);
|
|
22
|
-
}
|
|
23
|
-
return inner["~standard"].validate(input);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
return wrapped;
|
|
28
|
-
}
|
|
29
|
-
function coerceEnv(value) {
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { coerceEnv, withPrefix };
|
|
1
|
+
import {e,d,f}from'../chunk-NQDE3WLR.js';function u(n,d$1){if(!d$1)return n;let o=n;return {"~standard":{...o["~standard"],validate:e$1=>{if(e$1&&typeof e$1=="object"&&!Array.isArray(e$1)){let m=e$1,t={};for(let[r,i]of Object.entries(m)){if(e(r))throw new d([{path:r,from:"withPrefix",message:"E_PROTO: forbidden key"}],"E_PROTO");let c=f(r,d$1);if(c===null){r.toLowerCase()in t||(t[r]=i);continue}let f$1=c.toLowerCase();if(e(f$1))throw new d([{path:r,from:"withPrefix",message:"E_PROTO: forbidden key"}],"E_PROTO");t[f$1]=i;}return o["~standard"].validate(t)}return o["~standard"].validate(e$1)}}}}function k(n){return n}export{k as coerceEnv,u as withPrefix};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{b as runCheck}from'./chunk-FQYD5ZKE.js';import'./chunk-4EAMKDNK.js';import'./chunk-NQDE3WLR.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import {d,j,a,b,e,i,h,g,c}from'./chunk-NQDE3WLR.js';import {parseAllDocuments}from'yaml';import {parse}from'smol-toml';function N(e){let t={};e.charCodeAt(0)===65279&&(e=e.slice(1));let n=he(e);for(let o of n){let r=o.trim();if(!r||r.startsWith("#"))continue;r.startsWith("export ")&&(r=r.slice(7).trimStart());let s=r.indexOf("=");if(s===-1)throw new Error(`ParseError: bare key without '=': ${JSON.stringify(r)}`);let i=r.slice(0,s).trim(),a=r.slice(s+1).trimStart();if(!i)throw new Error("ParseError: empty key");let{value:u,quoted:f}=ye(a,r);t[i]=f&&!me(u)?pe(u):u;}return t}function me(e){let t=e.trim();return t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")}function pe(e){let t="";for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\"&&n+1<e.length){t+=o+e[n+1],n++;continue}if(o===","){t+="\\,";continue}t+=o;}return t}function he(e){let t=e.split(/\r?\n/),n=[],o="",r=false;for(let s of t)r?(o+=`
|
|
2
|
+
`+s,G(o.split("=").slice(1).join("="))%2===0&&(r=false,n.push(o),o="")):G(s)%2===1&&we(s)?(o=s,r=true):n.push(s);if(r)throw new Error("ParseError: unterminated double-quoted value");return n}function we(e){let t=e.indexOf("=");if(t===-1)return false;let n=e.slice(t+1).trimStart();return n.startsWith('"')&&!n.endsWith('"')}function G(e){let t=0;for(let n=0;n<e.length;n++)e[n]==='"'&&e[n-1]!=="\\"&&t++;return t}function ye(e,t){if(!e)return {value:"",quoted:false};if(e.startsWith("'")){let r=e.indexOf("'",1);if(r===-1)throw new Error("ParseError: unterminated single-quoted value");return H(e.slice(r+1),t),{value:e.slice(1,r),quoted:true}}if(e.startsWith('"')){let r=1,s="";for(;r<e.length;){let i=e[r];if(i==="\\"&&r+1<e.length){let a=e[r+1];a==="n"?s+=`
|
|
3
|
+
`:a==="r"?s+="\r":a==="t"?s+=" ":s+=a,r+=2;continue}if(i==='"')break;s+=i,r++;}if(e[r]!=='"')throw new Error("ParseError: unterminated double-quoted value");return H(e.slice(r+1),t),{value:s,quoted:true}}if(e.startsWith("`"))throw new Error("ParseError: backtick values not supported");let n=Ee(e);return {value:(n===-1?e:e.slice(0,n)).trim(),quoted:false}}function H(e,t){if(!/^\s*(#.*)?$/.test(e))throw new Error(`ParseError: trailing characters after quoted value: ${JSON.stringify(t)}`)}function Ee(e){for(let t=0;t<e.length;t++)if(e[t]==="#"&&(t===0||/\s/.test(e[t-1])))return t;return -1}function J(e,t="json"){let n=e.charCodeAt(0)===65279?e.slice(1):e;if(!n.trim())return {};try{return JSON.parse(n)}catch(o){let r=o;throw new Error(`ParseError (${t}): ${r.message}`)}}function Y(e,t="yaml"){let n=e.charCodeAt(0)===65279?e.slice(1):e;if(!n.trim())return {};let o=parseAllDocuments(n,{version:"1.2",uniqueKeys:true,maxAliasCount:100}).filter(i=>{if(i.errors.length>0)return true;try{let a=i.toJS();return a!=null}catch{return true}});if(o.length===0)return {};if(o.length>1)throw new Error(`ParseError (${t}): multi-doc YAML not supported (got ${o.length} documents)`);let r=o[0];if(r.errors.length>0){let i=r.errors[0],a=i.linePos?.[0]?.line??"?";throw new Error(`ParseError (${t}:${a}): ${i.message}`)}let s;try{s=r.toJS();}catch(i){throw new Error(`ParseError (${t}): ${i.message}`)}return s}function X(e,t="toml"){let n=e.charCodeAt(0)===65279?e.slice(1):e;if(!n.trim())return {};try{return parse(n)}catch(o){let r=o;throw new Error(`ParseError (${t}): ${r.message}`)}}var ee="[A-Za-z_][A-Za-z0-9_]*",be=new RegExp(`^\\$(?<name>${ee})`),Oe=new RegExp(`^(?<name>${ee})`),Z=50;function M(e,t,n,o=0){if(o>Z)throw new d([{path:n?.leafPath??"<expand>",from:n?.from??"config",message:`E_DEPTH: \${} nesting too deep (>${Z})`}],"E_DEPTH");let r="",s=0;for(;s<e.length;){let i=e[s];if(i==="$"&&e[s+1]==="$"){r+="$",s+=2;continue}if(i==="\\"&&e[s+1]==="$"){r+="\\$",s+=2;continue}if(i!=="$"){r+=i,s++;continue}let a=e.slice(s);if(a.startsWith("${")){let m=Re(e,s,n);if(!m){r+="$",s++;continue}let{name:p,op:c,def:g,end:h}=m,y=n?.leafPath??p,P=n?.from??"config";if(c&&c!==":-"&&c!=="-")throw new d([{path:y,from:P,message:`E_BAD_OP: only :- and - supported, got ${c}`}],"E_BAD_OP");let S=t(p);if(!(S===void 0||c===":-"&&S===""))r+=S;else if(g!==void 0)r+=M(g,t,n,o+1);else if(n?.allowUnresolved)r+=e.slice(s,h);else throw new d([{path:y,from:P,message:`E_UNRESOLVED: ${p} missing (expand)`}],"E_UNRESOLVED");s=h;continue}let u=be.exec(a);if(!u||!u.groups){r+="$",s++;continue}let f=u.groups.name,d$1=t(f);if(d$1===void 0)if(n?.allowUnresolved)r+="$"+f;else throw new d([{path:n?.leafPath??f,from:n?.from??"config",message:`E_UNRESOLVED: ${f} missing (expand)`}],"E_UNRESOLVED");else r+=d$1;s+=1+f.length;}return r}function Re(e,t,n){let o=t+2,r=Oe.exec(e.slice(o));if(!r?.groups)return null;let s=r.groups.name;if(o+=s.length,e[o]==="}")return {name:s,end:o+1};if(o>=e.length)throw new d([{path:n?.leafPath??s,from:n?.from??"config",message:"E_EXPAND: unterminated ${}"}],"E_EXPAND");if(e[o]===":"){if(e.slice(o,o+2)!==":-"){let f=e.slice(o).split("}")[0].slice(0,12);return {name:s,op:f,def:"",end:e.length}}o+=2;let{value:a,end:u}=Q(e,o);return {name:s,op:":-",def:a,end:u}}if(e[o]==="-"){o+=1;let{value:i,end:a}=Q(e,o);return {name:s,op:"-",def:i,end:a}}return null}function Q(e,t){let n=0,o=t,r="";for(;o<e.length;){if(e[o]==="\\"&&e[o+1]==="}"){r+="}",o+=2;continue}if(e[o]==="{"&&n++,e[o]==="}"){if(n===0)return {value:r,end:o+1};n--;}r+=e[o],o++;}throw new d([{path:"<expand>",from:"expand",message:"E_EXPAND: unterminated ${}"}],"E_EXPAND")}var ve=/^-?\d+$/,_e=/^-?(\d+\.\d*|\.\d+|\d+)(e[+-]?\d+)?$/i;function xe(e){return ne(e,true)}function ne(e,t){if(typeof e!="string")return e;let n=e;if(n==="")return "";let o=n.toLowerCase();if(o==="true"||o==="false")return o==="true";if(o==="null")return null;if(ve.test(n)){let s=Number(n);return Number.isSafeInteger(s)?s:n}if(_e.test(n)&&n!=="-"&&n!=="."){let s=Number(n);return Number.isFinite(s)?s:n}let r=n.trim();if(r.startsWith("{")&&r.endsWith("}")||r.startsWith("[")&&r.endsWith("]"))try{return JSON.parse(r)}catch{return e}if(t&&n.includes(",")){if(!Pe(n))return n.replace(/\\,/g,",");let s=Te(n);if(s!==null)return s.map(i=>ne(i,false))}return e}function Pe(e){let t=null;for(let n=0;n<e.length;n++){let o=e[n];if(t){if(o==="\\"&&n+1<e.length){n++;continue}o===t&&(t=null);continue}if(o==='"'||o==="'"){t=o;continue}if(o==="\\"&&e[n+1]===","){n++;continue}if(o===",")return true}return false}function Te(e){let t=[],n="",o=null;for(let r=0;r<e.length;r++){let s=e[r];if(o){if(s==="\\"&&r+1<e.length){n+=s+e[r+1],r++;continue}if(s===o){o=null,n+=s;continue}n+=s;continue}if(s==='"'||s==="'"){o=s,n+=s;continue}if(s==="\\"&&e[r+1]===","){n+=",",r++;continue}if(s===","){t.push(n.trim()),n="";continue}n+=s;}return o?null:(t.push(n.trim()),t.map(r=>r.length>=2&&r.startsWith("'")&&r.endsWith("'")?r.slice(1,-1).replace(/\\,/g,","):r.length>=2&&r.startsWith('"')&&r.endsWith('"')?r.slice(1,-1):r.replace(/\\,/g,",")))}function v(e$1){if(typeof e$1=="string")return xe(e$1);if(Array.isArray(e$1))return e$1.map(v);if(e$1&&typeof e$1=="object"){let t=Object.getPrototypeOf(e$1);if(t!==Object.prototype&&t!==null)return e$1;let n={};for(let[o,r]of Object.entries(e$1)){if(e(o))throw new d([{path:o,from:"coerce",message:"E_PROTO: forbidden key"}],"E_PROTO");n[o]=v(r);}return n}return e$1}function Ae(e){if(!e||e.length===0)return "<root>";let t=[];for(let n of e)n!==null&&typeof n=="object"&&"key"in n?t.push(String(n.key)):t.push(String(n));return t.join(".")}function A(e,t){let n;try{n=e["~standard"].validate(t);}catch(r){return {issues:[{path:"<root>",message:r instanceof Error?r.message:String(r)}],async:false}}if(typeof n?.then=="function")return {promise:n.then(s=>te(s),s=>({ok:false,issues:[{path:"<root>",message:s instanceof Error?s.message:String(s)}]}))};let o=te(n);return o.ok?{value:o.value}:{issues:o.issues,async:false}}function te(e){return !e.issues||e.issues.length===0?{ok:true,value:e.value}:{ok:false,issues:e.issues.map(t=>({path:Ae(t.path),message:t.message}))}}var re=50;function se(e){if(e)return {...e};let t=globalThis;return t.process?.env?{...t.process.env}:{}}function on(e,t){let n=globalThis,o=Object.keys(e),r=new Set,s=new Map,i=()=>{let u=n.process?.env;if(u)for(let f of o)r.has(f)?u[f]=s.get(f):delete u[f];};if(n.process?.env)for(let u of o){u in n.process.env&&(r.add(u),s.set(u,n.process.env[u]));let f=e[u];f===void 0?delete n.process.env[u]:n.process.env[u]=f;}let a;try{a=t();}catch(u){throw i(),u}return ce(a)?Promise.resolve(a).finally(i):(i(),a)}function an(e,t){let n={};for(let o of t){let r=String(o);r==="__proto__"||r==="constructor"||r==="prototype"||Object.hasOwn(e,o)&&(n[o]=e[o]);}return n}function fn(e,t){return je({...e,sources:[{map:t}],env:{}})}function O(e,t=2*1024*1024,n){let o=()=>{if(n)return n;let r=globalThis.__typedSettingsFs;if(r)return r;if(globalThis.process){let i;try{i=new Function('return typeof require !== "undefined" ? require("node:fs") : null')();}catch{i=null;}if(!i)throw new d([{path:"<root>",from:e,message:`E_NO_FS: cannot read '${e}' under ESM \u2014 import 'typed-settings/node', pass opts.fs, or use { text }/{ map }`}],"E_NO_FS");return i}return null};try{let r=o();if(!r)return;if(r.statSync)try{if(r.statSync(e).size>t)throw new d([{path:"<root>",from:e,message:`E_FILE_TOO_LARGE: '${e}' >${t} bytes \u2014 raise maxBytes or shrink the file`}],"E_FILE_TOO_LARGE")}catch(i){if(i instanceof d)throw i}let s=r.readFileSync(e,"utf8");if(c(s)>t)throw new d([{path:"<root>",from:e,message:`E_FILE_TOO_LARGE: '${e}' >${t} bytes \u2014 raise maxBytes or shrink the file`}],"E_FILE_TOO_LARGE");return s}catch(r){if(r instanceof d)throw r;if(r?.code==="ENOENT")return;throw r}}function oe(e){if(e.maxBytes!==void 0&&(!Number.isFinite(e.maxBytes)||e.maxBytes<=0))throw new d([{path:"maxBytes",from:"options",message:"E_USAGE: maxBytes must be a positive finite number"}],"E_USAGE");if(e.timeoutMs!==void 0&&(!Number.isFinite(e.timeoutMs)||e.timeoutMs<=0))throw new d([{path:"timeoutMs",from:"options",message:"E_USAGE: timeoutMs must be a positive finite number"}],"E_USAGE")}function E(e,t){try{return t()}catch(n){throw n instanceof d?n:n instanceof RangeError&&/call stack|recursion|too much/i.test(n.message)?new d([{path:"<root>",from:e,message:"E_DEPTH: nesting too deep (possible hostile input)"}],"E_DEPTH"):n}}function L(e,t){let n=e.toLowerCase();try{return n.endsWith(".json")?J(t,e):n.endsWith(".yaml")||n.endsWith(".yml")?Y(t,e):X(t,e)}catch(o){let r=o;throw new d([{path:"<root>",from:e,message:r.message}],"E_PARSE")}}function ie(e,t){if(!t)return e;if(e.length<=t.length||e.slice(0,t.length).toLowerCase()!==t.toLowerCase())return null;let n=e.slice(t.length);return /[A-Za-z0-9]$/.test(t)&&/^[A-Za-z0-9]/.test(n)?null:n}function ae(e,t){let n=new Set,o=(r,s)=>{if(!(!r||typeof r!="object")){if(n.has(r))throw new d([{path:s,from:t,message:`E_CIRCULAR: cyclic value at '${s}' \u2014 remove the self-reference (shared DAG refs are fine, true cycles are not)`}],"E_CIRCULAR");n.add(r);try{for(let[i,a]of Object.entries(r))o(a,s?`${s}.${i}`:i);}finally{n.delete(r);}}};o(e,"");}function w(e$1,t,n,o,r,s,i=false){ae(e$1,t);let a=n??o,u={};for(let[d$1,m]of Object.entries(e$1)){let p=ie(d$1,a);if(p!==null){if(e(p))throw new d([{path:d$1,from:t,message:"E_PROTO: forbidden key"}],"E_PROTO");u[p]=m;}}return {node:h(g(u,{prefix:void 0,envMap:r.envMap,tolerantKeys:i})),label:t,skipExpand:s}}function $(e$1,t,n){if(ae(e$1,t),U(e$1,t),!i(e$1))return {node:e$1??{},label:t,skipExpand:false};let o={};for(let[r,s]of Object.entries(e$1))if(n){let i=ie(r,n);if(i===null)continue;if(e(i))throw new d([{path:r,from:t,message:"E_PROTO: forbidden key"}],"E_PROTO");o[i]=s;}else o[r]=s;return {node:h(o,t),label:t,skipExpand:false}}function U(e$1,t){if(Array.isArray(e$1)){for(let n of e$1)U(n,t);return}if(e$1&&typeof e$1=="object")for(let[n,o]of Object.entries(e$1)){if(e(n))throw new d([{path:n,from:t,message:"E_PROTO: forbidden key"}],"E_PROTO");U(o,t);}}function fe(e,t){let n=t.node;if(n&&typeof n=="object"&&!Array.isArray(n))for(let o of Object.keys(n))e.set(o.toLowerCase(),t.label);}function ce(e){return !!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function W(e){if(!("provider"in e||"load"in e))return null;let t="provider"in e?e.provider:e;return !t||typeof t.load!="function"?null:{load:t.load,name:typeof t.name=="string"?t.name:"<provider>"}}function Le(e,t){return new d([{path:"<root>",from:e,message:`E_TIMEOUT: provider '${e}' load outran timeoutMs (${t}ms) \u2014 raise timeoutMs or fix the backend`}],"E_TIMEOUT")}function ue(e,t){let n=e.sources??[".env","env"],o=e.prefix,r=[],s=new Map,i=e.maxBytes??2*1024*1024,a=f=>{r.push(f),fe(s,f);},u=(f,d$1)=>{try{return N(f)}catch(m){let p=m;throw new d([{path:"<root>",from:d$1,message:p.message}],"E_PARSE")}};for(let f of n)if(f==="env")a(w({...t},"env",void 0,o,e,false,true));else if(f===".env"||f===".env.local"){let d=O(f,i,e.fs);if(d===void 0)continue;a(w(u(d,f),f,void 0,o,e,false));}else if(typeof f=="string"){let d=O(f,i,e.fs);if(d===void 0)continue;let m=f.toLowerCase();m.endsWith(".json")||m.endsWith(".yaml")||m.endsWith(".yml")||m.endsWith(".toml")?a($(L(f,d),f,o)):a(w(u(d,f),f,void 0,o,e,false));}else if(f&&typeof f=="object"&&"text"in f)a(w(u(f.text,"text"),"text",void 0,o,e,false));else if(f&&typeof f=="object"&&"map"in f){let d=f;a(w(d.map??{},"overrides",d.prefix,o,e,false));}else if(f&&typeof f=="object"&&"file"in f){let d=f.file,m=O(d,i,e.fs);if(m===void 0)continue;let p=d.toLowerCase();p.endsWith(".json")||p.endsWith(".yaml")||p.endsWith(".yml")||p.endsWith(".toml")?a($(L(d,m),d,o)):a(w(u(m,d),d,void 0,o,e,false));}else {if(f&&typeof f=="object"&&"dir"in f)throw new d([{path:f.dir,from:"config",message:"E_USAGE: { dir } sources need loadSecretsDir() from typed-settings/node, passed back as { map }"}],"E_USAGE");if(f&&typeof f=="object"){let d$1=W(f);if(d$1){let m="prefix"in f?f.prefix:void 0,p;try{p=d$1.load();}catch(c){if(c instanceof d)throw c;let g=c;throw new d([{path:d$1.name,from:d$1.name,message:`E_PROVIDER: ${g?.message??String(c)}`}],"E_PROVIDER")}if(ce(p))throw new d([{path:"<root>",from:d$1.name,message:`USE_ASYNC: provider '${d$1.name}' is async \u2014 switch to settingsAsync()`}],"USE_ASYNC");a(w(p??{},d$1.name,m,o,e,!e.expandSecrets));}else a(w(f,"overrides",void 0,o,e,false));}}return {layers:r,fromMap:s}}async function $e(e,t){let n=e.timeoutMs??5e3;if(!(e.sources??[]).some(c=>c&&typeof c=="object"&&W(c)!==null))return ue(e,t);let r=Date.now()+n,s=e.sources,i=e.prefix,a=[],u=new Map,f=e.maxBytes??2*1024*1024,d$1=c=>{a.push(c),fe(u,c);},m=(c,g)=>{try{return N(c)}catch(h){let y=h;throw new d([{path:"<root>",from:g,message:y.message}],"E_PARSE")}},p=async(c,g)=>{let h=Math.max(1,r-Date.now()),y,P=new Promise((R,j)=>{y=setTimeout(()=>j(Le(c,n)),h);}),S=Promise.resolve().then(g);S.catch(()=>{});let K=await Promise.race([S,P]).catch(R=>{if(clearTimeout(y),R instanceof d)throw R;let j=R;throw new d([{path:c,from:c,message:`E_PROVIDER: ${j?.message??String(R)}`}],"E_PROVIDER")});return clearTimeout(y),K};for(let c of s)if(c==="env")d$1(w({...t},"env",void 0,i,e,false,true));else if(c===".env"||c===".env.local"){let g=O(c,f,e.fs);if(g===void 0)continue;d$1(w(m(g,c),c,void 0,i,e,false));}else if(typeof c=="string"){let g=O(c,f,e.fs);if(g===void 0)continue;let h=c.toLowerCase();h.endsWith(".json")||h.endsWith(".yaml")||h.endsWith(".yml")||h.endsWith(".toml")?d$1($(L(c,g),c,i)):d$1(w(m(g,c),c,void 0,i,e,false));}else if(c&&typeof c=="object"&&"text"in c)d$1(w(m(c.text,"text"),"text",void 0,i,e,false));else if(c&&typeof c=="object"&&"map"in c){let g=c;d$1(w(g.map??{},"overrides",g.prefix,i,e,false));}else if(c&&typeof c=="object"&&"file"in c){let g=c.file,h=O(g,f,e.fs);if(h===void 0)continue;let y=g.toLowerCase();y.endsWith(".json")||y.endsWith(".yaml")||y.endsWith(".yml")||y.endsWith(".toml")?d$1($(L(g,h),g,i)):d$1(w(m(h,g),g,void 0,i,e,false));}else {if(c&&typeof c=="object"&&"dir"in c)throw new d([{path:c.dir,from:"config",message:"E_USAGE: { dir } sources need loadSecretsDir() from typed-settings/node, passed back as { map }"}],"E_USAGE");if(c&&typeof c=="object"){let g=W(c);if(g){let h="prefix"in c?c.prefix:void 0,y=await p(g.name,()=>g.load());d$1(w(y??{},g.name,h,i,e,!e.expandSecrets));}else d$1(w(c,"overrides",void 0,i,e,false));}}return {layers:a,fromMap:u}}function le(e){return new Set(e.filter(t=>t.skipExpand).flatMap(t=>Object.keys(t.node)).map(t=>t.toLowerCase()))}function Ce(e,t){let{layers:n,fromMap:o}=ue(e,t),r=e.arrayStrategy??"replace",s={};for(let u of n)s=j(s,u.node,r);let i=le(n);return e.expand!==false&&(s=_(s,de(s,t),{allowUnresolved:e.allowUnresolved,fromMap:o,skipTops:i})),e.coerce!==false&&(s=v(s)),{input:s,fromFor:u=>{let f=u.split(".")[0].toLowerCase();return f==="<root>"?"schema":o.get(f)??"defaults"}}}function de(e,t){let n=e&&typeof e=="object"&&!Array.isArray(e)?e:{},o=new Map(Object.keys(n).map(s=>[s.toLowerCase(),s])),r=new Map;for(let[s,i]of Object.entries(t))r.set(s.toLowerCase(),i);return s=>{let i=o.get(s.toLowerCase());if(i!==void 0){let a=n[i];return typeof a=="string"?a:typeof a=="number"||typeof a=="boolean"||typeof a=="bigint"?String(a):a==null?t[s]??r.get(s.toLowerCase()):void 0}return t[s]??r.get(s.toLowerCase())}}function _(e,t,n,o=[]){if(typeof e=="string"){if(!e.includes("$"))return e;let r=(o[0]??"<root>").toLowerCase(),s=n.fromMap.get(r)??"config",i=o.map(a=>String(a).toLowerCase()).join(".")||"<root>";try{return ge(e,t,{...n,from:s},[],i)}catch(a){if(s==="env"&&a instanceof d&&a.code==="E_UNRESOLVED")return e;throw a}}if(Array.isArray(e))return e.map((r,s)=>_(r,t,n,[...o,String(s)]));if(e&&typeof e=="object"){if(o.length===0){let s={};for(let[i,a]of Object.entries(e))s[i]=n.skipTops.has(i.toLowerCase())?a:_(a,t,n,[i]);return s}let r={};for(let[s,i]of Object.entries(e))r[s]=_(i,t,n,[...o,s]);return r}return e}function ge(e,t,n,o,r){return M(e,s=>{let i=s.toLowerCase();if(o.includes(i))throw new d([{path:r,from:n.from,message:`E_CIRCULAR: $${[...o,s].join("->$")} reachable from '${r}' \u2014 unwind the $VAR references`}],"E_CIRCULAR");if(o.length>=re)throw new d([{path:r,from:n.from,message:`E_CIRCULAR: $VAR chain from '${r}' exceeded ${re} links \u2014 flatten the indirection`}],"E_CIRCULAR");let a=t(s);if(a!==void 0)return a.includes("$")?ge(a,t,n,[...o,i],r):a},{allowUnresolved:n.allowUnresolved,from:n.from,leafPath:r})}function C(e,t=""){if(Array.isArray(e)){let n=[];return e.forEach((o,r)=>n.push(...C(o,t?`${t}.${r}`:`${r}`))),n}if(i(e)){let n=[];for(let[o,r]of Object.entries(e)){let s=t?`${t}.${o.toLowerCase()}`:o.toLowerCase();i(r)||Array.isArray(r)?n.push(...C(r,s)):n.push(s);}return n}return t?[t.toLowerCase()]:[]}function D(e,t,n,o){if(n==="strip"||n===void 0)return t;if(n==="preserve")return i(e)&&i(t)?j(e,t,"replace"):t;let r=new Set(C(e)),s=new Set(C(t)),i$1=[...r].filter(a=>!s.has(a));if(i$1.length>0)throw new d(i$1.map(a=>({path:a,from:o(a),message:`E_UNKNOWN_KEY: '${a}' is not in the schema \u2014 remove it, or use unknownKeys 'strip'/'preserve'`})),"E_UNKNOWN_KEY");return t}function x(e){if(Array.isArray(e)){for(let t of e)x(t);return Object.freeze(e)}if(e&&typeof e=="object"){for(let t of Object.keys(e))x(e[t]);return Object.freeze(e)}return e}function je(e){oe(e);let t=e.secretKeys,n=se(e.env),{input:o,fromFor:r}=E("config",()=>Ce(e,n)),s=E("schema",()=>A(e.schema,o));if("promise"in s)throw new d([{path:"<root>",from:"schema",message:"USE_ASYNC: schema is async, use settingsAsync()"}],"USE_ASYNC");if("issues"in s)throw new d(s.issues.map(u=>({path:u.path,from:r(u.path),message:I(u.path,u.message,o,t)})));let i=s.value,a=E("config",()=>D(o,i,e.unknownKeys??"strip",r));return e.freeze===false?a:E("config",()=>x(a))}async function cn(e){let t=e.timeoutMs??5e3;oe(e);let n=e.secretKeys,o=se(e.env),{input:r,fromFor:s}=await Fe(e,o).catch(f=>{throw f instanceof d?f:f instanceof RangeError?new d([{path:"<root>",from:"config",message:"E_DEPTH: nesting too deep (possible hostile input)"}],"E_DEPTH"):f}),i=A(e.schema,r);if("promise"in i){i.promise.catch(()=>{});let f,d$1=new Promise((g,h)=>{f=setTimeout(()=>h(new d([{path:"<root>",from:"schema",message:`E_TIMEOUT: async validation outran timeoutMs (${t}ms) \u2014 raise timeoutMs or fix the validator`}],"E_TIMEOUT")),t);}),m;try{m=await Promise.race([i.promise,d$1]);}finally{f&&clearTimeout(f);}if(!m.ok)throw new d(m.issues.map(g=>({path:g.path,from:s(g.path),message:I(g.path,g.message,r,n)})));let p=m.value,c=E("config",()=>D(r,p,e.unknownKeys??"strip",s));return e.freeze===false?c:E("config",()=>x(c))}if("issues"in i)throw new d(i.issues.map(f=>({path:f.path,from:s(f.path),message:I(f.path,f.message,r,n)})));let a=i.value,u=E("config",()=>D(r,a,e.unknownKeys??"strip",s));return e.freeze===false?u:E("config",()=>x(u))}async function Fe(e,t){let{layers:n,fromMap:o}=await $e(e,t),r=e.arrayStrategy??"replace",s={};for(let u of n)s=j(s,u.node,r);let i=le(n);return e.expand!==false&&(s=_(s,de(s,t),{allowUnresolved:e.allowUnresolved,fromMap:o,skipTops:i})),e.coerce!==false&&(s=v(s)),{input:s,fromFor:u=>{let f=u.split(".")[0].toLowerCase();return f==="<root>"?"schema":o.get(f)??"defaults"}}}function Ve(e,t){let n=[];for(let r of t.split(".")){let s=/^([^\[\]]+)\[(\d+)\]$/.exec(r);s?n.push(s[1],Number(s[2])):n.push(r);}let o=e;for(let r of n){if(o===null||typeof o!="object")return;if(Array.isArray(o)){let a=typeof r=="number"?r:Number(r);if(!Number.isInteger(a))return;o=o[a];continue}let s=o,i=Object.keys(s).find(a=>a.toLowerCase()===String(r).toLowerCase());if(!i)return;o=s[i];}return o}function Ne(e){let t=globalThis;if(t.btoa)try{return t.btoa(e)}catch{}try{if(t.Buffer)return t.Buffer.from(e,"utf8").toString("base64")}catch{}return null}function I(e,t,n,o){if(!a(e,o))return t;let r=t,s=Ve(n,e),i=typeof s=="string"?s:typeof s=="number"||typeof s=="boolean"||typeof s=="bigint"?String(s):void 0;if(i!==void 0&&i.length>=4){let a=b(e,i,o);r=r.split(i).join(a);let u=Ne(i);u&&u.length>8&&(r=r.split(u).join(a));}return `${r} (redacted)`}export{N as a,A as b,on as c,an as d,fn as e,je as f,cn as g};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {d,e,c}from'./chunk-NQDE3WLR.js';function y(e){if(e)return e;let t=globalThis;if(t.fetch)return t.fetch.bind(globalThis);throw new d([{path:"<provider>",from:"vault",message:"E_NO_FETCH: global fetch unavailable"}],"E_NO_FETCH")}function l(e,t){try{return new URL(e).host===new URL(t).host}catch{return false}}var h=/authorization|token|secret|api[-_]?key|cookie|auth/i;function p(e,t){try{return new URL(e).protocol==="https:"&&new URL(t).protocol!=="https:"}catch{return false}}function g(e){let t=new Headers;return e.forEach((r,a)=>{h.test(a)||t.set(a,r);}),t}async function R(e,t,r,a=2){let i=e,s=new Headers(t.headers);for(let o=0;o<=a;o++){let n=await r(i,{...t,headers:s,redirect:"manual"}),c=n.status;if(![301,302,303,307,308].includes(c))return n;let m=n.headers.get("location");if(!m)return n;let f;try{f=new URL(m,i).toString();}catch{throw new d([{path:i,from:"vault",message:"E_REDIRECT: invalid Location header"}],"E_REDIRECT")}if(o===a)throw new d([{path:f,from:"vault",message:"E_REDIRECT: too many redirects"}],"E_REDIRECT");(!l(i,f)||p(i,f))&&(s=g(s)),i=f;}throw new d([{path:e,from:"vault",message:"E_REDIRECT"}],"E_REDIRECT")}function _(e$1,t,r){let a=r?.trimNewline!==false,i=o=>{if(o==null)return;let n=typeof o=="string"?o:String(o);return a&&(n=n.replace(/\r?\n$/,"")),n},s={};if(!e$1||typeof e$1!="object"||Array.isArray(e$1))throw new d([{path:"<root>",from:t,message:"E_SHAPE: provider returned non-object"}],"E_SHAPE");for(let[o,n]of Object.entries(e$1)){if(e(o))throw new d([{path:o,from:t,message:"E_PROTO: forbidden key"}],"E_PROTO");if(n!==null&&typeof n=="object"&&!Array.isArray(n)){s[o]=n;continue}let c=i(n);c!==void 0&&(s[o]=c);}return s}function b(e){return e===403||e===401?"E_DENIED":e===404?"E_NOT_FOUND":e===429?"E_THROTTLED":e===408||e===504?"E_TIMEOUT":e>=500?"E_UPSTREAM":"E_PROVIDER"}function P(e,t){let r=t??AbortSignal;if(typeof r.timeout=="function")try{return r.timeout(e)}catch{return}}function O(e,t,r){if(!Number.isFinite(e)||e<=0)throw new d([{path:t,from:r,message:`E_USAGE: ${t} must be a positive finite number`}],"E_USAGE")}function S(e){try{let t=new URL(e);t.username="",t.password="";for(let r of [...t.searchParams.keys()])/token|secret|auth|password|credential|api[-_]?key|pwd|passphrase/i.test(r)&&t.searchParams.delete(r);return t.hash="",t.toString()}catch{return e}}async function F(e,t,r,a){let i,s=new Promise((o,n)=>{i=setTimeout(()=>n(new d([{path:r,from:a,message:"E_TIMEOUT: request timed out"}],"E_TIMEOUT")),t);});e.catch(()=>{});try{return await Promise.race([e,s])}finally{i&&clearTimeout(i);}}async function I(e,t,r,a,i){let s,o=new Promise((n,c)=>{s=setTimeout(()=>c(new d([{path:t,from:r,message:"E_TIMEOUT: response body timed out"}],"E_TIMEOUT")),i);});try{let n=e.text();n.catch(()=>{});let c$1=await Promise.race([n,o]);if(c(c$1)>a)throw new d([{path:t,from:r,message:"E_TOO_LARGE"}],"E_TOO_LARGE");return c$1}finally{s&&clearTimeout(s);}}export{y as a,R as b,_ as c,b as d,P as e,O as f,S as g,F as h,I as i};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a,f}from'./chunk-4EAMKDNK.js';import {d,c,i}from'./chunk-NQDE3WLR.js';import {statSync,readFileSync,readdirSync,lstatSync,realpathSync,watch}from'fs';import {resolve,join,relative,sep,isAbsolute,dirname,basename}from'path';globalThis.__typedSettingsFs??={readFileSync:(e,t)=>readFileSync(e,t),statSync:e=>statSync(e)};function oe(e,t={}){let n=t.maxBytes??2097152;if(!Number.isFinite(n)||n<=0)throw new d([{path:"<envFiles>",from:"loadEnvFiles",message:"E_USAGE: maxBytes must be a positive number"}],"E_USAGE");let o=[],l=0;for(let s of e)try{let r=readFileSync(s,"utf8"),c$1=c(r);if(c$1>n||l+c$1>n)throw new d([{path:s,from:"loadEnvFiles",message:"E_FILE_TOO_LARGE: env text over cap"}],"E_FILE_TOO_LARGE");l+=c$1,o.push(r);}catch(r){if(r?.code==="ENOENT")continue;throw r}return {text:o.join(`
|
|
2
|
+
`)}}function ie(e,t={}){let n=t.maxBytes??2097152;if(!Number.isFinite(n)||n<=0)throw new d([{path:e,from:e,message:"E_USAGE: maxBytes must be a positive finite number"}],"E_USAGE");let o={},l;try{l=readdirSync(e);}catch(r){if(r?.code==="ENOENT")return o;throw r}let s=resolve(e);for(let r of l){let c$1=join(e,r),p;try{p=lstatSync(c$1);}catch(f){if(f?.code==="ENOENT")continue;throw f}if(p.isSymbolicLink()){let f;try{f=realpathSync(c$1);}catch(m){if(m?.code==="ENOENT")continue;throw m}let d$1=relative(s,f);if(d$1===""||d$1===".."||d$1.startsWith(`..${sep}`)||isAbsolute(d$1))throw new d([{path:r,from:e,message:"E_SHAPE: secret symlink escapes its directory"}],"E_SHAPE");try{let m=statSync(f);if(!m.isFile())continue;if(m.size>n+1)throw new d([{path:r,from:e,message:"E_FILE_TOO_LARGE: secret over cap"}],"E_FILE_TOO_LARGE")}catch(m){if(m instanceof d)throw m;if(m?.code==="ENOENT")continue;throw m}}else if(p.isFile()){if(p.size>n+1)throw new d([{path:r,from:e,message:"E_FILE_TOO_LARGE: secret over cap"}],"E_FILE_TOO_LARGE")}else continue;if(r.startsWith(".."))continue;let i;try{i=readFileSync(c$1,"utf8");}catch(f){if(f?.code==="ENOENT")continue;throw f}if(c(i)>n+1)throw new d([{path:r,from:e,message:"E_FILE_TOO_LARGE: secret over cap"}],"E_FILE_TOO_LARGE");let a=i.replace(/\r?\n$/,"");if(!a&&!t.preserveEmpty)continue;let u=r.replace(/[a-z]/g,f=>f.toUpperCase());if(u in o)throw new d([{path:r,from:e,message:`E_SHAPE: secret name collision on ${u}`}],"E_SHAPE");o[u]=a;}return o}function ae(e){try{let t=readFileSync(e,"utf8");return a(t)}catch(t){if(t?.code==="ENOENT")return {};throw t}}function j(e){let t=[];for(let n of e??[])if(n!=="env")if(n===".env"||n===".env.local")t.push(resolve(n));else if(typeof n=="string"){let o=n.toLowerCase();o.endsWith(".env")||n===".env.local"||o.endsWith(".json")||o.endsWith(".yaml")||o.endsWith(".yml")||o.endsWith(".toml")?t.push(resolve(n)):o.endsWith(".env")||t.push(resolve(n));}else n&&typeof n=="object"&&"file"in n&&t.push(resolve(n.file));return [...new Set(t)]}function q(e){return (e??[]).some(t=>t&&typeof t=="object"&&("provider"in t||"load"in t))}function K(e,t){if(e===t||Object.is(e,t))return true;if(typeof e!=typeof t)return false;if(e&&t&&typeof e=="object")try{return JSON.stringify(e)===JSON.stringify(t)}catch{return false}return false}function Q(e,t,n=""){let o=[],l=[[e,t,n]];for(;l.length>0;){let[s,r,c]=l.pop();if(Array.isArray(s)&&Array.isArray(r)){let p=Math.max(s.length,r.length);for(let i=p-1;i>=0;i--){let a=c?`${c}[${i}]`:`[${i}]`;i>=s.length||i>=r.length?o.push(a):l.push([s[i],r[i],a]);}}else if(i(s)&&i(r)){let p=[...new Set([...Object.keys(s),...Object.keys(r)])];for(let i=p.length-1;i>=0;i--){let a=p[i],u=c?`${c}.${a}`:a;!(a in s)||!(a in r)?o.push(u):l.push([s[a],r[a],u]);}}else K(s,r)||o.push(c||"<root>");}return o}async function X(e,t=3){for(let n=0;n<t;n++){let o=null,l=null;try{let s=statSync(e);o={size:s.size,mtimeMs:s.mtimeMs};}catch{return}await new Promise(s=>setTimeout(s,20));try{let s=statSync(e);l={size:s.size,mtimeMs:s.mtimeMs};}catch{return}if(o.size===l.size&&o.mtimeMs===l.mtimeMs)return}}function ce(e,t={}){let n=t.debounceMs??100,o=t.refreshMs??(q(e.sources)?6e4:0),l=t.pollMs??0,s=f(e),r=0,i=0,a=false,u=null,f$1=[],d=[],m=new Set,v=new Map,R={get:()=>s,reload:async()=>{await O();},dispose:async()=>{if(!a){a=true,u&&(clearTimeout(u),u=null);for(let E of d)clearInterval(E);for(let E of f$1)try{E.close();}catch{}}},get version(){return r}};async function O(){let E=++i;if(a)return;T();let g=j(e.sources);if(await Promise.all(g.map(h=>X(h).catch(()=>{}))),a||E!==i)return;let w;try{w=f(e);}catch(h){try{t.onError?.(h,{version:r});}catch{}return}if(a||E!==i)return;let S=Q(s,w);s=w,r++;try{t.onUpdate?.(s,S);}catch{}}function z(){a||(u&&clearTimeout(u),u=setTimeout(()=>{u=null,O();},n));}function T(){let E=new Map;for(let g of j(e.sources)){let w=dirname(g),S=basename(g),h=E.get(w)??[];h.push(S),E.set(w,h);}for(let[g,w]of E){let S=v.get(g);S||(S=new Set,v.set(g,S));for(let N of w)S.add(N);let h=g;if(!m.has(h))try{let N=S,k=watch(g,(Y,_)=>{let I=typeof _=="string"?_:_?String(_):null;I&&!N.has(I)||z();});k.on("error",()=>{m.delete(h),v.delete(h),f$1.splice(f$1.indexOf(k),1),setTimeout(()=>{a||T();},0);}),f$1.push(k),m.add(h);}catch{}}}return T(),l>0&&d.push(setInterval(()=>{O();},l)),o>0&&d.push(setInterval(()=>{O();},o)),R}export{oe as a,ie as b,ae as c,ce as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {f}from'./chunk-4EAMKDNK.js';import {d,a,b}from'./chunk-NQDE3WLR.js';import {resolve}from'path';async function g(e,a){let s=resolve(e),r;try{let{createJiti:n}=await import('jiti');r=await n(import.meta.url,{interopDefault:!1,fsCache:!1,moduleCache:!1}).import(s);}catch(n){let i=n,d=new Error(`SCHEMA_LOAD_ERROR: ${s}: ${i.message}`);throw d.code="SCHEMA_LOAD_ERROR",d}let t=n=>r[n],o=n=>!n||typeof n!="object"&&typeof n!="function"?false:"~standard"in n;if(a){let n=t(a);if(!o(n)){let i=new Error(`SCHEMA_LOAD_ERROR: --schema-export ${JSON.stringify(a)} did not resolve to a Standard Schema in ${s}`);throw i.code="SCHEMA_LOAD_ERROR",i}return n}for(let n of ["schema","settingsSchema","default"])if(o(t(n)))return t(n);let c=Object.values(r).filter(n=>o(n));if(c.length>1){let n=Object.entries(r).filter(([,d])=>o(d)).map(([d])=>d),i=new Error(`SCHEMA_LOAD_ERROR: ${c.length} Standard Schema exports in ${s} (${n.join(", ")}) \u2014 pass --schema-export NAME to pick one`);throw i.code="SCHEMA_LOAD_ERROR",i}if(c[0])return c[0];let f=new Error(`SCHEMA_LOAD_ERROR: no Standard Schema export in ${s} (tried default/schema/settingsSchema)`);throw f.code="SCHEMA_LOAD_ERROR",f}function m(e,a$1,s=""){if(Array.isArray(e))return e.map(r=>m(r,a$1,s));if(e&&typeof e=="object"){let r={};for(let[t,o]of Object.entries(e)){let c=s?`${s}.${t}`:t,f=a(c,a$1)&&(typeof o=="string"&&o.length>0||typeof o=="number"||typeof o=="boolean");r[t]=f?typeof o=="string"?b(c,o,a$1):"(redacted)":m(o,a$1,c);}return r}return e}var S=new Set(["E_INVALID_CONFIG","E_UNKNOWN_KEY","E_UNRESOLVED","E_CIRCULAR","E_BAD_OP","E_EXPAND"]);async function w(e){let a;try{a=await g(e.schema,e.schemaExport);}catch(r){let t=r,o=t.code;return e.format==="json"?console.log(JSON.stringify({ok:false,code:o,error:t.message})):console.error(t.message),2}let s=(e.config??".env,env").split(",").map(r=>r.trim()).filter(Boolean);try{let r=f({schema:a,sources:s.length?s:[".env","env"],unknownKeys:e.strict?"reject":"strip",expand:e.expand??!0,arrayStrategy:e.array??"replace",prefix:e.prefix,secretKeys:e.secretKeys});return e.format==="json"?console.log(JSON.stringify({ok:!0,config:m(r,e.secretKeys)})):console.log("OK: config valid"),0}catch(r){if(r instanceof d)return e.format==="json"?console.log(JSON.stringify({ok:false,code:r.code,issues:r.issues})):console.error(r.message),S.has(r.code)?1:2;let t=r;return e.format==="json"?console.log(JSON.stringify({ok:false,code:"E_LOAD",error:t.message})):console.error(`E_LOAD: ${t.message}`),2}}export{g as a,w as b};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var C=/key|secret|token|password|private/i;function $(e,n){if(C.test(e))return true;if(n){for(let o of n)if(typeof o=="string"){if(o&&e.toLowerCase().includes(o.toLowerCase()))return true}else if(o instanceof RegExp){if(o.lastIndex=0,o.test(e))return true}else if(o!==null&&typeof o=="object"&&typeof o.test=="function"&&o.test(e))return true}return false}function L(e,n,o){return $(e,o)&&typeof n=="string"&&n.length>0?n.length<=8?"(redacted)":`(redacted: ${n.length} chars)`:String(n)}function S(e){try{let n=globalThis;if(n.TextEncoder)return new n.TextEncoder().encode(e).length;if(n.Buffer)return n.Buffer.byteLength(e,"utf8")}catch{}return e.length}var f=class extends Error{code="E_INVALID_CONFIG";issues;static[Symbol.hasInstance](n){return typeof n=="object"&&n!==null&&n.name==="ConfigError"&&typeof n.code=="string"&&Array.isArray(n.issues)}constructor(n=[],o="E_INVALID_CONFIG"){let s=n.map(r=>`- ${r.path} (from ${r.from}): ${r.message}`);super(n.length===0?"Invalid config: unknown error (no issues attached)":`Invalid config (${n.length} issue${n.length===1?"":"s"}):
|
|
2
|
+
${s.join(`
|
|
3
|
+
`)}`),this.name="ConfigError",this.code=o,this.issues=n;}};var y=/^(0|[1-9][0-9]*)$/;function E(e){return e.toLowerCase()==="__proto__"}function b(e,n){if(!n)return e;if(e.length<=n.length||e.slice(0,n.length).toLowerCase()!==n.toLowerCase())return null;let o=e.slice(n.length);return /[A-Za-z0-9]$/.test(n)&&/^[A-Za-z0-9]/.test(o)?null:o}function K(e,n){let o={},s=new Map,r=i=>{let c=s.get(i);return c||(c={indexed:false,named:false},s.set(i,c)),c},t=new Map,l=i=>{if(!n?.envMap)return;let c=i.toLowerCase();for(let[u,p]of Object.entries(n.envMap))if(u.toLowerCase()===c)return p},g=(i,c,u)=>{throw new f([{path:i,from:"keys",message:`E_COLLISION: '${i}' ${u} (already claimed by '${t.get(c)}')`}],"E_COLLISION")};for(let[i,c]of Object.entries(e)){let u=l(i);if(u!==void 0){let a=u.toLowerCase();if(E(a))throw new f([{path:i,from:"keys",message:"E_PROTO: forbidden key"}],"E_PROTO");o[a]=c;continue}if(!/^[A-Za-z0-9_]+$/.test(i)){if(n?.tolerantKeys)continue;throw new f([{path:i,from:"keys",message:`E_BAD_KEY: '${i}' cannot be a config key (allowed: A-Z a-z 0-9 _, nesting with __) \u2014 bridge it with envMap`}],"E_BAD_KEY")}let p=b(i,n?.prefix);if(p===null)continue;let _=p;if(E(_))throw new f([{path:i,from:"keys",message:"E_PROTO: forbidden key"}],"E_PROTO");let R=_.split("__");if(R.length>1&&R.every(a=>a!=="")){let a=R.map(m=>m.toLowerCase()),d=a.join("."),h=a.slice(0,-1).join("."),I=a[0];if(t.get(d)!==void 0&&g(i,d,"duplicates a claimed path"),a.length===2&&t.has(I)&&y.test(a[1]))throw new f([{path:i,from:"keys",message:`E_ARRAY_MIX: '${I}' has both scalar/list and indexed (__0) values in the same layer`}],"E_ARRAY_MIX");for(let[m]of t)(m.startsWith(`${d}.`)||d.startsWith(`${m}.`))&&g(i,m,"collides with a conflicting value at");let A=r(h);if(y.test(a[a.length-1])){if(A.named)throw new f([{path:i,from:"keys",message:`E_ARRAY_MIX: '${h}' mixes indexed (__0) and named children in the same layer`}],"E_ARRAY_MIX");A.indexed=true;}else {if(A.indexed)throw new f([{path:i,from:"keys",message:`E_ARRAY_MIX: '${h}' mixes named and indexed (__0) children in the same layer`}],"E_ARRAY_MIX");A.named=true;}t.set(d,i),j(o,a,c);}else {let a=_.toLowerCase();if(s.get(a)?.indexed)throw new f([{path:i,from:"keys",message:`E_ARRAY_MIX: '${a}' has both indexed (__0) and scalar/list values in the same layer`}],"E_ARRAY_MIX");t.get(a)!==void 0&&g(i,a,"duplicates a claimed path");for(let[h]of t)h.startsWith(`${a}.`)&&g(i,h,"collides with a conflicting value at");t.set(a,i),o[a]=c;}}return o}function O(e,n="<root>"){if(Array.isArray(e))return e.map((r,t)=>O(r,`${n}[${t}]`));if(!w(e))return e;let o=Object.entries(e),s={};for(let[r,t]of o)s[r]=O(t,n==="<root>"?r:`${n}.${r}`);if(o.length>0&&o.every(([r])=>y.test(r))){let r=o.map(([t])=>Number(t)).sort((t,l)=>t-l);if(r.length>1024)throw new f([{path:n,from:"keys",message:"E_ARRAY_CAP: >1024 elements"}],"E_ARRAY_CAP");for(let t=0;t<r.length;t++)if(r[t]!==t)throw new f([{path:n,from:"keys",message:`E_SPARSE_ARRAY: indexes [${r.join(",")}] are not dense 0..${r[r.length-1]}`}],"E_SPARSE_ARRAY");return r.map((t,l)=>s[String(l)])}return s}function j(e,n,o){let s=e;for(let r=0;r<n.length-1;r++){let t=n[r],l=s[t];if(l&&typeof l=="object"&&!Array.isArray(l))s=l;else {let g={};s[t]=g,s=g;}}s[n[n.length-1]]=o;}function w(e){if(!e||typeof e!="object")return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function N(e,n,o="replace"){return x(n),k(e,n,o)}function k(e,n,o){if(n===void 0)return e;if(e===void 0)return n;if(n===null)return null;if(Array.isArray(e)!==Array.isArray(n)&&(w(e)||w(n))){let s=r=>r!=null&&typeof r=="object"&&(Array.isArray(r)?r.length===0:w(r)&&Object.keys(r).length===0);if(!s(e)&&!s(n))throw new f([{path:"<array>",from:"merge",message:`E_ARRAY_MIX: cannot merge object with array across layers (arrayStrategy '${o}' only merges arrays with arrays) \u2014 use matching shapes`}],"E_ARRAY_MIX")}if(Array.isArray(e)&&Array.isArray(n)){if(o==="replace")return n;if(o==="concat"){if(e.length+n.length>1024)throw new f([{path:"<array>",from:"merge",message:"E_ARRAY_CAP: concat would exceed 1024 elements"}],"E_ARRAY_CAP");return [...e,...n]}let s=Math.max(e.length,n.length);if(s>1024)throw new f([{path:"<array>",from:"merge",message:"E_ARRAY_CAP: >1024"}],"E_ARRAY_CAP");let r=[];for(let t=0;t<s;t++)t in n?r[t]=t in e?k(e[t],n[t],o):n[t]:t in e&&(r[t]=e[t]);for(let t=0;t<s;t++)if(!(t in r))throw new f([{path:`<array>[${t}]`,from:"merge",message:"E_SPARSE_ARRAY: hole at index "+t}],"E_SPARSE_ARRAY");return r}if(w(e)&&w(n)){let s={...e};for(let[r,t]of Object.entries(n))s[r]=r in s?k(s[r],t,o):t;return s}return n}function x(e){if(Array.isArray(e)){for(let n of e)x(n);return}if(e!==null&&typeof e=="object")for(let[n,o]of Object.entries(e)){if(E(n))throw new f([{path:n,from:"merge",message:"E_PROTO"}],"E_PROTO");x(o);}}export{$ as a,L as b,S as c,f as d,E as e,b as f,K as g,O as h,w as i,N as j};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(a){return {"~standard":{version:1,vendor:"typed-settings.yup",validate:r=>{try{return {value:a.validateSync(r,{stripUnknown:!0,abortEarly:!1})}}catch(e){let t=e;return {issues:(t.inner?.length?t.inner:[{path:"<root>",message:t.message??String(e)}]).map(s=>({message:String(s.message??String(e)),path:s.path?[s.path]:void 0}))}}}}}}function g(a){return {"~standard":{version:1,vendor:"typed-settings.joi",validate:r=>{let e;try{e=a.validate(r,{abortEarly:!1,convert:!0,allowUnknown:!0,stripUnknown:!0});}catch(n){return {issues:[{message:n?.message??String(n)}]}}if(e&&typeof e.then=="function")return {issues:[{message:"USE_ASYNC: Joi schema is async, which legacy bridges do not support"}]};if(!e.error)return {value:e.value};let t=(e.error.details??[]).map(n=>({message:n.message,path:n.path.map(String)}));return t.length===0?{issues:[{message:e.error.message??"Invalid input"}]}:{issues:t}}}}}function d(a){return {"~standard":{version:1,vendor:"typed-settings.superstruct",validate:r=>{let e;try{return e=a.create(r),{value:e}}catch(t){let n=t,s;try{if(typeof n.failures=="function"){let i=n.failures().map(u=>({message:u.message,path:u.path.map(String)}));i.length>0&&(s=i);}}catch{}return s?{issues:s}:{issues:[{message:n?.message??String(t)}]}}}}}}export{o as a,g as b,d as c};
|