@univer-cli/config 1.0.0-beta.2
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 +75 -0
- package/README.zh-CN.md +79 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.mjs +1 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @univer-cli/config
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Provide well-typed local configuration for CLIs, Agents, and other Node.js applications. The application declares the available keys, default values, and codecs; the package validates and reads effective values and persists values explicitly set by the user.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @univer-cli/config
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js 22.12 or higher.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { configCodecs, createFileConfig, defineConfig } from "@univer-cli/config";
|
|
20
|
+
|
|
21
|
+
const definitions = defineConfig({
|
|
22
|
+
"workspace.origin": {
|
|
23
|
+
description: "Workspace service origin.",
|
|
24
|
+
defaultValue: "https://workspace.univer.plus",
|
|
25
|
+
codec: configCodecs.httpOrigin(),
|
|
26
|
+
},
|
|
27
|
+
"runtime.enabled": {
|
|
28
|
+
description: "Enable the runtime.",
|
|
29
|
+
defaultValue: true,
|
|
30
|
+
codec: configCodecs.boolean(),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const config = createFileConfig({
|
|
35
|
+
definitions,
|
|
36
|
+
path: join(process.cwd(), ".my-cli", "config.json"),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const entry = await config.get({ key: "workspace.origin" });
|
|
40
|
+
console.log(entry.value, entry.source);
|
|
41
|
+
|
|
42
|
+
await config.set({ key: "runtime.enabled", value: false });
|
|
43
|
+
await config.unset({ key: "runtime.enabled" });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`path` must be an absolute `.json` path chosen by the application. The package does not choose a product directory or configuration filename for you.
|
|
47
|
+
|
|
48
|
+
## Where does the value come from?
|
|
49
|
+
|
|
50
|
+
Reading the result will indicate the source of the effective value:
|
|
51
|
+
|
|
52
|
+
- `explicit`: The value was written to the configuration file.
|
|
53
|
+
- `default`: The value comes from the in-memory configuration definition.
|
|
54
|
+
- `unset`: There is neither an explicit value nor a default.
|
|
55
|
+
|
|
56
|
+
Configuration files contain only explicit values. Descriptions, codecs, and default values exist only in the application's definitions and are not written to disk.
|
|
57
|
+
|
|
58
|
+
## Codec
|
|
59
|
+
|
|
60
|
+
Built-in codecs cover common CLI configuration types:
|
|
61
|
+
|
|
62
|
+
- `nonEmptyString()`
|
|
63
|
+
- `boolean()`
|
|
64
|
+
- `integer({ minimum, maximum })`
|
|
65
|
+
- `enumeration(values)`
|
|
66
|
+
- `httpUrl()`
|
|
67
|
+
- `httpOrigin()`
|
|
68
|
+
|
|
69
|
+
A custom codec must both validate JSON values and define how CLI text is converted to the same type. Every value must satisfy `ConfigValue`; functions, class instances, and other arbitrary objects cannot be persisted.
|
|
70
|
+
|
|
71
|
+
## Persistence and errors
|
|
72
|
+
|
|
73
|
+
The package uses `conf` for JSON reads, writes, and atomic replacement, but does not expose the `conf` instance, its storage interface, or the internal document shape. Unknown keys, invalid values, codec failures, and file errors all throw `ConfigError`; adapters can use its error code to choose terminal or UI presentation.
|
|
74
|
+
|
|
75
|
+
For the preset command, see [`@univer-cli/config-command`](../config-command/README.md).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @univer-cli/config
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
为 CLI、Agent 或其他 Node.js application 提供类型明确的本地配置:由 application 声明可用 key、默认值和
|
|
6
|
+
codec,package 负责校验、读取 effective value,并持久化用户显式设置的值。
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @univer-cli/config
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
要求 Node.js 22.12 或更高版本。
|
|
15
|
+
|
|
16
|
+
## 快速开始
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { configCodecs, createFileConfig, defineConfig } from "@univer-cli/config";
|
|
21
|
+
|
|
22
|
+
const definitions = defineConfig({
|
|
23
|
+
"workspace.origin": {
|
|
24
|
+
description: "Workspace service origin.",
|
|
25
|
+
defaultValue: "https://workspace.univer.plus",
|
|
26
|
+
codec: configCodecs.httpOrigin(),
|
|
27
|
+
},
|
|
28
|
+
"runtime.enabled": {
|
|
29
|
+
description: "Enable the runtime.",
|
|
30
|
+
defaultValue: true,
|
|
31
|
+
codec: configCodecs.boolean(),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const config = createFileConfig({
|
|
36
|
+
definitions,
|
|
37
|
+
path: join(process.cwd(), ".my-cli", "config.json"),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const entry = await config.get({ key: "workspace.origin" });
|
|
41
|
+
console.log(entry.value, entry.source);
|
|
42
|
+
|
|
43
|
+
await config.set({ key: "runtime.enabled", value: false });
|
|
44
|
+
await config.unset({ key: "runtime.enabled" });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`path` 必须是由 application 决定的绝对 `.json` 路径。Package 不替你选择产品目录或配置文件名。
|
|
48
|
+
|
|
49
|
+
## 值从哪里来
|
|
50
|
+
|
|
51
|
+
读取结果会说明 effective value 的来源:
|
|
52
|
+
|
|
53
|
+
- `explicit`:用户已写入配置文件;
|
|
54
|
+
- `default`:配置定义提供的内存默认值;
|
|
55
|
+
- `unset`:既没有显式值,也没有默认值。
|
|
56
|
+
|
|
57
|
+
配置文件只保存显式值。description、codec 和默认值只存在于 application 的定义中,不会写入磁盘。
|
|
58
|
+
|
|
59
|
+
## Codec
|
|
60
|
+
|
|
61
|
+
内置 codec 覆盖常见 CLI 配置:
|
|
62
|
+
|
|
63
|
+
- `nonEmptyString()`
|
|
64
|
+
- `boolean()`
|
|
65
|
+
- `integer({ minimum, maximum })`
|
|
66
|
+
- `enumeration(values)`
|
|
67
|
+
- `httpUrl()`
|
|
68
|
+
- `httpOrigin()`
|
|
69
|
+
|
|
70
|
+
自定义 codec 需要同时校验 JSON value,并定义 CLI 文本如何转换为同一类型。所有值都必须满足
|
|
71
|
+
`ConfigValue`,不能持久化函数、class instance 或其他任意对象。
|
|
72
|
+
|
|
73
|
+
## 持久化与错误
|
|
74
|
+
|
|
75
|
+
Package 使用 `conf` 完成 JSON 读写和原子替换,但不会公开 `conf` instance、storage interface 或内部
|
|
76
|
+
document shape。未知 key、非法值、codec 失败和文件错误统一抛出 `ConfigError`;adapter 可根据 error code
|
|
77
|
+
决定终端或 UI 呈现。
|
|
78
|
+
|
|
79
|
+
预设 command 见 [`@univer-cli/config-command`](../config-command/README.zh-CN.md)。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';module['exports']=require('./index.mjs');
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type ConfigPrimitive = string | number | boolean | null;
|
|
3
|
+
type ConfigValue = ConfigPrimitive | readonly ConfigValue[] | {
|
|
4
|
+
readonly [key: string]: ConfigValue;
|
|
5
|
+
};
|
|
6
|
+
interface ConfigCodec<Value extends ConfigValue = ConfigValue> {
|
|
7
|
+
readonly parse: (value: unknown) => Value;
|
|
8
|
+
readonly parseText: (text: string) => Value;
|
|
9
|
+
}
|
|
10
|
+
interface ConfigDefinition<Value extends ConfigValue = ConfigValue> {
|
|
11
|
+
readonly codec: ConfigCodec<Value>;
|
|
12
|
+
readonly defaultValue?: Value;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
}
|
|
15
|
+
type ConfigDefinitions = Readonly<Record<string, ConfigDefinition>>;
|
|
16
|
+
interface ConfigEntryBase {
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly key: string;
|
|
19
|
+
}
|
|
20
|
+
type ConfigEntry = (ConfigEntryBase & {
|
|
21
|
+
readonly defaultValue?: ConfigValue;
|
|
22
|
+
readonly source: "config";
|
|
23
|
+
readonly value: ConfigValue;
|
|
24
|
+
}) | (ConfigEntryBase & {
|
|
25
|
+
readonly defaultValue: ConfigValue;
|
|
26
|
+
readonly source: "default";
|
|
27
|
+
readonly value: ConfigValue;
|
|
28
|
+
}) | (ConfigEntryBase & {
|
|
29
|
+
readonly source: "unset";
|
|
30
|
+
});
|
|
31
|
+
interface Config {
|
|
32
|
+
readonly path: string;
|
|
33
|
+
get(input: {
|
|
34
|
+
readonly key: string;
|
|
35
|
+
}): Promise<ConfigEntry>;
|
|
36
|
+
list(): Promise<readonly ConfigEntry[]>;
|
|
37
|
+
set(input: {
|
|
38
|
+
readonly key: string;
|
|
39
|
+
readonly value: unknown;
|
|
40
|
+
}): Promise<ConfigEntry>;
|
|
41
|
+
setFromText(input: {
|
|
42
|
+
readonly key: string;
|
|
43
|
+
readonly text: string;
|
|
44
|
+
}): Promise<ConfigEntry>;
|
|
45
|
+
unset(input: {
|
|
46
|
+
readonly key: string;
|
|
47
|
+
}): Promise<ConfigEntry>;
|
|
48
|
+
}
|
|
49
|
+
interface CreateFileConfigOptions {
|
|
50
|
+
readonly definitions: ConfigDefinitions;
|
|
51
|
+
readonly path: string;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/codecs.d.ts
|
|
55
|
+
interface IntegerCodecOptions {
|
|
56
|
+
readonly maximum?: number;
|
|
57
|
+
readonly minimum?: number;
|
|
58
|
+
}
|
|
59
|
+
declare const configCodecs: {
|
|
60
|
+
readonly nonEmptyString: () => ConfigCodec<string>;
|
|
61
|
+
readonly boolean: () => ConfigCodec<boolean>;
|
|
62
|
+
readonly integer: (options?: IntegerCodecOptions) => ConfigCodec<number>;
|
|
63
|
+
readonly enumeration: <const Values extends readonly [string, ...string[]]>(values: Values) => ConfigCodec<Values[number]>;
|
|
64
|
+
readonly httpUrl: () => ConfigCodec<string>;
|
|
65
|
+
readonly httpOrigin: () => ConfigCodec<string>;
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/definitions.d.ts
|
|
69
|
+
declare function defineConfig<const Definitions extends ConfigDefinitions>(definitions: Definitions): Definitions;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/errors.d.ts
|
|
72
|
+
type ConfigErrorCode = "CONFIG_INVALID_DEFINITION" | "CONFIG_UNKNOWN_KEY" | "CONFIG_INVALID_VALUE" | "CONFIG_INVALID_DOCUMENT" | "CONFIG_READ_FAILED" | "CONFIG_WRITE_FAILED";
|
|
73
|
+
declare class ConfigError extends Error {
|
|
74
|
+
readonly code: ConfigErrorCode;
|
|
75
|
+
readonly details: Readonly<Record<string, ConfigValue>>;
|
|
76
|
+
constructor(code: ConfigErrorCode, message: string, details?: Readonly<Record<string, ConfigValue>>, options?: ErrorOptions);
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/file-config.d.ts
|
|
80
|
+
declare function createFileConfig(options: CreateFileConfigOptions): Config;
|
|
81
|
+
//#endregion
|
|
82
|
+
export { type Config, type ConfigCodec, type ConfigDefinition, type ConfigDefinitions, type ConfigEntry, ConfigError, type ConfigErrorCode, type ConfigPrimitive, type ConfigValue, type CreateFileConfigOptions, type IntegerCodecOptions, configCodecs, createFileConfig, defineConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const _0x41576a=_0x3a52;(function(_0x2f1af9,_0x581685){const _0xab6a2a=_0x3a52,_0x2eee13=_0x2f1af9();while(!![]){try{const _0x5644a1=-parseInt(_0xab6a2a(0x143))/0x1+-parseInt(_0xab6a2a(0x151))/0x2*(parseInt(_0xab6a2a(0x174))/0x3)+-parseInt(_0xab6a2a(0x170))/0x4+parseInt(_0xab6a2a(0x134))/0x5+-parseInt(_0xab6a2a(0x163))/0x6+-parseInt(_0xab6a2a(0x186))/0x7*(parseInt(_0xab6a2a(0x146))/0x8)+-parseInt(_0xab6a2a(0x133))/0x9*(-parseInt(_0xab6a2a(0x16d))/0xa);if(_0x5644a1===_0x581685)break;else _0x2eee13['push'](_0x2eee13['shift']());}catch(_0x4f9326){_0x2eee13['push'](_0x2eee13['shift']());}}}(_0x3512,0xc526b));import _0x1d3fae from'conf';import{mkdirSync as _0x58971a}from'node:fs';import{isAbsolute as _0x481089,parse as _0x183bad,resolve as _0x39c959}from'node:path';var a={'nonEmptyString'(){return{'parse':o,'parseText':o};},'boolean'(){return{'parse'(_0x495a92){const _0x13eb64=_0x3a52;if(typeof _0x495a92!=_0x13eb64(0x17a))throw Error(_0x13eb64(0x164));return _0x495a92;},'parseText'(_0x38cc98){const _0x4a3be0=_0x3a52;if(_0x38cc98==='true')return!0x0;if(_0x38cc98===_0x4a3be0(0x13e))return!0x1;throw Error(_0x4a3be0(0x136));}};},'integer'(_0x43c8ce={}){let _0x50f266=_0x1de4dc=>{const _0x32119b=_0x3a52;if(typeof _0x1de4dc!=_0x32119b(0x168)||!Number[_0x32119b(0x185)](_0x1de4dc))throw Error(_0x32119b(0x176));if(_0x43c8ce['minimum']!==void 0x0&&_0x1de4dc<_0x43c8ce['minimum'])throw Error(_0x32119b(0x17c)+_0x43c8ce[_0x32119b(0x16c)]+'.');if(_0x43c8ce[_0x32119b(0x182)]!==void 0x0&&_0x1de4dc>_0x43c8ce[_0x32119b(0x182)])throw Error(_0x32119b(0x16b)+_0x43c8ce[_0x32119b(0x182)]+'.');return _0x1de4dc;};return{'parse':_0x50f266,'parseText'(_0x2906f4){const _0x409684=_0x3a52;if(!/^-?(?:0|[1-9]\d*)$/u[_0x409684(0x172)](_0x2906f4))throw Error('Expected\x20an\x20integer.');return _0x50f266(Number(_0x2906f4));}};},'enumeration'(_0x9fbeb3){let _0x475382=_0x1dd0da=>{const _0x1a273e=_0x3a52;if(typeof _0x1dd0da!='string'||!_0x9fbeb3[_0x1a273e(0x17b)](_0x1dd0da))throw Error(_0x1a273e(0x132)+_0x9fbeb3[_0x1a273e(0x14b)](',\x20')+'.');return _0x1dd0da;};return{'parse':_0x475382,'parseText':_0x475382};},'httpUrl'(){return{'parse':s,'parseText':s};},'httpOrigin'(){const _0x116697=_0x3a52;let _0xdbb40e=_0x558053=>new URL(s(_0x558053))[_0x116697(0x13a)];return{'parse':_0xdbb40e,'parseText':_0xdbb40e};}};function o(_0x273879){const _0xd319d2=_0x3a52;if(typeof _0x273879!='string'||_0x273879['length']===0x0||_0x273879[_0xd319d2(0x13d)]()!==_0x273879)throw Error(_0xd319d2(0x17f));return _0x273879;}function s(_0x37c126){const _0xa7f3cd=_0x3a52;let _0x4eefd4=o(_0x37c126),_0x272f11;try{_0x272f11=new URL(_0x4eefd4);}catch{throw Error('Expected\x20an\x20absolute\x20HTTP\x20or\x20HTTPS\x20URL.');}if(_0x272f11[_0xa7f3cd(0x187)]!==_0xa7f3cd(0x140)&&_0x272f11['protocol']!==_0xa7f3cd(0x183))throw Error(_0xa7f3cd(0x14f));return _0x272f11[_0xa7f3cd(0x137)]();}function c(_0x1a8845){l(_0x1a8845,new Set());}function l(_0x3c5d4e,_0x101fb7){const _0x36bfdb=_0x3a52;if(_0x3c5d4e===null||typeof _0x3c5d4e==_0x36bfdb(0x141)||typeof _0x3c5d4e==_0x36bfdb(0x17a))return;if(typeof _0x3c5d4e==_0x36bfdb(0x168)){if(!Number[_0x36bfdb(0x150)](_0x3c5d4e))throw Error('Expected\x20a\x20finite\x20JSON\x20number.');return;}if(typeof _0x3c5d4e!=_0x36bfdb(0x130))throw Error(_0x36bfdb(0x18e));if(_0x101fb7[_0x36bfdb(0x160)](_0x3c5d4e))throw Error(_0x36bfdb(0x14e));if(_0x101fb7['add'](_0x3c5d4e),Array[_0x36bfdb(0x190)](_0x3c5d4e)){for(let _0x1f6bfe of _0x3c5d4e)l(_0x1f6bfe,_0x101fb7);_0x101fb7['delete'](_0x3c5d4e);return;}let _0x10fa67=Object[_0x36bfdb(0x158)](_0x3c5d4e);if(_0x10fa67!==Object[_0x36bfdb(0x15a)]&&_0x10fa67!==null)throw Error(_0x36bfdb(0x14a));for(let _0x379c12 of Object[_0x36bfdb(0x15c)](_0x3c5d4e))l(_0x379c12,_0x101fb7);_0x101fb7[_0x36bfdb(0x13f)](_0x3c5d4e);}function _0x3512(){const _0x3073c0=['Invalid\x20default\x20value:\x20','Config\x20path\x20must\x20be\x20absolute.','number','hasOwn','description','Expected\x20an\x20integer\x20less\x20than\x20or\x20equal\x20to\x20','minimum','1560qyzFSf','function','definitions','2995060YLsKmi','unset','test','length','3xONnPy','json','Expected\x20a\x20safe\x20integer.','code','path','CONFIG_INVALID_DEFINITION','boolean','includes','Expected\x20an\x20integer\x20greater\x20than\x20or\x20equal\x20to\x20','CONFIG_INVALID_DOCUMENT','Config\x20key\x20is\x20not\x20available:\x20','Expected\x20a\x20non-empty\x20string\x20without\x20surrounding\x20whitespace.','found','default','maximum','https:','ext','isSafeInteger','21HhmtAL','protocol','ConfigError','slice','then','details','segment','CONFIG_INVALID_VALUE','Expected\x20a\x20JSON-compatible\x20value.','codec','isArray','reverse','push','Invalid\x20config\x20definition\x20','object','CONFIG_WRITE_FAILED','Expected\x20one\x20of:\x20','251892UwftEz','178420KAnZuU','message','Expected\x20\x22true\x22\x20or\x20\x22false\x22.','toString','Config\x20path\x20must\x20use\x20the\x20.json\x20extension.','key','origin','CONFIG_UNKNOWN_KEY','entries','trim','false','delete','http:','string','freeze','622363mgLFoM','__proto__','dir','1998776vStynW','parse','Codec\x20must\x20provide\x20parse\x20and\x20parseText\x20functions.','Key\x20must\x20contain\x20safe\x20dot-separated\x20identifier\x20segments.','Expected\x20a\x20plain\x20JSON\x20object.','join','name','value','Expected\x20an\x20acyclic\x20JSON-compatible\x20value.','Expected\x20an\x20absolute\x20HTTP\x20or\x20HTTPS\x20URL.','isFinite','2388130ZBuvBQ','parseText','resolve','defaultValue','store','write','split','getPrototypeOf','text','prototype','some','values','keys','map','Invalid\x20value\x20for\x20config\x20key\x20','has','CONFIG_READ_FAILED','Config\x20document\x20conflicts\x20with\x20registered\x20key\x20','1677282yCiNEj','Expected\x20a\x20boolean.','constructor'];_0x3512=function(){return _0x3073c0;};return _0x3512();}var u=class extends Error{[_0x41576a(0x177)];[_0x41576a(0x18b)];constructor(_0x124f31,_0x942c7,_0x15391e={},_0x19db61){const _0x28100d=_0x41576a;super(_0x942c7,_0x19db61),this[_0x28100d(0x14c)]=_0x28100d(0x188),this['code']=_0x124f31,this[_0x28100d(0x18b)]=_0x15391e;}};function d(_0x1ce6ec){const _0x46edbc=_0x41576a;return _0x1ce6ec instanceof Error?_0x1ce6ec[_0x46edbc(0x135)]:String(_0x1ce6ec);}var f=new Set([_0x41576a(0x144),_0x41576a(0x165),_0x41576a(0x15a)]);function p(_0xee8a8a){const _0x506cc8=_0x41576a;let _0x39ee23={};for(let [_0x2851bc,_0x1ea68c]of Object[_0x506cc8(0x13c)](_0xee8a8a)){m(_0x2851bc);let _0x52a15b=_0x1ea68c['description'][_0x506cc8(0x13d)]();if(_0x52a15b==='')throw h(_0x2851bc,'Description\x20must\x20not\x20be\x20empty.');if(typeof _0x1ea68c['codec']?.['parse']!=_0x506cc8(0x16e)||typeof _0x1ea68c[_0x506cc8(0x18f)][_0x506cc8(0x152)]!=_0x506cc8(0x16e))throw h(_0x2851bc,_0x506cc8(0x148));let _0x172ecd;if(Object['hasOwn'](_0x1ea68c,_0x506cc8(0x154)))try{_0x172ecd=_0x1ea68c[_0x506cc8(0x18f)]['parse'](_0x1ea68c[_0x506cc8(0x154)]),c(_0x172ecd);}catch(_0x47f032){throw h(_0x2851bc,_0x506cc8(0x166)+d(_0x47f032),_0x47f032);}_0x39ee23[_0x2851bc]=Object[_0x506cc8(0x142)]({'codec':_0x1ea68c[_0x506cc8(0x18f)],'description':_0x52a15b,...Object[_0x506cc8(0x169)](_0x1ea68c,_0x506cc8(0x154))?{'defaultValue':_0x172ecd}:{}});}return Object[_0x506cc8(0x142)](_0x39ee23);}function m(_0x2d4bf8){const _0x446fba=_0x41576a;let _0x15b03e=_0x2d4bf8[_0x446fba(0x157)]('.');if(_0x2d4bf8[_0x446fba(0x173)]===0x0||_0x2d4bf8[_0x446fba(0x13d)]()!==_0x2d4bf8||_0x15b03e[_0x446fba(0x15b)](_0x3aaec1=>_0x3aaec1[_0x446fba(0x173)]===0x0||f[_0x446fba(0x160)](_0x3aaec1)||!/^[A-Za-z][A-Za-z0-9_-]*$/u[_0x446fba(0x172)](_0x3aaec1)))throw h(_0x2d4bf8,_0x446fba(0x149));}function h(_0x3e6481,_0x4eeaf1,_0x5c848e){const _0x1013b7=_0x41576a;return new u(_0x1013b7(0x179),_0x1013b7(0x12f)+_0x3e6481+':\x20'+_0x4eeaf1,{'key':_0x3e6481},_0x5c848e===void 0x0?void 0x0:{'cause':_0x5c848e});}function g(_0x347b04){const _0x1201f5=_0x41576a;if(!_0x481089(_0x347b04[_0x1201f5(0x178)]))throw Error(_0x1201f5(0x167));let _0x1e4d08=_0x39c959(_0x347b04[_0x1201f5(0x178)]),_0x1ea9ca=_0x183bad(_0x1e4d08);if(_0x1ea9ca[_0x1201f5(0x184)]!=='.json')throw Error(_0x1201f5(0x138));try{_0x58971a(_0x1ea9ca[_0x1201f5(0x145)],{'mode':0x1c0,'recursive':!0x0});}catch(_0x195d36){throw D(_0x1201f5(0x131),_0x1e4d08,_0x195d36);}let _0xb48cf0;try{_0xb48cf0=new _0x1d3fae({'configFileMode':0x180,'configName':_0x1ea9ca[_0x1201f5(0x14c)],'cwd':_0x1ea9ca[_0x1201f5(0x145)],'fileExtension':_0x1201f5(0x175)});}catch(_0x12c5ff){throw D('CONFIG_READ_FAILED',_0x1e4d08,_0x12c5ff);}let _0x10c23a=Promise[_0x1201f5(0x153)](),_0x4e0072=()=>{const _0x25e26a=_0x1201f5;try{return _0xb48cf0[_0x25e26a(0x155)];}catch(_0x219888){throw D(_0x25e26a(0x161),_0x1e4d08,_0x219888);}},_0x4bceb4=_0xeb0f9d=>{const _0x3f810e=_0x1201f5;try{_0xb48cf0[_0x3f810e(0x155)]=_0xeb0f9d;}catch(_0x27979e){throw D(_0x3f810e(0x131),_0x1e4d08,_0x27979e);}},_0x53e1fe=_0xc005a5=>{const _0x43ac8b=_0x1201f5;let _0x1918bb=_(_0x347b04,_0xc005a5),_0x177734=x(_0x4e0072(),_0xc005a5);return _0x177734[_0x43ac8b(0x180)]?v(_0xc005a5,_0x1918bb,_0x177734[_0x43ac8b(0x14d)]):b(_0xc005a5,_0x1918bb);},_0x2a5025=async(_0x2c1667,_0x4d2d53)=>{const _0x3f98be=_0x1201f5;let _0x3bb7e6=_0x10c23a[_0x3f98be(0x18a)](()=>{let _0x335714=_0x4e0072();if(_0x4d2d53===void 0x0&&!x(_0x335714,_0x2c1667)['found'])return _0x53e1fe(_0x2c1667);let _0x3104aa=_0x4d2d53===void 0x0?C(_0x335714,_0x2c1667):S(_0x335714,_0x2c1667,_0x4d2d53);return _0x4bceb4(_0x3104aa),_0x53e1fe(_0x2c1667);});return _0x10c23a=_0x3bb7e6['then'](()=>void 0x0,()=>void 0x0),await _0x3bb7e6;};return{'path':_0xb48cf0[_0x1201f5(0x178)],async 'get'(_0x24cba7){const _0x58043d=_0x1201f5;return _0x53e1fe(_0x24cba7[_0x58043d(0x139)]);},async 'list'(){const _0x37f68f=_0x1201f5;return Object[_0x37f68f(0x15d)](_0x347b04[_0x37f68f(0x16f)])[_0x37f68f(0x15e)](_0x41e6ee=>_0x53e1fe(_0x41e6ee));},async 'set'(_0x41dca1){const _0xd90e6c=_0x1201f5;let _0x396d71=_(_0x347b04,_0x41dca1[_0xd90e6c(0x139)]);return await _0x2a5025(_0x41dca1[_0xd90e6c(0x139)],y(_0x41dca1[_0xd90e6c(0x139)],()=>_0x396d71[_0xd90e6c(0x18f)]['parse'](_0x41dca1['value'])));},async 'setFromText'(_0x5206b1){const _0x1a1a90=_0x1201f5;let _0x5ac3bd=_(_0x347b04,_0x5206b1[_0x1a1a90(0x139)]);return await _0x2a5025(_0x5206b1[_0x1a1a90(0x139)],y(_0x5206b1[_0x1a1a90(0x139)],()=>_0x5ac3bd[_0x1a1a90(0x18f)]['parseText'](_0x5206b1[_0x1a1a90(0x159)])));},async 'unset'(_0x3a83f8){return _(_0x347b04,_0x3a83f8['key']),await _0x2a5025(_0x3a83f8['key'],void 0x0);}};}function _(_0x7532e5,_0x3c4d37){const _0x3a5904=_0x41576a;let _0x4abb83=_0x7532e5[_0x3a5904(0x16f)][_0x3c4d37];if(_0x4abb83===void 0x0)throw new u(_0x3a5904(0x13b),_0x3a5904(0x17e)+_0x3c4d37+'.',{'availableKeys':Object['keys'](_0x7532e5[_0x3a5904(0x16f)]),'key':_0x3c4d37});return _0x4abb83;}function v(_0x354064,_0x5357e1,_0x3b4bca){const _0x3a153b=_0x41576a;let _0x125c10=y(_0x354064,()=>_0x5357e1[_0x3a153b(0x18f)][_0x3a153b(0x147)](_0x3b4bca));return{'description':_0x5357e1[_0x3a153b(0x16a)],'key':_0x354064,'source':'config','value':_0x125c10,...Object[_0x3a153b(0x169)](_0x5357e1,'defaultValue')?{'defaultValue':_0x5357e1[_0x3a153b(0x154)]}:{}};}function y(_0x247e93,_0x3fd15b){const _0x2667c4=_0x41576a;try{let _0x32b0bb=_0x3fd15b();return c(_0x32b0bb),_0x32b0bb;}catch(_0x26f691){throw new u(_0x2667c4(0x18d),_0x2667c4(0x15f)+_0x247e93+':\x20'+d(_0x26f691),{'key':_0x247e93},{'cause':_0x26f691});}}function b(_0x18316f,_0x2dfae2){const _0x13d52b=_0x41576a;return Object[_0x13d52b(0x169)](_0x2dfae2,_0x13d52b(0x154))?{'defaultValue':_0x2dfae2[_0x13d52b(0x154)],'description':_0x2dfae2[_0x13d52b(0x16a)],'key':_0x18316f,'source':_0x13d52b(0x181),'value':_0x2dfae2[_0x13d52b(0x154)]}:{'description':_0x2dfae2[_0x13d52b(0x16a)],'key':_0x18316f,'source':_0x13d52b(0x171)};}function x(_0x3baffc,_0x46b766){const _0x1830ca=_0x41576a;let _0x563461=_0x3baffc;for(let _0x3766b8 of _0x46b766[_0x1830ca(0x157)]('.')){if(!w(_0x563461))throw E(_0x46b766);if(!Object[_0x1830ca(0x169)](_0x563461,_0x3766b8))return{'found':!0x1};_0x563461=_0x563461[_0x3766b8];}return{'found':!0x0,'value':_0x563461};}function S(_0x4277f4,_0x54c2c1,_0x18e257){const _0x5a0326=_0x41576a;let _0x4a32d4={...structuredClone(_0x4277f4)},_0x393f76=_0x54c2c1[_0x5a0326(0x157)]('.'),_0x6f87ba=_0x4a32d4;for(let _0x186dd8 of _0x393f76[_0x5a0326(0x189)](0x0,-0x1)){let _0x2f503f=_0x6f87ba[_0x186dd8];if(_0x2f503f===void 0x0){let _0x1b7b16={};_0x6f87ba[_0x186dd8]=_0x1b7b16,_0x6f87ba=_0x1b7b16;}else{if(T(_0x2f503f))_0x6f87ba=_0x2f503f;else throw E(_0x54c2c1);}}return _0x6f87ba[_0x393f76['at'](-0x1)]=structuredClone(_0x18e257),_0x4a32d4;}function _0x3a52(_0x4ad66c,_0x48d3de){_0x4ad66c=_0x4ad66c-0x12e;const _0x351211=_0x3512();let _0x3a52e2=_0x351211[_0x4ad66c];return _0x3a52e2;}function C(_0x242110,_0xd8b603){const _0x3d5254=_0x41576a;let _0x562460={...structuredClone(_0x242110)},_0x5b6a9f=_0xd8b603[_0x3d5254(0x157)]('.'),_0x340ac8=[],_0x2b2378=_0x562460;for(let _0x3c32ba of _0x5b6a9f['slice'](0x0,-0x1)){let _0x56384e=_0x2b2378[_0x3c32ba];if(_0x56384e===void 0x0)return _0x562460;if(!T(_0x56384e))throw E(_0xd8b603);_0x340ac8[_0x3d5254(0x12e)]({'object':_0x2b2378,'segment':_0x3c32ba}),_0x2b2378=_0x56384e;}delete _0x2b2378[_0x5b6a9f['at'](-0x1)];for(let _0x3c341e of _0x340ac8[_0x3d5254(0x191)]()){let _0x24471e=_0x3c341e[_0x3d5254(0x130)][_0x3c341e[_0x3d5254(0x18c)]];if(w(_0x24471e)&&Object[_0x3d5254(0x15d)](_0x24471e)[_0x3d5254(0x173)]===0x0)delete _0x3c341e[_0x3d5254(0x130)][_0x3c341e[_0x3d5254(0x18c)]];else break;}return _0x562460;}function w(_0x1f42f4){const _0x161eaf=_0x41576a;return typeof _0x1f42f4==_0x161eaf(0x130)&&!!_0x1f42f4&&!Array[_0x161eaf(0x190)](_0x1f42f4);}function T(_0x42069c){return w(_0x42069c);}function E(_0x206b99){const _0x4558ba=_0x41576a;return new u(_0x4558ba(0x17d),_0x4558ba(0x162)+_0x206b99+'.',{'key':_0x206b99});}function D(_0x3da7d7,_0x3aa544,_0x310c94){const _0x5dd69f=_0x41576a;return new u(_0x3da7d7,'Failed\x20to\x20'+(_0x3da7d7==='CONFIG_READ_FAILED'?'read':_0x5dd69f(0x156))+'\x20config\x20file\x20'+_0x3aa544+':\x20'+d(_0x310c94),{'path':_0x3aa544},{'cause':_0x310c94});}export{u as ConfigError,a as configCodecs,g as createFileConfig,p as defineConfig};
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@univer-cli/config",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"README.zh-CN.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"conf": "^15.1.0"
|
|
22
|
+
}
|
|
23
|
+
}
|