soma-core 1.4.1 → 1.4.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.
@@ -9,6 +9,14 @@ export interface SomaHttpClientConfig {
9
9
  /** Generic headers supplied by the host runtime, such as page context. */
10
10
  defaultHeaders?: Record<string, string> | (() => Record<string, string>);
11
11
  }
12
+ /**
13
+ * 从错误响应正文里提炼一句可读文案。
14
+ *
15
+ * 服务端精心写的结构化错误(`{ ok: false, error: "未知组件:X" }`)才是调用方要的信息,
16
+ * 只留 statusText 等于把它整条丢掉。正文也可能是 HTML 错误页或空串,
17
+ * 因此 JSON 解析必须容错——解析失败只是"没有结构化字段",不该把请求变成另一种崩法。
18
+ */
19
+ export declare function describeHttpErrorBody(body: string, statusText: string): string;
12
20
  /**
13
21
  * SomaHttpClient — API 请求封装
14
22
  *
@@ -59,6 +59,15 @@ export interface SomaAiCatalogEntry {
59
59
  example: string;
60
60
  antiPatterns?: string[];
61
61
  };
62
+ /**
63
+ * 字段行原文(REQ-012):对象 / 数组 prop 的逐字段形状与示例。
64
+ *
65
+ * 只在契约真写了嵌套形状或示例时出现——否则它与上面的 props 表逐字重复。
66
+ * 目录直接打印它,不另生成第二张字段表:作者写的和读者读到的是同一份东西。
67
+ */
68
+ spec?: string;
69
+ /** 派生样张(REQ-012):展示页与视觉矩阵喂给组件的那份 props */
70
+ sample?: Record<string, unknown>;
62
71
  }
63
72
  /**
64
73
  * 旧组件契约的迁移归族。
@@ -6,6 +6,16 @@ export interface VerifyPackOptions {
6
6
  * 换肤与 RTL 的正确性没有任何自动保障。
7
7
  */
8
8
  skipStyleChecks?: boolean;
9
+ /**
10
+ * 要求 solution 层组件带得出样张(REQ-012,默认开)。
11
+ *
12
+ * 没有示例值的业务组件在展示页上只有一个空壳,在视觉矩阵里量不出真实高度,
13
+ * 在 AI 那边只剩一句 desc——三处都不报错,所以要在这里拦。
14
+ * 存量组件用 samplePending 豁免,清单只减不增。
15
+ */
16
+ requireSamples?: boolean;
17
+ /** 样张待补清单(组件名):只减不增 */
18
+ samplePending?: readonly string[];
9
19
  }
