@o3co/ts.hocon 1.12.0 → 1.14.0

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 (43) hide show
  1. package/README.ja.md +256 -32
  2. package/README.md +166 -32
  3. package/dist/adapters/env.cjs +26 -1678
  4. package/dist/adapters/env.d.cts +1 -1
  5. package/dist/adapters/env.d.ts +1 -1
  6. package/dist/adapters/env.js +11 -1625
  7. package/dist/adapters/json5.cjs +496 -0
  8. package/dist/adapters/json5.d.cts +47 -0
  9. package/dist/adapters/json5.d.ts +47 -0
  10. package/dist/adapters/json5.js +496 -0
  11. package/dist/adapters/jsonc.cjs +17 -1632
  12. package/dist/adapters/jsonc.d.cts +1 -1
  13. package/dist/adapters/jsonc.d.ts +1 -1
  14. package/dist/adapters/jsonc.js +9 -1586
  15. package/dist/adapters/properties.cjs +7 -1773
  16. package/dist/adapters/properties.d.cts +1 -1
  17. package/dist/adapters/properties.d.ts +1 -1
  18. package/dist/adapters/properties.js +6 -1735
  19. package/dist/adapters/toml.cjs +12 -1626
  20. package/dist/adapters/toml.d.cts +1 -1
  21. package/dist/adapters/toml.d.ts +1 -1
  22. package/dist/adapters/toml.js +10 -1589
  23. package/dist/adapters/yaml.cjs +20 -1635
  24. package/dist/adapters/yaml.d.cts +1 -1
  25. package/dist/adapters/yaml.d.ts +1 -1
  26. package/dist/adapters/yaml.js +10 -1589
  27. package/dist/chunk-GBNQADHT.cjs +83 -0
  28. package/dist/chunk-IMJ7QHIK.cjs +158 -0
  29. package/dist/chunk-QY7ECGS6.js +83 -0
  30. package/dist/chunk-RO4D6BH7.cjs +3792 -0
  31. package/dist/chunk-WTXULUZS.js +3792 -0
  32. package/dist/chunk-XWKO4JM3.js +158 -0
  33. package/dist/{config-Dlq6rF3w.d.cts → config-OccaKqXu.d.cts} +148 -4
  34. package/dist/{config-Dlq6rF3w.d.ts → config-OccaKqXu.d.ts} +148 -4
  35. package/dist/index.cjs +35 -3449
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +25 -3383
  39. package/dist/zod.cjs +107 -3291
  40. package/dist/zod.d.cts +83 -3
  41. package/dist/zod.d.ts +83 -3
  42. package/dist/zod.js +95 -3245
  43. package/package.json +12 -2
