@pooder/core 1.1.0 → 2.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +33 -2
- package/dist/index.mjs +30 -1
- package/package.json +1 -1
- package/src/command.ts +10 -10
- package/src/context.ts +17 -17
- package/src/contribution/index.ts +12 -12
- package/src/contribution/points.ts +8 -1
- package/src/contribution/registry.ts +118 -118
- package/src/disposable.ts +3 -3
- package/src/extension.ts +164 -164
- package/src/index.ts +145 -140
- package/src/run-test-full.ts +98 -98
- package/src/services/CommandService.ts +79 -79
- package/src/services/ConfigurationService.ts +107 -107
- package/src/services/WorkbenchService.ts +30 -0
- package/src/services/index.ts +2 -1
- package/src/test-extension-full.ts +79 -79
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -61,7 +61,7 @@ interface ViewContribution {
|
|
|
61
61
|
*/
|
|
62
62
|
interface ConfigurationContribution {
|
|
63
63
|
id: string;
|
|
64
|
-
type: "string" | "number" | "boolean" | "color" | "select" | "json";
|
|
64
|
+
type: "string" | "number" | "boolean" | "color" | "select" | "json" | "array";
|
|
65
65
|
label: string;
|
|
66
66
|
default?: any;
|
|
67
67
|
description?: string;
|
|
@@ -249,6 +249,16 @@ declare class ConfigurationService implements Service {
|
|
|
249
249
|
dispose(): void;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
declare class WorkbenchService implements Service {
|
|
253
|
+
private _activeToolId;
|
|
254
|
+
private eventBus?;
|
|
255
|
+
init(): void;
|
|
256
|
+
dispose(): void;
|
|
257
|
+
setEventBus(bus: EventBus): void;
|
|
258
|
+
get activeToolId(): string | null;
|
|
259
|
+
activate(id: string): void;
|
|
260
|
+
}
|
|
261
|
+
|
|
252
262
|
declare class Pooder {
|
|
253
263
|
readonly eventBus: EventBus;
|
|
254
264
|
private readonly services;
|
|
@@ -264,4 +274,4 @@ declare class Pooder {
|
|
|
264
274
|
getContributions<T>(pointId: string): Contribution<T>[];
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
export { type CommandContribution, CommandService, type ConfigurationContribution, ConfigurationService, type Contribution, type ContributionMetadata, type ContributionPoint, ContributionPointIds, ContributionRegistry, type Extension, type ExtensionContext, ExtensionManager, type ExtensionMetadata, ExtensionRegistry, Pooder, type Service, ServiceRegistry, type ToolContribution, type ViewContribution };
|
|
277
|
+
export { type CommandContribution, CommandService, type ConfigurationContribution, ConfigurationService, type Contribution, type ContributionMetadata, type ContributionPoint, ContributionPointIds, ContributionRegistry, EventBus, type Extension, type ExtensionContext, ExtensionManager, type ExtensionMetadata, ExtensionRegistry, Pooder, type Service, ServiceRegistry, type ToolContribution, type ViewContribution, WorkbenchService };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ interface ViewContribution {
|
|
|
61
61
|
*/
|
|
62
62
|
interface ConfigurationContribution {
|
|
63
63
|
id: string;
|
|
64
|
-
type: "string" | "number" | "boolean" | "color" | "select" | "json";
|
|
64
|
+
type: "string" | "number" | "boolean" | "color" | "select" | "json" | "array";
|
|
65
65
|
label: string;
|
|
66
66
|
default?: any;
|
|
67
67
|
description?: string;
|
|
@@ -249,6 +249,16 @@ declare class ConfigurationService implements Service {
|
|
|
249
249
|
dispose(): void;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
declare class WorkbenchService implements Service {
|
|
253
|
+
private _activeToolId;
|
|
254
|
+
private eventBus?;
|
|
255
|
+
init(): void;
|
|
256
|
+
dispose(): void;
|
|
257
|
+
setEventBus(bus: EventBus): void;
|
|
258
|
+
get activeToolId(): string | null;
|
|
259
|
+
activate(id: string): void;
|
|
260
|
+
}
|
|
261
|
+
|
|
252
262
|
declare class Pooder {
|
|
253
263
|
readonly eventBus: EventBus;
|
|
254
264
|
private readonly services;
|
|
@@ -264,4 +274,4 @@ declare class Pooder {
|
|
|
264
274
|
getContributions<T>(pointId: string): Contribution<T>[];
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
export { type CommandContribution, CommandService, type ConfigurationContribution, ConfigurationService, type Contribution, type ContributionMetadata, type ContributionPoint, ContributionPointIds, ContributionRegistry, type Extension, type ExtensionContext, ExtensionManager, type ExtensionMetadata, ExtensionRegistry, Pooder, type Service, ServiceRegistry, type ToolContribution, type ViewContribution };
|
|
277
|
+
export { type CommandContribution, CommandService, type ConfigurationContribution, ConfigurationService, type Contribution, type ContributionMetadata, type ContributionPoint, ContributionPointIds, ContributionRegistry, EventBus, type Extension, type ExtensionContext, ExtensionManager, type ExtensionMetadata, ExtensionRegistry, Pooder, type Service, ServiceRegistry, type ToolContribution, type ViewContribution, WorkbenchService };
|
package/dist/index.js
CHANGED
|
@@ -24,10 +24,12 @@ __export(index_exports, {
|
|
|
24
24
|
ConfigurationService: () => ConfigurationService,
|
|
25
25
|
ContributionPointIds: () => ContributionPointIds,
|
|
26
26
|
ContributionRegistry: () => ContributionRegistry,
|
|
27
|
+
EventBus: () => event_default,
|
|
27
28
|
ExtensionManager: () => ExtensionManager,
|
|
28
29
|
ExtensionRegistry: () => ExtensionRegistry,
|
|
29
30
|
Pooder: () => Pooder,
|
|
30
|
-
ServiceRegistry: () => ServiceRegistry
|
|
31
|
+
ServiceRegistry: () => ServiceRegistry,
|
|
32
|
+
WorkbenchService: () => WorkbenchService
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(index_exports);
|
|
33
35
|
|
|
@@ -480,6 +482,30 @@ var ConfigurationService = class {
|
|
|
480
482
|
}
|
|
481
483
|
};
|
|
482
484
|
|
|
485
|
+
// src/services/WorkbenchService.ts
|
|
486
|
+
var WorkbenchService = class {
|
|
487
|
+
constructor() {
|
|
488
|
+
this._activeToolId = null;
|
|
489
|
+
}
|
|
490
|
+
init() {
|
|
491
|
+
}
|
|
492
|
+
dispose() {
|
|
493
|
+
}
|
|
494
|
+
setEventBus(bus) {
|
|
495
|
+
this.eventBus = bus;
|
|
496
|
+
}
|
|
497
|
+
get activeToolId() {
|
|
498
|
+
return this._activeToolId;
|
|
499
|
+
}
|
|
500
|
+
activate(id) {
|
|
501
|
+
var _a;
|
|
502
|
+
if (this._activeToolId === id) return;
|
|
503
|
+
const previous = this._activeToolId;
|
|
504
|
+
this._activeToolId = id;
|
|
505
|
+
(_a = this.eventBus) == null ? void 0 : _a.emit("tool:activated", { id, previous });
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
483
509
|
// src/index.ts
|
|
484
510
|
var Pooder = class {
|
|
485
511
|
constructor() {
|
|
@@ -491,6 +517,9 @@ var Pooder = class {
|
|
|
491
517
|
this.registerService(commandService, "CommandService");
|
|
492
518
|
const configurationService = new ConfigurationService();
|
|
493
519
|
this.registerService(configurationService, "ConfigurationService");
|
|
520
|
+
const workbenchService = new WorkbenchService();
|
|
521
|
+
workbenchService.setEventBus(this.eventBus);
|
|
522
|
+
this.registerService(workbenchService, "WorkbenchService");
|
|
494
523
|
const context = {
|
|
495
524
|
eventBus: this.eventBus,
|
|
496
525
|
services: {
|
|
@@ -579,8 +608,10 @@ var Pooder = class {
|
|
|
579
608
|
ConfigurationService,
|
|
580
609
|
ContributionPointIds,
|
|
581
610
|
ContributionRegistry,
|
|
611
|
+
EventBus,
|
|
582
612
|
ExtensionManager,
|
|
583
613
|
ExtensionRegistry,
|
|
584
614
|
Pooder,
|
|
585
|
-
ServiceRegistry
|
|
615
|
+
ServiceRegistry,
|
|
616
|
+
WorkbenchService
|
|
586
617
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -447,6 +447,30 @@ var ConfigurationService = class {
|
|
|
447
447
|
}
|
|
448
448
|
};
|
|
449
449
|
|
|
450
|
+
// src/services/WorkbenchService.ts
|
|
451
|
+
var WorkbenchService = class {
|
|
452
|
+
constructor() {
|
|
453
|
+
this._activeToolId = null;
|
|
454
|
+
}
|
|
455
|
+
init() {
|
|
456
|
+
}
|
|
457
|
+
dispose() {
|
|
458
|
+
}
|
|
459
|
+
setEventBus(bus) {
|
|
460
|
+
this.eventBus = bus;
|
|
461
|
+
}
|
|
462
|
+
get activeToolId() {
|
|
463
|
+
return this._activeToolId;
|
|
464
|
+
}
|
|
465
|
+
activate(id) {
|
|
466
|
+
var _a;
|
|
467
|
+
if (this._activeToolId === id) return;
|
|
468
|
+
const previous = this._activeToolId;
|
|
469
|
+
this._activeToolId = id;
|
|
470
|
+
(_a = this.eventBus) == null ? void 0 : _a.emit("tool:activated", { id, previous });
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
450
474
|
// src/index.ts
|
|
451
475
|
var Pooder = class {
|
|
452
476
|
constructor() {
|
|
@@ -458,6 +482,9 @@ var Pooder = class {
|
|
|
458
482
|
this.registerService(commandService, "CommandService");
|
|
459
483
|
const configurationService = new ConfigurationService();
|
|
460
484
|
this.registerService(configurationService, "ConfigurationService");
|
|
485
|
+
const workbenchService = new WorkbenchService();
|
|
486
|
+
workbenchService.setEventBus(this.eventBus);
|
|
487
|
+
this.registerService(workbenchService, "WorkbenchService");
|
|
461
488
|
const context = {
|
|
462
489
|
eventBus: this.eventBus,
|
|
463
490
|
services: {
|
|
@@ -545,8 +572,10 @@ export {
|
|
|
545
572
|
ConfigurationService,
|
|
546
573
|
ContributionPointIds,
|
|
547
574
|
ContributionRegistry,
|
|
575
|
+
event_default as EventBus,
|
|
548
576
|
ExtensionManager,
|
|
549
577
|
ExtensionRegistry,
|
|
550
578
|
Pooder,
|
|
551
|
-
ServiceRegistry
|
|
579
|
+
ServiceRegistry,
|
|
580
|
+
WorkbenchService
|
|
552
581
|
};
|
package/package.json
CHANGED
package/src/command.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface CommandArgSchema {}
|
|
2
|
-
|
|
3
|
-
export interface Command {
|
|
4
|
-
id: string;
|
|
5
|
-
handler: (...args: any[]) => any;
|
|
6
|
-
title?: string;
|
|
7
|
-
category?: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
schema?: Record<string, CommandArgSchema>;
|
|
10
|
-
}
|
|
1
|
+
export interface CommandArgSchema {}
|
|
2
|
+
|
|
3
|
+
export interface Command {
|
|
4
|
+
id: string;
|
|
5
|
+
handler: (...args: any[]) => any;
|
|
6
|
+
title?: string;
|
|
7
|
+
category?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
schema?: Record<string, CommandArgSchema>;
|
|
10
|
+
}
|
package/src/context.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import EventBus from "./event";
|
|
2
|
-
import { Contribution } from "./contribution";
|
|
3
|
-
import { Service } from "./service";
|
|
4
|
-
import Disposable from "./disposable";
|
|
5
|
-
|
|
6
|
-
interface ExtensionContext {
|
|
7
|
-
readonly eventBus: EventBus;
|
|
8
|
-
readonly services: {
|
|
9
|
-
get<T extends Service>(serviceName: string): T | undefined;
|
|
10
|
-
};
|
|
11
|
-
readonly contributions: {
|
|
12
|
-
get<T>(pointId: string): Contribution<T>[];
|
|
13
|
-
register<T>(pointId: string, contribution: Contribution<T>): Disposable;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { ExtensionContext };
|
|
1
|
+
import EventBus from "./event";
|
|
2
|
+
import { Contribution } from "./contribution";
|
|
3
|
+
import { Service } from "./service";
|
|
4
|
+
import Disposable from "./disposable";
|
|
5
|
+
|
|
6
|
+
interface ExtensionContext {
|
|
7
|
+
readonly eventBus: EventBus;
|
|
8
|
+
readonly services: {
|
|
9
|
+
get<T extends Service>(serviceName: string): T | undefined;
|
|
10
|
+
};
|
|
11
|
+
readonly contributions: {
|
|
12
|
+
get<T>(pointId: string): Contribution<T>[];
|
|
13
|
+
register<T>(pointId: string, contribution: Contribution<T>): Disposable;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ExtensionContext };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./points";
|
|
2
|
-
export * from "./registry";
|
|
3
|
-
|
|
4
|
-
export interface ContributionMetadata {
|
|
5
|
-
name: string;
|
|
6
|
-
extensionId: string;
|
|
7
|
-
}
|
|
8
|
-
export interface Contribution<T = any> {
|
|
9
|
-
id: string;
|
|
10
|
-
data: T;
|
|
11
|
-
metadata?: Partial<ContributionMetadata>;
|
|
12
|
-
}
|
|
1
|
+
export * from "./points";
|
|
2
|
+
export * from "./registry";
|
|
3
|
+
|
|
4
|
+
export interface ContributionMetadata {
|
|
5
|
+
name: string;
|
|
6
|
+
extensionId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Contribution<T = any> {
|
|
9
|
+
id: string;
|
|
10
|
+
data: T;
|
|
11
|
+
metadata?: Partial<ContributionMetadata>;
|
|
12
|
+
}
|
|
@@ -43,7 +43,14 @@ export interface ViewContribution {
|
|
|
43
43
|
*/
|
|
44
44
|
export interface ConfigurationContribution {
|
|
45
45
|
id: string;
|
|
46
|
-
type:
|
|
46
|
+
type:
|
|
47
|
+
| "string"
|
|
48
|
+
| "number"
|
|
49
|
+
| "boolean"
|
|
50
|
+
| "color"
|
|
51
|
+
| "select"
|
|
52
|
+
| "json"
|
|
53
|
+
| "array";
|
|
47
54
|
label: string;
|
|
48
55
|
default?: any;
|
|
49
56
|
description?: string;
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import { Contribution, ContributionPoint, ContributionPointIds } from "./index";
|
|
2
|
-
import Disposable from "../disposable";
|
|
3
|
-
|
|
4
|
-
export class ContributionRegistry {
|
|
5
|
-
private points: Map<string, ContributionPoint> = new Map();
|
|
6
|
-
private contributions = {
|
|
7
|
-
byId: new Map<string, Contribution>(),
|
|
8
|
-
byPointId: new Map<string, Contribution[]>(),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Register a new contribution point
|
|
13
|
-
*/
|
|
14
|
-
registerPoint<T>(point: ContributionPoint<T>): void {
|
|
15
|
-
if (this.points.has(point.id)) {
|
|
16
|
-
console.warn(
|
|
17
|
-
`Contribution point ${point.id} already exists. Overwriting definitions may cause issues.`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
this.points.set(point.id, point);
|
|
21
|
-
if (!this.contributions.byPointId.has(point.id)) {
|
|
22
|
-
this.contributions.byPointId.set(point.id, []);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Register a contribution to a specific point
|
|
28
|
-
* @returns Disposable to unregister the contribution
|
|
29
|
-
*/
|
|
30
|
-
register<T>(pointId: string, contribution: Contribution<T>): Disposable {
|
|
31
|
-
if (this.contributions.byId.has(contribution.id)) {
|
|
32
|
-
console.warn(
|
|
33
|
-
`Contribution with ID "${contribution.id}" is already registered. Overwriting.`,
|
|
34
|
-
);
|
|
35
|
-
// We could choose to throw, or overwrite. Let's overwrite for now but warn.
|
|
36
|
-
// If we overwrite, we should probably remove the old one from the list first to avoid duplicates.
|
|
37
|
-
this.unregister(pointId, contribution.id);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!this.points.has(pointId)) {
|
|
41
|
-
console.warn(
|
|
42
|
-
`Contribution point ${pointId} does not exist. The contribution ${contribution.id} will be queued but may not be valid.`,
|
|
43
|
-
);
|
|
44
|
-
if (!this.contributions.byPointId.has(pointId)) {
|
|
45
|
-
this.contributions.byPointId.set(pointId, []);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const point = this.points.get(pointId);
|
|
50
|
-
if (point?.validate) {
|
|
51
|
-
try {
|
|
52
|
-
if (!point.validate(contribution.data)) {
|
|
53
|
-
console.error(
|
|
54
|
-
`Contribution ${contribution.id} failed validation for point ${pointId}.`,
|
|
55
|
-
);
|
|
56
|
-
return { dispose: () => {} };
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(
|
|
60
|
-
`Validation error for contribution ${contribution.id}:`,
|
|
61
|
-
e,
|
|
62
|
-
);
|
|
63
|
-
return { dispose: () => {} };
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const arr = this.contributions.byPointId.get(pointId)!;
|
|
68
|
-
|
|
69
|
-
arr.push(contribution);
|
|
70
|
-
this.contributions.byId.set(contribution.id, contribution);
|
|
71
|
-
|
|
72
|
-
// Auto-register if this is a contribution point contribution
|
|
73
|
-
if (pointId === ContributionPointIds.CONTRIBUTIONS) {
|
|
74
|
-
this.registerPoint(contribution.data as ContributionPoint);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
dispose: () => {
|
|
79
|
-
this.unregister(pointId, contribution.id);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get all contributions for a given point
|
|
86
|
-
*/
|
|
87
|
-
get<T>(pointId: string): Contribution<T>[] {
|
|
88
|
-
return Array.from(
|
|
89
|
-
this.contributions.byPointId.get(pointId)?.values() || [],
|
|
90
|
-
) as Contribution<T>[];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get a specific contribution by ID
|
|
95
|
-
*/
|
|
96
|
-
getById<T>(id: string): Contribution<T> | undefined {
|
|
97
|
-
return this.contributions.byId.get(id) as Contribution<T> | undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the contribution point definition
|
|
102
|
-
*/
|
|
103
|
-
getPoint(pointId: string): ContributionPoint | undefined {
|
|
104
|
-
return this.points.get(pointId);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Unregister a contribution
|
|
109
|
-
*/
|
|
110
|
-
private unregister(pointId: string, contributionId: string): void {
|
|
111
|
-
const arr = this.contributions.byPointId.get(pointId);
|
|
112
|
-
arr?.splice(
|
|
113
|
-
arr.findIndex((c) => c.id === contributionId),
|
|
114
|
-
1,
|
|
115
|
-
);
|
|
116
|
-
this.contributions.byId.delete(contributionId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
1
|
+
import { Contribution, ContributionPoint, ContributionPointIds } from "./index";
|
|
2
|
+
import Disposable from "../disposable";
|
|
3
|
+
|
|
4
|
+
export class ContributionRegistry {
|
|
5
|
+
private points: Map<string, ContributionPoint> = new Map();
|
|
6
|
+
private contributions = {
|
|
7
|
+
byId: new Map<string, Contribution>(),
|
|
8
|
+
byPointId: new Map<string, Contribution[]>(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Register a new contribution point
|
|
13
|
+
*/
|
|
14
|
+
registerPoint<T>(point: ContributionPoint<T>): void {
|
|
15
|
+
if (this.points.has(point.id)) {
|
|
16
|
+
console.warn(
|
|
17
|
+
`Contribution point ${point.id} already exists. Overwriting definitions may cause issues.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
this.points.set(point.id, point);
|
|
21
|
+
if (!this.contributions.byPointId.has(point.id)) {
|
|
22
|
+
this.contributions.byPointId.set(point.id, []);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Register a contribution to a specific point
|
|
28
|
+
* @returns Disposable to unregister the contribution
|
|
29
|
+
*/
|
|
30
|
+
register<T>(pointId: string, contribution: Contribution<T>): Disposable {
|
|
31
|
+
if (this.contributions.byId.has(contribution.id)) {
|
|
32
|
+
console.warn(
|
|
33
|
+
`Contribution with ID "${contribution.id}" is already registered. Overwriting.`,
|
|
34
|
+
);
|
|
35
|
+
// We could choose to throw, or overwrite. Let's overwrite for now but warn.
|
|
36
|
+
// If we overwrite, we should probably remove the old one from the list first to avoid duplicates.
|
|
37
|
+
this.unregister(pointId, contribution.id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!this.points.has(pointId)) {
|
|
41
|
+
console.warn(
|
|
42
|
+
`Contribution point ${pointId} does not exist. The contribution ${contribution.id} will be queued but may not be valid.`,
|
|
43
|
+
);
|
|
44
|
+
if (!this.contributions.byPointId.has(pointId)) {
|
|
45
|
+
this.contributions.byPointId.set(pointId, []);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const point = this.points.get(pointId);
|
|
50
|
+
if (point?.validate) {
|
|
51
|
+
try {
|
|
52
|
+
if (!point.validate(contribution.data)) {
|
|
53
|
+
console.error(
|
|
54
|
+
`Contribution ${contribution.id} failed validation for point ${pointId}.`,
|
|
55
|
+
);
|
|
56
|
+
return { dispose: () => {} };
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error(
|
|
60
|
+
`Validation error for contribution ${contribution.id}:`,
|
|
61
|
+
e,
|
|
62
|
+
);
|
|
63
|
+
return { dispose: () => {} };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const arr = this.contributions.byPointId.get(pointId)!;
|
|
68
|
+
|
|
69
|
+
arr.push(contribution);
|
|
70
|
+
this.contributions.byId.set(contribution.id, contribution);
|
|
71
|
+
|
|
72
|
+
// Auto-register if this is a contribution point contribution
|
|
73
|
+
if (pointId === ContributionPointIds.CONTRIBUTIONS) {
|
|
74
|
+
this.registerPoint(contribution.data as ContributionPoint);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
dispose: () => {
|
|
79
|
+
this.unregister(pointId, contribution.id);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get all contributions for a given point
|
|
86
|
+
*/
|
|
87
|
+
get<T>(pointId: string): Contribution<T>[] {
|
|
88
|
+
return Array.from(
|
|
89
|
+
this.contributions.byPointId.get(pointId)?.values() || [],
|
|
90
|
+
) as Contribution<T>[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get a specific contribution by ID
|
|
95
|
+
*/
|
|
96
|
+
getById<T>(id: string): Contribution<T> | undefined {
|
|
97
|
+
return this.contributions.byId.get(id) as Contribution<T> | undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get the contribution point definition
|
|
102
|
+
*/
|
|
103
|
+
getPoint(pointId: string): ContributionPoint | undefined {
|
|
104
|
+
return this.points.get(pointId);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Unregister a contribution
|
|
109
|
+
*/
|
|
110
|
+
private unregister(pointId: string, contributionId: string): void {
|
|
111
|
+
const arr = this.contributions.byPointId.get(pointId);
|
|
112
|
+
arr?.splice(
|
|
113
|
+
arr.findIndex((c) => c.id === contributionId),
|
|
114
|
+
1,
|
|
115
|
+
);
|
|
116
|
+
this.contributions.byId.delete(contributionId);
|
|
117
|
+
}
|
|
118
|
+
}
|
package/src/disposable.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default interface Disposable {
|
|
2
|
-
dispose(): void;
|
|
3
|
-
}
|
|
1
|
+
export default interface Disposable {
|
|
2
|
+
dispose(): void;
|
|
3
|
+
}
|