@d2m/april 0.0.0-stage → 0.1.1

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.
Files changed (50) hide show
  1. package/dist/bridge.d.ts +116 -0
  2. package/dist/bridge.d.ts.map +1 -0
  3. package/dist/bridge.js +1046 -0
  4. package/dist/bridge.js.map +1 -0
  5. package/dist/errors.d.ts +6 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +188 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/events.d.ts +18 -0
  10. package/dist/events.d.ts.map +1 -0
  11. package/dist/events.js +85 -0
  12. package/dist/events.js.map +1 -0
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/internal/initialization.d.ts +46 -0
  18. package/dist/internal/initialization.d.ts.map +1 -0
  19. package/dist/internal/initialization.js +569 -0
  20. package/dist/internal/initialization.js.map +1 -0
  21. package/dist/internal/modules.d.ts +54 -0
  22. package/dist/internal/modules.d.ts.map +1 -0
  23. package/dist/internal/modules.js +318 -0
  24. package/dist/internal/modules.js.map +1 -0
  25. package/dist/internal/mount.d.ts +21 -0
  26. package/dist/internal/mount.d.ts.map +1 -0
  27. package/dist/internal/mount.js +305 -0
  28. package/dist/internal/mount.js.map +1 -0
  29. package/dist/internal/shell-core-entry.d.ts +2 -0
  30. package/dist/internal/shell-core-entry.d.ts.map +1 -0
  31. package/dist/internal/shell-core-entry.js +63 -0
  32. package/dist/internal/shell-core-entry.js.map +1 -0
  33. package/dist/internal/shell-core-modules.d.ts +6 -0
  34. package/dist/internal/shell-core-modules.d.ts.map +1 -0
  35. package/dist/internal/shell-core-modules.js +218 -0
  36. package/dist/internal/shell-core-modules.js.map +1 -0
  37. package/dist/internal/shell-core.d.ts +17 -0
  38. package/dist/internal/shell-core.d.ts.map +1 -0
  39. package/dist/internal/shell-core.js +2 -0
  40. package/dist/internal/shell-core.js.map +1 -0
  41. package/dist/internal/shell-transport.d.ts +12 -0
  42. package/dist/internal/shell-transport.d.ts.map +1 -0
  43. package/dist/internal/shell-transport.js +33 -0
  44. package/dist/internal/shell-transport.js.map +1 -0
  45. package/dist/types.d.ts +123 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +2 -0
  48. package/dist/types.js.map +1 -0
  49. package/package.json +21 -3
  50. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/internal/modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,KAAK,EACV,KAAK,EACL,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5D,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC;CACjD;AAED,MAAM,WAAW,wBAAwB;IACvC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC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C,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;IAS5C,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAgBpC,QAAQ,IAAI,IAAI;IAUhB,gBAAgB,IAAI,sBAAsB;IAc1C,kBAAkB,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAkBvD,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAShD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCrC,OAAO,CAAC,KAAK;CAOd"}