@@ -0,0 +1,83 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkRO4D6BH7cjs = require('./chunk-RO4D6BH7.cjs');
7
+
8
+ // src/value-factory.ts
9
+ function fromMap(values, originDescription) {
10
+ const fields = _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
11
+ () => coerceObject(values, ""),
12
+ (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `fromMap: ${msg}`)
13
+ );
14
+ const root = { kind: "object", fields };
15
+ return _chunkRO4D6BH7cjs.Config._fromResolvedValue(root, { originDescription });
16
+ }
17
+ function empty(originDescription) {
18
+ const root = { kind: "object", fields: /* @__PURE__ */ new Map() };
19
+ return _chunkRO4D6BH7cjs.Config._fromResolvedValue(root, { originDescription });
20
+ }
21
+ var INT64_MAX = 9223372036854775807n;
22
+ var INT64_MIN = -9223372036854775808n;
23
+ function coerceObject(obj, atPath) {
24
+ const fields = /* @__PURE__ */ new Map();
25
+ for (const [k, v] of Object.entries(obj)) {
26
+ const childPath = atPath ? `${atPath}.${k}` : k;
27
+ fields.set(k, coerceValue(v, childPath));
28
+ }
29
+ return fields;
30
+ }
31
+ function coerceValue(v, atPath) {
32
+ if (v === null) {
33
+ return { kind: "scalar", raw: "null", valueType: "null" };
34
+ }
35
+ if (v === void 0) {
36
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
37
+ `fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
38
+ atPath
39
+ );
40
+ }
41
+ switch (typeof v) {
42
+ case "string":
43
+ return { kind: "scalar", raw: v, valueType: "string" };
44
+ case "number": {
45
+ if (Number.isNaN(v) || !Number.isFinite(v)) {
46
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
47
+ `fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
48
+ atPath
49
+ );
50
+ }
51
+ return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
52
+ }
53
+ case "boolean":
54
+ return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
55
+ case "bigint": {
56
+ if (v > INT64_MAX || v < INT64_MIN) {
57
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
58
+ `fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
59
+ atPath
60
+ );
61
+ }
62
+ return { kind: "scalar", raw: String(v), valueType: "number" };
63
+ }
64
+ case "object": {
65
+ if (Array.isArray(v)) {
66
+ const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
67
+ return { kind: "array", items };
68
+ }
69
+ const fields = coerceObject(v, atPath);
70
+ return { kind: "object", fields };
71
+ }
72
+ default:
73
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
74
+ `fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
75
+ atPath
76
+ );
77
+ }
78
+ }
79
+
80
+
81
+
82
+
83
+ exports.fromMap = fromMap; exports.empty = empty;
@@ -0,0 +1,158 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _chunkRO4D6BH7cjs = require('./chunk-RO4D6BH7.cjs');
15
+
16
+ // src/parse.ts
17
+ var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
18
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
19
+ function defaultParseOptions() {
20
+ return { resolveSubstitutions: true };
21
+ }
22
+ function defaultResolveOptions() {
23
+ return { useSystemEnvironment: true, allowUnresolved: false };
24
+ }
25
+ function getEnv(opts) {
26
+ if (opts.env !== void 0) return opts.env;
27
+ if (typeof process !== "undefined" && process.env) return process.env;
28
+ return {};
29
+ }
30
+ function defaultReadFileSync(filePath) {
31
+ return fs.readFileSync(filePath, "utf-8");
32
+ }
33
+ async function defaultReadFile(filePath) {
34
+ return fs.promises.readFile(filePath, "utf-8");
35
+ }
36
+ function buildResolveContext(input, opts) {
37
+ const tokens = _chunkRO4D6BH7cjs.tokenize.call(void 0, input);
38
+ const ast = _chunkRO4D6BH7cjs.parseTokens.call(void 0, tokens);
39
+ if (ast.kind === "array") {
40
+ const origin = _nullishCoalesce(opts.originDescription, () => ( "input"));
41
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
42
+ `${origin}: ${ast.pos.line}:${ast.pos.col}: document has type array rather than object at file root (HOCON.md L989-991); the Config API requires an object root`,
43
+ ""
44
+ );
45
+ }
46
+ const resolveOpts = {
47
+ env: getEnv(opts),
48
+ baseDir: opts.baseDir,
49
+ readFileSync: _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync)),
50
+ readFile: opts.readFile,
51
+ originDescription: opts.originDescription,
52
+ resolveFrom: opts.resolveFrom,
53
+ packageResolver: opts.packageResolver
54
+ };
55
+ return { ast, resolveOpts };
56
+ }
57
+ function parse(input, opts = {}) {
58
+ return parseStringWithOptions(input, opts);
59
+ }
60
+ var parseString = parse;
61
+ function parseStringWithOptions(input, opts = {}) {
62
+ return _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
63
+ () => parseStringInner(input, opts),
64
+ (msg) => new (0, _chunkRO4D6BH7cjs.ParseError)(msg, 1, 1, opts.originDescription)
65
+ );
66
+ }
67
+ function parseStringInner(input, opts) {
68
+ const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
69
+ const { ast, resolveOpts } = buildResolveContext(input, opts);
70
+ if (resolveSubstitutions) {
71
+ const value = _chunkRO4D6BH7cjs.resolve.call(void 0, ast, resolveOpts);
72
+ if (value.kind !== "object") throw new Error("resolved value is not an object");
73
+ return new (0, _chunkRO4D6BH7cjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
74
+ }
75
+ const tree = _chunkRO4D6BH7cjs.buildTree.call(void 0, ast, resolveOpts);
76
+ const hasPlaceholders = _chunkRO4D6BH7cjs.containsPlaceholders.call(void 0, tree);
77
+ return _chunkRO4D6BH7cjs.Config._fromUnresolvedResObj(tree, {
78
+ parseBaseDir: opts.baseDir,
79
+ originDescription: opts.originDescription,
80
+ resolved: !hasPlaceholders,
81
+ resolveOpts
82
+ });
83
+ }
84
+ function parseFileWithOptions(filePath, opts = {}) {
85
+ if (typeof process === "undefined" && !opts.readFileSync) {
86
+ throw new Error("parseFileWithOptions is not supported in browser environments without opts.readFileSync.");
87
+ }
88
+ const resolvedPath = path.resolve(filePath);
89
+ const readFileSync2 = _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync));
90
+ const input = readFileSync2(resolvedPath);
91
+ return parseStringWithOptions(input, {
92
+ ...opts,
93
+ baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
94
+ readFileSync: readFileSync2
95
+ });
96
+ }
97
+ async function parseAsync(input, opts = {}) {
98
+ return _chunkRO4D6BH7cjs.guardStackDepthAsync.call(void 0,
99
+ () => parseStringInnerAsync(input, opts),
100
+ (msg) => new (0, _chunkRO4D6BH7cjs.ParseError)(msg, 1, 1, opts.originDescription)
101
+ );
102
+ }
103
+ async function parseStringInnerAsync(input, opts) {
104
+ const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
105
+ const { ast, resolveOpts } = buildResolveContext(input, opts);
106
+ if (resolveSubstitutions) {
107
+ const value = await _chunkRO4D6BH7cjs.resolveAsync.call(void 0, ast, resolveOpts);
108
+ if (value.kind !== "object") throw new Error("resolved value is not an object");
109
+ return new (0, _chunkRO4D6BH7cjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
110
+ }
111
+ const tree = await _chunkRO4D6BH7cjs.buildTreeAsync.call(void 0, ast, resolveOpts);
112
+ const hasPlaceholders = _chunkRO4D6BH7cjs.containsPlaceholders.call(void 0, tree);
113
+ return _chunkRO4D6BH7cjs.Config._fromUnresolvedResObj(tree, {
114
+ parseBaseDir: opts.baseDir,
115
+ originDescription: opts.originDescription,
116
+ resolved: !hasPlaceholders,
117
+ resolveOpts
118
+ });
119
+ }
120
+ function parseFile(filePath, opts = {}) {
121
+ if (typeof process === "undefined" && !opts.readFileSync) {
122
+ throw new Error("parseFile is not supported in browser environments. Provide opts.readFileSync or use parse() instead.");
123
+ }
124
+ const resolvedPath = path.resolve(filePath);
125
+ const readFileSync2 = _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync));
126
+ const input = readFileSync2(resolvedPath);
127
+ return parse(input, {
128
+ ...opts,
129
+ baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
130
+ readFileSync: readFileSync2
131
+ });
132
+ }
133
+ async function parseFileAsync(filePath, opts = {}) {
134
+ if (typeof process === "undefined" && !opts.readFile) {
135
+ throw new Error("parseFileAsync is not supported in browser environments. Provide opts.readFile or use parseAsync() instead.");
136
+ }
137
+ const resolvedPath = path.resolve(filePath);
138
+ const readFile = _nullishCoalesce(opts.readFile, () => ( defaultReadFile));
139
+ const input = await readFile(resolvedPath);
140
+ return parseAsync(input, {
141
+ ...opts,
142
+ baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
143
+ readFile,
144
+ readFileSync: _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync))
145
+ });
146
+ }
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+ exports.defaultParseOptions = defaultParseOptions; exports.defaultResolveOptions = defaultResolveOptions; exports.parse = parse; exports.parseString = parseString; exports.parseStringWithOptions = parseStringWithOptions; exports.parseFileWithOptions = parseFileWithOptions; exports.parseAsync = parseAsync; exports.parseFile = parseFile; exports.parseFileAsync = parseFileAsync;
@@ -0,0 +1,83 @@
1
+ import {
2
+ Config,
3
+ ConfigError,
4
+ depthError,
5
+ guardStackDepth
6
+ } from "./chunk-WTXULUZS.js";
7
+
8
+ // src/value-factory.ts
9
+ function fromMap(values, originDescription) {
10
+ const fields = guardStackDepth(
11
+ () => coerceObject(values, ""),
12
+ (msg) => depthError(`fromMap: ${msg}`)
13
+ );
14
+ const root = { kind: "object", fields };
15
+ return Config._fromResolvedValue(root, { originDescription });
16
+ }
17
+ function empty(originDescription) {
18
+ const root = { kind: "object", fields: /* @__PURE__ */ new Map() };
19
+ return Config._fromResolvedValue(root, { originDescription });
20
+ }
21
+ var INT64_MAX = 9223372036854775807n;
22
+ var INT64_MIN = -9223372036854775808n;
23
+ function coerceObject(obj, atPath) {
24
+ const fields = /* @__PURE__ */ new Map();
25
+ for (const [k, v] of Object.entries(obj)) {
26
+ const childPath = atPath ? `${atPath}.${k}` : k;
27
+ fields.set(k, coerceValue(v, childPath));
28
+ }
29
+ return fields;
30
+ }
31
+ function coerceValue(v, atPath) {
32
+ if (v === null) {
33
+ return { kind: "scalar", raw: "null", valueType: "null" };
34
+ }
35
+ if (v === void 0) {
36
+ throw new ConfigError(
37
+ `fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
38
+ atPath
39
+ );
40
+ }
41
+ switch (typeof v) {
42
+ case "string":
43
+ return { kind: "scalar", raw: v, valueType: "string" };
44
+ case "number": {
45
+ if (Number.isNaN(v) || !Number.isFinite(v)) {
46
+ throw new ConfigError(
47
+ `fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
48
+ atPath
49
+ );
50
+ }
51
+ return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
52
+ }
53
+ case "boolean":
54
+ return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
55
+ case "bigint": {
56
+ if (v > INT64_MAX || v < INT64_MIN) {
57
+ throw new ConfigError(
58
+ `fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
59
+ atPath
60
+ );
61
+ }
62
+ return { kind: "scalar", raw: String(v), valueType: "number" };
63
+ }
64
+ case "object": {
65
+ if (Array.isArray(v)) {
66
+ const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
67
+ return { kind: "array", items };
68
+ }
69
+ const fields = coerceObject(v, atPath);
70
+ return { kind: "object", fields };
71
+ }
72
+ default:
73
+ throw new ConfigError(
74
+ `fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
75
+ atPath
76
+ );
77
+ }
78
+ }
79
+
80
+ export {
81
+ fromMap,
82
+ empty
83
+ };