10
20
  /**
11
21
  * 自检一个组件包,返回中文问题清单(空数组 = 通过)。
@@ -59,8 +59,11 @@ export type { SomaAdaptiveProfile, SomaAdaptiveConfig, SomaAdaptiveLevel, SomaAd
59
59
  export { createAdaptiveObserverPool, scheduleAdaptiveFlush, resolveTierWithHysteresis, SOMA_DEFAULT_HYSTERESIS, } from './client/adaptive/index';
60
60
  export type { SomaAdaptiveObserverPool, SomaAdaptiveSize, SomaAdaptiveSizeCallback, SomaAdaptiveTask, } from './client/adaptive/index';
61
61
  export type { SomaComponentDefinition, SomaComponentControllerContext, SomaComponentControllerFactory, } from './client/component/component-definition.types';
62
- export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractProp, SomaContractEmit, SomaContractSlot, SomaContractKeyboard, SomaContractOverlay, SomaContractToken, } from './shared/types/component-contract.types';
62
+ export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractField, SomaContractProp, SomaContractEmit, SomaContractSlot, SomaContractKeyboard, SomaContractOverlay, SomaContractToken, } from './shared/types/component-contract.types';
63
63
  export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
64
+ export { parseFieldLines, parseEmitLines, parseSlotLines, renderFieldLines, somaFields, somaEmits, somaSlots, SomaFieldLinesError, } from './shared/component/field-lines';
65
+ export { deriveContractSample, deriveFieldSample, hasRenderableSample, } from './shared/component/derive-sample';
66
+ export type { DeriveSampleResult, SampleGap } from './shared/component/derive-sample';
64
67
  export { componentTokenPrefix, componentTokenVar, COMPONENT_TOKEN_KEY_PATTERN, } from './shared/types/component-contract.types';
65
68
  export { createDefaultRuntimeServices } from './client/runtime/SomaRuntimeServices';
66
69
  export type { SomaRuntimeServices } from './client/runtime/SomaRuntimeServices';
@@ -0,0 +1,23 @@
1
+ import type { SomaComponentContract, SomaContractField } from '../types/component-contract.types';
2
+ export interface SampleGap {
3
+ /** 缺口路径,如 `order.items[].sku_id` */
4
+ path: string;
5
+ reason: string;
6
+ }
7
+ export interface DeriveSampleResult {
8
+ /** 可直接喂给组件的 props */
9
+ props: Record<string, unknown>;
10
+ /** 必填却既无 example 也无 default 的字段 */
11
+ gaps: SampleGap[];
12
+ }
13
+ /** 从契约派生一份样张 props */
14
+ export declare function deriveContractSample(contract: SomaComponentContract): DeriveSampleResult;
15
+ /** 单个字段的样张值(组件内部或工具按需调用) */
16
+ export declare function deriveFieldSample(field: SomaContractField): unknown;
17
+ /**
18
+ * 这份契约够不够渲染一张有内容的样张。
19
+ *
20
+ * 判据是「至少有一个 prop 写了 example,或有嵌套字段写了 example」——
21
+ * 全靠 default 派生出来的是空态,展示页放上去只有一个空壳。
22
+ */
23
+ export declare function hasRenderableSample(contract: SomaComponentContract): boolean;
@@ -0,0 +1,19 @@
1
+ import type { SomaContractEmit, SomaContractField, SomaContractProp, SomaContractSlot } from '../types/component-contract.types';
2
+ export declare class SomaFieldLinesError extends Error {
3
+ readonly line: number;
4
+ constructor(message: string, line: number);
5
+ }
6
+ /** props 文本块 → 契约 props */
7
+ export declare function parseFieldLines(text: string): Record<string, SomaContractProp>;
8
+ /** emits 文本块 → 契约 emits。事件行是 `名: 描述`,下一级是载荷行 `名: 类型, 描述` */
9
+ export declare function parseEmitLines(text: string): Record<string, SomaContractEmit>;
10
+ /** slots 文本块 → 契约 slots。插槽行是 `名: 描述, 必填`(必填可省) */
11
+ export declare function parseSlotLines(text: string): Record<string, SomaContractSlot>;
12
+ /** 契约 props(或任意字段表)→ 字段行文本块 */
13
+ export declare function renderFieldLines(fields: Record<string, SomaContractField>): string;
14
+ /** TS 组件里写同一段文本:`props: somaFields\`…\`` */
15
+ export declare function somaFields(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractProp>;
16
+ /** TS 组件里写事件文本块 */
17
+ export declare function somaEmits(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractEmit>;
18
+ /** TS 组件里写插槽文本块 */
19
+ export declare function somaSlots(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractSlot>;
@@ -8,15 +8,33 @@ export type SomaComponentLayer = 'atom' | 'composite' | 'solution' | 'template';
8
8
  */
9
9
  export type SomaGeometryFamily = 'control' | 'surface' | 'message' | 'data' | 'overlay' | 'layout' | 'display';
10
10
  export type SomaContractPropType = 'number' | 'string' | 'boolean' | 'enum' | 'object' | 'array';
11
- export interface SomaContractProp {
11
+ /**
12
+ * 字段(REQ-012)。
13
+ *
14
+ * prop、对象里的字段、数组元素、事件载荷是同一种东西,所以只有这一个形状,递归到底:
15
+ * `type: object` 用 `fields` 继续描述,`type: array` 用 `items` 描述元素。
16
+ *
17
+ * 为什么要 `example` 而不是靠 `default`:规则 C4 要求可选 prop 有默认值,而默认值按
18
+ * C4a 必须是空串 / 空数组这类浅结构——拿它渲染出来的永远是空态。展示页、视觉矩阵与
19
+ * AI 需要的是「这个字段真实长什么样」,那是另一个值,必须另有一处写。
20
+ */
21
+ export interface SomaContractField {
12
22
  type: SomaContractPropType;
23
+ desc?: string;
13
24
  required?: boolean;
14
25
  /** 非 required 的 prop 必须有默认值(契约规则 C4:零 props 可渲染) */
15
26
  default?: unknown;
16
- desc?: string;
27
+ /** 示例值(REQ-012):样张与展示页的数据来源;不参与运行时,只被派生与目录消费 */
28
+ example?: unknown;
17
29
  /** type === 'enum' 时的取值集合 */
18
30
  values?: (string | number)[];
19
- /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个) */
31
+ /** type === 'object' 时的子字段(REQ-012) */
32
+ fields?: Record<string, SomaContractField>;
33
+ /** type === 'array' 时的元素形状(REQ-012) */
34
+ items?: SomaContractField;
35
+ }
36
+ export interface SomaContractProp extends SomaContractField {
37
+ /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个)。只在 prop 一层有意义 */
20
38
  mode?: 'oneway' | 'model';
21
39
  }
22
40
  /**
@@ -29,9 +47,7 @@ export interface SomaContractProp {
29
47
  * 返回相对 default 的首个违规路径;`null` 表示最外层浅拷贝已足够隔离。
30
48
  */
31
49
  export declare function findNestedMutableContractDefault(value: unknown): string | null;
32
- export interface SomaContractEmitPayloadField {
33
- type: SomaContractPropType;
34
- desc?: string;
50
+ export interface SomaContractEmitPayloadField extends SomaContractField {
35
51
  }
36
52
  export interface SomaContractEmit {
37
53
  payload?: Record<string, SomaContractEmitPayloadField>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soma-core",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 16 App Router.",
5
5
  "keywords": [
6
6
  "soma",
@@ -157,7 +157,7 @@
157
157
  "@vitest/coverage-v8": "^3.2.7",
158
158
  "ajv-formats": "3.0.1",
159
159
  "esbuild": "^0.25.12",
160
- "js-yaml": "^4.3.1",
160
+ "js-yaml": "^4.3.2",
161
161
  "jsdom": "^26.1.0",
162
162
  "next": "16.3.1",
163
163
  "playwright": "^1.62.1",