webloom-framework 0.1.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/LICENSE +661 -0
- package/README.md +92 -0
- package/dist/chunk-KGNF36DZ.js +3736 -0
- package/dist/chunk-KGNF36DZ.js.map +1 -0
- package/dist/createPluginHost-CcW9sPNs.d.ts +1340 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.js +583 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +80 -0
- package/dist/react.js +177 -0
- package/dist/react.js.map +1 -0
- package/dist/resourceRegistry-BAnqKcp7.d.ts +157 -0
- package/dist/testing.d.ts +23 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/docs/api.md +29 -0
- package/docs/migration-baseline.md +32 -0
- package/package.json +68 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { an as RemoteServiceCallContext, o as CreatePluginHostOptions, a0 as PluginHost, au as RemoteServiceTransport } from './createPluginHost-CcW9sPNs.js';
|
|
2
|
+
export { j as CapabilityRegistry, k as ContextExtensionInput, l as ContributionAdapter, m as ContributionAdapterInput, n as ContributionHandle, T as PermissionPolicyInput, V as PermissionPolicyResult, Y as PluginConfigStore, aH as RuntimeUnitSnapshot, aJ as ScopeResolution, aK as ScopeResolver, aL as ScopeResolverInput, aO as StartupCapabilityError, aQ as StartupPluginError, a_ as createCapabilityRegistry, a$ as createInMemoryPluginConfigStore, b0 as createPluginHost, b2 as createResourceStore } from './createPluginHost-CcW9sPNs.js';
|
|
3
|
+
export { C as CreateMessagePortServiceTransportOptions, a as CreatePluginIntentControllerOptions, b as CreateResourceScopeOptions, c as CreateServiceBridgeOptions, R as RemoteServicePortCallMessage, d as RemoteServicePortCancelMessage, e as RemoteServicePortErrorMessage, f as RemoteServicePortResponseMessage, g as RemoteServicePortResultMessage, h as ResourceScopeOptions, i as RuntimeUnitImplementation, j as createLifecycleScope, k as createMessageBus, l as createMessagePortServiceTransport, m as createPluginIntentController, n as createRemoteServiceBridge, o as createResourceRegistry, p as createResourceScope, q as createRuntimeUnitImplementationRegistry, r as createServiceBridge } from './resourceRegistry-BAnqKcp7.js';
|
|
4
|
+
|
|
5
|
+
interface FakeTransportCall {
|
|
6
|
+
/** 调用请求体。 */
|
|
7
|
+
request: unknown;
|
|
8
|
+
/** Host 已绑定的调用上下文。 */
|
|
9
|
+
context: RemoteServiceCallContext;
|
|
10
|
+
}
|
|
11
|
+
interface CreateFakeTransportOptions {
|
|
12
|
+
/** 假服务返回值;缺省返回 undefined。 */
|
|
13
|
+
handle?: (request: unknown, context: RemoteServiceCallContext) => unknown | Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
/** 创建可观察的假服务传输;每次 call 都记录 request 和 context。 */
|
|
16
|
+
declare function createFakeRemoteServiceTransport(options?: CreateFakeTransportOptions): RemoteServiceTransport & {
|
|
17
|
+
readonly calls: readonly FakeTransportCall[];
|
|
18
|
+
reset(): void;
|
|
19
|
+
};
|
|
20
|
+
/** 创建测试 Host;默认关闭任何领域装配,只保留通用核心。 */
|
|
21
|
+
declare function createFakePluginHost(options?: CreatePluginHostOptions): PluginHost;
|
|
22
|
+
|
|
23
|
+
export { type CreateFakeTransportOptions, CreatePluginHostOptions, type FakeTransportCall, PluginHost, createFakePluginHost, createFakeRemoteServiceTransport };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createPluginHost } from './chunk-KGNF36DZ.js';
|
|
2
|
+
export { StartupCapabilityError, StartupPluginError, createCapabilityRegistry, createInMemoryPluginConfigStore, createLifecycleScope, createMessageBus, createMessagePortServiceTransport, createPluginHost, createPluginIntentController, createRemoteServiceBridge, createResourceRegistry, createResourceScope, createResourceStore, createRuntimeUnitImplementationRegistry, createServiceBridge } from './chunk-KGNF36DZ.js';
|
|
3
|
+
|
|
4
|
+
// src/testing/fakes.ts
|
|
5
|
+
function createFakeRemoteServiceTransport(options = {}) {
|
|
6
|
+
const calls = [];
|
|
7
|
+
return {
|
|
8
|
+
calls,
|
|
9
|
+
reset() {
|
|
10
|
+
calls.length = 0;
|
|
11
|
+
},
|
|
12
|
+
async call(request, context) {
|
|
13
|
+
calls.push({ request, context });
|
|
14
|
+
return await options.handle?.(request, context);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createFakePluginHost(options = {}) {
|
|
19
|
+
return createPluginHost({
|
|
20
|
+
...options,
|
|
21
|
+
initialPluginConfig: options.initialPluginConfig ?? {}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createFakePluginHost, createFakeRemoteServiceTransport };
|
|
26
|
+
//# sourceMappingURL=testing.js.map
|
|
27
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/fakes.ts"],"names":[],"mappings":";;;;AAyBO,SAAS,gCAAA,CACd,OAAA,GAAsC,EAAC,EACmD;AAC1F,EAAA,MAAM,QAA6B,EAAC;AACpC,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,KAAA,GAAQ;AAAE,MAAA,KAAA,CAAM,MAAA,GAAS,CAAA;AAAA,IAAG,CAAA;AAAA,IAC5B,MAAM,IAAA,CAAwB,OAAA,EAAmB,OAAA,EAAqD;AACpG,MAAA,KAAA,CAAM,IAAA,CAAK,EAAE,OAAA,EAAS,OAAA,EAAS,CAAA;AAC/B,MAAA,OAAO,MAAM,OAAA,CAAQ,MAAA,GAAS,OAAA,EAAS,OAAO,CAAA;AAAA,IAChD;AAAA,GACF;AACF;AAGO,SAAS,oBAAA,CAAqB,OAAA,GAAmC,EAAC,EAAe;AACtF,EAAA,OAAO,gBAAA,CAAiB;AAAA,IACtB,GAAG,OAAA;AAAA,IACH,mBAAA,EAAqB,OAAA,CAAQ,mBAAA,IAAuB;AAAC,GACtD,CAAA;AACH","file":"testing.js","sourcesContent":["// WebLoom 测试辅助:只提供通用假实现,不携带产品语义。\n\nimport type {\n RemoteServiceCallContext,\n RemoteServiceTransport,\n} from \"../contracts/lifecycle.js\";\nimport {\n createPluginHost,\n type CreatePluginHostOptions,\n type PluginHost,\n} from \"../host/createPluginHost.js\";\n\nexport interface FakeTransportCall {\n /** 调用请求体。 */\n request: unknown;\n /** Host 已绑定的调用上下文。 */\n context: RemoteServiceCallContext;\n}\n\nexport interface CreateFakeTransportOptions {\n /** 假服务返回值;缺省返回 undefined。 */\n handle?: (request: unknown, context: RemoteServiceCallContext) => unknown | Promise<unknown>;\n}\n\n/** 创建可观察的假服务传输;每次 call 都记录 request 和 context。 */\nexport function createFakeRemoteServiceTransport(\n options: CreateFakeTransportOptions = {},\n): RemoteServiceTransport & { readonly calls: readonly FakeTransportCall[]; reset(): void } {\n const calls: FakeTransportCall[] = [];\n return {\n calls,\n reset() { calls.length = 0; },\n async call<TRequest, TResult>(request: TRequest, context: RemoteServiceCallContext): Promise<TResult> {\n calls.push({ request, context });\n return await options.handle?.(request, context) as TResult;\n },\n };\n}\n\n/** 创建测试 Host;默认关闭任何领域装配,只保留通用核心。 */\nexport function createFakePluginHost(options: CreatePluginHostOptions = {}): PluginHost {\n return createPluginHost({\n ...options,\n initialPluginConfig: options.initialPluginConfig ?? {},\n });\n}\n"]}
|
package/docs/api.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# WebLoom API 说明
|
|
2
|
+
|
|
3
|
+
## 依赖和运行单元
|
|
4
|
+
|
|
5
|
+
`PluginManifest` 描述一个产品,`RuntimeUnitDescriptor` 描述该产品在某个 `execution` 环境中的运行单元。`pluginId` 是产品级稳定身份,`unitId` 是单元级稳定身份,`instanceId` 是每次启动新生成的实例身份。运行单元依赖必须同时声明 `capability`、`contractVersion`、`sourceExecution` 和 `scope`,Host 不根据 capability 名猜测远端服务。可执行 setup 必须由宿主的 `runtimeUnitImplementationRegistry` 按 `pluginId + unitId` 提供,静态清单不携带函数。
|
|
6
|
+
|
|
7
|
+
`meta.defaultEnabled` 是初始启用意图,`PluginState.kind` 是实际运行状态。两者必须分开读取:依赖缺失时可以得到 `blocked`,同时保留 `desiredEnabled: true`。
|
|
8
|
+
|
|
9
|
+
## Context 和 Scope
|
|
10
|
+
|
|
11
|
+
`PluginContext` 的基础字段只包含插件身份、实例身份、Scope、取消信号、权限租约、MessageBus、配置和 capability 访问。产品服务通过 `contextExtension` 注入,扩展属性按只读对象处理。
|
|
12
|
+
|
|
13
|
+
`LifecycleScope.revoke()` 是同步安全边界:它先阻止新资源、撤销权限租约并触发 `AbortSignal`;`dispose()` 再等待清理。清理失败和超时通过 `LifecycleDisposeResult` 暴露,不能被包装成成功。异步创建在撤权后才返回时,资源会立即释放且不会进入旧实例。
|
|
14
|
+
|
|
15
|
+
## 权限
|
|
16
|
+
|
|
17
|
+
权限租约把插件申请、可信批准和会话约束求交集。`permissions` 只是 Context 视图,最终远端调用或持久化写入仍需使用 `verifyPermissionLease()` 和 `assertBinding()` 做 fail-closed 检查。`attributes` 参与租约身份比较,但不作为任意数据仓库。
|
|
18
|
+
|
|
19
|
+
## 服务桥和 wire codec
|
|
20
|
+
|
|
21
|
+
`createServiceBridge()` 只接受同一连接、权威身份、连续快照和精确契约版本。旧 revision、revision gap、Provider 实例重建和断线都会使旧代理永久失效。传输层每次调用生成独立 `callId`;业务 `operationId` 可以重用,两者不混淆。
|
|
22
|
+
|
|
23
|
+
`createRemoteServiceMessageCodec()` 默认生成 `webloom.remote-service.*` 消息名。产品迁移旧协议时可以传入旧前缀,编码、解码和版本仍由 codec 集中负责。
|
|
24
|
+
|
|
25
|
+
## 宿主扩展点
|
|
26
|
+
|
|
27
|
+
`CreatePluginHostOptions` 提供 `capabilities`、`contextExtension`、`manifestValidator`、`scopeResolver`、`permissionPolicy`、`configStore`、`pluginIntentCoordinator`、`runtimeSnapshots`、`contributionAdapters` 和 `serviceBridgeForPlugin`。WebLoom 不创建产品 Registry、日志、存储或身份状态机。
|
|
28
|
+
|
|
29
|
+
贡献适配器返回的 `ContributionHandle` 支持 `revoke()` 和 `dispose()`:前者用于同步撤下入口,后者用于等待异步收尾。任何贡献都必须绑定当前 `instanceId` 和 Scope。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# WebLoom 拆分基线
|
|
2
|
+
|
|
3
|
+
本次独立拆分的源码基线记录如下:
|
|
4
|
+
|
|
5
|
+
| 项目 | 值 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| 来源仓库基线 | `f937804fe47c53b3e452ba6cbad4d1687c7671c4` |
|
|
8
|
+
| WebLoom 起始提交 | `f1c801655c3132c57b66045ff6d5e642fba4a8ea` |
|
|
9
|
+
| Node | `v22.13.1` |
|
|
10
|
+
| pnpm | `11.5.1` |
|
|
11
|
+
| 首发包版本 | `0.1.0` |
|
|
12
|
+
|
|
13
|
+
迁入范围是通用 Manifest、依赖图、Host 调度、MessageBus、生命周期 Scope、权限租约、服务桥、MessagePort 传输、升级门禁、意图控制、任务调度、资源 Store 和 React 绑定。产品 Registry、业务配置、产品日志、身份状态机和视觉组件不属于 WebLoom。
|
|
14
|
+
|
|
15
|
+
本文件只记录代码迁移基线。npm 包名占用查询、许可证归属确认、provenance、发布和部署由发布责任人在发布批次执行;施工代理不自动发布。
|
|
16
|
+
|
|
17
|
+
## 当前工作区发布状态
|
|
18
|
+
|
|
19
|
+
当前拆分源码仍在工作树中,尚未形成包含全部实现的正式提交;上表的
|
|
20
|
+
`WebLoom 起始提交` 只是独立仓库初始化提交,不能充当 `0.1.0` 的源码 provenance。
|
|
21
|
+
|
|
22
|
+
正式发布前必须由负责人完成以下确认:
|
|
23
|
+
|
|
24
|
+
- 提交 WebLoom 全部实现和测试,并把该提交记录为发布 provenance;
|
|
25
|
+
- 确认 `AGPL-3.0-only` 源码归属和发布责任;
|
|
26
|
+
- 使用 `pnpm run pack:consumer` 验证 tarball 的 core-only、React 和 Worker 三类消费者;
|
|
27
|
+
- 每个临时消费者都生成独立的 `smoke.ts`,使用临时项目自己的 `tsc --noEmit`
|
|
28
|
+
编译公开声明;Worker 消费者使用 `lib: ["ES2022", "WebWorker"]` 且不安装 React;
|
|
29
|
+
- `npm pack --json` 必须通过发布文件白名单、tarball/解包体积上限和必需入口文件检查;
|
|
30
|
+
- 从 tarball 解包后扫描全部 `.d.ts` 与 `.js.map`,禁止本地绝对路径、不可发布的
|
|
31
|
+
source map 路径以及产品领域字段;
|
|
32
|
+
- 在负责人确认后创建 `v0.1.0` tag 并发布 npm 包。
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webloom-framework",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "通用前端插件生命周期框架",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bsv8/WebLoom.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/bsv8/WebLoom/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/bsv8/WebLoom#readme",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"packageManager": "pnpm@11.5.1",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"docs"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./dist/react.d.ts",
|
|
33
|
+
"import": "./dist/react.js"
|
|
34
|
+
},
|
|
35
|
+
"./testing": {
|
|
36
|
+
"types": "./dist/testing.d.ts",
|
|
37
|
+
"import": "./dist/testing.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"lint:boundaries": "node scripts/check-boundaries.mjs",
|
|
45
|
+
"prepack": "pnpm typecheck && pnpm test && pnpm build && pnpm lint:boundaries",
|
|
46
|
+
"pack": "npm pack",
|
|
47
|
+
"pack:consumer": "pnpm run prepack && node scripts/pack-consumer-smoke.mjs"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"react": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@testing-library/react": "16.3.2",
|
|
59
|
+
"@types/react": "18.3.3",
|
|
60
|
+
"@types/react-dom": "18.3.0",
|
|
61
|
+
"jsdom": "25.0.1",
|
|
62
|
+
"react": "18.3.1",
|
|
63
|
+
"react-dom": "18.3.1",
|
|
64
|
+
"tsup": "8.5.1",
|
|
65
|
+
"typescript": "5.5.4",
|
|
66
|
+
"vitest": "3.2.4"
|
|
67
|
+
}
|
|
68
|
+
}
|