soma-core 2.2.5 → 2.2.7
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 +1972 -3312
- 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/IContainerAdapter.ts +4 -0
- package/core/client/container/SomaContainerAdapter.ts +52 -3
- package/core/client/data/data-object-resolver.ts +523 -184
- 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 +29 -108
- 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 +387 -99
- 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/infra/notify/DefaultNotifyService.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 +100 -7
- package/core/client/parser/data-config-parser.ts +28 -211
- package/core/client/parser/pipeline-parser.ts +16 -60
- 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/render-ports/hide-transition.ts +9 -0
- package/core/client/render-ports/index.ts +4 -0
- package/core/client/render-ports/notify-renderer.ts +2 -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 +17 -39
- 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 +8 -4
- package/core/server/api/paged-list.ts +259 -0
- package/core/server/compile-port.ts +1 -1
- package/core/server/host/app-config-composer.ts +2 -1
- package/core/server/host/empty-host-bootstrap.mjs +3 -0
- package/core/server/host/host-assembly-entry.ts +1 -0
- package/core/server/host/host-assembly.ts +50 -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/source-aliases.cjs +345 -0
- package/core/server/host/source-aliases.ts +32 -0
- package/core/server/host/source-packages.cjs +1 -0
- package/core/server/host/virtual-pages.ts +3 -2
- package/core/server/infra/cache/ServerFileCache.ts +83 -10
- package/core/server/node.ts +10 -0
- 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 +78 -16
- 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 +14 -0
- package/core/shared/data-declaration-checks.ts +29 -3
- 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 +21 -19
- package/core/shared/registry-generated/diagnostic-registry.ts +170 -177
- package/core/shared/registry-generated/limits.ts +65 -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 +43 -21
- 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 +20 -18
- package/core/shared/types/engine.types.ts +0 -3
- package/core/shared/types/event.types.ts +10 -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 +2733 -2712
- package/dist/core/index.cjs +5665 -5534
- package/dist/host-native/aot-builder.cjs +330 -1
- package/dist/host-native/native-server.cjs +5434 -4726
- package/dist/lsp/component-tree.cjs +5868 -7040
- 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/container/IContainerAdapter.d.ts +3 -0
- package/dist/types/client/container/SomaContainerAdapter.d.ts +5 -0
- package/dist/types/client/data/data-object-resolver.d.ts +93 -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/confirm-spec.d.ts +27 -3
- 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/render-ports/hide-transition.d.ts +9 -0
- package/dist/types/client/render-ports/index.d.ts +4 -0
- package/dist/types/client/render-ports/notify-renderer.d.ts +2 -1
- 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 +6 -11
- 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/api/paged-list.d.ts +101 -0
- 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/host/source-aliases.d.cts +53 -0
- package/dist/types/server/host/source-aliases.d.ts +30 -0
- package/dist/types/server/host/source-packages.d.cts +2 -0
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
- package/dist/types/server/node.d.ts +1 -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 +149 -158
- package/dist/types/shared/registry-generated/limits.d.ts +54 -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 +110 -242
- package/dist/types/shared/soma-error.d.ts +15 -0
- package/dist/types/shared/types/data-config.types.d.ts +17 -17
- package/dist/types/shared/types/engine.types.d.ts +0 -3
- package/dist/types/shared/types/event.types.d.ts +9 -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 +75 -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/host-native/styles/globals.css +30 -28
- package/package.json +14 -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,5 +1,5 @@
|
|
|
1
1
|
// 写入类内置动作(MV-EVT-2):组件 emit → `ACTION | data.submit` / `data.orderMove` → 这里调写通道,
|
|
2
|
-
// 并把结构化结果写回数据层的写入结果存储(字段错误、冲突、待确认、乐观叠层)。
|
|
2
|
+
// 并把结构化结果写回数据层的写入结果存储(字段错误、冲突、待确认、乐观叠层)。ui / kit 组件只发事件、只读结果。
|
|
3
3
|
// 乐观更新与失败回滚复用写通道已有的 `runWithFeedback`(apply / rollback 回调落在存储的乐观叠层上)。
|
|
4
4
|
|
|
5
5
|
import type { SomaDataSubmitResult } from '../../shared/types/data-config.types';
|
|
@@ -78,21 +78,85 @@ export function createDataWriteActions(options: {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
// 在途去重(仅 data.submit):键 = scope + 提交内容(object / mode / model),同键在途时复用同一个 Promise、不再发请求。
|
|
82
|
+
// 不能只按 scope:表格就地编辑等同 scope 下载荷不同的提交必须各自发出。落定(成功 / 失败 / 超时 / 取消)后在 finally 解除;
|
|
83
|
+
// 占用还要对得上存储里的在途序号:范围被 clear / reset(页面卸载、用完即清)或被更新的 begin 顶替后视为失效,不会永久卡住。
|
|
84
|
+
// 键 = scope + object + mode + model + 拆分配置(split)+ 其余提交选项(信号本身不入键,另存于占用条目上)。
|
|
85
|
+
// 载荷里含无法可靠序列化比较的值(File / Blob / FormData / Map / Set / ArrayBuffer 及视图 / 函数)时不参与去重。
|
|
86
|
+
const inflight = new Map<string, { readonly seq: number; readonly promise: Promise<SomaDataSubmitResult>; readonly signal: AbortSignal | undefined }>();
|
|
87
|
+
// `ancestors` 只含当前递归路径上的祖先:同一对象被引用两次(非环)不误判,真正的环才算。
|
|
88
|
+
const hasOpaqueValue = (value: unknown, ancestors: WeakSet<object>): boolean => {
|
|
89
|
+
if (typeof value === 'function') return true;
|
|
90
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
91
|
+
if (ancestors.has(value)) return true; // 环:不去重
|
|
92
|
+
if (
|
|
93
|
+
(typeof Blob !== 'undefined' && value instanceof Blob) // File 是 Blob 子类
|
|
94
|
+
|| (typeof FormData !== 'undefined' && value instanceof FormData)
|
|
95
|
+
|| value instanceof Map // Map / Set 经 JSON.stringify 都成 {},内容不同会得到相同键
|
|
96
|
+
|| value instanceof Set
|
|
97
|
+
|| value instanceof ArrayBuffer
|
|
98
|
+
|| ArrayBuffer.isView(value)
|
|
99
|
+
) return true;
|
|
100
|
+
ancestors.add(value);
|
|
101
|
+
try {
|
|
102
|
+
const children = Array.isArray(value) ? value : Object.values(value as Record<string, unknown>);
|
|
103
|
+
return children.some((child) => hasOpaqueValue(child, ancestors));
|
|
104
|
+
} finally {
|
|
105
|
+
ancestors.delete(value);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const submitKeyOf = (payload: Record<string, unknown>, scope: string): string | null => {
|
|
109
|
+
const rawOptions = typeof payload.options === 'object' && payload.options !== null ? payload.options as Record<string, unknown> : null;
|
|
110
|
+
const { signal: _signal, ...optionsWithoutSignal } = rawOptions ?? {};
|
|
111
|
+
const parts = [scope, payload.object, payload.mode === 'create' ? 'create' : 'update', payload.model ?? null, payload.split ?? null, rawOptions === null ? null : optionsWithoutSignal];
|
|
112
|
+
try {
|
|
113
|
+
if (hasOpaqueValue(parts, new WeakSet())) return null;
|
|
114
|
+
return JSON.stringify(parts);
|
|
115
|
+
} catch {
|
|
116
|
+
return null; // 载荷不可序列化(循环引用等):不去重
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const signalOf = (payload: Record<string, unknown>): AbortSignal | undefined => {
|
|
120
|
+
const opts = payload.options;
|
|
121
|
+
const signal = typeof opts === 'object' && opts !== null ? (opts as { signal?: unknown }).signal : undefined;
|
|
122
|
+
return signal instanceof AbortSignal ? signal : undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const submit = async (payload: Record<string, unknown>): Promise<SomaDataSubmitResult> => {
|
|
126
|
+
const result = await run(payload, async (object) => {
|
|
127
|
+
const resolver = options.resolver();
|
|
128
|
+
if (!resolver) return failure(`数据对象尚未就绪,无法提交 "${object}"`);
|
|
129
|
+
const mode = payload.mode === 'create' ? 'create' : 'update';
|
|
130
|
+
const model = typeof payload.model === 'object' && payload.model !== null ? payload.model as Record<string, unknown> : {};
|
|
131
|
+
type SubmitOptions = Parameters<SomaDataObjectResolver['submit']>[3];
|
|
132
|
+
const opts = typeof payload.options === 'object' && payload.options !== null ? payload.options as SubmitOptions : undefined;
|
|
133
|
+
return opts === undefined
|
|
134
|
+
? resolver.submit(object, model, mode)
|
|
135
|
+
: resolver.submit(object, model, mode, opts);
|
|
136
|
+
});
|
|
137
|
+
splitByRow(payload, result);
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
|
|
81
141
|
return {
|
|
82
|
-
'data.submit':
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
142
|
+
'data.submit': (payload) => {
|
|
143
|
+
const scope = scopeOf(payload);
|
|
144
|
+
const key = scope === null ? null : submitKeyOf(payload, scope);
|
|
145
|
+
if (scope === null || key === null) return submit(payload);
|
|
146
|
+
const held = inflight.get(key);
|
|
147
|
+
if (held !== undefined) {
|
|
148
|
+
const view = store.get(scope);
|
|
149
|
+
// 旧提交带的取消信号已 aborted(调用方取消后立刻重发):不复用已取消的那一次,丢弃占用并正常发起新请求
|
|
150
|
+
if (view.status === 'pending' && view.seq === held.seq && held.signal?.aborted !== true) return held.promise;
|
|
151
|
+
inflight.delete(key);
|
|
152
|
+
}
|
|
153
|
+
const promise = submit(payload);
|
|
154
|
+
// run 在第一个 await 之前已同步 begin:此刻存储里的序号就是这次提交的
|
|
155
|
+
const entry = { seq: store.get(scope).seq, promise, signal: signalOf(payload) };
|
|
156
|
+
inflight.set(key, entry);
|
|
157
|
+
const release = (): void => { if (inflight.get(key) === entry) inflight.delete(key); };
|
|
158
|
+
promise.then(release, release);
|
|
159
|
+
return promise;
|
|
96
160
|
},
|
|
97
161
|
'data.orderMove': (payload) => run(payload, async (object, scope) => {
|
|
98
162
|
const resolver = options.resolver();
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// 运行期消费:管道注册表 `setFormatDefaults`、数据解析器选项 `formatDefaults`(字段 `display` 的时区缺省与占位);
|
|
9
9
|
// `services.format` 工厂读它由 bootstrap 接线(不在本文件)。
|
|
10
10
|
|
|
11
|
+
import { SomaError } from '../../shared/soma-error';
|
|
12
|
+
|
|
11
13
|
/** `format:` 的封闭键集 */
|
|
12
14
|
export const SOMA_FORMAT_APP_CONFIG_KEYS = ['placeholder', 'time_zone'] as const;
|
|
13
15
|
|
|
@@ -16,7 +18,7 @@ export interface SomaFormatDefaults {
|
|
|
16
18
|
readonly timeZone?: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
export class SomaFormatConfigError extends
|
|
21
|
+
export class SomaFormatConfigError extends SomaError {
|
|
20
22
|
readonly code = 'CORE-FORMAT-CONFIG' as const;
|
|
21
23
|
readonly path: string;
|
|
22
24
|
constructor(message: string, path: string) {
|
|
@@ -213,6 +213,17 @@ export function createRegionScopeStore(): SomaRegionScopeStore {
|
|
|
213
213
|
scope.semantic.add(listener);
|
|
214
214
|
return () => { scope.semantic.delete(listener); };
|
|
215
215
|
},
|
|
216
|
+
// 发语义事件:与 `SCOPE | semantic` 管道同一条通道(订阅方一致),供组件 / 展示对象在代码里按顺序编排时发出;旧代次句柄空操作
|
|
217
|
+
emit(name, payload) {
|
|
218
|
+
if (owner !== generation) return;
|
|
219
|
+
for (const listener of [...scope.semantic]) {
|
|
220
|
+
try {
|
|
221
|
+
listener(name, payload ?? {});
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error('[soma-core][数据] 语义事件订阅者抛错(已隔离)', error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
216
227
|
};
|
|
217
228
|
},
|
|
218
229
|
routeSet(spec, writer, payload) {
|
|
@@ -5,7 +5,7 @@ import yaml from 'js-yaml';
|
|
|
5
5
|
import type { ICache } from '../infra/cache/ICache';
|
|
6
6
|
import { MemoryCache } from '../infra/cache/MemoryCache';
|
|
7
7
|
import { parseEventConfig } from '../parser/pipeline-parser';
|
|
8
|
-
import { splitEventConfigRaw } from '../parser/
|
|
8
|
+
import { splitEventConfigRaw } from '../parser/timer-parser';
|
|
9
9
|
import { parseStyleConfig } from '../parser/style-config-parser';
|
|
10
10
|
import { parseUiConfig } from '../parser/ui-config-parser';
|
|
11
11
|
import { extractConfigFromDomainClass } from '../parser/annotation-extractor';
|
|
@@ -31,7 +31,6 @@ export class SomaAssetResolver {
|
|
|
31
31
|
return {
|
|
32
32
|
uiConfig: assets.uiConfig,
|
|
33
33
|
eventConfig: assets.eventConfig,
|
|
34
|
-
triggers: assets.triggerConfig ?? [],
|
|
35
34
|
timers: assets.timerConfig ?? [],
|
|
36
35
|
styleConfig: assets.styleConfig ?? this.parseStyleConfig(assets.styleYaml),
|
|
37
36
|
locale: this.parseLocale(assets.locale),
|
|
@@ -50,7 +49,6 @@ export class SomaAssetResolver {
|
|
|
50
49
|
return {
|
|
51
50
|
uiConfig: extracted.uiConfig,
|
|
52
51
|
eventConfig: extracted.eventConfig,
|
|
53
|
-
triggers: assets.triggerConfig ?? [],
|
|
54
52
|
timers: assets.timerConfig ?? [],
|
|
55
53
|
styleConfig: this.parseStyleConfig(assets.styleYaml),
|
|
56
54
|
locale: this.parseLocale(assets.locale),
|
|
@@ -65,12 +63,11 @@ export class SomaAssetResolver {
|
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
const eventRaw = eventYaml.trim() ? yaml.load(eventYaml) : {};
|
|
68
|
-
const { eventsRaw,
|
|
66
|
+
const { eventsRaw, timers } = splitEventConfigRaw(eventRaw);
|
|
69
67
|
|
|
70
68
|
const result: ParsedRuntimeAssets = {
|
|
71
69
|
uiConfig: parseUiConfig(yaml.load(uiYaml)),
|
|
72
70
|
eventConfig: parseEventConfig(eventsRaw as any),
|
|
73
|
-
triggers,
|
|
74
71
|
timers,
|
|
75
72
|
styleConfig: this.parseStyleConfig(assets.styleYaml),
|
|
76
73
|
locale: this.parseLocale(assets.locale),
|
|
@@ -9,7 +9,6 @@ import type {
|
|
|
9
9
|
} from '../../shared/types/ui-config.types';
|
|
10
10
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
11
11
|
import { longestIncreasingSubsequence } from './lis';
|
|
12
|
-
import { evaluateShowWhen, type SomaShowWhen } from '../../shared/show-when';
|
|
13
12
|
import {
|
|
14
13
|
defaultPipeRegistry,
|
|
15
14
|
hasPipes,
|
|
@@ -247,8 +246,6 @@ export class SomaDomRenderer {
|
|
|
247
246
|
itemAlias: binding.itemAlias,
|
|
248
247
|
repeatPlanId: binding.repeatPlanId,
|
|
249
248
|
attrName: binding.attrName,
|
|
250
|
-
negate: binding.negate,
|
|
251
|
-
whenTest: binding.whenTest,
|
|
252
249
|
classRules: binding.classRules,
|
|
253
250
|
pipes: binding.pipes,
|
|
254
251
|
};
|
|
@@ -325,16 +322,8 @@ export class SomaDomRenderer {
|
|
|
325
322
|
};
|
|
326
323
|
}
|
|
327
324
|
|
|
328
|
-
case 'when':
|
|
329
|
-
const whenTest = entry.whenTest;
|
|
330
|
-
if (whenTest) {
|
|
331
|
-
return (v) => adapter.setVisibility(el, evaluateShowWhen(whenTest, v));
|
|
332
|
-
}
|
|
333
|
-
if (entry.negate) {
|
|
334
|
-
return (v) => adapter.setVisibility(el, !v);
|
|
335
|
-
}
|
|
325
|
+
case 'when':
|
|
336
326
|
return (v) => adapter.setVisibility(el, !!v);
|
|
337
|
-
}
|
|
338
327
|
|
|
339
328
|
case 'class': {
|
|
340
329
|
if (!entry.classRules || !this.resolver) {
|
|
@@ -344,14 +333,11 @@ export class SomaDomRenderer {
|
|
|
344
333
|
const resolver = this.resolver;
|
|
345
334
|
const rules = Object.entries(entry.classRules).map(([classes, condPath]) => ({
|
|
346
335
|
classList: classes.split(' ').filter(Boolean),
|
|
347
|
-
|
|
348
|
-
condPath: condPath.startsWith('!') ? condPath.slice(1) : condPath,
|
|
336
|
+
condPath,
|
|
349
337
|
}));
|
|
350
338
|
return () => {
|
|
351
339
|
for (const rule of rules) {
|
|
352
|
-
|
|
353
|
-
const enabled = rule.negate ? !raw : raw;
|
|
354
|
-
adapter.toggleClasses(el, rule.classList, enabled);
|
|
340
|
+
adapter.toggleClasses(el, rule.classList, !!resolver.readFromRootCompiled(rule.condPath));
|
|
355
341
|
}
|
|
356
342
|
};
|
|
357
343
|
}
|
|
@@ -958,10 +944,7 @@ export class SomaDomRenderer {
|
|
|
958
944
|
|
|
959
945
|
if (config.class) {
|
|
960
946
|
for (const [classes, path] of Object.entries(config.class)) {
|
|
961
|
-
|
|
962
|
-
const raw = !!this.resolveShowValue(condPath, data);
|
|
963
|
-
const enabled = negate ? !raw : raw;
|
|
964
|
-
this.adapter?.toggleClasses(element, classes.split(' ').filter(Boolean), enabled);
|
|
947
|
+
this.adapter?.toggleClasses(element, classes.split(' ').filter(Boolean), !!this.resolveShowValue(path, data));
|
|
965
948
|
}
|
|
966
949
|
}
|
|
967
950
|
}
|
|
@@ -1005,25 +988,9 @@ export class SomaDomRenderer {
|
|
|
1005
988
|
return segments.reduce((obj: any, key: string) => obj?.[key], itemData);
|
|
1006
989
|
}
|
|
1007
990
|
|
|
1008
|
-
/** 行内 `when`
|
|
1009
|
-
private rowWhenVisible(when:
|
|
1010
|
-
|
|
1011
|
-
return evaluateShowWhen(
|
|
1012
|
-
{ op: when.op, ...(when.value !== undefined ? { value: when.value } : {}) },
|
|
1013
|
-
this.resolveShowValue(when.field, data),
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
const { path, negate } = this.parseConditionalPath(when);
|
|
1017
|
-
const raw = this.resolveShowValue(path, data);
|
|
1018
|
-
return negate ? !raw : Boolean(raw);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
private parseConditionalPath(valuePath: string): { path: string; negate: boolean } {
|
|
1022
|
-
const negate = valuePath.startsWith('!');
|
|
1023
|
-
return {
|
|
1024
|
-
path: negate ? valuePath.slice(1) : valuePath,
|
|
1025
|
-
negate,
|
|
1026
|
-
};
|
|
991
|
+
/** 行内 `when` 的可见性:纯路径真值(页面不取反) */
|
|
992
|
+
private rowWhenVisible(when: string, data: any): boolean {
|
|
993
|
+
return Boolean(this.resolveShowValue(when, data));
|
|
1027
994
|
}
|
|
1028
995
|
|
|
1029
996
|
private isNestedShowMapping(value: ShowValue): value is NestedShowMapping {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { recordMetric } from '../diagnostics/telemetry-context';
|
|
2
2
|
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
3
3
|
import { SomaRowScope, readRowPath } from './row-scope';
|
|
4
|
+
import {
|
|
5
|
+
confirmContextOf,
|
|
6
|
+
resolveConfirmSpec,
|
|
7
|
+
warnConfirmMissing,
|
|
8
|
+
type SomaConfirmContext,
|
|
9
|
+
} from '../parser/confirm-spec';
|
|
4
10
|
import { SOMA_KEY_MODIFIERS } from '../../shared/types/keyboard.types';
|
|
5
11
|
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
6
12
|
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
@@ -11,7 +17,6 @@ import { dispatchNotifyDeclaration } from '../infra/notify/notify-declaration';
|
|
|
11
17
|
import type { INotifyService } from '../infra/notify/INotifyService';
|
|
12
18
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
13
19
|
import { isSomaEmitEvent } from './emit-event';
|
|
14
|
-
import { runSteps } from './step-runner';
|
|
15
20
|
import { captureSomaProjectionInteraction } from '../component/projection-registry';
|
|
16
21
|
import { SOMA_SELECTED_ATTR } from '../../shared/hook-attributes';
|
|
17
22
|
import type { SomaScopeEventSpec } from '../../shared/types/region-scope.types';
|
|
@@ -257,7 +262,15 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
257
262
|
return false;
|
|
258
263
|
};
|
|
259
264
|
if (!isCurrent()) return;
|
|
260
|
-
const preChecked = this.preCheck(
|
|
265
|
+
const preChecked = this.preCheck(
|
|
266
|
+
config,
|
|
267
|
+
config.somaId,
|
|
268
|
+
element,
|
|
269
|
+
confirmContextOf(
|
|
270
|
+
isSomaEmitEvent(originalEvent) ? originalEvent.payload : undefined,
|
|
271
|
+
rowContext instanceof SomaRowScope ? rowContext.data : undefined,
|
|
272
|
+
),
|
|
273
|
+
);
|
|
261
274
|
if (!(preChecked instanceof Promise ? await preChecked : preChecked)) {
|
|
262
275
|
runtime.status = 'blocked';
|
|
263
276
|
runtime.message = 'pre-check rejected';
|
|
@@ -320,7 +333,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
320
333
|
// namedActions 里时必然解析失败)。查找序:应用具名动作(`browserMount.actions`)→ 页面 Domain 同名方法
|
|
321
334
|
// → 都没有报诊断(status error + 控制台,不静默)。载荷 `{ object, field?, value?, row? }`:
|
|
322
335
|
// 数据动作经 emit 带来;DOM 事件在行内时补 `row`。执行包在一次事务里,成功后 commit(与编排同口径)。
|
|
323
|
-
if (config.type === 'ACTION'
|
|
336
|
+
if (config.type === 'ACTION') {
|
|
324
337
|
const payload = this.namedActionPayload(originalEvent, rowContext);
|
|
325
338
|
this.callbacks.onBeginTransaction?.();
|
|
326
339
|
try {
|
|
@@ -346,69 +359,6 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
346
359
|
return;
|
|
347
360
|
}
|
|
348
361
|
|
|
349
|
-
// ── 动作编排(REQ-010 F-13)─────────────────────────────────
|
|
350
|
-
//
|
|
351
|
-
// 带 `steps` 的事件走编排;不带的一律照旧。这条分叉刻意放在最前面:
|
|
352
|
-
// 编排有自己的错误语义(on_error 三档)与自己的输出槽生命周期,
|
|
353
|
-
// 混进下面那套单管道流程只会让两边都变形。
|
|
354
|
-
if (config.steps !== undefined) {
|
|
355
|
-
const payload = isSomaEmitEvent(originalEvent)
|
|
356
|
-
? (originalEvent.payload as Record<string, unknown>)
|
|
357
|
-
: {};
|
|
358
|
-
this.callbacks.onBeginTransaction?.();
|
|
359
|
-
try {
|
|
360
|
-
const outcome = await runSteps(config.steps, {
|
|
361
|
-
payload: { ...payload, ...((rowContext instanceof SomaRowScope ? rowContext.data : currentVar) ?? {}) },
|
|
362
|
-
dispatch: (pipeline, scope) => this.dispatchPipeline(pipeline, element, isCurrent, scope, config.somaId),
|
|
363
|
-
isValid: isCurrent,
|
|
364
|
-
confirm: (spec) => this.askConfirm(spec),
|
|
365
|
-
// 步骤尾段 permission:交给与单管道同一条 Host 事件中间件链判(用这一步的码构造最小上下文),
|
|
366
|
-
// 不直接查 core 权限集;没配中间件就不判(与单管道一致)。confirm / roles 复用引擎的出口与角色门。
|
|
367
|
-
permission: async (code) => {
|
|
368
|
-
const chain = this.middleware;
|
|
369
|
-
if (chain === null) return true;
|
|
370
|
-
const stepContext = {
|
|
371
|
-
...runtime,
|
|
372
|
-
config: { ...config, permission: code },
|
|
373
|
-
status: 'success' as 'success' | 'blocked' | 'error',
|
|
374
|
-
message: undefined as string | undefined,
|
|
375
|
-
};
|
|
376
|
-
let reached = false;
|
|
377
|
-
await chain.execute(stepContext, async () => { reached = true; });
|
|
378
|
-
if (reached && stepContext.status !== 'blocked') return true;
|
|
379
|
-
runtime.status = 'blocked';
|
|
380
|
-
runtime.message = stepContext.message ?? `Permission denied: ${code}`;
|
|
381
|
-
return false;
|
|
382
|
-
},
|
|
383
|
-
roles: (roles) => {
|
|
384
|
-
if (this.roleGate?.(roles) === true) return true;
|
|
385
|
-
runtime.status = 'blocked';
|
|
386
|
-
runtime.message = `role denied: ${roles.join(',')}`;
|
|
387
|
-
return false;
|
|
388
|
-
},
|
|
389
|
-
...((this.namedActions || this.builtinActions)
|
|
390
|
-
? { actions: { ...(this.namedActions ?? {}), ...(this.builtinActions ?? {}) } }
|
|
391
|
-
: {}),
|
|
392
|
-
onError: (message, detail) => {
|
|
393
|
-
runtime.status = 'error';
|
|
394
|
-
runtime.message = `第 ${detail.step + 1} 步:${message}`;
|
|
395
|
-
},
|
|
396
|
-
});
|
|
397
|
-
if (!isCurrent()) return;
|
|
398
|
-
if (outcome.cancelled) {
|
|
399
|
-
runtime.status = 'blocked';
|
|
400
|
-
runtime.message = 'pre-check rejected';
|
|
401
|
-
}
|
|
402
|
-
if (outcome.stopped) this.callbacks.onDiscardPending?.();
|
|
403
|
-
else await this.callbacks.onCommit();
|
|
404
|
-
isCurrent();
|
|
405
|
-
} finally {
|
|
406
|
-
if (!isValid()) this.callbacks.onDiscardPending?.();
|
|
407
|
-
this.callbacks.onEndTransaction?.();
|
|
408
|
-
}
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
362
|
let result: EventHandlerResult = true;
|
|
413
363
|
const runsHandler = Boolean(config.funcPath && config.type !== 'NAV_STATIC');
|
|
414
364
|
let inTransaction = false;
|
|
@@ -500,46 +450,6 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
500
450
|
recordMetric(`event.${config.type}`, this.adapter.now() - startedAt);
|
|
501
451
|
}
|
|
502
452
|
|
|
503
|
-
/**
|
|
504
|
-
* 编排里的一步:执行一条已解析的管道,返回 handler 的返回值(进输出槽)。
|
|
505
|
-
*
|
|
506
|
-
* 复用与单管道同一条执行路径的**语义**,但不复用 `executeNow`——那里有确认框、
|
|
507
|
-
* 键盘修饰符、诊断打点、事务开合,都是"一次交互"级别的事情。一步不是一次交互。
|
|
508
|
-
*/
|
|
509
|
-
private async dispatchPipeline(
|
|
510
|
-
pipeline: { type: string; funcPath?: string | null; targetUrl?: string; targetId?: string; action?: InteractAction; scope?: SomaScopeEventSpec; notify?: NotifyDeclaration; navReplace?: boolean },
|
|
511
|
-
element: HTMLElement,
|
|
512
|
-
isValid: () => boolean,
|
|
513
|
-
stepScope?: Record<string, unknown>,
|
|
514
|
-
writer?: string,
|
|
515
|
-
): Promise<unknown> {
|
|
516
|
-
if (!isValid()) return undefined;
|
|
517
|
-
if (pipeline.type === 'SCOPE') {
|
|
518
|
-
await this.runScopeEvent(pipeline.scope, writer ?? '', stepScope ?? {});
|
|
519
|
-
return undefined;
|
|
520
|
-
}
|
|
521
|
-
if (pipeline.type === 'NOTIFY') {
|
|
522
|
-
await this.runNotify(pipeline.notify);
|
|
523
|
-
return undefined;
|
|
524
|
-
}
|
|
525
|
-
let value: unknown;
|
|
526
|
-
if (pipeline.funcPath && pipeline.type !== 'NAV_STATIC') {
|
|
527
|
-
const currentVar = this.getContext(element);
|
|
528
|
-
if (currentVar instanceof SomaRowScope && !currentVar.active) return undefined;
|
|
529
|
-
const fn = this.resolveFunction(pipeline.funcPath, currentVar);
|
|
530
|
-
if (!isValid()) return undefined;
|
|
531
|
-
value = await fn(currentVar instanceof SomaRowScope ? currentVar.data : currentVar, stepScope);
|
|
532
|
-
if (!isValid()) return undefined;
|
|
533
|
-
if (currentVar instanceof SomaRowScope && !currentVar.active) return undefined;
|
|
534
|
-
// 一步之内就 commit:后面的步骤(和它们的 when)要看得见这一步的效果
|
|
535
|
-
await this.callbacks.onCommit();
|
|
536
|
-
}
|
|
537
|
-
if (!isValid()) return undefined;
|
|
538
|
-
await this.postAction(pipeline as unknown as SomaCompiledEvent, element);
|
|
539
|
-
if (!isValid()) return undefined;
|
|
540
|
-
return value;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
453
|
/** 具名动作注册表(AO-3):由 bootstrap 注入 */
|
|
544
454
|
private namedActions: Record<string, (payload: Record<string, unknown>) => Promise<unknown> | unknown> | null = null;
|
|
545
455
|
|
|
@@ -695,13 +605,24 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
695
605
|
return this.adapter.confirm(spec.text);
|
|
696
606
|
}
|
|
697
607
|
|
|
698
|
-
private preCheck(
|
|
608
|
+
private preCheck(
|
|
609
|
+
config: SomaCompiledEvent,
|
|
610
|
+
somaId: string,
|
|
611
|
+
element: HTMLElement,
|
|
612
|
+
confirmContext: SomaConfirmContext,
|
|
613
|
+
): boolean | Promise<boolean> {
|
|
699
614
|
if (this.getContext(element) instanceof SomaRowScope ? this.pendingRows.has(element) : this.pendingSet.has(somaId)) {
|
|
700
615
|
return false;
|
|
701
616
|
}
|
|
702
617
|
|
|
703
618
|
if (config.confirm) {
|
|
704
|
-
|
|
619
|
+
// 确认文案占位(`{字段}` / `{n}`)在触发时代入:只替换 text / impact,permission / roles 顺序与确认级别不受影响
|
|
620
|
+
const spec = resolveConfirmSpec(
|
|
621
|
+
config.confirmSpec ?? { level: 'plain', text: config.confirm },
|
|
622
|
+
confirmContext,
|
|
623
|
+
(name) => warnConfirmMissing(name, `${somaId}.${config.domEvent}`),
|
|
624
|
+
);
|
|
625
|
+
return this.askConfirm(spec);
|
|
705
626
|
}
|
|
706
627
|
|
|
707
628
|
return true;
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
// core/client/engine/reactive-proxy.ts
|
|
2
2
|
|
|
3
|
+
import { SomaError } from '../../shared/soma-error';
|
|
4
|
+
import { VIEW_ARRAY_MUTATING_METHODS } from 'soma-foundation/view-state';
|
|
3
5
|
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/** 数组变异方法名单只在 soma-design/spec/pipeline/view-state-rules.json(经 soma-foundation/view-state 投影),本处不再手写 */
|
|
8
|
+
const ARRAY_MUTATING_METHODS: ReadonlySet<string> = new Set(VIEW_ARRAY_MUTATING_METHODS);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 生产构建判定:打包器替换 process.env.NODE_ENV 或 Node 环境变量为 production 时关闭 dev 拦截(行为回到静默不刷新)。
|
|
12
|
+
* 拿不到 process(纯浏览器无替换)视为 dev。
|
|
13
|
+
*/
|
|
14
|
+
function isProductionBuild(): boolean {
|
|
15
|
+
try {
|
|
16
|
+
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'production';
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** dev 层错误:写法不会触发刷新,必须改(与 soma-foundation 检查层同一份判据) */
|
|
23
|
+
export class SomaReactiveWriteError extends SomaError {
|
|
24
|
+
readonly code = 'CORE-REACTIVE-WRITE';
|
|
25
|
+
constructor(message: string) {
|
|
26
|
+
super(`[soma-core][引擎][CORE-REACTIVE-WRITE] ${message}`);
|
|
27
|
+
this.name = 'SomaReactiveWriteError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
8
30
|
|
|
9
31
|
/**
|
|
10
32
|
* SOMA 响应式代理
|
|
@@ -13,14 +35,14 @@ const ARRAY_MUTATING_METHODS = new Set([
|
|
|
13
35
|
* - 使用 WeakMap 缓存,同一对象只创建一个 Proxy
|
|
14
36
|
* - 跳过内置类型(Set/Map/Date 等);数组通过引用替换触发更新
|
|
15
37
|
* - 函数绑定到 Proxy receiver,确保 this 正确
|
|
16
|
-
* - devMode
|
|
38
|
+
* - devMode 开启时(默认:非生产构建),数组原地变异 / 下标写入 / 元素字段写入 / 同一对象挂多路径一律抛 SomaReactiveWriteError(生产不抛,行为不变)
|
|
17
39
|
*/
|
|
18
40
|
export class SomaReactiveProxy {
|
|
19
41
|
/** 原始对象 → Proxy 实例的缓存(仅用于顶层 wrap 调用) */
|
|
20
42
|
private cache = new WeakMap<object, any>();
|
|
21
43
|
|
|
22
44
|
/** 子对象 Proxy 缓存:避免每次 get 嵌套对象都 new Proxy() */
|
|
23
|
-
private childProxyCache = new WeakMap<object, any>();
|
|
45
|
+
private childProxyCache = new WeakMap<object, { proxy: any; path: string }>();
|
|
24
46
|
|
|
25
47
|
/** 变更回调(可延迟设置) */
|
|
26
48
|
private onChange: ((path: string, value: any, oldValue: any) => void) | null = null;
|
|
@@ -30,7 +52,7 @@ export class SomaReactiveProxy {
|
|
|
30
52
|
constructor(
|
|
31
53
|
onChange?: (path: string, value: any, oldValue: any) => void,
|
|
32
54
|
diagnostics?: SomaDiagnostics,
|
|
33
|
-
devMode: boolean =
|
|
55
|
+
devMode: boolean = !isProductionBuild(),
|
|
34
56
|
) {
|
|
35
57
|
this.onChange = onChange ?? null;
|
|
36
58
|
this.diagnostics = diagnostics ?? null;
|
|
@@ -144,12 +166,21 @@ export class SomaReactiveProxy {
|
|
|
144
166
|
|
|
145
167
|
// 嵌套对象返回 Proxy 包装版本(缓存子 Proxy 减少 GC 压力)
|
|
146
168
|
if (!self.shouldSkip(value)) {
|
|
169
|
+
const childPath = basePath ? `${basePath}.${String(prop)}` : String(prop);
|
|
147
170
|
const cachedChild = self.childProxyCache.get(value);
|
|
148
|
-
if (cachedChild)
|
|
171
|
+
if (cachedChild) {
|
|
172
|
+
// 子 Proxy 按对象缓存、路径以首次访问为准:同一对象经另一路径访问,写入会上报成第一个路径,刷新错位
|
|
173
|
+
if (self.devMode && cachedChild.path !== childPath) {
|
|
174
|
+
throw new SomaReactiveWriteError(
|
|
175
|
+
`同一对象同时挂在 "${cachedChild.path}" 与 "${childPath}" 两个路径下,经后者写入会上报成前者,刷新错位。` +
|
|
176
|
+
`每个路径放各自的对象:${childPath} = { ...${cachedChild.path} }(浅拷贝)或重新构造。`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return cachedChild.proxy;
|
|
180
|
+
}
|
|
149
181
|
|
|
150
|
-
const childPath = basePath ? `${basePath}.${String(prop)}` : String(prop);
|
|
151
182
|
const childProxy = new Proxy(value, self.createHandler(childPath));
|
|
152
|
-
self.childProxyCache.set(value, childProxy);
|
|
183
|
+
self.childProxyCache.set(value, { proxy: childProxy, path: childPath });
|
|
153
184
|
return childProxy;
|
|
154
185
|
}
|
|
155
186
|
|
|
@@ -189,25 +220,55 @@ export class SomaReactiveProxy {
|
|
|
189
220
|
}
|
|
190
221
|
|
|
191
222
|
/**
|
|
192
|
-
*
|
|
193
|
-
* 纯读方法(map/filter/length
|
|
194
|
-
* 不缓存,每次 get 都创建新 Proxy,保证 arrayPath 路径准确。
|
|
223
|
+
* 为数组创建 dev 守卫 Proxy:变异方法、下标 / length 写入、元素(及其嵌套对象)字段写入都不会触发刷新,一律抛错。
|
|
224
|
+
* 纯读方法(map/filter/length 等)直接透传,不影响性能。不缓存,每次 get 都创建新 Proxy,保证 arrayPath 路径准确。
|
|
195
225
|
*/
|
|
196
226
|
private wrapArrayDevGuard(arr: any[], arrayPath: string): any[] {
|
|
227
|
+
const replaceHint = `${arrayPath} = [...${arrayPath}, 新项](或 .map / .filter 产生新数组后整体赋值)`;
|
|
197
228
|
return new Proxy(arr, {
|
|
198
229
|
get(target, prop) {
|
|
199
230
|
const value = Reflect.get(target, prop);
|
|
200
231
|
if (typeof prop === 'string' && ARRAY_MUTATING_METHODS.has(prop) && typeof value === 'function') {
|
|
201
|
-
return (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`Use reference replacement instead: this.${arrayPath} = [...this.${arrayPath}]`,
|
|
232
|
+
return () => {
|
|
233
|
+
throw new SomaReactiveWriteError(
|
|
234
|
+
`对数组 "${arrayPath}" 原地调用 ${prop}() 不会触发刷新。请整体替换引用:${replaceHint};排序先拷贝:${arrayPath} = [...${arrayPath}].sort(...)`,
|
|
205
235
|
);
|
|
206
|
-
return value.apply(target, args);
|
|
207
236
|
};
|
|
208
237
|
}
|
|
238
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop) && value !== null && typeof value === 'object') {
|
|
239
|
+
return SomaReactiveProxy.elementGuard(value, `${arrayPath}[${prop}]`, replaceHint);
|
|
240
|
+
}
|
|
209
241
|
return value;
|
|
210
242
|
},
|
|
243
|
+
set(_target, prop) {
|
|
244
|
+
throw new SomaReactiveWriteError(
|
|
245
|
+
`对数组 "${arrayPath}" 写 ${String(prop)} 不会触发刷新。请整体替换引用:${replaceHint}`,
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
deleteProperty(_target, prop) {
|
|
249
|
+
throw new SomaReactiveWriteError(`对数组 "${arrayPath}" 删除 ${String(prop)} 不会触发刷新。请整体替换引用:${replaceHint}`);
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** 数组元素(数组不代理,元素也没有被代理)的只读守卫:字段写入抛错,嵌套对象继续守 */
|
|
255
|
+
private static elementGuard(obj: object, at: string, _replaceHint: string): object {
|
|
256
|
+
return new Proxy(obj, {
|
|
257
|
+
get(target, prop) {
|
|
258
|
+
const value = Reflect.get(target, prop);
|
|
259
|
+
if (value !== null && typeof value === 'object' && typeof prop === 'string') {
|
|
260
|
+
return SomaReactiveProxy.elementGuard(value, `${at}.${prop}`, _replaceHint);
|
|
261
|
+
}
|
|
262
|
+
return value;
|
|
263
|
+
},
|
|
264
|
+
set(_target, prop) {
|
|
265
|
+
throw new SomaReactiveWriteError(
|
|
266
|
+
`写 ${at}.${String(prop)} 不会触发刷新(数组元素没有被代理)。请用新元素替换整个数组:旧数组.map(行 => 行 === 目标 ? { ...行, ${String(prop)}: 新值 } : 行),再整体赋值。`,
|
|
267
|
+
);
|
|
268
|
+
},
|
|
269
|
+
deleteProperty(_target, prop) {
|
|
270
|
+
throw new SomaReactiveWriteError(`删除 ${at}.${String(prop)} 不会触发刷新(数组元素没有被代理)。请整体替换数组引用。`);
|
|
271
|
+
},
|
|
211
272
|
});
|
|
212
273
|
}
|
|
213
274
|
|