brix-runtime-sdk-api-web 1.0.0
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/dist/index.js +190 -0
- package/dist/types/api-exports.test.d.ts +33 -0
- package/dist/types/api-exports.test.d.ts.map +1 -0
- package/dist/types/context/RuntimeContext.d.ts +69 -0
- package/dist/types/context/RuntimeContext.d.ts.map +1 -0
- package/dist/types/context/index.d.ts +23 -0
- package/dist/types/context/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +52 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/auth.d.ts +405 -0
- package/dist/types/types/auth.d.ts.map +1 -0
- package/dist/types/types/capability.d.ts +218 -0
- package/dist/types/types/capability.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +99 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/config.d.ts +85 -0
- package/dist/types/types/config.d.ts.map +1 -0
- package/dist/types/types/event.d.ts +658 -0
- package/dist/types/types/event.d.ts.map +1 -0
- package/dist/types/types/http.d.ts +132 -0
- package/dist/types/types/http.d.ts.map +1 -0
- package/dist/types/types/i18n.d.ts +327 -0
- package/dist/types/types/i18n.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +61 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/layout.d.ts +301 -0
- package/dist/types/types/layout.d.ts.map +1 -0
- package/dist/types/types/module.d.ts +78 -0
- package/dist/types/types/module.d.ts.map +1 -0
- package/dist/types/types/navigation.d.ts +295 -0
- package/dist/types/types/navigation.d.ts.map +1 -0
- package/dist/types/types/plugin-loader-capability.d.ts +142 -0
- package/dist/types/types/plugin-loader-capability.d.ts.map +1 -0
- package/dist/types/types/plugin.d.ts +250 -0
- package/dist/types/types/plugin.d.ts.map +1 -0
- package/dist/types/types/state.d.ts +306 -0
- package/dist/types/types/state.d.ts.map +1 -0
- package/dist/types/types/theme.d.ts +279 -0
- package/dist/types/types/theme.d.ts.map +1 -0
- package/dist/types/types/ui/adapter.d.ts +181 -0
- package/dist/types/types/ui/adapter.d.ts.map +1 -0
- package/dist/types/types/ui/avatar.d.ts +102 -0
- package/dist/types/types/ui/avatar.d.ts.map +1 -0
- package/dist/types/types/ui/badge.d.ts +101 -0
- package/dist/types/types/ui/badge.d.ts.map +1 -0
- package/dist/types/types/ui/button.d.ts +135 -0
- package/dist/types/types/ui/button.d.ts.map +1 -0
- package/dist/types/types/ui/card.d.ts +105 -0
- package/dist/types/types/ui/card.d.ts.map +1 -0
- package/dist/types/types/ui/common.d.ts +29 -0
- package/dist/types/types/ui/common.d.ts.map +1 -0
- package/dist/types/types/ui/icon.d.ts +78 -0
- package/dist/types/types/ui/icon.d.ts.map +1 -0
- package/dist/types/types/ui/index.d.ts +59 -0
- package/dist/types/types/ui/index.d.ts.map +1 -0
- package/dist/types/types/ui/input.d.ts +200 -0
- package/dist/types/types/ui/input.d.ts.map +1 -0
- package/dist/types/types/ui/menu.d.ts +211 -0
- package/dist/types/types/ui/menu.d.ts.map +1 -0
- package/dist/types/types/ui/message.d.ts +121 -0
- package/dist/types/types/ui/message.d.ts.map +1 -0
- package/dist/types/types/ui/modal.d.ts +167 -0
- package/dist/types/types/ui/modal.d.ts.map +1 -0
- package/dist/types/types/ui/select.d.ts +213 -0
- package/dist/types/types/ui/select.d.ts.map +1 -0
- package/dist/types/types/ui/theme-tokens.d.ts +226 -0
- package/dist/types/types/ui/theme-tokens.d.ts.map +1 -0
- package/dist/types/types/ui/tooltip.d.ts +98 -0
- package/dist/types/types/ui/tooltip.d.ts.map +1 -0
- package/dist/types/types/ui.d.ts +49 -0
- package/dist/types/types/ui.d.ts.map +1 -0
- package/package.json +34 -0
- package/src/api-exports.test.ts +199 -0
- package/src/context/RuntimeContext.d.ts +69 -0
- package/src/context/RuntimeContext.d.ts.map +1 -0
- package/src/context/RuntimeContext.ts +75 -0
- package/src/context/index.d.ts +23 -0
- package/src/context/index.d.ts.map +1 -0
- package/src/context/index.ts +23 -0
- package/src/index.d.ts +52 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +59 -0
- package/src/types/auth.d.ts +146 -0
- package/src/types/auth.d.ts.map +1 -0
- package/src/types/auth.ts +479 -0
- package/src/types/capability.d.ts +218 -0
- package/src/types/capability.d.ts.map +1 -0
- package/src/types/capability.ts +302 -0
- package/src/types/common.d.ts +99 -0
- package/src/types/common.d.ts.map +1 -0
- package/src/types/common.ts +115 -0
- package/src/types/config.d.ts +64 -0
- package/src/types/config.d.ts.map +1 -0
- package/src/types/config.ts +96 -0
- package/src/types/event.d.ts +206 -0
- package/src/types/event.d.ts.map +1 -0
- package/src/types/event.ts +776 -0
- package/src/types/http.d.ts +132 -0
- package/src/types/http.d.ts.map +1 -0
- package/src/types/http.ts +156 -0
- package/src/types/i18n.ts +420 -0
- package/src/types/index.d.ts +50 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.ts +120 -0
- package/src/types/layout.ts +394 -0
- package/src/types/module.d.ts +78 -0
- package/src/types/module.d.ts.map +1 -0
- package/src/types/module.ts +92 -0
- package/src/types/navigation.d.ts +101 -0
- package/src/types/navigation.d.ts.map +1 -0
- package/src/types/navigation.ts +361 -0
- package/src/types/plugin-loader-capability.ts +159 -0
- package/src/types/plugin.d.ts +250 -0
- package/src/types/plugin.d.ts.map +1 -0
- package/src/types/plugin.ts +344 -0
- package/src/types/state.d.ts +119 -0
- package/src/types/state.d.ts.map +1 -0
- package/src/types/state.ts +366 -0
- package/src/types/theme.ts +378 -0
- package/src/types/ui/adapter.ts +222 -0
- package/src/types/ui/avatar.ts +113 -0
- package/src/types/ui/badge.ts +112 -0
- package/src/types/ui/button.ts +148 -0
- package/src/types/ui/card.ts +116 -0
- package/src/types/ui/common.ts +29 -0
- package/src/types/ui/icon.ts +85 -0
- package/src/types/ui/index.ts +78 -0
- package/src/types/ui/input.ts +225 -0
- package/src/types/ui/menu.ts +237 -0
- package/src/types/ui/message.ts +135 -0
- package/src/types/ui/modal.ts +188 -0
- package/src/types/ui/select.ts +239 -0
- package/src/types/ui/theme-tokens.ts +357 -0
- package/src/types/ui/tooltip.ts +120 -0
- package/src/types/ui.ts +49 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Brix Platform Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file Plugin-Related Type Definitions
|
|
18
|
+
* @description Defines core types for the plugin system, including manifest, instance, lifecycle, etc.
|
|
19
|
+
* @module @brix/runtime-sdk-api-web/types/plugin
|
|
20
|
+
* @version 3.2.1
|
|
21
|
+
*
|
|
22
|
+
* [v3.2.1 Changes]
|
|
23
|
+
* - Removed React dependency, using framework-agnostic ComponentType definition (v3.0.4 architectural constraint fix)
|
|
24
|
+
*
|
|
25
|
+
* [v3.2 Changes]
|
|
26
|
+
* Extracted from index.ts into a standalone type file, and promoted common contracts from infra-adapters.
|
|
27
|
+
*
|
|
28
|
+
* [Design Principles]
|
|
29
|
+
* - Define common plugin contracts, adapters (MF/Iframe/Native) can extend
|
|
30
|
+
* - Use generics to support different manifest and instance types
|
|
31
|
+
* - Framework-agnostic: no dependency on React/Vue/Angular or other UI frameworks
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { CapabilityRegistry } from './capability';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Framework-Agnostic Component Type
|
|
38
|
+
*
|
|
39
|
+
* <p>v3.0.4 architectural constraint fix: contract layer does not depend on any UI framework.
|
|
40
|
+
* Actual component types are defined by specific adapters or React binding layer.</p>
|
|
41
|
+
*
|
|
42
|
+
* <p>Usage:</p>
|
|
43
|
+
* <ul>
|
|
44
|
+
* <li>In React projects, use type definitions from @brix/runtime-sdk-react</li>
|
|
45
|
+
* <li>In Vue projects, use type definitions from @brix/runtime-sdk-vue</li>
|
|
46
|
+
* <li>In framework-agnostic scenarios, use unknown and handle at runtime</li>
|
|
47
|
+
* </ul>
|
|
48
|
+
*/
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
export type ComponentType = unknown;
|
|
51
|
+
|
|
52
|
+
// =========================================
|
|
53
|
+
// Plugin Status
|
|
54
|
+
// =========================================
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Plugin Status
|
|
58
|
+
*
|
|
59
|
+
* <p>Describes the current state of a plugin in its lifecycle.</p>
|
|
60
|
+
*/
|
|
61
|
+
export type PluginStatus =
|
|
62
|
+
| 'registered' // Registered
|
|
63
|
+
| 'loading' // Loading
|
|
64
|
+
| 'loaded' // Loaded
|
|
65
|
+
| 'activating' // Activating
|
|
66
|
+
| 'active' // Active
|
|
67
|
+
| 'deactivating' // Deactivating
|
|
68
|
+
| 'inactive' // Inactive
|
|
69
|
+
| 'error'; // Error state
|
|
70
|
+
|
|
71
|
+
// =========================================
|
|
72
|
+
// Plugin Manifest (Common Base Contract)
|
|
73
|
+
// =========================================
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Plugin Manifest Base Interface
|
|
77
|
+
*
|
|
78
|
+
* <p>All adapter manifests (MF, Iframe, Native) must extend this interface.</p>
|
|
79
|
+
*/
|
|
80
|
+
export interface PluginManifest {
|
|
81
|
+
/** Plugin unique identifier */
|
|
82
|
+
readonly id: string;
|
|
83
|
+
/** Plugin name */
|
|
84
|
+
readonly name: string;
|
|
85
|
+
/** Plugin version */
|
|
86
|
+
readonly version: string;
|
|
87
|
+
/** Whether enabled */
|
|
88
|
+
readonly enabled?: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Plugin Metadata
|
|
93
|
+
*
|
|
94
|
+
* <p>Describes detailed information about a plugin, including required capabilities, published/subscribed events, etc.</p>
|
|
95
|
+
*/
|
|
96
|
+
export interface PluginMetadata {
|
|
97
|
+
/** Version */
|
|
98
|
+
readonly version: string;
|
|
99
|
+
/** Name */
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/** Description */
|
|
102
|
+
readonly description?: string;
|
|
103
|
+
/** List of required capabilities */
|
|
104
|
+
readonly requiredCapabilities?: string[];
|
|
105
|
+
/** List of published events */
|
|
106
|
+
readonly publishedEvents?: string[];
|
|
107
|
+
/** List of subscribed events */
|
|
108
|
+
readonly subscribedEvents?: string[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// =========================================
|
|
112
|
+
// Plugin Instance (Common Base Contract)
|
|
113
|
+
// =========================================
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Plugin Instance Base Interface
|
|
117
|
+
*
|
|
118
|
+
* <p>All adapter instances must extend this interface.</p>
|
|
119
|
+
*
|
|
120
|
+
* @template M Manifest type
|
|
121
|
+
*/
|
|
122
|
+
export interface PluginInstance<M extends PluginManifest = PluginManifest> {
|
|
123
|
+
/** Plugin ID */
|
|
124
|
+
readonly id: string;
|
|
125
|
+
/** Corresponding manifest */
|
|
126
|
+
readonly manifest: M;
|
|
127
|
+
/** Current status */
|
|
128
|
+
status: string;
|
|
129
|
+
/** Error information */
|
|
130
|
+
readonly error?: Error;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// =========================================
|
|
134
|
+
// Plugin Loader (Common Contract)
|
|
135
|
+
// =========================================
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Plugin Loader Interface
|
|
139
|
+
*
|
|
140
|
+
* <p>All adapters (MFPluginLoader, IframePluginLoader, NativePluginLoader)
|
|
141
|
+
* must implement this interface.</p>
|
|
142
|
+
*
|
|
143
|
+
* @template M Manifest type
|
|
144
|
+
* @template I Instance type
|
|
145
|
+
*/
|
|
146
|
+
export interface PluginLoader<
|
|
147
|
+
M extends PluginManifest = PluginManifest,
|
|
148
|
+
I extends PluginInstance<M> = PluginInstance<M>
|
|
149
|
+
> {
|
|
150
|
+
/** Load a single plugin */
|
|
151
|
+
load(manifest: M): Promise<I>;
|
|
152
|
+
/** Unload plugin */
|
|
153
|
+
unload(pluginId: string): void;
|
|
154
|
+
/** Preload multiple plugins */
|
|
155
|
+
preload?(manifests: M[]): Promise<void>;
|
|
156
|
+
/** Get loaded plugins list */
|
|
157
|
+
getLoaded(): I[];
|
|
158
|
+
/** Check if plugin is loaded */
|
|
159
|
+
isLoaded(pluginId: string): boolean;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// =========================================
|
|
163
|
+
// Plugin Load Error
|
|
164
|
+
// =========================================
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Plugin Load Error
|
|
168
|
+
*
|
|
169
|
+
* <p>Encapsulates errors that occur during plugin loading, includes error phase information.</p>
|
|
170
|
+
*/
|
|
171
|
+
export class PluginLoadError extends Error {
|
|
172
|
+
constructor(
|
|
173
|
+
message: string,
|
|
174
|
+
public readonly pluginId: string,
|
|
175
|
+
public readonly phase: 'script' | 'init' | 'module' | 'component' | 'iframe' | 'bridge',
|
|
176
|
+
public readonly cause?: Error
|
|
177
|
+
) {
|
|
178
|
+
super(message);
|
|
179
|
+
this.name = 'PluginLoadError';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// =========================================
|
|
184
|
+
// Plugin Dependency Declaration
|
|
185
|
+
// =========================================
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Plugin Dependency Declaration
|
|
189
|
+
*
|
|
190
|
+
* <p>Describes plugin dependencies on other plugins, used for manifest parsing and dependency validation.</p>
|
|
191
|
+
*/
|
|
192
|
+
export interface PluginDependency {
|
|
193
|
+
/** Dependency plugin name */
|
|
194
|
+
readonly name: string;
|
|
195
|
+
/** Dependency version */
|
|
196
|
+
readonly version: string;
|
|
197
|
+
/** Maven GroupId */
|
|
198
|
+
readonly groupId: string;
|
|
199
|
+
/** Maven ArtifactId (auto-generated: {name}-core) */
|
|
200
|
+
readonly artifactId: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// =========================================
|
|
204
|
+
// Plugin Entry Configuration
|
|
205
|
+
// =========================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Plugin Entry Configuration
|
|
209
|
+
*
|
|
210
|
+
* <p>Defines the loading entry point and basic information for a plugin.</p>
|
|
211
|
+
*/
|
|
212
|
+
export interface PluginEntry {
|
|
213
|
+
/** Plugin unique identifier */
|
|
214
|
+
readonly id: string;
|
|
215
|
+
|
|
216
|
+
/** Plugin name */
|
|
217
|
+
readonly name: string;
|
|
218
|
+
|
|
219
|
+
/** Plugin version */
|
|
220
|
+
readonly version: string;
|
|
221
|
+
|
|
222
|
+
/** Plugin loader function */
|
|
223
|
+
readonly loader: () => Promise<PluginLifecycle>;
|
|
224
|
+
|
|
225
|
+
/** List of dependent plugin IDs */
|
|
226
|
+
readonly dependencies?: string[];
|
|
227
|
+
|
|
228
|
+
/** Plugin configuration */
|
|
229
|
+
readonly config?: Record<string, unknown>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// =========================================
|
|
233
|
+
// Plugin Lifecycle
|
|
234
|
+
// =========================================
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Plugin Lifecycle Interface
|
|
238
|
+
*
|
|
239
|
+
* <p>Defines callback methods for plugin activation and deactivation.</p>
|
|
240
|
+
*/
|
|
241
|
+
export interface PluginLifecycle {
|
|
242
|
+
/**
|
|
243
|
+
* Called When Plugin Activates
|
|
244
|
+
*
|
|
245
|
+
* <p>Initialize plugin resources, register capabilities, contribute routes, etc. in this method.</p>
|
|
246
|
+
*
|
|
247
|
+
* @param context Plugin context
|
|
248
|
+
*/
|
|
249
|
+
activate(context: PluginContext): void | Promise<void>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Called When Plugin Deactivates
|
|
253
|
+
*
|
|
254
|
+
* <p>Clean up plugin resources, unsubscribe, etc. in this method.</p>
|
|
255
|
+
*/
|
|
256
|
+
deactivate?(): void | Promise<void>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// =========================================
|
|
260
|
+
// Plugin Context
|
|
261
|
+
// =========================================
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Plugin Context
|
|
265
|
+
*
|
|
266
|
+
* <p>Runtime context provided to plugins, containing capability registry and contribution methods.</p>
|
|
267
|
+
*/
|
|
268
|
+
export interface PluginContext {
|
|
269
|
+
/** Plugin ID */
|
|
270
|
+
readonly pluginId: string;
|
|
271
|
+
|
|
272
|
+
/** Capability registry */
|
|
273
|
+
readonly registry: CapabilityRegistry;
|
|
274
|
+
|
|
275
|
+
/** Contribute routes */
|
|
276
|
+
contributeRoutes?(routes: RouteContribution[]): void;
|
|
277
|
+
|
|
278
|
+
/** Contribute menus */
|
|
279
|
+
contributeMenus?(menus: MenuContribution[]): void;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// =========================================
|
|
283
|
+
// Route Contribution
|
|
284
|
+
// =========================================
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Route Contribution
|
|
288
|
+
*
|
|
289
|
+
* <p>Route configuration contributed by plugins to the Host.</p>
|
|
290
|
+
*/
|
|
291
|
+
export interface RouteContribution {
|
|
292
|
+
/** Route path */
|
|
293
|
+
path: string;
|
|
294
|
+
|
|
295
|
+
/** Route component */
|
|
296
|
+
component: ComponentType;
|
|
297
|
+
|
|
298
|
+
/** Exact match */
|
|
299
|
+
exact?: boolean;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// =========================================
|
|
303
|
+
// Menu Contribution
|
|
304
|
+
// =========================================
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Menu Contribution
|
|
308
|
+
*
|
|
309
|
+
* <p>Menu configuration contributed by plugins to the Host.</p>
|
|
310
|
+
*/
|
|
311
|
+
export interface MenuContribution {
|
|
312
|
+
/** Menu ID */
|
|
313
|
+
id: string;
|
|
314
|
+
|
|
315
|
+
/** Menu label */
|
|
316
|
+
label: string;
|
|
317
|
+
|
|
318
|
+
/** Menu icon */
|
|
319
|
+
icon?: string;
|
|
320
|
+
|
|
321
|
+
/** Menu path */
|
|
322
|
+
path?: string;
|
|
323
|
+
|
|
324
|
+
/** Sub-menus */
|
|
325
|
+
children?: MenuContribution[];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// =========================================
|
|
329
|
+
// Route Page Configuration (Adapter Contract)
|
|
330
|
+
// =========================================
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Route Page Configuration
|
|
334
|
+
*
|
|
335
|
+
* <p>Page registration format used by adapters.</p>
|
|
336
|
+
*/
|
|
337
|
+
export interface PageConfig {
|
|
338
|
+
/** Page ID (format: pluginId:pageName) */
|
|
339
|
+
readonly pageId: string;
|
|
340
|
+
/** URL path */
|
|
341
|
+
readonly path: string;
|
|
342
|
+
/** Page component */
|
|
343
|
+
readonly component: ComponentType;
|
|
344
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Brix Platform Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file State-Related Type Definitions
|
|
18
|
+
* @description Defines core types for the state management system, including state change events, listeners, etc.
|
|
19
|
+
* @module @brix/runtime-sdk-api-web/types/state
|
|
20
|
+
* @version 3.2.0
|
|
21
|
+
*
|
|
22
|
+
* [v3.2 Changes]
|
|
23
|
+
* Extracted from index.ts into a standalone type file, and promoted common contracts from infra-adapter-state-web.
|
|
24
|
+
*
|
|
25
|
+
* [Design Principles]
|
|
26
|
+
* - Define common state management contracts, state adapters implement specific storage logic
|
|
27
|
+
* - Support namespace isolation (each plugin has independent state space)
|
|
28
|
+
* - Support state change subscription
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Plugin State Storage Structure
|
|
32
|
+
*
|
|
33
|
+
* <p>Top level partitioned by plugin ID, each plugin has independent state namespace.</p>
|
|
34
|
+
*
|
|
35
|
+
* <h3>Namespace Isolation Mechanism</h3>
|
|
36
|
+
* <ul>
|
|
37
|
+
* <li>booking plugin: state.booking.*</li>
|
|
38
|
+
* <li>identity plugin: state.identity.*</li>
|
|
39
|
+
* </ul>
|
|
40
|
+
* <p>Plugin A cannot directly read/write Plugin B's state.</p>
|
|
41
|
+
*/
|
|
42
|
+
export interface PluginStoreState {
|
|
43
|
+
/** State partitioned by plugin ID */
|
|
44
|
+
[pluginId: string]: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* State Change Event
|
|
48
|
+
*
|
|
49
|
+
* <p>Describes details of state changes, used for observability and debugging.</p>
|
|
50
|
+
*/
|
|
51
|
+
export interface StateChangeEvent {
|
|
52
|
+
/** Plugin ID */
|
|
53
|
+
readonly pluginId: string;
|
|
54
|
+
/** State key */
|
|
55
|
+
readonly key: string;
|
|
56
|
+
/** Old value */
|
|
57
|
+
readonly oldValue: unknown;
|
|
58
|
+
/** New value */
|
|
59
|
+
readonly newValue: unknown;
|
|
60
|
+
/** Timestamp */
|
|
61
|
+
readonly timestamp?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* State Change Listener
|
|
65
|
+
*/
|
|
66
|
+
export type StateChangeListener = (event: StateChangeEvent) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Plugin State Capability Type Identifier
|
|
69
|
+
*/
|
|
70
|
+
export declare const PluginStateCapabilityType: unique symbol;
|
|
71
|
+
/**
|
|
72
|
+
* Plugin State Capability Contract
|
|
73
|
+
*
|
|
74
|
+
* <p>Provides isolated state management capability for plugins, replacing direct use of localStorage/sessionStorage/zustand.</p>
|
|
75
|
+
*
|
|
76
|
+
* <h3>Usage Example</h3>
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const state = context.getCapability<PluginStateCapability>(PluginStateCapabilityType);
|
|
79
|
+
* state.setState('selectedDate', new Date());
|
|
80
|
+
* const date = state.getState<Date>('selectedDate');
|
|
81
|
+
*
|
|
82
|
+
* // Subscribe to state changes
|
|
83
|
+
* const unsubscribe = state.subscribe('selectedDate', (value) => {
|
|
84
|
+
* console.log('Date changed:', value);
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* <h3>Architectural Notes</h3>
|
|
89
|
+
* <ul>
|
|
90
|
+
* <li>Each plugin's state is in an independent namespace</li>
|
|
91
|
+
* <li>Cross-plugin state sharing through EventBus</li>
|
|
92
|
+
* <li>Direct access to other plugins' state is prohibited</li>
|
|
93
|
+
* </ul>
|
|
94
|
+
*/
|
|
95
|
+
export interface PluginStateCapability {
|
|
96
|
+
/**
|
|
97
|
+
* Get State Value
|
|
98
|
+
*
|
|
99
|
+
* @param key State key
|
|
100
|
+
* @returns State value, returns undefined if not exists (supports sync/async)
|
|
101
|
+
*/
|
|
102
|
+
getState<T>(key: string): T | undefined | Promise<T | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Set State Value
|
|
105
|
+
*
|
|
106
|
+
* @param key State key
|
|
107
|
+
* @param value State value
|
|
108
|
+
*/
|
|
109
|
+
setState<T>(key: string, value: T): void;
|
|
110
|
+
/**
|
|
111
|
+
* Subscribe to State Changes
|
|
112
|
+
*
|
|
113
|
+
* @param key State key
|
|
114
|
+
* @param listener Change listener
|
|
115
|
+
* @returns Unsubscribe function
|
|
116
|
+
*/
|
|
117
|
+
subscribe<T>(key: string, listener: (value: T) => void): () => void;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB;IACnB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAMD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY;IACZ,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,UAAU;IACV,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,SAAS;IACT,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,SAAS;IACT,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,UAAU;IACV,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAMpE;;GAEG;AACH,eAAO,MAAM,yBAAyB,eAAsC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAEzC;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACrE"}
|