typed-settings 0.1.1 → 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.
Files changed (83) hide show
  1. package/README.md +18 -9
  2. package/bin/typed-settings.mjs +5 -0
  3. package/dist/adapters/joi.cjs +1 -26
  4. package/dist/adapters/joi.d.cts +2 -1
  5. package/dist/adapters/joi.d.ts +2 -1
  6. package/dist/adapters/joi.js +1 -1
  7. package/dist/adapters/superstruct.cjs +1 -26
  8. package/dist/adapters/superstruct.js +1 -1
  9. package/dist/adapters/yup.cjs +1 -25
  10. package/dist/adapters/yup.js +1 -1
  11. package/dist/adapters/zod.cjs +3 -36
  12. package/dist/adapters/zod.d.cts +2 -0
  13. package/dist/adapters/zod.d.ts +2 -0
  14. package/dist/adapters/zod.js +1 -33
  15. package/dist/check-XVFZEVNV.js +1 -0
  16. package/dist/chunk-4EAMKDNK.js +3 -0
  17. package/dist/chunk-5D2AQWDG.js +1 -0
  18. package/dist/chunk-C6CG2D4B.js +2 -0
  19. package/dist/chunk-FQYD5ZKE.js +1 -0
  20. package/dist/chunk-NQDE3WLR.js +3 -0
  21. package/dist/chunk-RURPDXIJ.js +1 -0
  22. package/dist/cli/main.cjs +36 -2220
  23. package/dist/cli/main.js +32 -806
  24. package/dist/errors-JkkOM0u-.d.cts +25 -0
  25. package/dist/errors-JkkOM0u-.d.ts +25 -0
  26. package/dist/framework/next.cjs +5 -1153
  27. package/dist/framework/next.d.cts +5 -3
  28. package/dist/framework/next.d.ts +5 -3
  29. package/dist/framework/next.js +1 -15
  30. package/dist/framework/vite.cjs +5 -1151
  31. package/dist/framework/vite.d.cts +10 -3
  32. package/dist/framework/vite.d.ts +10 -3
  33. package/dist/framework/vite.js +1 -14
  34. package/dist/index.cjs +5 -1176
  35. package/dist/index.d.cts +46 -10
  36. package/dist/index.d.ts +46 -10
  37. package/dist/index.js +1 -6
  38. package/dist/node.cjs +6 -1236
  39. package/dist/node.d.cts +23 -9
  40. package/dist/node.d.ts +23 -9
  41. package/dist/node.js +1 -7
  42. package/dist/{types-CClP1lxq.d.ts → types-CcsYDAdO.d.cts} +27 -3
  43. package/dist/{types-CClP1lxq.d.cts → types-CcsYDAdO.d.ts} +27 -3
  44. package/dist/vault/aws.cjs +4 -217
  45. package/dist/vault/aws.d.cts +3 -1
  46. package/dist/vault/aws.d.ts +3 -1
  47. package/dist/vault/aws.js +2 -167
  48. package/dist/vault/hashicorp.cjs +4 -183
  49. package/dist/vault/hashicorp.d.cts +3 -1
  50. package/dist/vault/hashicorp.d.ts +3 -1
  51. package/dist/vault/hashicorp.js +2 -77
  52. package/dist/vault/http.cjs +4 -185
  53. package/dist/vault/http.d.cts +3 -1
  54. package/dist/vault/http.d.ts +3 -1
  55. package/dist/vault/http.js +2 -79
  56. package/package.json +10 -3
  57. package/dist/chunk-33M5GIKQ.js +0 -13
  58. package/dist/chunk-A5TCQJ7L.js +0 -65
  59. package/dist/chunk-EE6LXNJV.js +0 -34
  60. package/dist/chunk-F6DX3HXZ.js +0 -101
  61. package/dist/chunk-OVFMKC2O.js +0 -15
  62. package/dist/chunk-RCO6K3WQ.js +0 -984
  63. package/dist/chunk-RQC6OMVV.js +0 -86
  64. package/dist/chunk-UFUHHR2J.js +0 -38
  65. package/dist/chunk-VTIYOSG2.js +0 -233
  66. package/dist/errors-itGaU4Q8.d.cts +0 -17
  67. package/dist/errors-itGaU4Q8.d.ts +0 -17
  68. package/dist/formats/env.cjs +0 -103
  69. package/dist/formats/env.d.cts +0 -8
  70. package/dist/formats/env.d.ts +0 -8
  71. package/dist/formats/env.js +0 -1
  72. package/dist/formats/json.cjs +0 -15
  73. package/dist/formats/json.d.cts +0 -7
  74. package/dist/formats/json.d.ts +0 -7
  75. package/dist/formats/json.js +0 -1
  76. package/dist/formats/toml.cjs +0 -17
  77. package/dist/formats/toml.d.cts +0 -7
  78. package/dist/formats/toml.d.ts +0 -7
  79. package/dist/formats/toml.js +0 -1
  80. package/dist/formats/yaml.cjs +0 -40
  81. package/dist/formats/yaml.d.cts +0 -8
  82. package/dist/formats/yaml.d.ts +0 -8
  83. package/dist/formats/yaml.js +0 -1
