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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import yaml from 'js-yaml';
|
|
5
5
|
import { parseUiConfig } from '../../client/parser/ui-config-parser';
|
|
6
6
|
import { parseEventConfig } from '../../client/parser/pipeline-parser';
|
|
7
|
-
import { splitEventConfigRaw } from '../../client/parser/
|
|
7
|
+
import { splitEventConfigRaw } from '../../client/parser/timer-parser';
|
|
8
8
|
import { parseStyleConfig } from '../../client/parser/style-config-parser';
|
|
9
9
|
import { parseDataConfig } from '../../client/parser/data-config-parser';
|
|
10
10
|
import { flatUiNonStandardKeys, readFlatDoc } from './flat-page';
|
|
@@ -12,14 +12,12 @@ import { SOMA_STANDARD_PAGE_KEYS } from '../../shared/declaration-keys';
|
|
|
12
12
|
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
13
13
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
14
14
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
15
|
-
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
16
15
|
|
|
17
16
|
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
18
17
|
|
|
19
18
|
/** _event.yaml 预编译产物 */
|
|
20
19
|
export interface CompiledEventConfig {
|
|
21
20
|
events: ParsedEvent[];
|
|
22
|
-
triggers: PropertyTrigger[];
|
|
23
21
|
timers: ParsedTimer[];
|
|
24
22
|
}
|
|
25
23
|
import type { StyleConfig } from '../../shared/types/style-config.types';
|
|
@@ -50,7 +48,7 @@ export function precompileUiModule(yamlStr: string): string {
|
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
|
-
* 预编译 Event YAML → JSON 字符串(含 events +
|
|
51
|
+
* 预编译 Event YAML → JSON 字符串(含 events + timers)
|
|
54
52
|
*/
|
|
55
53
|
export function precompileEventYaml(yamlStr: string): string {
|
|
56
54
|
const raw = readFlatDoc(yamlStr, 'event');
|
|
@@ -82,16 +80,15 @@ export function compileUiConfig(yamlStr: string): UiConfig {
|
|
|
82
80
|
*/
|
|
83
81
|
export function compileEventConfig(yamlStr: string): CompiledEventConfig {
|
|
84
82
|
if (!yamlStr.trim()) {
|
|
85
|
-
return { events: [],
|
|
83
|
+
return { events: [], timers: [] };
|
|
86
84
|
}
|
|
87
85
|
return compileEventConfigFromRaw(yaml.load(yamlStr));
|
|
88
86
|
}
|
|
89
87
|
|
|
90
88
|
export function compileEventConfigFromRaw(raw: unknown): CompiledEventConfig {
|
|
91
|
-
const { eventsRaw,
|
|
89
|
+
const { eventsRaw, timers } = splitEventConfigRaw(raw);
|
|
92
90
|
return {
|
|
93
91
|
events: parseEventConfig(eventsRaw as any),
|
|
94
|
-
triggers,
|
|
95
92
|
timers,
|
|
96
93
|
};
|
|
97
94
|
}
|
|
@@ -15,8 +15,6 @@ export interface RuntimeConfigInput {
|
|
|
15
15
|
uiYaml?: string;
|
|
16
16
|
eventConfig?: unknown;
|
|
17
17
|
eventYaml?: string;
|
|
18
|
-
triggers?: unknown;
|
|
19
|
-
triggerConfig?: unknown;
|
|
20
18
|
timers?: unknown;
|
|
21
19
|
timerConfig?: unknown;
|
|
22
20
|
dataConfig?: unknown;
|
|
@@ -78,19 +76,17 @@ export function normalizeRuntimeConfig(input: RuntimeConfigInput): Data {
|
|
|
78
76
|
const yamlUi = safe.uiYaml === undefined ? undefined : normalizeUi(yaml.load(safe.uiYaml), safe);
|
|
79
77
|
const ui = same(objectUi, yamlUi, 'ui');
|
|
80
78
|
if (ui === undefined) fail('ui');
|
|
81
|
-
const triggers = same(safe.triggers, safe.triggerConfig, 'event.triggers');
|
|
82
79
|
const timers = same(safe.timers, safe.timerConfig, 'event.timers');
|
|
83
80
|
const objectEvent = safe.eventConfig === undefined ? undefined : {
|
|
84
|
-
events: safe.eventConfig,
|
|
81
|
+
events: safe.eventConfig, timers: timers ?? [],
|
|
85
82
|
};
|
|
86
|
-
if (objectEvent && (!Array.isArray(objectEvent.events) || !Array.isArray(objectEvent.
|
|
83
|
+
if (objectEvent && (!Array.isArray(objectEvent.events) || !Array.isArray(objectEvent.timers))) fail('event');
|
|
87
84
|
const yamlEvent = safe.eventYaml === undefined ? undefined : compileEventConfig(safe.eventYaml);
|
|
88
85
|
if (yamlEvent) {
|
|
89
|
-
same(triggers, yamlEvent.triggers, 'event.triggers');
|
|
90
86
|
same(timers, yamlEvent.timers, 'event.timers');
|
|
91
87
|
}
|
|
92
|
-
if (objectEvent === undefined && yamlEvent === undefined &&
|
|
93
|
-
const event = same(objectEvent, yamlEvent, 'event') ?? { events: [],
|
|
88
|
+
if (objectEvent === undefined && yamlEvent === undefined && timers !== undefined) fail('event');
|
|
89
|
+
const event = same(objectEvent, yamlEvent, 'event') ?? { events: [], timers: [] };
|
|
94
90
|
const data = same(safe.dataConfig, safe.dataYaml === undefined ? undefined : compileDataConfig(safe.dataYaml), 'data') ?? { objects: {} };
|
|
95
91
|
return canonicalTreeData({ ui, event, data });
|
|
96
92
|
} catch (error) {
|
|
@@ -52,7 +52,7 @@ function collectUiAnchors(show, result = new Set()) {
|
|
|
52
52
|
function collectEventAnchors(event, result = new Set()) {
|
|
53
53
|
if (!event || typeof event !== 'object' || Array.isArray(event)) return result;
|
|
54
54
|
for (const [key, value] of Object.entries(event)) {
|
|
55
|
-
if (key === 'timers'
|
|
55
|
+
if (key === 'timers') continue;
|
|
56
56
|
if (typeof value === 'string') {
|
|
57
57
|
const anchor = key.split('.')[0];
|
|
58
58
|
if (anchor) result.add(anchor);
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
{ "id": "style-file", "files": ["style/*_style.yaml"], "root": [] }
|
|
7
7
|
],
|
|
8
8
|
"contexts": [
|
|
9
|
-
{ "id": "object", "title": "数据对象", "scopes": [{ "host": "page-file", "path": ["data", "*"] }], "keys": [{ "key": "from", "value": { "kind": "list", "of": "shape" }, "summary": "集合读取", "status": "implemented" }, { "key": "
|
|
9
|
+
{ "id": "object", "title": "数据对象", "scopes": [{ "host": "page-file", "path": ["data", "*"] }], "keys": [{ "key": "from", "value": { "kind": "list", "of": "shape" }, "summary": "集合读取", "status": "implemented" }, { "key": "fields", "value": { "kind": "map", "of": "shape", "context": "field" }, "summary": "字段字典", "status": "implemented" }, { "key": "write", "value": { "kind": "shape", "context": "write" }, "summary": "写通道", "status": "implemented" }, { "key": "name", "value": { "kind": "string" }, "summary": "显示名", "status": "implemented" }, { "key": "poll", "value": { "kind": "shape", "context": "poll" }, "summary": "自动重取", "status": "implemented" }] },
|
|
10
10
|
{ "id": "poll", "title": "对象 poll", "scopes": [{ "host": "page-file", "path": ["data", "*", "poll"] }], "keys": [{ "key": "every", "value": { "kind": "int", "min": 2, "max": 300, "unit": "秒" }, "summary": "轮询间隔(2..300 的整数秒)", "status": "implemented" }, { "key": "while", "value": { "kind": "shape", "context": "poll.while" }, "summary": "继续轮询的条件", "status": "implemented" }] },
|
|
11
11
|
{ "id": "poll.while", "title": "对象 poll.while", "scopes": [{ "host": "page-file", "path": ["data", "*", "poll", "while"] }], "keys": [{ "key": "field", "value": { "kind": "string" }, "summary": "看哪个字段(roles.status 字段或枚举字段)", "status": "implemented" }, { "key": "in", "value": { "kind": "list", "of": "string" }, "summary": "字段取这些候选键时继续轮询", "status": "implemented" }] },
|
|
12
12
|
{ "id": "write", "title": "写通道", "scopes": [{ "host": "page-file", "path": ["data", "*", "write"] }], "keys": [{ "key": "create", "value": { "kind": "shape" }, "summary": "新建端点 { api, method: POST | PUT | PATCH }", "status": "implemented" }, { "key": "update", "value": { "kind": "shape" }, "summary": "更新端点 { api, method: POST | PUT | PATCH }", "status": "implemented" }, { "key": "version", "value": { "kind": "string" }, "summary": "乐观锁字段(必须在字典里,随请求体上行)", "status": "implemented" }, { "key": "map", "value": { "kind": "map" }, "summary": "表单键 → 请求体键的改名(键是可写的字典字段)", "status": "implemented" }, { "key": "only", "value": { "kind": "list", "of": "string" }, "summary": "请求体字段白名单(非空字段名列表)", "status": "implemented" }, { "key": "reload", "value": { "kind": "list", "of": "string", "also": ["self", "all"] }, "summary": "提交成功后重取:self / all / 本页数据对象名列表", "status": "implemented" }, { "key": "delete", "value": { "kind": "shape" }, "summary": "删除端点 { api, method?: DELETE },不带请求体", "status": "implemented" }, { "key": "validate_on", "value": { "kind": "list", "domain": "validate-triggers", "values": ["change", "blur", "submit"], "of": "string" }, "summary": "校验时机:change / blur / submit 的非空无重复列表", "status": "implemented" }, { "key": "failWhen", "value": { "kind": "map" }, "summary": "HTTP 成功但响应体命中此闭集谓词即按失败落账(字段是响应体顶层键,深取用 path);core 不预设后端字段约定", "status": "implemented" }, { "key": "messagePath", "value": { "kind": "string" }, "summary": "命中 failWhen 时业务错误信息在响应体里的点路径", "status": "implemented" }, { "key": "timeoutMs", "value": { "kind": "int", "min": 1000, "max": 600000, "unit": "毫秒" }, "summary": "本写通道各端点(create / update / delete)单次请求的超时毫秒数,1000..600000 的整数;不写 = 沿用 Host http 服务的缺省超时。用于耗时长的后端调用,超时按网络失败落账", "status": "implemented" }] },
|
|
13
|
-
{ "id": "field", "title": "字段", "scopes": [{ "host": "page-file", "path": ["data", "*", "fields", "*"] }], "keys": [{ "key": "name", "value": { "kind": "string" }, "summary": "字段显示名", "status": "implemented" }, { "key": "type", "value": { "kind": "enum", "domain": "field-types", "values": ["text", "int", "float", "money", "bool", "enum", "date", "datetime", "image", "url", "richtext", "percent", "progress", "tags", "file", "tree", "cascade", "embed", "code", "secret", "time_of_day", "timezone", "schedule", "exceptions", "window", "limits", "duration", "filesize", "colour", "path", "measure", "signature"] }, "summary": "类型(二十六种)", "status": "implemented" }, { "key": "rules", "value": { "kind": "list", "of": "shape", "context": "field.rule" }, "summary": "校验", "status": "implemented" }, { "key": "options", "value": { "kind": "list", "of": "shape", "context": "field.option" }, "summary": "枚举候选", "status": "implemented" }, { "key": "
|
|
13
|
+
{ "id": "field", "title": "字段", "scopes": [{ "host": "page-file", "path": ["data", "*", "fields", "*"] }], "keys": [{ "key": "name", "value": { "kind": "string" }, "summary": "字段显示名", "status": "implemented" }, { "key": "type", "value": { "kind": "enum", "domain": "field-types", "values": ["text", "int", "float", "money", "bool", "enum", "date", "datetime", "image", "url", "richtext", "percent", "progress", "tags", "file", "tree", "cascade", "embed", "code", "secret", "time_of_day", "timezone", "schedule", "exceptions", "window", "limits", "duration", "filesize", "colour", "path", "measure", "signature"] }, "summary": "类型(二十六种)", "status": "implemented" }, { "key": "rules", "value": { "kind": "list", "of": "shape", "context": "field.rule" }, "summary": "校验", "status": "implemented" }, { "key": "options", "value": { "kind": "list", "of": "shape", "context": "field.option" }, "summary": "枚举候选", "status": "implemented" }, { "key": "default", "value": { "kind": "any" }, "summary": "新建初值", "status": "implemented" }] },
|
|
14
14
|
{ "id": "field.option", "title": "枚举候选项", "scopes": [{ "host": "page-file", "path": ["data", "*", "fields", "*", "options", "#"] }], "keys": [{ "key": "key", "value": { "kind": "string" }, "summary": "候选键", "status": "implemented" }, { "key": "label", "value": { "kind": "string" }, "summary": "候选显示名", "status": "implemented" }, { "key": "children", "value": { "kind": "list", "of": "shape", "context": "field.option", "maxDepth": 6 }, "summary": "下一级候选(tree / cascade)", "status": "implemented" }] },
|
|
15
|
-
{ "id": "field.rule", "title": "字段校验规则条目", "scopes": [{ "host": "page-file", "path": ["data", "*", "fields", "*", "rules", "#"] }], "keys": [{ "key": "required", "value": { "kind": "bool" }, "summary": "必填", "status": "implemented" }, { "key": "max_len", "value": { "kind": "int" }, "summary": "最大长度", "status": "implemented" }, { "key": "min_len", "value": { "kind": "int" }, "summary": "最小长度", "status": "implemented" }, { "key": "pattern", "value": { "kind": "string" }, "summary": "正则", "status": "implemented" }, { "key": "min", "value": { "kind": "number" }, "summary": "最小值", "status": "implemented" }, { "key": "max", "value": { "kind": "number" }, "summary": "最大值", "status": "implemented" }, { "key": "step", "value": { "kind": "number", "exclusiveMin": 0 }, "summary": "步长(取值格点)", "status": "implemented" }, { "key": "message", "value": { "kind": "string" }, "summary": "校验失败提示", "status": "implemented" }, { "key": "
|
|
15
|
+
{ "id": "field.rule", "title": "字段校验规则条目", "scopes": [{ "host": "page-file", "path": ["data", "*", "fields", "*", "rules", "#"] }], "keys": [{ "key": "required", "value": { "kind": "bool" }, "summary": "必填", "status": "implemented" }, { "key": "max_len", "value": { "kind": "int" }, "summary": "最大长度", "status": "implemented" }, { "key": "min_len", "value": { "kind": "int" }, "summary": "最小长度", "status": "implemented" }, { "key": "pattern", "value": { "kind": "string" }, "summary": "正则", "status": "implemented" }, { "key": "min", "value": { "kind": "number" }, "summary": "最小值", "status": "implemented" }, { "key": "max", "value": { "kind": "number" }, "summary": "最大值", "status": "implemented" }, { "key": "step", "value": { "kind": "number", "exclusiveMin": 0 }, "summary": "步长(取值格点)", "status": "implemented" }, { "key": "message", "value": { "kind": "string" }, "summary": "校验失败提示", "status": "implemented" }, { "key": "async", "value": { "kind": "any" }, "summary": "异步校验 检查器名 | { check, on_error: pass | block }", "status": "implemented" }, { "key": "severity", "value": { "kind": "enum", "domain": "validation-severities", "values": ["hard", "soft-once", "hint", "discourage"] }, "summary": "校验强度(hard / soft-once / hint / discourage)", "status": "implemented" }] },
|
|
16
16
|
{ "id": "page.envelope", "title": "页面信封 envelope", "scopes": [{ "host": "page-file", "path": ["envelope"] }], "keys": [{ "key": "url", "value": { "kind": "string" }, "summary": "页面地址(精确 / 模式 :参数 / 前缀 /*)", "status": "implemented" }, { "key": "params", "value": { "kind": "map", "context": "page.envelope.params" }, "summary": "地址参数规格(名与 url 的 :名 对应)", "status": "implemented" }, { "key": "query", "value": { "kind": "map", "context": "page.envelope.query" }, "summary": "对外接受的查询参数契约", "status": "implemented" }, { "key": "title", "value": { "kind": "any" }, "summary": "页面标题(字面量或 { t: 词条键 })", "status": "implemented" }, { "key": "subtitle", "value": { "kind": "any" }, "summary": "页面副标题(同 title)", "status": "implemented" }, { "key": "nav", "value": { "kind": "shape", "context": "page.envelope.nav", "also": ["false"] }, "summary": "导航(false,或 group / order / icon / parent)", "status": "implemented" }, { "key": "access", "value": { "kind": "shape", "context": "page.envelope.access" }, "summary": "访问要求(roles / signed_in)", "status": "implemented" }, { "key": "frame", "value": { "kind": "string" }, "summary": "逻辑外壳名(或 none)", "status": "implemented" }, { "key": "locale", "value": { "kind": "string" }, "summary": "本页字面量所用语言(BCP 47)", "status": "implemented" }, { "key": "meta", "value": { "kind": "shape", "context": "page.envelope.meta" }, "summary": "页面元信息(description / tags)", "status": "implemented" }, { "key": "version", "value": { "kind": "string" }, "summary": "作者修订标签", "status": "implemented" }, { "key": "source", "value": { "kind": "shape", "context": "page.envelope.source" }, "summary": "来源盖章(format / author)", "status": "implemented" }, { "key": "lifecycle", "value": { "kind": "shape", "context": "page.envelope.lifecycle" }, "summary": "生命周期(persist / expires / warm)", "status": "implemented" }] },
|
|
17
17
|
{ "id": "page.envelope.params", "title": "信封 params.<名>", "scopes": [{ "host": "page-file", "path": ["envelope", "params", "*"] }], "keys": [{ "key": "type", "value": { "kind": "enum", "domain": "envelope-param-types", "values": ["int", "string", "slug", "uuid", "enum"] }, "summary": "参数类型(int / string / slug / uuid / enum)", "status": "implemented" }, { "key": "required", "value": { "kind": "bool" }, "summary": "是否必填(模式参数恒必填,仅前缀 rest 可 false)", "status": "implemented" }, { "key": "min", "value": { "kind": "int" }, "summary": "int 下界", "status": "implemented" }, { "key": "max", "value": { "kind": "int" }, "summary": "int 上界", "status": "implemented" }, { "key": "max_len", "value": { "kind": "int", "min": 1, "max": 200 }, "summary": "string / slug 最大长度", "status": "implemented" }, { "key": "values", "value": { "kind": "list", "of": "string" }, "summary": "enum 候选(1–32 个)", "status": "implemented" }] },
|
|
18
18
|
{ "id": "page.envelope.query", "title": "信封 query.<名>", "scopes": [{ "host": "page-file", "path": ["envelope", "query", "*"] }], "keys": [{ "key": "type", "value": { "kind": "enum", "domain": "envelope-query-types", "values": ["string", "int", "bool", "enum", "slug"] }, "summary": "查询类型(string / int / bool / enum / slug)", "status": "implemented" }, { "key": "default", "value": { "kind": "any" }, "summary": "缺省值(与 type 相符的标量)", "status": "implemented" }, { "key": "mode", "value": { "kind": "string" }, "summary": "写回地址栏方式(replace / push)", "status": "implemented" }, { "key": "values", "value": { "kind": "list", "of": "string" }, "summary": "enum 候选(1–32 个)", "status": "implemented" }, { "key": "max_len", "value": { "kind": "int", "min": 1, "max": 200 }, "summary": "string / slug 最大长度", "status": "implemented" }] },
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// 只做「配置 → 已校验值」;越界(闭集外键、错值、非映射)抛 SomaA11yConfigError(码 `CORE-A11Y-CONFIG`,登记归收口线)。
|
|
7
7
|
// 运行期消费:`installMotionHook` 把合并结果写到容器根的 `data-soma-motion`(bootstrap 接线)。
|
|
8
8
|
|
|
9
|
+
import { SomaError } from '../../shared/soma-error';
|
|
9
10
|
import type { MotionOverride } from './motion';
|
|
10
11
|
|
|
11
12
|
/** `a11y:` 的封闭键集 */
|
|
@@ -18,7 +19,7 @@ export interface SomaA11yConfig {
|
|
|
18
19
|
readonly motion: MotionOverride;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export class SomaA11yConfigError extends
|
|
22
|
+
export class SomaA11yConfigError extends SomaError {
|
|
22
23
|
readonly code = 'CORE-A11Y-CONFIG' as const;
|
|
23
24
|
readonly path: string;
|
|
24
25
|
constructor(message: string, path: string) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 全库唯一的 DOM 实例 id(S7;对应 soma-ui `shared/dom-id.ts
|
|
1
|
+
// 全库唯一的 DOM 实例 id(S7;对应 soma-ui `shared/dom-id.ts`)。
|
|
2
2
|
//
|
|
3
3
|
// 同页混用两个 UI 体系或外部组件包时,各自一条序列会产生相同 id,`aria-activedescendant` 解析到文档序靠前的那个——读屏器读错项。
|
|
4
4
|
// 序列因此挂在 `globalThis` 的 `Symbol.for` 键上:即使 core 被打包成多份副本,同页仍只有一条序列。
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
// 不依赖任何 DOM API,可在 Node.js 环境下独立运行
|
|
4
4
|
// 使用全局 fetch(Node.js 18+ 原生支持,或通过 polyfill 提供)
|
|
5
5
|
|
|
6
|
+
import { SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS } from 'soma-foundation/values';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* HTTP 客户端配置
|
|
8
10
|
*/
|
|
9
11
|
export interface SomaHttpClientConfig {
|
|
10
12
|
/** API 基础地址(如 "https://api.example.com") */
|
|
11
13
|
baseURL: string;
|
|
12
|
-
/**
|
|
14
|
+
/** 请求超时时间(毫秒),缺省取 soma-foundation/values 的 Host HTTP 默认值 */
|
|
13
15
|
timeout?: number;
|
|
14
16
|
/** Generic headers supplied by the host runtime, such as page context. */
|
|
15
17
|
defaultHeaders?: Record<string, string> | (() => Record<string, string>);
|
|
@@ -141,7 +143,7 @@ export class SomaHttpClient {
|
|
|
141
143
|
|
|
142
144
|
constructor(config: SomaHttpClientConfig) {
|
|
143
145
|
this.baseURL = config.baseURL;
|
|
144
|
-
this.timeout = config.timeout ??
|
|
146
|
+
this.timeout = config.timeout ?? SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS;
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
/**
|
|
@@ -225,7 +227,13 @@ export class SomaHttpClient {
|
|
|
225
227
|
throw new Error(`HTTP ${res.status}: ${describeHttpErrorBody(errorBody, res.statusText, res.status)}`);
|
|
226
228
|
}
|
|
227
229
|
|
|
228
|
-
|
|
230
|
+
// 204 / 205 / 空响应体:成功但无内容,返回 undefined(不当 JSON 解析失败)
|
|
231
|
+
if (res.status === 204 || res.status === 205) return undefined as T;
|
|
232
|
+
// 兼容只实现 json() 的响应对象(测试桩 / 精简 polyfill)
|
|
233
|
+
if (typeof res.text !== 'function') return (await res.json()) as T;
|
|
234
|
+
const rawText = await res.text();
|
|
235
|
+
if (rawText.trim() === '') return undefined as T;
|
|
236
|
+
return JSON.parse(rawText) as T;
|
|
229
237
|
} finally {
|
|
230
238
|
clearTimeout(timeoutId);
|
|
231
239
|
this.abortControllers.delete(controller);
|
|
@@ -64,6 +64,12 @@ export abstract class SomaPageRootBase implements SomaPageRoot {
|
|
|
64
64
|
*/
|
|
65
65
|
data!: Record<string, unknown>;
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* 展示对象的宿主面(`defineSomaView` 的 ctx 经它调具名动作、读 / 重取数据、旁路订阅组件事件)。
|
|
69
|
+
* 由 bootstrap 在创建页面根时以非枚举属性注入;非展示对象的页面根不使用。
|
|
70
|
+
*/
|
|
71
|
+
declare _viewHost?: import('./view-context').SomaViewHost;
|
|
72
|
+
|
|
67
73
|
/** 由 bootstrap 注入的数据对象重取钩子(无 `data:` 声明时保持未定义) */
|
|
68
74
|
_reloadData?: () => Promise<void>;
|
|
69
75
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// defineSomaView:把「展示对象」声明成 core 的页面根类(Domain 页面类的方言中性定义函数)。
|
|
2
|
+
//
|
|
3
|
+
// 展示对象承载页面的交互逻辑(显隐、禁用、必填、联动、动作可否执行),与页面 1:1;页面只做纯路径绑定。
|
|
4
|
+
// 本函数生成的类继承 SomaPageRootBase,走 core 现有的 `domain:` / `bind.obj` 与反应式代理,
|
|
5
|
+
// 方言(kit)的 defineKitView 是它的薄封装,只加各自的命名规则与诊断码。
|
|
6
|
+
// 类经 SomaBootstrapOptions.pageRoots(类名 → 类)交给引擎,bootstrap 按页面 `bind.obj` 取类。
|
|
7
|
+
|
|
8
|
+
import { SomaError } from '../../shared/soma-error';
|
|
9
|
+
import { findSharedStateReferences, inferStateShape, type ViewStateShape } from 'soma-foundation/view-state';
|
|
10
|
+
import { SomaPageRootBase } from './SomaPageRootBase';
|
|
11
|
+
import { createViewContext, type SomaViewContext, type SomaViewContextHandle } from './view-context';
|
|
12
|
+
|
|
13
|
+
/** 深只读:数组与其元素一路只读(元素没有被代理,改了也不刷新),函数原样 */
|
|
14
|
+
export type DeepReadonly<T> = T extends (...args: never[]) => unknown
|
|
15
|
+
? T
|
|
16
|
+
: T extends readonly (infer U)[]
|
|
17
|
+
? ReadonlyArray<DeepReadonly<U>>
|
|
18
|
+
: T extends object
|
|
19
|
+
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
|
20
|
+
: T;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* data 对象(展示对象 state)的形状推导出的成员类型:数组成员一律 `ReadonlyArray<DeepReadonly<元素>>`
|
|
24
|
+
* (`push` / 下标赋值 / `rows[3].status = …` 在 tsc 下直接报错),对象成员保持可写(字段写入触发刷新),标量原样。
|
|
25
|
+
* 整体赋值 `view.rows = [...view.rows, x]` / `view.rows = view.rows.map(...)` 仍允许。
|
|
26
|
+
* 原生 Domain 类(SomaPageRootBase 子类)把数组字段标成 `SomaState<{...}>['rows']` 或直接 `ReadonlyArray<...>` 获得同样的拦截。
|
|
27
|
+
* 初值 `[]` 会被推成 `never[]`,请写 `[] as Row[]`。
|
|
28
|
+
*/
|
|
29
|
+
export type SomaState<S> = {
|
|
30
|
+
[K in keyof S]: S[K] extends (...args: never[]) => unknown
|
|
31
|
+
? S[K]
|
|
32
|
+
: S[K] extends readonly (infer U)[]
|
|
33
|
+
? ReadonlyArray<DeepReadonly<U>>
|
|
34
|
+
: S[K] extends object
|
|
35
|
+
? SomaState<S[K]>
|
|
36
|
+
: S[K];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export interface SomaViewDefinition<
|
|
40
|
+
S extends Record<string, unknown>,
|
|
41
|
+
M extends Record<string, (view: any, payload: any, ctx: SomaViewContext) => unknown> = Record<string, (view: SomaPageRootBase & SomaState<S>, payload: any, ctx: SomaViewContext) => unknown>,
|
|
42
|
+
> {
|
|
43
|
+
/** 类名:页面 `domain:` / `bind.obj` 写的就是它,也是 pageRoots 表的键 */
|
|
44
|
+
readonly name: string;
|
|
45
|
+
/** 可绑定的成员与初值(页面路径只能指向这里声明过的成员);初值须是 JSON 值,每个实例各拷一份 */
|
|
46
|
+
readonly state: S;
|
|
47
|
+
/** 方法:`(view, payload, ctx) => void | false`;`view` 是响应式页面根,改成员即触发被动刷新;`ctx` 是能力上下文(调业务对象、改下层对象、在下层注册事件、托管计时) */
|
|
48
|
+
readonly methods?: M;
|
|
49
|
+
/** 页面挂载后调用一次:在这里用 ctx 注册事件订阅、定时器;订阅与计时随卸载自动撤销 */
|
|
50
|
+
readonly onMount?: (view: SomaPageRootBase & SomaState<S>, ctx: SomaViewContext) => void | Promise<void>;
|
|
51
|
+
/** 页面卸载时调用(先于 ctx 自动撤销订阅与计时) */
|
|
52
|
+
readonly onUnmount?: (view: SomaPageRootBase & SomaState<S>, ctx: SomaViewContext) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface SomaViewMeta {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly stateKeys: readonly string[];
|
|
58
|
+
/** state 初值扫出的形状表(路径 → scalar / object / array):页面绑定性质核对与检查层写入核对读它 */
|
|
59
|
+
readonly shape: ViewStateShape;
|
|
60
|
+
readonly methodNames: readonly string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class SomaViewDefineError extends SomaError {
|
|
64
|
+
readonly code = 'CORE-VIEW-DEFINE';
|
|
65
|
+
constructor(message: string) {
|
|
66
|
+
super(`[CORE-VIEW-DEFINE] ${message}`);
|
|
67
|
+
this.name = 'SomaViewDefineError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const META = Symbol.for('soma.view.meta');
|
|
72
|
+
|
|
73
|
+
class ReservedProbe extends SomaPageRootBase {}
|
|
74
|
+
|
|
75
|
+
/** 页面根上已有的成员名(含原型链):展示对象的成员 / 方法不得与之重名 */
|
|
76
|
+
function reservedMemberNames(): ReadonlySet<string> {
|
|
77
|
+
const probe = new ReservedProbe();
|
|
78
|
+
const names = new Set<string>(Object.getOwnPropertyNames(probe));
|
|
79
|
+
for (let proto = Object.getPrototypeOf(probe) as object | null; proto !== null && proto !== Object.prototype; proto = Object.getPrototypeOf(proto) as object | null) {
|
|
80
|
+
for (const n of Object.getOwnPropertyNames(proto)) names.add(n);
|
|
81
|
+
}
|
|
82
|
+
// 引擎在挂载时注入的成员(构造期还不存在)
|
|
83
|
+
for (const n of ['params', 'query', 'region_mirror', 'shell_open', '_viewHost', '_viewContext']) names.add(n);
|
|
84
|
+
return names;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 取页面根(原始实例或响应式代理)上的 ctx */
|
|
88
|
+
function ctxOf(view: unknown): SomaViewContext {
|
|
89
|
+
return (view as { _viewContext(): SomaViewContextHandle })._viewContext().ctx;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const MEMBER = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
93
|
+
|
|
94
|
+
function cloneJson<T>(value: T, where: string): T {
|
|
95
|
+
let text: string | undefined;
|
|
96
|
+
try { text = JSON.stringify(value); } catch { text = undefined; }
|
|
97
|
+
if (text === undefined) throw new SomaViewDefineError(`${where} 的初值不是 JSON 值(对象 / 数组 / 字符串 / 数字 / 布尔 / null)`);
|
|
98
|
+
return JSON.parse(text) as T;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 读一个展示对象类的元信息;不是 defineSomaView 生成的类返回 undefined */
|
|
102
|
+
export function readSomaViewMeta(cls: unknown): SomaViewMeta | undefined {
|
|
103
|
+
if (typeof cls !== 'function') return undefined;
|
|
104
|
+
const meta = (cls as unknown as Record<symbol, unknown>)[META];
|
|
105
|
+
return meta === undefined ? undefined : (meta as SomaViewMeta);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function defineSomaView<
|
|
109
|
+
S extends Record<string, unknown>,
|
|
110
|
+
M extends Record<string, (view: SomaPageRootBase & SomaState<S>, payload: any, ctx: SomaViewContext) => unknown> = Record<string, (view: SomaPageRootBase & SomaState<S>, payload: any, ctx: SomaViewContext) => unknown>,
|
|
111
|
+
>(definition: SomaViewDefinition<S, M>): (new () => SomaPageRootBase & SomaState<S>) & { readonly viewName: string } {
|
|
112
|
+
const { name, state } = definition;
|
|
113
|
+
const methods = (definition.methods ?? {}) as Record<string, (view: unknown, payload: unknown, ctx: SomaViewContext) => unknown>;
|
|
114
|
+
if (typeof name !== 'string' || !/^[A-Z][A-Za-z0-9]*$/.test(name)) {
|
|
115
|
+
throw new SomaViewDefineError(`展示对象类名 ${JSON.stringify(name)} 不合法(大写字母开头的标识符)`);
|
|
116
|
+
}
|
|
117
|
+
if (state === null || typeof state !== 'object' || Array.isArray(state)) {
|
|
118
|
+
throw new SomaViewDefineError(`${name}:state 必须是 { 成员: 初值 } 对象`);
|
|
119
|
+
}
|
|
120
|
+
const reserved = reservedMemberNames();
|
|
121
|
+
const check = (member: string, kind: string): void => {
|
|
122
|
+
if (!MEMBER.test(member)) throw new SomaViewDefineError(`${name}:${kind} ${JSON.stringify(member)} 不是合法标识符`);
|
|
123
|
+
if (reserved.has(member)) throw new SomaViewDefineError(`${name}:${kind} ${member} 与页面根成员重名`);
|
|
124
|
+
};
|
|
125
|
+
const stateKeys = Object.keys(state);
|
|
126
|
+
for (const key of stateKeys) { check(key, '成员'); cloneJson(state[key], `${name}.${key}`); }
|
|
127
|
+
// 同一对象挂多路径:初值里两处引用同一个对象 / 数组实例(子 Proxy 按对象缓存、路径以首次访问为准,会让刷新错位)
|
|
128
|
+
const shared = findSharedStateReferences(state);
|
|
129
|
+
if (shared.length > 0) {
|
|
130
|
+
const first = shared[0]!;
|
|
131
|
+
throw new SomaViewDefineError(`${name}:state 初值里 ${first.first} 与 ${first.second} 引用同一个对象(同一对象不能挂在两个路径下,刷新会错位),请各写各的字面量或浅拷贝`);
|
|
132
|
+
}
|
|
133
|
+
const methodNames = Object.keys(methods);
|
|
134
|
+
for (const key of methodNames) {
|
|
135
|
+
check(key, '方法');
|
|
136
|
+
if (stateKeys.includes(key)) throw new SomaViewDefineError(`${name}:${key} 同时是成员和方法`);
|
|
137
|
+
if (typeof methods[key] !== 'function') throw new SomaViewDefineError(`${name}:方法 ${key} 不是函数`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { onMount, onUnmount } = definition;
|
|
141
|
+
const cls = class extends SomaPageRootBase {
|
|
142
|
+
constructor() {
|
|
143
|
+
super();
|
|
144
|
+
for (const key of stateKeys) (this as Record<string, unknown>)[key] = cloneJson(state[key], `${name}.${key}`);
|
|
145
|
+
// ctx 住在构造期的原始实例闭包里(经响应式代理读到的是函数,调用返回原对象,不会被代理包裹);宿主面由引擎之后注入
|
|
146
|
+
const raw = this as unknown as { _viewHost?: import('./view-context').SomaViewHost };
|
|
147
|
+
const handle = createViewContext(() => raw._viewHost);
|
|
148
|
+
Object.defineProperty(this, '_viewContext', { value: (): SomaViewContextHandle => handle, enumerable: false, configurable: true, writable: true });
|
|
149
|
+
}
|
|
150
|
+
override async onMount(): Promise<void> {
|
|
151
|
+
await super.onMount();
|
|
152
|
+
if (onMount !== undefined) await onMount(this as unknown as SomaPageRootBase & SomaState<S>, ctxOf(this));
|
|
153
|
+
}
|
|
154
|
+
override onUnmount(): void {
|
|
155
|
+
try {
|
|
156
|
+
if (onUnmount !== undefined) onUnmount(this as unknown as SomaPageRootBase & SomaState<S>, ctxOf(this));
|
|
157
|
+
} finally {
|
|
158
|
+
(this as unknown as { _viewContext(): SomaViewContextHandle })._viewContext().dispose();
|
|
159
|
+
super.onUnmount();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
Object.defineProperty(cls, 'name', { value: name });
|
|
164
|
+
for (const key of methodNames) {
|
|
165
|
+
const fn = methods[key]!;
|
|
166
|
+
// core 的 `UI_REFRESH | page.方法` 以 (当前页面根, 载荷) 调用;this 与第一实参都是响应式页面根
|
|
167
|
+
Object.defineProperty(cls.prototype, key, {
|
|
168
|
+
value: function (this: unknown, view: unknown, payload: unknown): unknown { const v = view ?? this; return fn(v, payload, ctxOf(v)); },
|
|
169
|
+
writable: true,
|
|
170
|
+
configurable: true,
|
|
171
|
+
enumerable: false,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const meta: SomaViewMeta = { name, stateKeys, shape: inferStateShape(state), methodNames };
|
|
175
|
+
Object.defineProperty(cls, META, { value: meta });
|
|
176
|
+
Object.defineProperty(cls, 'viewName', { value: name });
|
|
177
|
+
return cls as unknown as (new () => SomaPageRootBase & SomaState<S>) & { readonly viewName: string };
|
|
178
|
+
}
|
|
@@ -7,5 +7,18 @@ export { SomaEntity } from './SomaEntity';
|
|
|
7
7
|
export { SomaHttpClient, describeHttpErrorBody, type SomaHttpClientConfig } from './SomaHttpClient';
|
|
8
8
|
export { SomaPageRootBase } from './SomaPageRootBase';
|
|
9
9
|
export { SomaValidator } from './SomaValidator';
|
|
10
|
+
export { defineSomaView, readSomaViewMeta, SomaViewDefineError, type SomaViewDefinition, type SomaViewMeta, type SomaState, type DeepReadonly } from './defineSomaView';
|
|
10
11
|
export { runAsync, type AsyncStateHost } from './runAsync';
|
|
11
12
|
export * from './decorators/index';
|
|
13
|
+
export {
|
|
14
|
+
createViewContext,
|
|
15
|
+
SomaViewContextError,
|
|
16
|
+
type SomaViewContext,
|
|
17
|
+
type SomaViewContextHandle,
|
|
18
|
+
type SomaViewHost,
|
|
19
|
+
type SomaViewHttp,
|
|
20
|
+
type SomaViewComponentHandle,
|
|
21
|
+
type SomaViewDataHandle,
|
|
22
|
+
type SomaViewLatest,
|
|
23
|
+
type SomaViewDebounced,
|
|
24
|
+
} from './view-context';
|