@sns-parse/core 0.1.0 → 0.3.0-alpha.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.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 中立配置描述 DSL(core 定义,工具无关)。
3
+ *
4
+ * 各扩展包(@sns-parse/ext-*)与各平台包(@sns-parse/platform-*)以
5
+ * ConfigContribution 声明自己需要的配置项;core 聚合为完整清单;
6
+ * koishi 兼容层把清单翻译为 koishi Schema,CLI 兼容层翻译为默认配置/参数。
7
+ *
8
+ * core 与各碎片包都不依赖 koishi。
9
+ */
10
+ export type ConfigFieldType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'union';
11
+ export interface ConfigUnionValue {
12
+ value: string;
13
+ description?: string;
14
+ }
15
+ /** 一个配置字段的中立描述 */
16
+ export interface ConfigField {
17
+ /** 字段键(对象内相对键;顶层为绝对键) */
18
+ key: string;
19
+ type: ConfigFieldType;
20
+ description?: string;
21
+ default?: any;
22
+ /** koishi 的 role:多行文本 / 密钥 */
23
+ role?: 'textarea' | 'secret';
24
+ hidden?: boolean;
25
+ min?: number;
26
+ max?: number;
27
+ step?: number;
28
+ /** type='union' 的可选常量 */
29
+ values?: ConfigUnionValue[];
30
+ /** type='array' 且元素为标量时的元素类型 */
31
+ itemType?: ConfigFieldType;
32
+ /** type='array' 且元素为对象时的元素字段 */
33
+ itemFields?: ConfigField[];
34
+ /** type='object' 的子字段 */
35
+ fields?: ConfigField[];
36
+ }
37
+ /** 一组配置(通常对应 koishi 中的一个分组) */
38
+ export interface ConfigContribution {
39
+ /** 分组标题 */
40
+ group: string;
41
+ description?: string;
42
+ fields: ConfigField[];
43
+ }
44
+ /** 类型辅助:声明即校验 */
45
+ export declare function defineConfig(contribution: ConfigContribution): ConfigContribution;
46
+ /**
47
+ * 聚合多组配置声明:同 group 合并字段(后者追加),保持首次出现顺序。
48
+ * 用于 core 汇总所有扩展与平台声明的配置。
49
+ */
50
+ export declare function mergeConfigContributions(lists: ConfigContribution[][]): ConfigContribution[];
package/lib/config.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * 中立配置描述 DSL(core 定义,工具无关)。
4
+ *
5
+ * 各扩展包(@sns-parse/ext-*)与各平台包(@sns-parse/platform-*)以
6
+ * ConfigContribution 声明自己需要的配置项;core 聚合为完整清单;
7
+ * koishi 兼容层把清单翻译为 koishi Schema,CLI 兼容层翻译为默认配置/参数。
8
+ *
9
+ * core 与各碎片包都不依赖 koishi。
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.defineConfig = defineConfig;
13
+ exports.mergeConfigContributions = mergeConfigContributions;
14
+ /** 类型辅助:声明即校验 */
15
+ function defineConfig(contribution) {
16
+ return contribution;
17
+ }
18
+ /**
19
+ * 聚合多组配置声明:同 group 合并字段(后者追加),保持首次出现顺序。
20
+ * 用于 core 汇总所有扩展与平台声明的配置。
21
+ */
22
+ function mergeConfigContributions(lists) {
23
+ const out = [];
24
+ const byGroup = new Map();
25
+ for (const list of lists) {
26
+ for (const c of list) {
27
+ const existing = byGroup.get(c.group);
28
+ if (existing)
29
+ existing.fields.push(...c.fields);
30
+ else {
31
+ const copy = { ...c, fields: [...c.fields] };
32
+ byGroup.set(c.group, copy);
33
+ out.push(copy);
34
+ }
35
+ }
36
+ }
37
+ return out;
38
+ }
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @sns-parse/core 公共出口。
3
3
  */
4
4
  export * from './types';
5
+ export * from './config';
5
6
  export * from './logger';
6
7
  export * from './sender';
7
8
  export * from './extensions';
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  * @sns-parse/core 公共出口。
19
19
  */
20
20
  __exportStar(require("./types"), exports);
21
+ __exportStar(require("./config"), exports);
21
22
  __exportStar(require("./logger"), exports);
22
23
  __exportStar(require("./sender"), exports);
23
24
  __exportStar(require("./extensions"), exports);
package/lib/platform.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type ConfigContribution } from './config';
1
2
  /**
2
3
  * 平台定义契约:每个平台的自描述单元,是「每平台一个包」的基础。
3
4
  *
@@ -18,6 +19,13 @@ export interface PlatformDefinition {
18
19
  };
19
20
  /** 是否默认优先专属 API(可被 config.platformDedicatedFirst 覆盖) */
20
21
  dedicatedFirst?: boolean;
22
+ /** 中文名(用于配置项描述与界面展示) */
23
+ label?: string;
21
24
  /** 解析失败时的平台特定引导提示 */
22
25
  hints?: string[];
23
26
  }
27
+ /**
28
+ * 由平台定义聚合出「平台相关配置」(平台开关 / 专属 API 优先)。
29
+ * koishi / cli 兼容层据此动态生成配置,无需硬编码平台列表。
30
+ */
31
+ export declare function platformConfigContributions(defs: PlatformDefinition[]): ConfigContribution[];
package/lib/platform.js CHANGED
@@ -1,2 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.platformConfigContributions = platformConfigContributions;
4
+ const config_1 = require("./config");
5
+ /**
6
+ * 由平台定义聚合出「平台相关配置」(平台开关 / 专属 API 优先)。
7
+ * koishi / cli 兼容层据此动态生成配置,无需硬编码平台列表。
8
+ */
9
+ function platformConfigContributions(defs) {
10
+ return [
11
+ (0, config_1.defineConfig)({
12
+ group: '平台开关',
13
+ fields: [
14
+ {
15
+ key: 'platformEnabled', type: 'object', description: '各平台解析开关',
16
+ fields: defs.map(d => ({ key: d.type, type: 'boolean', default: true, description: d.label || d.type })),
17
+ },
18
+ ],
19
+ }),
20
+ (0, config_1.defineConfig)({
21
+ group: 'API 与平台',
22
+ description: '优先使用专属 API',
23
+ fields: [
24
+ {
25
+ key: 'platformDedicatedFirst', type: 'object', description: '优先使用专属 API',
26
+ fields: defs.map(d => ({ key: d.type, type: 'boolean', default: d.dedicatedFirst ?? false, description: d.label || d.type })),
27
+ },
28
+ ],
29
+ }),
30
+ ];
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sns-parse/core",
3
- "version": "0.1.0",
3
+ "version": "0.3.0-alpha.1+upstream.1.6.7",
4
4
  "description": "sns-parse 核心契约与宿主抽象:类型、可注入日志、Host、发送层契约、平台定义",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",