@@ -1,13 +0,0 @@
1
- // src/formats/json.ts
2
- function parseJsonText(text, from = "json") {
3
- const stripped = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
4
- if (!stripped.trim()) return {};
5
- try {
6
- return JSON.parse(stripped);
7
- } catch (e) {
8
- const err = e;
9
- throw new Error(`ParseError (${from}): ${err.message}`);
10
- }
11
- }
12
-
13
- export { parseJsonText };
@@ -1,65 +0,0 @@
1
- // src/adapters/legacy.ts
2
- function yupAdapter(schema) {
3
- return {
4
- "~standard": {
5
- version: 1,
6
- vendor: "typed-settings.yup",
7
- validate: (input) => {
8
- try {
9
- const value = schema.validateSync(input, { stripUnknown: true, abortEarly: false });
10
- return { value };
11
- } catch (e) {
12
- const err = e;
13
- const issues = (err.inner?.length ? err.inner : [{ path: "<root>", message: err.message ?? String(e) }]).map(
14
- (i) => ({ message: String(i.message ?? String(e)), path: i.path ? [i.path] : void 0 })
15
- );
16
- return { issues };
17
- }
18
- }
19
- }
20
- };
21
- }
22
- function joiAdapter(schema) {
23
- return {
24
- "~standard": {
25
- version: 1,
26
- vendor: "typed-settings.joi",
27
- validate: (input) => {
28
- let res;
29
- try {
30
- res = schema.validate(input, { abortEarly: false, convert: true, allowUnknown: true, stripUnknown: true });
31
- } catch (e) {
32
- const err = e;
33
- return { issues: [{ message: err?.message ?? String(e) }] };
34
- }
35
- if (!res.error) return { value: res.value };
36
- const issues = (res.error.details ?? []).map((d) => ({ message: d.message, path: d.path.map(String) }));
37
- if (issues.length === 0) return { issues: [{ message: res.error.message ?? "Invalid input" }] };
38
- return { issues };
39
- }
40
- }
41
- };
42
- }
43
- function superstructAdapter(schema) {
44
- return {
45
- "~standard": {
46
- version: 1,
47
- vendor: "typed-settings.superstruct",
48
- validate: (input) => {
49
- try {
50
- const value = schema.create(input);
51
- return { value };
52
- } catch (e) {
53
- const err = e;
54
- if (typeof err.failures === "function") {
55
- const issues = err.failures().map((f) => ({ message: f.message, path: f.path.map(String) }));
56
- if (issues.length > 0) return { issues };
57
- }
58
- return { issues: [{ message: err.message ?? String(e) }] };
59
- }
60
- }
61
- }
62
- };
63
- }
64
-
65
- export { joiAdapter, superstructAdapter, yupAdapter };
@@ -1,34 +0,0 @@
1
- // src/errors.ts
2
- var SECRET_RE = /key|secret|token|password|private/i;
3
- function redactValue(key, value) {
4
- if (SECRET_RE.test(key) && typeof value === "string" && value.length > 0) {
5
- if (value.length <= 8) return "(redacted)";
6
- return `${value.slice(0, 3)}-*** (${value.length} chars)`;
7
- }
8
- return String(value);
9
- }
10
- function byteLengthUtf8(text) {
11
- try {
12
- const g = globalThis;
13
- if (g.TextEncoder) return new g.TextEncoder().encode(text).length;
14
- if (g.Buffer) return g.Buffer.byteLength(text, "utf8");
15
- } catch {
16
- }
17
- return text.length;
18
- }
19
- var ConfigError = class extends Error {
20
- code = "E_INVALID_CONFIG";
21
- issues;
22
- constructor(issues, code = "E_INVALID_CONFIG") {
23
- const lines = issues.map(
24
- (i) => `- ${i.path} (from ${i.from}): ${i.message}`
25
- );
26
- super(`Invalid config (${issues.length} issue${issues.length === 1 ? "" : "s"}):
27
- ${lines.join("\n")}`);
28
- this.name = "ConfigError";
29
- this.code = code;
30
- this.issues = issues;
31
- }
32
- };
33
-
34
- export { ConfigError, byteLengthUtf8, redactValue };
@@ -1,101 +0,0 @@
1
- // src/formats/env.ts
2
- function parseEnvText(text) {
3
- const out = {};
4
- if (text.charCodeAt(0) === 65279) text = text.slice(1);
5
- const lines = splitLogicalLines(text);
6
- for (const rawLine of lines) {
7
- let line = rawLine.trim();
8
- if (!line || line.startsWith("#")) continue;
9
- if (line.startsWith("export ")) line = line.slice(7).trimStart();
10
- const eq = line.indexOf("=");
11
- if (eq === -1) {
12
- throw new Error(`ParseError: bare key without '=': ${JSON.stringify(line)}`);
13
- }
14
- const key = line.slice(0, eq).trim();
15
- let rest = line.slice(eq + 1).trimStart();
16
- if (!key) throw new Error("ParseError: empty key");
17
- out[key] = parseValue(rest);
18
- }
19
- return out;
20
- }
21
- function splitLogicalLines(text) {
22
- const physical = text.split(/\r?\n/);
23
- const out = [];
24
- let buf = "";
25
- let inDouble = false;
26
- for (const pl of physical) {
27
- if (!inDouble) {
28
- const opens = countUnescapedQuotes(pl);
29
- if (opens % 2 === 1 && isValueStartDoubleQuoted(pl)) {
30
- buf = pl;
31
- inDouble = true;
32
- } else {
33
- out.push(pl);
34
- }
35
- } else {
36
- buf += "\n" + pl;
37
- const opens = countUnescapedQuotes(buf.split("=").slice(1).join("="));
38
- if (opens % 2 === 0) {
39
- inDouble = false;
40
- out.push(buf);
41
- buf = "";
42
- }
43
- }
44
- }
45
- if (inDouble) throw new Error("ParseError: unterminated double-quoted value");
46
- return out;
47
- }
48
- function isValueStartDoubleQuoted(line) {
49
- const eq = line.indexOf("=");
50
- if (eq === -1) return false;
51
- const rest = line.slice(eq + 1).trimStart();
52
- return rest.startsWith('"') && !rest.endsWith('"');
53
- }
54
- function countUnescapedQuotes(s) {
55
- let n = 0;
56
- for (let i = 0; i < s.length; i++) {
57
- if (s[i] === '"' && s[i - 1] !== "\\") n++;
58
- }
59
- return n;
60
- }
61
- function parseValue(rest) {
62
- if (!rest) return "";
63
- if (rest.startsWith("'")) {
64
- const end = rest.indexOf("'", 1);
65
- if (end === -1) throw new Error("ParseError: unterminated single-quoted value");
66
- return rest.slice(1, end);
67
- }
68
- if (rest.startsWith('"')) {
69
- let i = 1;
70
- let val = "";
71
- while (i < rest.length) {
72
- const c = rest[i];
73
- if (c === "\\" && i + 1 < rest.length) {
74
- const n = rest[i + 1];
75
- if (n === "n") val += "\n";
76
- else if (n === "r") val += "\r";
77
- else if (n === "t") val += " ";
78
- else val += n;
79
- i += 2;
80
- continue;
81
- }
82
- if (c === '"') break;
83
- val += c;
84
- i++;
85
- }
86
- if (rest[i] !== '"') throw new Error("ParseError: unterminated double-quoted value");
87
- return val;
88
- }
89
- if (rest.startsWith("`")) throw new Error("ParseError: backtick values not supported");
90
- const hash = findCommentStart(rest);
91
- const v = (hash === -1 ? rest : rest.slice(0, hash)).trim();
92
- return v;
93
- }
94
- function findCommentStart(s) {
95
- for (let i = 0; i < s.length; i++) {
96
- if (s[i] === "#" && (i === 0 || /\s/.test(s[i - 1]))) return i;
97
- }
98
- return -1;
99
- }
100
-
101
- export { parseEnvText };
@@ -1,15 +0,0 @@
1
- import { parse } from 'smol-toml';
2
-
3
- // src/formats/toml.ts
4
- function parseTomlText(text, from = "toml") {
5
- const stripped = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
6
- if (!stripped.trim()) return {};
7
- try {
8
- return parse(stripped);
9
- } catch (e) {
10
- const err = e;
11
- throw new Error(`ParseError (${from}): ${err.message}`);
12
- }
13
- }
14
-
15
- export { parseTomlText };