@@ -0,0 +1,318 @@
1
+ import { createAprilError, isAprilError } from "../errors.js";
2
+ const MODULE_INSTALL_FAILED = "plugin.jsModuleInstallFailed";
3
+ const MODULE_DEPENDENCY_INVALID = "plugin.jsModuleDependencyInvalid";
4
+ const MODULE_INITIALIZATION_FAILED = "plugin.jsModuleInitializationFailed";
5
+ const MODULE_CANCELED = "canceled.byPage";
6
+ export class AprilPluginModuleRuntime {
7
+ april;
8
+ mountAuthority;
9
+ locale;
10
+ installedModules = new Map();
11
+ activeInstallations = new Set();
12
+ installing = 0;
13
+ finalized = false;
14
+ disposed = false;
15
+ finalizationLease;
16
+ constructor(april, mountAuthority, locale) {
17
+ this.april = april;
18
+ this.mountAuthority = mountAuthority;
19
+ this.locale = locale;
20
+ }
21
+ async install(request) {
22
+ if (this.disposed) {
23
+ throw this.error("canceled", MODULE_CANCELED, true);
24
+ }
25
+ if (this.finalized) {
26
+ throw this.error("bridge", MODULE_INITIALIZATION_FAILED, false);
27
+ }
28
+ const validated = validateInstallRequest(request, this.locale);
29
+ if (this.installedModules.has(validated.moduleId)) {
30
+ throw this.error("validation", MODULE_DEPENDENCY_INVALID, false);
31
+ }
32
+ const directDependencies = new Set(validated.dependsOn);
33
+ for (const dependencyId of directDependencies) {
34
+ const dependency = this.installedModules.get(dependencyId);
35
+ if (!dependency || dependency.exports === undefined) {
36
+ throw this.error("validation", MODULE_DEPENDENCY_INVALID, false);
37
+ }
38
+ }
39
+ const controller = new AbortController();
40
+ let transaction;
41
+ let result;
42
+ this.installing += 1;
43
+ try {
44
+ transaction = this.mountAuthority.beginTransaction(validated.moduleId, validated.mounts);
45
+ const activeInstallation = { moduleId: validated.moduleId, transaction, controller };
46
+ this.activeInstallations.add(activeInstallation);
47
+ const capabilities = freezeCapabilities(validated.capabilities);
48
+ const currentTransaction = transaction;
49
+ const context = Object.freeze({
50
+ april: this.april,
51
+ pluginCode: validated.pluginCode,
52
+ pluginVersion: validated.pluginVersion,
53
+ moduleId: validated.moduleId,
54
+ locale: this.locale,
55
+ capabilities,
56
+ signal: controller.signal,
57
+ mount: (path, value) => {
58
+ try {
59
+ currentTransaction.mount(path, value);
60
+ }
61
+ catch (error) {
62
+ throw normalizeMountError(error, this.locale);
63
+ }
64
+ },
65
+ hasCapability: (ref) => hasCapability(capabilities, ref),
66
+ });
67
+ const imports = createImports(directDependencies, this.installedModules, this.locale);
68
+ const installResult = await validated.installer(context, imports);
69
+ result = installResult === undefined ? undefined : installResult;
70
+ if (result !== undefined) {
71
+ validateInstallResult(result, this.locale);
72
+ }
73
+ if (this.disposed || controller.signal.aborted) {
74
+ throw this.error("canceled", MODULE_CANCELED, true);
75
+ }
76
+ currentTransaction.commit();
77
+ this.installedModules.set(validated.moduleId, {
78
+ moduleId: validated.moduleId,
79
+ controller,
80
+ exports: result?.exports,
81
+ dispose: result?.dispose,
82
+ });
83
+ }
84
+ catch (error) {
85
+ transaction?.abort();
86
+ controller.abort();
87
+ try {
88
+ await disposeInstallResult(result);
89
+ }
90
+ catch {
91
+ // 清理失败不能覆盖原始安装错误,也不能阻止事务回滚。
92
+ }
93
+ throw normalizeModuleError(error, this.locale, MODULE_INSTALL_FAILED);
94
+ }
95
+ finally {
96
+ if (transaction) {
97
+ this.activeInstallations.forEach((activeInstallation) => {
98
+ if (activeInstallation.transaction === transaction) {
99
+ this.activeInstallations.delete(activeInstallation);
100
+ }
101
+ });
102
+ }
103
+ this.installing -= 1;
104
+ }
105
+ }
106
+ getExports(moduleId) {
107
+ const module = this.installedModules.get(moduleId);
108
+ if (!module || module.exports === undefined) {
109
+ throw this.error("validation", MODULE_DEPENDENCY_INVALID, false);
110
+ }
111
+ return module.exports;
112
+ }
113
+ abortInstall(moduleId) {
114
+ if (!isNonEmptyString(moduleId)) {
115
+ throw this.error("validation", MODULE_DEPENDENCY_INVALID, false);
116
+ }
117
+ for (const installation of this.activeInstallations) {
118
+ if (installation.moduleId !== moduleId) {
119
+ continue;
120
+ }
121
+ installation.controller.abort();
122
+ installation.transaction.abort();
123
+ return;
124
+ }
125
+ }
126
+ finalize() {
127
+ const lease = this.openFinalization();
128
+ try {
129
+ this.commitFinalization(lease);
130
+ }
131
+ catch (error) {
132
+ this.abortFinalization(lease);
133
+ throw error;
134
+ }
135
+ }
136
+ openFinalization() {
137
+ if (this.disposed || this.finalized || this.installing !== 0 || this.finalizationLease) {
138
+ throw this.error("platform", MODULE_INITIALIZATION_FAILED, false);
139
+ }
140
+ try {
141
+ const lease = this.mountAuthority.openFinalization();
142
+ this.finalizationLease = lease;
143
+ return lease;
144
+ }
145
+ catch (error) {
146
+ throw normalizeModuleError(error, this.locale, MODULE_INITIALIZATION_FAILED);
147
+ }
148
+ }
149
+ commitFinalization(lease) {
150
+ if (this.finalizationLease !== lease || this.disposed || this.finalized || this.installing !== 0) {
151
+ throw this.error("platform", MODULE_INITIALIZATION_FAILED, false);
152
+ }
153
+ try {
154
+ for (const module of this.installedModules.values()) {
155
+ deepFreeze(module.exports);
156
+ }
157
+ this.mountAuthority.finalize(lease);
158
+ this.finalizationLease = undefined;
159
+ this.finalized = true;
160
+ }
161
+ catch (error) {
162
+ throw normalizeModuleError(error, this.locale, MODULE_INITIALIZATION_FAILED);
163
+ }
164
+ }
165
+ abortFinalization(lease) {
166
+ if (this.finalizationLease !== lease) {
167
+ return;
168
+ }
169
+ this.finalizationLease = undefined;
170
+ lease.abort();
171
+ }
172
+ async dispose() {
173
+ if (this.disposed) {
174
+ return;
175
+ }
176
+ this.disposed = true;
177
+ if (this.finalizationLease) {
178
+ this.finalizationLease.abort();
179
+ this.finalizationLease = undefined;
180
+ }
181
+ for (const activeInstallation of this.activeInstallations) {
182
+ activeInstallation.controller.abort();
183
+ activeInstallation.transaction.abort();
184
+ }
185
+ const modules = [...this.installedModules.values()].reverse();
186
+ this.installedModules.clear();
187
+ let firstError;
188
+ for (const module of modules) {
189
+ module.controller.abort();
190
+ try {
191
+ await module.dispose?.();
192
+ }
193
+ catch (error) {
194
+ firstError ??= error;
195
+ }
196
+ }
197
+ if (firstError !== undefined) {
198
+ throw normalizeModuleError(firstError, this.locale, MODULE_INSTALL_FAILED);
199
+ }
200
+ }
201
+ error(category, code, retryable) {
202
+ return createAprilError(this.locale, category, code, retryable);
203
+ }
204
+ }
205
+ function validateInstallRequest(request, locale) {
206
+ if (!isRecord(request) ||
207
+ !isNonEmptyString(request.pluginCode) ||
208
+ !isNonEmptyString(request.pluginVersion) ||
209
+ !isNonEmptyString(request.moduleId) ||
210
+ !Array.isArray(request.mounts) ||
211
+ !Array.isArray(request.dependsOn) ||
212
+ !Array.isArray(request.capabilities) ||
213
+ typeof request.installer !== "function") {
214
+ throw createAprilError(locale, "validation", MODULE_INSTALL_FAILED, false);
215
+ }
216
+ if (request.dependsOn.some((dependency) => !isNonEmptyString(dependency)) ||
217
+ request.dependsOn.includes(request.moduleId) ||
218
+ new Set(request.dependsOn).size !== request.dependsOn.length ||
219
+ request.mounts.some((mount) => typeof mount !== "string")) {
220
+ throw createAprilError(locale, "validation", MODULE_DEPENDENCY_INVALID, false);
221
+ }
222
+ return Object.freeze({
223
+ pluginCode: request.pluginCode,
224
+ pluginVersion: request.pluginVersion,
225
+ moduleId: request.moduleId,
226
+ mounts: Object.freeze([...request.mounts]),
227
+ dependsOn: Object.freeze([...request.dependsOn]),
228
+ capabilities: Object.freeze([...request.capabilities]),
229
+ installer: request.installer,
230
+ });
231
+ }
232
+ function createImports(directDependencies, installedModules, locale) {
233
+ return Object.freeze({
234
+ has(moduleId) {
235
+ return directDependencies.has(moduleId) && installedModules.get(moduleId)?.exports !== undefined;
236
+ },
237
+ get(moduleId) {
238
+ if (!directDependencies.has(moduleId)) {
239
+ throw createAprilError(locale, "validation", MODULE_DEPENDENCY_INVALID, false);
240
+ }
241
+ const module = installedModules.get(moduleId);
242
+ if (!module || module.exports === undefined) {
243
+ throw createAprilError(locale, "validation", MODULE_DEPENDENCY_INVALID, false);
244
+ }
245
+ return module.exports;
246
+ },
247
+ });
248
+ }
249
+ function freezeCapabilities(capabilities) {
250
+ return Object.freeze(capabilities.map((descriptor) => Object.freeze({
251
+ ...descriptor,
252
+ connectionResult: Object.freeze({ ...descriptor.connectionResult }),
253
+ })));
254
+ }
255
+ function hasCapability(capabilities, ref) {
256
+ if (!isRecord(ref) ||
257
+ !isNonEmptyString(ref.capability) ||
258
+ !isNonEmptyString(ref.action) ||
259
+ !isNonEmptyString(ref.contractVersion)) {
260
+ return false;
261
+ }
262
+ return capabilities.some((descriptor) => descriptor.capability === ref.capability &&
263
+ descriptor.action === ref.action &&
264
+ descriptor.contractVersion === ref.contractVersion);
265
+ }
266
+ function validateInstallResult(result, locale) {
267
+ if (!isRecord(result) ||
268
+ (result.dispose !== undefined && typeof result.dispose !== "function")) {
269
+ throw createAprilError(locale, "validation", MODULE_INSTALL_FAILED, false);
270
+ }
271
+ }
272
+ async function disposeInstallResult(result) {
273
+ if (typeof result?.dispose === "function") {
274
+ await result.dispose();
275
+ }
276
+ }
277
+ function normalizeMountError(error, locale) {
278
+ if (isAprilError(error)) {
279
+ return error;
280
+ }
281
+ const message = error instanceof Error ? error.message : "";
282
+ const code = /\b(extension\.[A-Za-z0-9]+)\b/.exec(message)?.[1];
283
+ return createAprilError(locale, "bridge", code ?? MODULE_INSTALL_FAILED, false);
284
+ }
285
+ function normalizeModuleError(error, locale, fallbackCode) {
286
+ if (isAprilError(error)) {
287
+ return error;
288
+ }
289
+ const mountError = normalizeMountError(error, locale);
290
+ if (mountError.code !== MODULE_INSTALL_FAILED) {
291
+ return mountError;
292
+ }
293
+ return createAprilError(locale, "bridge", fallbackCode, false);
294
+ }
295
+ function deepFreeze(value, seen = new WeakSet()) {
296
+ if ((typeof value !== "object" && typeof value !== "function") || value === null) {
297
+ return value;
298
+ }
299
+ const objectValue = value;
300
+ if (seen.has(objectValue)) {
301
+ return value;
302
+ }
303
+ seen.add(objectValue);
304
+ for (const key of Reflect.ownKeys(objectValue)) {
305
+ const descriptor = Reflect.getOwnPropertyDescriptor(objectValue, key);
306
+ if (descriptor && "value" in descriptor) {
307
+ deepFreeze(descriptor.value, seen);
308
+ }
309
+ }
310
+ return Object.freeze(value);
311
+ }
312
+ function isNonEmptyString(value) {
313
+ return typeof value === "string" && value.trim().length > 0;
314
+ }
315
+ function isRecord(value) {
316
+ return typeof value === "object" && value !== null && !Array.isArray(value);
317
+ }
318
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../../src/internal/modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AA8DhF,MAAM,qBAAqB,GAAG,8BAA8B,CAAC;AAC7D,MAAM,yBAAyB,GAAG,kCAAkC,CAAC;AACrE,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAC3E,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAE1C,MAAM,OAAO,wBAAwB;IAShB;IACA;IACA;IAVF,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;IACtD,mBAAmB,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7D,UAAU,GAAG,CAAC,CAAC;IACf,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAG,KAAK,CAAC;IACjB,iBAAiB,CAAqC;IAE9D,YACmB,KAAY,EACZ,cAAmC,EACnC,MAAmB;QAFnB,UAAK,GAAL,KAAK,CAAO;QACZ,mBAAc,GAAd,cAAc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C,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QACtE,IAAI,UAAU,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;YACxC,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAM,CAAC;AACnC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { April } from "../types.js";
2
+ export interface AprilMountAuthority {
3
+ publish(stagingGraph: Record<string, unknown>): void;
4
+ beginTransaction(moduleId: string, mounts: readonly string[]): AprilMountTransaction;
5
+ openFinalization(): AprilFinalizationLease;
6
+ finalize(lease: AprilFinalizationLease): void;
7
+ }
8
+ export interface AprilMountTransaction {
9
+ mount(path: string, value: unknown): void;
10
+ commit(): void;
11
+ abort(): void;
12
+ }
13
+ export interface AprilFinalizationLease {
14
+ commit(): void;
15
+ abort(): void;
16
+ }
17
+ export declare function createAprilFacade(coreGraph: Record<string, unknown>): {
18
+ readonly facade: April;
19
+ readonly mountAuthority: AprilMountAuthority;
20
+ };
21
+ //# sourceMappingURL=mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/internal/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,qBAAqB,CAAC;IACrF,gBAAgB,IAAI,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACrE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC;CAC9C,CAyJA"}
@@ -0,0 +1,305 @@
1
+ export function createAprilFacade(coreGraph) {
2
+ const coreNames = new Set(Object.keys(coreGraph));
3
+ let backingGraph = deepFreeze(copyNullPrototype(coreGraph));
4
+ let published = false;
5
+ let stagingGraph = Object.create(null);
6
+ const committedMounts = new Set();
7
+ const openTransactions = new Set();
8
+ const target = Object.freeze(Object.create(null));
9
+ const facade = new Proxy(target, {
10
+ get(_target, property) {
11
+ return backingGraph[property];
12
+ },
13
+ set() {
14
+ return false;
15
+ },
16
+ defineProperty() {
17
+ return false;
18
+ },
19
+ deleteProperty() {
20
+ return false;
21
+ },
22
+ setPrototypeOf() {
23
+ return false;
24
+ },
25
+ getPrototypeOf() {
26
+ return null;
27
+ },
28
+ ownKeys() {
29
+ return [];
30
+ },
31
+ getOwnPropertyDescriptor() {
32
+ return undefined;
33
+ },
34
+ });
35
+ return {
36
+ facade: facade,
37
+ mountAuthority: {
38
+ publish(stagingGraph) {
39
+ if (published) {
40
+ throw new Error("April 扩展 backing graph 已经封闭。");
41
+ }
42
+ for (const name of Object.keys(stagingGraph)) {
43
+ if (coreNames.has(name)) {
44
+ throw new Error(`April Core 名称不可被模块覆盖:${name}`);
45
+ }
46
+ }
47
+ backingGraph = deepFreeze(copyNullPrototype({ ...backingGraph, ...stagingGraph }));
48
+ published = true;
49
+ },
50
+ beginTransaction(moduleId, mounts) {
51
+ if (published) {
52
+ throw new Error("April 扩展 backing graph 已经封闭。");
53
+ }
54
+ if (typeof moduleId !== "string" || moduleId.trim().length === 0) {
55
+ throw new Error("插件模块 ID 无效。");
56
+ }
57
+ const declaredMounts = validateMountDeclarations(mounts, coreNames, committedMounts);
58
+ const transactionId = Symbol(moduleId);
59
+ openTransactions.add(transactionId);
60
+ let closed = false;
61
+ const values = new Map();
62
+ const close = () => {
63
+ closed = true;
64
+ openTransactions.delete(transactionId);
65
+ };
66
+ return {
67
+ mount(path, value) {
68
+ if (closed) {
69
+ throw new Error("extension.mountClosed: transaction is closed.");
70
+ }
71
+ if (!declaredMounts.has(path) || values.has(path)) {
72
+ throw new Error("extension.mountContractMismatch: mount is not declared or duplicated.");
73
+ }
74
+ validateMountValue(value);
75
+ values.set(path, value);
76
+ },
77
+ commit() {
78
+ if (closed) {
79
+ throw new Error("extension.mountClosed: transaction is closed.");
80
+ }
81
+ if (values.size !== declaredMounts.size) {
82
+ throw new Error("extension.mountContractMismatch: declared mounts are incomplete.");
83
+ }
84
+ const commitPlan = createMountCommitPlan(stagingGraph, values, committedMounts);
85
+ for (const [path, value] of commitPlan) {
86
+ assignMount(stagingGraph, path, value);
87
+ }
88
+ for (const [path] of commitPlan) {
89
+ committedMounts.add(path);
90
+ }
91
+ close();
92
+ },
93
+ abort() {
94
+ if (!closed) {
95
+ values.clear();
96
+ close();
97
+ }
98
+ },
99
+ };
100
+ },
101
+ openFinalization() {
102
+ if (published) {
103
+ throw new Error("April 扩展 backing graph 已经封闭。");
104
+ }
105
+ let open = true;
106
+ const lease = {
107
+ commit() {
108
+ if (!open) {
109
+ throw new Error("April 模块 finalization lease 已关闭。");
110
+ }
111
+ open = false;
112
+ finalizeGraph(lease);
113
+ },
114
+ abort() {
115
+ open = false;
116
+ },
117
+ };
118
+ return lease;
119
+ },
120
+ finalize(lease) {
121
+ if (published) {
122
+ throw new Error("April 扩展 backing graph 已经封闭。");
123
+ }
124
+ lease.commit();
125
+ },
126
+ },
127
+ };
128
+ function finalizeGraph(lease) {
129
+ if (openTransactions.size > 0) {
130
+ throw new Error("April 模块仍有未关闭的挂载事务。");
131
+ }
132
+ void lease;
133
+ backingGraph = deepFreeze(copyNullPrototype({ ...backingGraph, ...stagingGraph }));
134
+ stagingGraph = Object.create(null);
135
+ published = true;
136
+ }
137
+ }
138
+ function validateMountDeclarations(mounts, coreNames, committedMounts) {
139
+ if (!Array.isArray(mounts)) {
140
+ throw new Error("extension.mountContractMismatch: mounts must be an array.");
141
+ }
142
+ const validated = new Set();
143
+ for (const path of mounts) {
144
+ if (typeof path !== "string" || !/^[a-z][A-Za-z0-9]*(\.[a-z][A-Za-z0-9]*)*$/.test(path)) {
145
+ throw new Error("extension.mountContractMismatch: mount path is invalid.");
146
+ }
147
+ const [root] = path.split(".");
148
+ if (coreNames.has(root) || root === "ui" || root === "__proto__" || root === "prototype" || root === "constructor") {
149
+ throw new Error("extension.mountConflict: mount path is reserved.");
150
+ }
151
+ if (!validated.add(path)) {
152
+ throw new Error("extension.mountContractMismatch: mount path is duplicated.");
153
+ }
154
+ if ([...committedMounts].some((existing) => hasPathConflict(path, existing))) {
155
+ throw new Error("extension.mountConflict: mount path is already committed.");
156
+ }
157
+ }
158
+ const declaredPaths = [...validated];
159
+ for (let index = 0; index < declaredPaths.length; index += 1) {
160
+ if (declaredPaths.slice(index + 1).some((path) => hasPathConflict(declaredPaths[index], path))) {
161
+ throw new Error("extension.mountConflict: mount paths have an ambiguous prefix.");
162
+ }
163
+ }
164
+ return validated;
165
+ }
166
+ function createMountCommitPlan(graph, values, committedMounts) {
167
+ const plan = [...values.entries()];
168
+ for (const [path] of plan) {
169
+ if ([...committedMounts].some((existing) => hasPathConflict(path, existing))) {
170
+ throw new Error("extension.mountConflict: mount path is already committed.");
171
+ }
172
+ const segments = path.split(".");
173
+ let current = graph;
174
+ let missingPrefix = false;
175
+ for (let index = 0; index < segments.length - 1; index += 1) {
176
+ const segment = segments[index];
177
+ const existing = current[segment];
178
+ if (existing === undefined) {
179
+ missingPrefix = true;
180
+ break;
181
+ }
182
+ const prefix = segments.slice(0, index + 1).join(".");
183
+ if (committedMounts.has(prefix) || !isPlainObject(existing)) {
184
+ throw new Error("extension.mountConflict: mount path has a non-object prefix.");
185
+ }
186
+ current = existing;
187
+ }
188
+ if (missingPrefix) {
189
+ continue;
190
+ }
191
+ const leaf = segments[segments.length - 1];
192
+ if (Object.hasOwn(current, leaf)) {
193
+ throw new Error("extension.mountConflict: mount path is already committed.");
194
+ }
195
+ }
196
+ return plan;
197
+ }
198
+ function hasPathConflict(left, right) {
199
+ return left === right || left.startsWith(`${right}.`) || right.startsWith(`${left}.`);
200
+ }
201
+ function assignMount(graph, path, value) {
202
+ const segments = path.split(".");
203
+ let current = graph;
204
+ for (const segment of segments.slice(0, -1)) {
205
+ const existing = current[segment];
206
+ if (existing !== undefined) {
207
+ if (!isPlainObject(existing)) {
208
+ throw new Error("extension.mountConflict: mount path has a non-object prefix.");
209
+ }
210
+ current = existing;
211
+ continue;
212
+ }
213
+ const child = Object.create(null);
214
+ current[segment] = child;
215
+ current = child;
216
+ }
217
+ const leaf = segments[segments.length - 1];
218
+ if (Object.hasOwn(current, leaf)) {
219
+ throw new Error("extension.mountConflict: mount path is already committed.");
220
+ }
221
+ current[leaf] = value;
222
+ }
223
+ function validateMountValue(value, seen = new WeakSet(), functionPrototype = false, functionOwner) {
224
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
225
+ return;
226
+ }
227
+ if (typeof value === "number") {
228
+ if (Number.isFinite(value)) {
229
+ return;
230
+ }
231
+ throw new Error("extension.mountContractMismatch: mount number is not finite.");
232
+ }
233
+ if (typeof value === "function") {
234
+ for (const key of Reflect.ownKeys(value)) {
235
+ if (typeof key === "symbol" || !["length", "name", "prototype", "arguments", "caller"].includes(key)) {
236
+ throw new Error("extension.mountContractMismatch: function has custom properties.");
237
+ }
238
+ }
239
+ const prototype = Object.getOwnPropertyDescriptor(value, "prototype");
240
+ if (prototype && "value" in prototype && !functionPrototype) {
241
+ validateMountValue(prototype.value, seen, true, value);
242
+ }
243
+ return;
244
+ }
245
+ if (typeof value !== "object" || value === null) {
246
+ throw new Error("extension.mountContractMismatch: mount value type is invalid.");
247
+ }
248
+ if (seen.has(value)) {
249
+ throw new Error("extension.mountContractMismatch: mount value contains a cycle.");
250
+ }
251
+ seen.add(value);
252
+ if (!Array.isArray(value) && !isPlainObject(value)) {
253
+ throw new Error("extension.mountContractMismatch: mount value contains a host object.");
254
+ }
255
+ for (const key of Reflect.ownKeys(value)) {
256
+ if (typeof key === "symbol" ||
257
+ ["__proto__", "prototype"].includes(key) ||
258
+ (key === "constructor" && !functionPrototype)) {
259
+ throw new Error("extension.mountContractMismatch: mount value contains a reserved key.");
260
+ }
261
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
262
+ if (!descriptor || !("value" in descriptor) || descriptor.get || descriptor.set) {
263
+ throw new Error("extension.mountContractMismatch: mount value contains an accessor.");
264
+ }
265
+ if (Array.isArray(value) && key === "length") {
266
+ continue;
267
+ }
268
+ if (functionPrototype && key === "constructor") {
269
+ if (descriptor.value !== functionOwner) {
270
+ throw new Error("extension.mountContractMismatch: function prototype is invalid.");
271
+ }
272
+ continue;
273
+ }
274
+ validateMountValue(descriptor.value, seen);
275
+ }
276
+ seen.delete(value);
277
+ }
278
+ function isPlainObject(value) {
279
+ if (typeof value !== "object" || value === null) {
280
+ return false;
281
+ }
282
+ const prototype = Object.getPrototypeOf(value);
283
+ return prototype === null || prototype === Object.prototype;
284
+ }
285
+ function copyNullPrototype(source) {
286
+ return Object.assign(Object.create(null), source);
287
+ }
288
+ function deepFreeze(value, seen = new WeakSet()) {
289
+ if ((typeof value !== "object" && typeof value !== "function") || value === null) {
290
+ return value;
291
+ }
292
+ const objectValue = value;
293
+ if (seen.has(objectValue)) {
294
+ return value;
295
+ }
296
+ seen.add(objectValue);
297
+ for (const key of Reflect.ownKeys(objectValue)) {
298
+ const descriptor = Reflect.getOwnPropertyDescriptor(objectValue, key);
299
+ if (descriptor && "value" in descriptor) {
300
+ deepFreeze(descriptor.value, seen);
301
+ }
302
+ }
303
+ return Object.freeze(objectValue);
304
+ }
305
+ //# sourceMappingURL=mount.js.map