soma-core 2.2.5 → 2.2.6
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 +5 -6
- package/bin/soma.cjs +2 -2
- package/core/build/compiler/flat-page.ts +16 -0
- package/core/build/compiler/full-manifest-builder.ts +0 -3
- package/core/build/compiler/page-assets.ts +0 -1
- package/core/build/compiler/page-closure.ts +245 -0
- package/core/build/compiler/page-declaration-compiler.ts +2 -5
- package/core/build/compiler/soma-precompile.js +1848 -3244
- package/core/build/compiler/soma-precompile.ts +4 -7
- package/core/build/component-tree/artifact-codec.ts +4 -8
- package/core/build/lsp/soma-declaration.cjs +1 -1
- package/core/build/lsp/std-completion.generated.json +3 -3
- package/core/client/a11y/a11y-config.ts +2 -1
- package/core/client/a11y/dom-id.ts +1 -1
- package/core/client/base/SomaHttpClient.ts +11 -3
- package/core/client/base/SomaPageRootBase.ts +6 -0
- package/core/client/base/defineSomaView.ts +178 -0
- package/core/client/base/index.ts +13 -0
- package/core/client/base/view-context.ts +328 -0
- package/core/client/behavior/adapter-collection.ts +2 -2
- package/core/client/compiler/manifest-compiler.ts +5 -36
- package/core/client/component/component-definition.types.ts +2 -1
- package/core/client/component/component-manager.ts +110 -20
- package/core/client/component/structure-adapter.ts +3 -7
- package/core/client/container/SomaContainerAdapter.ts +9 -1
- package/core/client/data/data-object-resolver.ts +516 -181
- package/core/client/data/data-write-actions.ts +79 -15
- package/core/client/data/format-config.ts +3 -1
- package/core/client/data/region-scope-port.ts +11 -0
- package/core/client/engine/asset-resolver.ts +2 -5
- package/core/client/engine/dom-renderer.ts +7 -40
- package/core/client/engine/event-engine.ts +1 -105
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +78 -17
- package/core/client/engine/runtime-builder.ts +0 -14
- package/core/client/engine/scope-resolver.ts +18 -0
- package/core/client/engine/soma-bootstrap.ts +385 -98
- package/core/client/engine/style-binder.ts +49 -106
- package/core/client/engine/timer-engine.ts +11 -1
- package/core/client/host-bridge/load-host-domain-class.ts +2 -1
- package/core/client/infra/http/SomaHttpService.ts +15 -4
- package/core/client/infra/i18n/pack-locales.ts +2 -2
- package/core/client/mount/domain-rule.ts +7 -3
- package/core/client/mount/mount-page.ts +38 -5
- package/core/client/mount/types.ts +2 -0
- package/core/client/parser/confirm-spec.ts +1 -1
- package/core/client/parser/data-config-parser.ts +27 -210
- package/core/client/parser/pipeline-parser.ts +14 -59
- package/core/client/parser/style-config-parser.ts +101 -95
- package/core/client/parser/timer-parser.ts +21 -0
- package/core/client/parser/ui-config-parser.ts +64 -12
- package/core/client/registry/declaration-renderer.ts +1 -1
- package/core/client/runtime/SomaRuntimeServices.ts +2 -1
- package/core/client/runtime/SomaSnapshotStore.ts +5 -0
- package/core/client/security/url-guard.ts +71 -11
- package/core/client/validation/async-check-registry.ts +2 -1
- package/core/client/validation/contract-validator.ts +2 -6
- package/core/client/validation/field-rules.ts +3 -13
- package/core/client/validation/object-rules.ts +2 -10
- package/core/index.ts +1 -35
- package/core/inspect/check-product.ts +5 -5
- package/core/inspect/runtime.ts +2 -1
- package/core/server/api/dispatch-service-api.ts +35 -36
- package/core/server/api/load-host-service.ts +5 -4
- package/core/server/compile-port.ts +1 -1
- package/core/server/host/app-config-composer.ts +2 -1
- package/core/server/host/host-assembly-entry.ts +1 -0
- package/core/server/host/host-assembly.ts +47 -3
- package/core/server/host/host-caller.ts +2 -1
- package/core/server/host/host-dir.ts +9 -0
- package/core/server/host/host-response-headers.ts +2 -1
- package/core/server/host/invoke-host-request-hook.ts +28 -4
- package/core/server/host/published-page-assets.ts +2 -1
- package/core/server/host/resolve-host-request-hook.ts +25 -7
- package/core/server/host/server-page-assets.ts +4 -4
- package/core/server/host/virtual-pages.ts +3 -2
- package/core/server/infra/cache/ServerFileCache.ts +79 -9
- package/core/server/registry/api-registry-store.ts +3 -1
- package/core/server/registry/declaration-precompiler.ts +0 -2
- package/core/server/registry/page-registry-repository.ts +2 -1
- package/core/server/registry/page-registry-store.ts +2 -1
- package/core/server/registry/registry-error.ts +6 -1
- package/core/server/registry/registry-file-lock.ts +296 -23
- package/core/server/registry/request-body-limit.ts +3 -2
- package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
- package/core/server/runtime-space/access-gate.ts +21 -7
- package/core/server/runtime-space/bindings.ts +3 -6
- package/core/server/runtime-space/dynamic-pages.ts +181 -49
- package/core/server/runtime-space/errors.ts +3 -0
- package/core/server/runtime-space/inject.ts +74 -15
- package/core/server/runtime-space/page-grants.ts +7 -1
- package/core/server/runtime-space/resolve.ts +66 -19
- package/core/server/runtime-space/store.ts +32 -3
- package/core/server/runtime-space/submit-steps.ts +2 -1
- package/core/server/runtime-space/types.ts +3 -1
- package/core/shared/component-tree-errors.ts +2 -1
- package/core/shared/contract-a11y.ts +1 -1
- package/core/shared/contract-sections.ts +2 -2
- package/core/shared/core-diagnostic-codes.ts +8 -0
- package/core/shared/declaration-keys.ts +1 -1
- package/core/shared/engines/engine-error.ts +2 -1
- package/core/shared/generation-error.ts +2 -1
- package/core/shared/page-envelope.ts +1 -1
- package/core/shared/pure-binding.ts +88 -0
- package/core/shared/registry-generated/diagnostic-registry-index.ts +16 -19
- package/core/shared/registry-generated/diagnostic-registry.ts +135 -177
- package/core/shared/registry-generated/limits.ts +49 -13
- package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
- package/core/shared/registry-generated/std-grammar-views.ts +40 -10
- package/core/shared/registry-generated/std-grammar.ts +42 -20
- package/core/shared/soma-error.ts +36 -0
- package/core/shared/types/compile-port.types.ts +1 -1
- package/core/shared/types/data-config.types.ts +17 -17
- package/core/shared/types/engine.types.ts +0 -3
- package/core/shared/types/event.types.ts +1 -11
- package/core/shared/types/generation-error.types.ts +5 -1
- package/core/shared/types/host-assembly.types.ts +7 -1
- package/core/shared/types/manifest.types.ts +0 -3
- package/core/shared/types/region-scope.types.ts +5 -1
- package/core/shared/types/scope-manifest.types.ts +0 -2
- package/core/shared/types/style-config.types.ts +21 -21
- package/core/shared/types/ui-config.types.ts +4 -5
- package/core/shared/types/watcher.types.ts +1 -1
- package/dist/browser/runtime-bundle.manifest.json +11 -13
- package/dist/browser/soma-runtime.js +2567 -2696
- package/dist/core/index.cjs +5446 -5486
- package/dist/host-native/aot-builder.cjs +46 -1
- package/dist/host-native/native-server.cjs +4879 -4505
- package/dist/lsp/component-tree.cjs +5814 -7042
- package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
- package/dist/types/build/compiler/page-closure.d.ts +21 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
- package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
- package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
- package/dist/types/client/a11y/a11y-config.d.ts +2 -1
- package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
- package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
- package/dist/types/client/base/defineSomaView.d.ts +46 -0
- package/dist/types/client/base/index.d.ts +2 -0
- package/dist/types/client/base/view-context.d.ts +136 -0
- package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
- package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
- package/dist/types/client/component/component-definition.types.d.ts +2 -1
- package/dist/types/client/component/component-manager.d.ts +29 -0
- package/dist/types/client/data/data-object-resolver.d.ts +91 -31
- package/dist/types/client/data/format-config.d.ts +2 -1
- package/dist/types/client/engine/dom-renderer.d.ts +1 -2
- package/dist/types/client/engine/event-engine.d.ts +0 -7
- package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
- package/dist/types/client/engine/runtime-builder.d.ts +0 -4
- package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
- package/dist/types/client/engine/style-binder.d.ts +8 -4
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
- package/dist/types/client/mount/domain-rule.d.ts +2 -0
- package/dist/types/client/mount/mount-page.d.ts +2 -1
- package/dist/types/client/mount/types.d.ts +2 -0
- package/dist/types/client/parser/data-config-parser.d.ts +6 -5
- package/dist/types/client/parser/style-config-parser.d.ts +7 -3
- package/dist/types/client/parser/timer-parser.d.ts +5 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
- package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
- package/dist/types/client/security/url-guard.d.ts +14 -0
- package/dist/types/client/validation/async-check-registry.d.ts +2 -1
- package/dist/types/client/validation/object-rules.d.ts +0 -5
- package/dist/types/index.d.ts +2 -7
- package/dist/types/inspect/runtime.d.ts +2 -1
- package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
- package/dist/types/server/api/load-host-service.d.ts +1 -1
- package/dist/types/server/compile-port.d.ts +1 -1
- package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
- package/dist/types/server/host/host-assembly.d.ts +2 -0
- package/dist/types/server/host/host-dir.d.ts +2 -0
- package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
- package/dist/types/server/host/published-page-assets.d.ts +2 -1
- package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
- package/dist/types/server/host/server-page-assets.d.ts +2 -1
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
- package/dist/types/server/registry/registry-error.d.ts +5 -1
- package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
- package/dist/types/server/registry/request-body-limit.d.ts +3 -2
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
- package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
- package/dist/types/server/runtime-space/bindings.d.ts +3 -2
- package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
- package/dist/types/server/runtime-space/errors.d.ts +1 -1
- package/dist/types/server/runtime-space/resolve.d.ts +2 -0
- package/dist/types/server/runtime-space/store.d.ts +8 -1
- package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
- package/dist/types/server/runtime-space/types.d.ts +3 -1
- package/dist/types/shared/component-tree-errors.d.ts +2 -1
- package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
- package/dist/types/shared/declaration-keys.d.ts +1 -1
- package/dist/types/shared/engines/engine-error.d.ts +2 -1
- package/dist/types/shared/generation-error.d.ts +2 -1
- package/dist/types/shared/pure-binding.d.ts +48 -0
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +119 -158
- package/dist/types/shared/registry-generated/limits.d.ts +40 -10
- package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
- package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
- package/dist/types/shared/registry-generated/std-grammar.d.ts +109 -241
- package/dist/types/shared/soma-error.d.ts +15 -0
- package/dist/types/shared/types/data-config.types.d.ts +14 -16
- package/dist/types/shared/types/engine.types.d.ts +0 -3
- package/dist/types/shared/types/event.types.d.ts +1 -7
- package/dist/types/shared/types/generation-error.types.d.ts +1 -1
- package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
- package/dist/types/shared/types/manifest.types.d.ts +0 -3
- package/dist/types/shared/types/region-scope.types.d.ts +4 -1
- package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
- package/dist/types/shared/types/style-config.types.d.ts +17 -19
- package/dist/types/shared/types/ui-config.types.d.ts +4 -5
- package/host-native/bin/host-native.cjs +22 -1
- package/host-native/client/browser-entry.ts +21 -172
- package/host-native/src/aot-builder.ts +52 -0
- package/host-native/src/host-prepare.ts +39 -5
- package/host-native/src/manifest-http.ts +2 -3
- package/host-native/src/native-server.ts +812 -174
- package/host-native/src/page-http.ts +3 -3
- package/host-native/src/public-packages.cjs +0 -1
- package/host-native/src/registry-handler.ts +12 -5
- package/host-native/src/static-file.ts +203 -53
- package/package.json +3 -2
- package/core/client/engine/step-runner.ts +0 -212
- package/core/client/engine/trigger-engine.ts +0 -55
- package/core/client/format/zoned.ts +0 -10
- package/core/client/parser/step-parser.ts +0 -359
- package/core/client/parser/trigger-parser.ts +0 -90
- package/core/client/parser/value-lang.ts +0 -340
- package/core/client/time/instant.ts +0 -2
- package/core/shared/calc/coerce.ts +0 -2
- package/core/shared/calc/errors.ts +0 -40
- package/core/shared/calc/evaluator.ts +0 -113
- package/core/shared/calc/index.ts +0 -11
- package/core/shared/calc/lexer.ts +0 -189
- package/core/shared/calc/parser.ts +0 -193
- package/core/shared/calc/typer.ts +0 -171
- package/core/shared/date-parts.ts +0 -2
- package/core/shared/show-when.ts +0 -77
- package/core/shared/types/step.types.ts +0 -91
- package/core/shared/types/trigger.types.ts +0 -14
- package/dist/types/client/engine/step-runner.d.ts +0 -42
- package/dist/types/client/engine/trigger-engine.d.ts +0 -16
- package/dist/types/client/format/zoned.d.ts +0 -1
- package/dist/types/client/parser/step-parser.d.ts +0 -23
- package/dist/types/client/parser/trigger-parser.d.ts +0 -13
- package/dist/types/client/parser/value-lang.d.ts +0 -63
- package/dist/types/client/time/instant.d.ts +0 -1
- package/dist/types/shared/calc/coerce.d.ts +0 -1
- package/dist/types/shared/calc/errors.d.ts +0 -14
- package/dist/types/shared/calc/evaluator.d.ts +0 -2
- package/dist/types/shared/calc/index.d.ts +0 -6
- package/dist/types/shared/calc/lexer.d.ts +0 -19
- package/dist/types/shared/calc/parser.d.ts +0 -43
- package/dist/types/shared/calc/typer.d.ts +0 -11
- package/dist/types/shared/date-parts.d.ts +0 -1
- package/dist/types/shared/show-when.d.ts +0 -21
- package/dist/types/shared/types/step.types.d.ts +0 -76
- package/dist/types/shared/types/trigger.types.d.ts +0 -12
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// core/client/engine/trigger-engine.ts
|
|
2
|
-
// 属性变化触发 DOM 事件 — 对应 _event.yaml triggers 块
|
|
3
|
-
|
|
4
|
-
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
5
|
-
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
6
|
-
import type { SomaScopeResolver } from './scope-resolver';
|
|
7
|
-
import type { SomaPropertyWatcher } from './property-watcher';
|
|
8
|
-
|
|
9
|
-
export interface SomaTriggerEngineOptions {
|
|
10
|
-
propertyWatcher: SomaPropertyWatcher;
|
|
11
|
-
resolver: SomaScopeResolver;
|
|
12
|
-
container: HTMLElement;
|
|
13
|
-
adapter: IContainerAdapter;
|
|
14
|
-
triggers: PropertyTrigger[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class SomaTriggerEngine {
|
|
18
|
-
private readonly unwatchers: Array<() => void> = [];
|
|
19
|
-
|
|
20
|
-
init(options: SomaTriggerEngineOptions): void {
|
|
21
|
-
for (const trigger of options.triggers) {
|
|
22
|
-
const resolvedPath = options.resolver.resolvePath(trigger.condition);
|
|
23
|
-
|
|
24
|
-
const unwatch = options.propertyWatcher.watch(
|
|
25
|
-
resolvedPath,
|
|
26
|
-
(newValue) => {
|
|
27
|
-
if (newValue !== trigger.value) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const targetEl = options.adapter.findAnchor(options.container, trigger.target);
|
|
32
|
-
if (!targetEl) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const eventInit: CustomEventInit = {
|
|
37
|
-
bubbles: true,
|
|
38
|
-
detail: trigger.detail,
|
|
39
|
-
};
|
|
40
|
-
targetEl.dispatchEvent(new CustomEvent(trigger.event, eventInit));
|
|
41
|
-
},
|
|
42
|
-
{ prefix: false },
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
this.unwatchers.push(unwatch);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
destroy(): void {
|
|
50
|
-
for (const unwatch of this.unwatchers) {
|
|
51
|
-
unwatch();
|
|
52
|
-
}
|
|
53
|
-
this.unwatchers.length = 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
// `steps:` 段解析(REQ-010 S4)——把一串交互编译成一张可终止、可画的图。
|
|
2
|
-
//
|
|
3
|
-
// 六步(《架构设计》§4.2):管道 → 条件 → 输出槽 → 控制流 → 可终止性 → 出图。
|
|
4
|
-
//
|
|
5
|
-
// 为什么可终止性要在**声明期**判:一条不终止的编排在运行期的表现是页面卡死,
|
|
6
|
-
// 而卡死的现场什么都留不下。所以这里干脆不给出不终止的写法——
|
|
7
|
-
// 没有 `while`,`goto` 只许向后,`for_each` 的 `over` 必须有界且嵌套不超过两层。
|
|
8
|
-
// 这三条加起来,步骤图是一个有限的 DAG,走完它的步数有上界。
|
|
9
|
-
|
|
10
|
-
import { collectPredicateFields, validatePredicate } from '../../shared/predicates';
|
|
11
|
-
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
12
|
-
import type {
|
|
13
|
-
SomaCompiledStep,
|
|
14
|
-
SomaStepGraph,
|
|
15
|
-
SomaStepOnError,
|
|
16
|
-
SomaStepSlot,
|
|
17
|
-
} from '../../shared/types/step.types';
|
|
18
|
-
|
|
19
|
-
export interface StepParseInput {
|
|
20
|
-
raw: unknown;
|
|
21
|
-
/** 事件载荷里的字段名:`when` 的作用域起点 */
|
|
22
|
-
payloadFields: readonly string[];
|
|
23
|
-
/** bootstrap 注册的具名动作;给了就校验 `do: ACTION | <name>` 的名字存在 */
|
|
24
|
-
actionNames?: readonly string[];
|
|
25
|
-
path: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface StepParseDeps {
|
|
29
|
-
fail(message: string, path: string): never;
|
|
30
|
-
/**
|
|
31
|
-
* 单条管道的解析器(`pipeline-parser` 的 `parsePipelineBody`)。
|
|
32
|
-
*
|
|
33
|
-
* 由调用方注入而不是直接 import,是为了不成环:`pipeline-parser` 的
|
|
34
|
-
* `parseEventConfig` 要认 `{ steps: [...] }` 形态,于是它得调本模块;
|
|
35
|
-
* 本模块再反向 import 它就构成循环,而循环 import 在 ESM 下"多数时候能跑"
|
|
36
|
-
* ——它坏起来是模块初始化顺序变了之后的一个 undefined,跟本次改动毫无关联。
|
|
37
|
-
*/
|
|
38
|
-
parsePipeline(expression: string): Omit<ParsedEvent, 'somaId' | 'domEvent'>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** `for_each` 最多两层。三层嵌套的遍历在声明层几乎肯定是数据结构没设计对 */
|
|
42
|
-
const MAX_FOR_EACH_DEPTH = 2;
|
|
43
|
-
|
|
44
|
-
const STEP_KEYS = new Set(['when', 'do', 'output', 'on_error', 'switch', 'parallel', 'for_each']);
|
|
45
|
-
const SLOT_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
46
|
-
|
|
47
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
48
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** 返回数组的动作:`for_each.over` 只认这种槽 */
|
|
52
|
-
function producesArray(pipelineType: string): boolean {
|
|
53
|
-
// 只有 Host 函数(UI_REFRESH / NAV_ACTION / ACTION)能返回数组;
|
|
54
|
-
// 导航与 UI 交互返回的是「做完了」,不是数据。
|
|
55
|
-
return pipelineType === 'UI_REFRESH' || pipelineType === 'NAV_ACTION' || pipelineType === 'ACTION';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function parseSteps(input: StepParseInput, deps: StepParseDeps): SomaStepGraph {
|
|
59
|
-
const { raw, payloadFields, path } = input;
|
|
60
|
-
// 显式标注:解构出来的方法不带控制流断言,收窄会整片失效
|
|
61
|
-
const fail: (message: string, at: string) => never = deps.fail;
|
|
62
|
-
|
|
63
|
-
if (!Array.isArray(raw) || raw.length === 0) {
|
|
64
|
-
fail('steps 必须是非空数组', path);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const slots: Record<string, SomaStepSlot> = {};
|
|
68
|
-
const edges: Array<[number, number]> = [];
|
|
69
|
-
let counter = 0;
|
|
70
|
-
|
|
71
|
-
/** `when` 的作用域:事件载荷字段 ∪ 已声明的输出槽(槽以 `名.子键` 的形态被引用) */
|
|
72
|
-
const scopeKeys = (): string[] => [...payloadFields, ...Object.keys(slots)];
|
|
73
|
-
|
|
74
|
-
const checkWhen = (when: unknown, at: string): void => {
|
|
75
|
-
if (when === undefined || when === null) return;
|
|
76
|
-
|
|
77
|
-
// 根引用先查,再走通用谓词校验。次序要紧:通用校验对"字段不在作用域里"只会说
|
|
78
|
-
// 「引用了不存在的字段」,而在编排里这句话答不了作者真正的问题——
|
|
79
|
-
// 到底是载荷里没有这个字段,还是槽声明在后面。先查根,才能把这两种情况分开说。
|
|
80
|
-
//
|
|
81
|
-
// 引用只许向后:槽必须**先于**引用它的步骤声明。少了这条,一个引用后面步骤输出的
|
|
82
|
-
// 条件会永远读到 undefined 并静默判假——那条分支于是永远不走,而且看不出来。
|
|
83
|
-
for (const field of collectPredicateFields(when as Parameters<typeof collectPredicateFields>[0])) {
|
|
84
|
-
const root = field.split('.')[0];
|
|
85
|
-
if (!payloadFields.includes(root) && slots[root] === undefined) {
|
|
86
|
-
fail(
|
|
87
|
-
`${at} 引用了 "${root}",但它既不是事件载荷字段`
|
|
88
|
-
+ `(${payloadFields.join(' / ') || '无'}),也不是先于本步声明的输出槽`
|
|
89
|
-
+ `(${Object.keys(slots).join(' / ') || '无'})`,
|
|
90
|
-
at,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const issues = validatePredicate(when, scopeKeys(), at, {});
|
|
96
|
-
if (issues.length > 0) fail(issues.join(';'), at);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const declareSlot = (name: unknown, at: string, index: number, pipelineType: string): string => {
|
|
100
|
-
const slot = String(name ?? '');
|
|
101
|
-
if (!SLOT_NAME_PATTERN.test(slot)) {
|
|
102
|
-
fail(`${at}.output "${slot}" 不是合法槽名(小写字母开头、下划线分隔)`, `${at}.output`);
|
|
103
|
-
}
|
|
104
|
-
if (slots[slot] !== undefined) {
|
|
105
|
-
fail(
|
|
106
|
-
`${at}.output 槽名 "${slot}" 与第 ${slots[slot].declaredAt + 1} 步重名`
|
|
107
|
-
+ '——同名槽的后写会覆盖前写,而引用它的条件读到哪一个取决于步骤次序',
|
|
108
|
-
`${at}.output`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
slots[slot] = { declaredAt: index, producedBy: pipelineType, bounded: producesArray(pipelineType) };
|
|
112
|
-
return slot;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const parsePipe = (expression: unknown, at: string): Omit<ParsedEvent, 'somaId' | 'domEvent'> => {
|
|
116
|
-
if (typeof expression !== 'string' || expression.trim() === '') {
|
|
117
|
-
fail(`${at}.do 必须是管道表达式字符串`, `${at}.do`);
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
return deps.parsePipeline(expression);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
// 管道自己的报错already说清了问题("未知事件类型 X"),原样转出去,
|
|
123
|
-
// 只补上是哪一步——包一层自己的话,作者会看到两句话说同一件事。
|
|
124
|
-
fail(error instanceof Error ? error.message : String(error), `${at}.do`);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const parseOnError = (value: unknown, at: string, total: number, index: number): SomaStepOnError => {
|
|
129
|
-
if (value === undefined) return 'stop';
|
|
130
|
-
const raw2 = String(value);
|
|
131
|
-
if (raw2 === 'stop' || raw2 === 'continue') return raw2;
|
|
132
|
-
const match = /^goto:(\d+)$/.exec(raw2);
|
|
133
|
-
if (!match) {
|
|
134
|
-
fail(`${at}.on_error 只能是 stop / continue / goto:<步骤序号>(收到 "${raw2}")`, `${at}.on_error`);
|
|
135
|
-
}
|
|
136
|
-
const target = Number(match[1]);
|
|
137
|
-
// 只许向后跳。向前跳就能构造循环,而一条不终止的编排在运行期的表现是页面卡死,
|
|
138
|
-
// 现场什么都留不下。这是 AO-1 的核心一条。
|
|
139
|
-
if (target <= index + 1) {
|
|
140
|
-
fail(
|
|
141
|
-
`${at}.on_error 的 goto:${target} 指向第 ${target} 步,不在本步(第 ${index + 1} 步)之后`
|
|
142
|
-
+ '——只许向后跳,否则编排可以不终止',
|
|
143
|
-
`${at}.on_error`,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
if (target > total) {
|
|
147
|
-
fail(`${at}.on_error 的 goto:${target} 越过了末步(共 ${total} 步)`, `${at}.on_error`);
|
|
148
|
-
}
|
|
149
|
-
return `goto:${target}`;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const walk = (
|
|
153
|
-
list: unknown[],
|
|
154
|
-
at: string,
|
|
155
|
-
depth: number,
|
|
156
|
-
inParallel: boolean,
|
|
157
|
-
): SomaCompiledStep[] => {
|
|
158
|
-
const out: SomaCompiledStep[] = [];
|
|
159
|
-
/** parallel 分支内声明的槽:分支之间不许互引(AO-2) */
|
|
160
|
-
const parallelLocalSlots: string[] = [];
|
|
161
|
-
|
|
162
|
-
list.forEach((entry, position) => {
|
|
163
|
-
const stepAt = `${at}[${position}]`;
|
|
164
|
-
if (!isPlainObject(entry)) fail(`${stepAt} 必须是映射`, stepAt);
|
|
165
|
-
for (const key of Object.keys(entry)) {
|
|
166
|
-
if (!STEP_KEYS.has(key)) {
|
|
167
|
-
fail(`${stepAt} 有未知键 "${key}"(支持: ${[...STEP_KEYS].join(' / ')})`, `${stepAt}.${key}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const index = counter;
|
|
171
|
-
counter += 1;
|
|
172
|
-
if (out.length > 0) edges.push([out[out.length - 1].index, index]);
|
|
173
|
-
|
|
174
|
-
// ── parallel ────────────────────────────────────────────────
|
|
175
|
-
if (entry.parallel !== undefined) {
|
|
176
|
-
if (!Array.isArray(entry.parallel) || entry.parallel.length < 2) {
|
|
177
|
-
fail(`${stepAt}.parallel 至少要两个分支(一个分支的并行就是顺序)`, `${stepAt}.parallel`);
|
|
178
|
-
}
|
|
179
|
-
const before = new Set(Object.keys(slots));
|
|
180
|
-
const children = walk(entry.parallel as unknown[], `${stepAt}.parallel`, depth, true);
|
|
181
|
-
const declared = Object.keys(slots).filter((name) => !before.has(name));
|
|
182
|
-
parallelLocalSlots.push(...declared);
|
|
183
|
-
out.push({ index, kind: 'parallel', onError: 'stop', children });
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// ── for_each ────────────────────────────────────────────────
|
|
188
|
-
if (entry.for_each !== undefined) {
|
|
189
|
-
if (depth + 1 > MAX_FOR_EACH_DEPTH) {
|
|
190
|
-
fail(
|
|
191
|
-
`${stepAt}.for_each 嵌套超过 ${MAX_FOR_EACH_DEPTH} 层`
|
|
192
|
-
+ '——三层遍历在声明层几乎肯定是数据结构没设计对',
|
|
193
|
-
`${stepAt}.for_each`,
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
const box = entry.for_each;
|
|
197
|
-
if (!isPlainObject(box)) fail(`${stepAt}.for_each 必须是 { over, as, steps }`, `${stepAt}.for_each`);
|
|
198
|
-
const over = String(box.over ?? '');
|
|
199
|
-
const as = String(box.as ?? '');
|
|
200
|
-
// `over` 必须有界:遍历一个来路不明的东西,步数就没有上界了
|
|
201
|
-
const isPayload = payloadFields.includes(over);
|
|
202
|
-
const slot = slots[over];
|
|
203
|
-
if (!isPayload && slot === undefined) {
|
|
204
|
-
fail(
|
|
205
|
-
`${stepAt}.for_each.over "${over}" 既不是事件载荷字段,也不是先于本步声明的输出槽`,
|
|
206
|
-
`${stepAt}.for_each.over`,
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (slot !== undefined && !slot.bounded) {
|
|
210
|
-
fail(
|
|
211
|
-
`${stepAt}.for_each.over "${over}" 来自 ${slot.producedBy},它不返回数组`
|
|
212
|
-
+ '——遍历一个不是数组的东西,步数就没有上界了',
|
|
213
|
-
`${stepAt}.for_each.over`,
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
if (!SLOT_NAME_PATTERN.test(as)) {
|
|
217
|
-
fail(`${stepAt}.for_each.as "${as}" 不是合法项名`, `${stepAt}.for_each.as`);
|
|
218
|
-
}
|
|
219
|
-
if (!Array.isArray(box.steps) || box.steps.length === 0) {
|
|
220
|
-
fail(`${stepAt}.for_each.steps 必须是非空数组`, `${stepAt}.for_each.steps`);
|
|
221
|
-
}
|
|
222
|
-
// 项名在体内可见:登记成一个有界槽,体内的 when 才能引用它
|
|
223
|
-
slots[as] = { declaredAt: index, producedBy: 'for_each', bounded: false };
|
|
224
|
-
const children = walk(box.steps as unknown[], `${stepAt}.for_each.steps`, depth + 1, inParallel);
|
|
225
|
-
delete slots[as];
|
|
226
|
-
out.push({ index, kind: 'for_each', onError: 'stop', over, as, children });
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// ── switch ──────────────────────────────────────────────────
|
|
231
|
-
if (entry.switch !== undefined) {
|
|
232
|
-
if (!Array.isArray(entry.switch) || entry.switch.length === 0) {
|
|
233
|
-
fail(`${stepAt}.switch 必须是非空分支数组`, `${stepAt}.switch`);
|
|
234
|
-
}
|
|
235
|
-
checkWhen(entry.when, `${stepAt}.when`);
|
|
236
|
-
const list2 = entry.switch as unknown[];
|
|
237
|
-
const branches: NonNullable<SomaCompiledStep['branches']> = [];
|
|
238
|
-
|
|
239
|
-
// 两条规则的判定次序要紧:先数个数、再看位置。反过来的话,两个 otherwise
|
|
240
|
-
// 的写法会先撞上「必须在末尾」,于是「只能有一个」那条永远走不到——
|
|
241
|
-
// 一条永远走不到的校验分支和没写是一样的。
|
|
242
|
-
const otherwiseAt = list2
|
|
243
|
-
.map((branch, position) => (isPlainObject(branch) && branch.otherwise === true ? position : -1))
|
|
244
|
-
.filter((position) => position !== -1);
|
|
245
|
-
if (otherwiseAt.length > 1) {
|
|
246
|
-
fail(
|
|
247
|
-
`${stepAt}.switch 有 ${otherwiseAt.length} 个 otherwise 分支(第 ${otherwiseAt.map((n) => n + 1).join(' / ')} 个)`
|
|
248
|
-
+ '——兜底只能有一个',
|
|
249
|
-
`${stepAt}.switch`,
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
if (otherwiseAt.length === 1 && otherwiseAt[0] !== list2.length - 1) {
|
|
253
|
-
fail(
|
|
254
|
-
`${stepAt}.switch[${otherwiseAt[0]}] 的 otherwise 必须是最后一个分支`
|
|
255
|
-
+ '(它是兜底,后面的分支永远走不到)',
|
|
256
|
-
`${stepAt}.switch[${otherwiseAt[0]}]`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
list2.forEach((branchRaw, branchIndex) => {
|
|
261
|
-
const branchAt = `${stepAt}.switch[${branchIndex}]`;
|
|
262
|
-
if (!isPlainObject(branchRaw)) fail(`${branchAt} 必须是映射`, branchAt);
|
|
263
|
-
const otherwise = branchRaw.otherwise === true;
|
|
264
|
-
if (!otherwise && branchRaw.when === undefined) {
|
|
265
|
-
fail(`${branchAt} 既没有 when 也不是 otherwise——它会无条件命中并吃掉后面的分支`, branchAt);
|
|
266
|
-
}
|
|
267
|
-
if (!otherwise) checkWhen(branchRaw.when, `${branchAt}.when`);
|
|
268
|
-
const pipeline = parsePipe(branchRaw.do, branchAt);
|
|
269
|
-
const output = branchRaw.output === undefined
|
|
270
|
-
? undefined
|
|
271
|
-
: declareSlot(branchRaw.output, branchAt, index, pipeline.type);
|
|
272
|
-
branches.push({
|
|
273
|
-
...(otherwise ? {} : { when: branchRaw.when as never }),
|
|
274
|
-
otherwise,
|
|
275
|
-
pipeline,
|
|
276
|
-
...(output === undefined ? {} : { output }),
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
out.push({ index, kind: 'switch', when: entry.when as never, onError: 'stop', branches });
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// ── do ──────────────────────────────────────────────────────
|
|
284
|
-
checkWhen(entry.when, `${stepAt}.when`);
|
|
285
|
-
const pipeline = parsePipe(entry.do, stepAt);
|
|
286
|
-
const onError = parseOnError(entry.on_error, stepAt, list.length, position);
|
|
287
|
-
if (onError.startsWith('goto:')) {
|
|
288
|
-
edges.push([index, index + (Number(onError.slice(5)) - position - 1)]);
|
|
289
|
-
}
|
|
290
|
-
const output = entry.output === undefined
|
|
291
|
-
? undefined
|
|
292
|
-
: declareSlot(entry.output, stepAt, index, pipeline.type);
|
|
293
|
-
if (inParallel && output !== undefined) parallelLocalSlots.push(output);
|
|
294
|
-
out.push({
|
|
295
|
-
index,
|
|
296
|
-
kind: 'do',
|
|
297
|
-
...(entry.when === undefined ? {} : { when: entry.when as never }),
|
|
298
|
-
pipeline,
|
|
299
|
-
onError,
|
|
300
|
-
...(output === undefined ? {} : { output }),
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
// 并行分支之间不许互引槽(AO-2):互引就意味着有顺序,那它就不是并行。
|
|
305
|
-
// 检法是「本层某个分支的 when 引用了本层另一个分支声明的槽」——
|
|
306
|
-
// 这在顺序执行下能跑通,一旦真的并行起来就变成竞态,而竞态只在压力下暴露。
|
|
307
|
-
if (inParallel && parallelLocalSlots.length > 0) {
|
|
308
|
-
out.forEach((step, position) => {
|
|
309
|
-
const refs = step.when === undefined ? [] : collectPredicateFields(step.when);
|
|
310
|
-
for (const ref of refs) {
|
|
311
|
-
const root = ref.split('.')[0];
|
|
312
|
-
if (!parallelLocalSlots.includes(root)) continue;
|
|
313
|
-
const owner = out.findIndex((other) => other.output === root);
|
|
314
|
-
if (owner !== -1 && owner !== position) {
|
|
315
|
-
fail(
|
|
316
|
-
`${at}[${position}] 的 when 引用了同一个 parallel 里另一个分支的输出槽 "${root}"`
|
|
317
|
-
+ '——并行分支之间不许互引:互引就意味着有顺序,那它就不该写成 parallel',
|
|
318
|
-
`${at}[${position}].when`,
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return out;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const steps = walk(raw as unknown[], path, 0, false);
|
|
329
|
-
|
|
330
|
-
// 具名动作全部可解析(AO-3 的声明期一半;bootstrap 期还会再查一次注册表)
|
|
331
|
-
if (input.actionNames !== undefined) {
|
|
332
|
-
const known = new Set(input.actionNames);
|
|
333
|
-
const visit = (list: SomaCompiledStep[]): void => {
|
|
334
|
-
for (const step of list) {
|
|
335
|
-
const pipes = [
|
|
336
|
-
...(step.pipeline ? [step.pipeline] : []),
|
|
337
|
-
...(step.branches ?? []).map((branch) => branch.pipeline),
|
|
338
|
-
];
|
|
339
|
-
for (const pipe of pipes) {
|
|
340
|
-
if (pipe.type !== 'ACTION') continue;
|
|
341
|
-
const name = String(pipe.funcPath ?? '');
|
|
342
|
-
if (!known.has(name)) {
|
|
343
|
-
fail(
|
|
344
|
-
`do: ACTION | ${name} —— 未注册的具名动作`
|
|
345
|
-
+ `(已注册:${[...known].join(' / ') || '无'})。`
|
|
346
|
-
+ '具名动作在 bootstrap 的 options.actions 里登记,这是 custom(script) 的替代:'
|
|
347
|
-
+ '实现在 Host 代码里、有名字、可审计。',
|
|
348
|
-
path,
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if (step.children) visit(step.children);
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
visit(steps);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return { steps, slots, edges };
|
|
359
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// core/client/parser/trigger-parser.ts — 解析 _event.yaml 的 triggers 块
|
|
2
|
-
|
|
3
|
-
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
4
|
-
import { parseTimers } from './timer-parser';
|
|
5
|
-
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
6
|
-
|
|
7
|
-
export class SomaTriggerParseError extends Error {
|
|
8
|
-
constructor(message: string) {
|
|
9
|
-
super(`[SOMA TriggerParser] ${message}`);
|
|
10
|
-
this.name = 'SomaTriggerParseError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function parseTriggerItem(raw: unknown, index: number): PropertyTrigger {
|
|
15
|
-
if (!raw || typeof raw !== 'object') {
|
|
16
|
-
throw new SomaTriggerParseError(`triggers[${index}] 必须是对象`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const item = raw as Record<string, unknown>;
|
|
20
|
-
|
|
21
|
-
if (typeof item.condition !== 'string' || !item.condition.trim()) {
|
|
22
|
-
throw new SomaTriggerParseError(`triggers[${index}].condition 必须是非空字符串`);
|
|
23
|
-
}
|
|
24
|
-
if (typeof item.target !== 'string' || !item.target.trim()) {
|
|
25
|
-
throw new SomaTriggerParseError(`triggers[${index}].target 必须是非空字符串`);
|
|
26
|
-
}
|
|
27
|
-
if (typeof item.event !== 'string' || !item.event.trim()) {
|
|
28
|
-
throw new SomaTriggerParseError(`triggers[${index}].event 必须是非空字符串`);
|
|
29
|
-
}
|
|
30
|
-
if (!('value' in item)) {
|
|
31
|
-
throw new SomaTriggerParseError(`triggers[${index}].value 为必填字段`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const value = item.value as PropertyTrigger['value'];
|
|
35
|
-
if (
|
|
36
|
-
value !== null &&
|
|
37
|
-
typeof value !== 'string' &&
|
|
38
|
-
typeof value !== 'number' &&
|
|
39
|
-
typeof value !== 'boolean'
|
|
40
|
-
) {
|
|
41
|
-
throw new SomaTriggerParseError(
|
|
42
|
-
`triggers[${index}].value 必须是 string | number | boolean | null`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const trigger: PropertyTrigger = {
|
|
47
|
-
condition: item.condition.trim(),
|
|
48
|
-
value,
|
|
49
|
-
target: item.target.trim(),
|
|
50
|
-
event: item.event.trim(),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
if (item.detail !== undefined) {
|
|
54
|
-
if (typeof item.detail !== 'object' || item.detail === null || Array.isArray(item.detail)) {
|
|
55
|
-
throw new SomaTriggerParseError(`triggers[${index}].detail 必须是对象`);
|
|
56
|
-
}
|
|
57
|
-
trigger.detail = item.detail as Record<string, unknown>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return trigger;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** 解析 triggers 数组(YAML 中 triggers: [...]) */
|
|
64
|
-
export function parseTriggers(raw: unknown): PropertyTrigger[] {
|
|
65
|
-
if (raw === undefined || raw === null) {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
if (!Array.isArray(raw)) {
|
|
69
|
-
throw new SomaTriggerParseError('triggers 必须是数组');
|
|
70
|
-
}
|
|
71
|
-
return raw.map((item, index) => parseTriggerItem(item, index));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** 从 event 配置根对象分离 triggers / timers 与事件声明 */
|
|
75
|
-
export function splitEventConfigRaw(raw: unknown): {
|
|
76
|
-
eventsRaw: Record<string, unknown>;
|
|
77
|
-
triggers: PropertyTrigger[];
|
|
78
|
-
timers: ParsedTimer[];
|
|
79
|
-
} {
|
|
80
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
81
|
-
return { eventsRaw: {}, triggers: [], timers: [] };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const { triggers: triggersRaw, timers: timersRaw, ...eventsRaw } = raw as Record<string, unknown>;
|
|
85
|
-
return {
|
|
86
|
-
eventsRaw,
|
|
87
|
-
triggers: parseTriggers(triggersRaw),
|
|
88
|
-
timers: parseTimers(timersRaw),
|
|
89
|
-
};
|
|
90
|
-
}
|