@pooder/core 2.1.0 → 2.2.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pooder/core
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - service
8
+
3
9
  ## 2.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,15 +1,3 @@
1
- interface Service {
2
- init?(): void;
3
- dispose?(): void;
4
- }
5
- declare class ServiceRegistry {
6
- private services;
7
- register<T extends Service>(name: string, service: T): T;
8
- get<T extends Service>(serviceName: string): T | undefined;
9
- has(serviceName: string): boolean;
10
- delete(serviceName: string): void;
11
- }
12
-
13
1
  type EventHandler = (...args: any[]) => void | boolean;
14
2
  declare class EventBus {
15
3
  private events;
@@ -20,6 +8,52 @@ declare class EventBus {
20
8
  count(event: string): number;
21
9
  }
22
10
 
11
+ interface Service {
12
+ init?(context: ServiceContext): void | Promise<void>;
13
+ dispose?(context: ServiceContext): void | Promise<void>;
14
+ }
15
+ interface ServiceToken<T extends Service = Service> {
16
+ readonly kind: "service-token";
17
+ readonly key: symbol;
18
+ readonly name: string;
19
+ }
20
+ type ServiceIdentifier<T extends Service = Service> = string | ServiceToken<T>;
21
+ interface ServiceContext {
22
+ readonly eventBus: EventBus;
23
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
24
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
25
+ has(identifier: ServiceIdentifier<Service>): boolean;
26
+ }
27
+ interface RegisterServiceOptions {
28
+ allowOverride?: boolean;
29
+ }
30
+ interface RegisteredService<T extends Service = Service> {
31
+ readonly id: string;
32
+ readonly token?: ServiceToken<T>;
33
+ readonly service: T;
34
+ }
35
+ declare function createServiceToken<T extends Service = Service>(name: string): ServiceToken<T>;
36
+ declare function isServiceToken<T extends Service = Service>(identifier: unknown): identifier is ServiceToken<T>;
37
+ declare class ServiceRegistry {
38
+ private readonly servicesByName;
39
+ private readonly servicesByToken;
40
+ private readonly registrationOrder;
41
+ register<T extends Service>(identifier: ServiceIdentifier<T>, service: T, options?: RegisterServiceOptions): T;
42
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
43
+ get<T extends Service>(identifier: ServiceToken<T>): T | undefined;
44
+ get<T extends Service>(identifier: string): T | undefined;
45
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
46
+ getOrThrow<T extends Service>(identifier: ServiceToken<T>, errorMessage?: string): T;
47
+ getOrThrow<T extends Service>(identifier: string, errorMessage?: string): T;
48
+ has(identifier: ServiceIdentifier<Service>): boolean;
49
+ delete(identifier: ServiceIdentifier<Service>): boolean;
50
+ list(): RegisteredService[];
51
+ clear(): void;
52
+ private findEntry;
53
+ private normalizeIdentifier;
54
+ private removeEntry;
55
+ }
56
+
23
57
  interface ContributionPoint<T = any> {
24
58
  id: string;
25
59
  description?: string;
@@ -146,7 +180,9 @@ interface Contribution<T = any> {
146
180
  interface ExtensionContext {
147
181
  readonly eventBus: EventBus;
148
182
  readonly services: {
149
- get<T extends Service>(serviceName: string): T | undefined;
183
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
184
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
185
+ has(identifier: ServiceIdentifier<Service>): boolean;
150
186
  };
151
187
  readonly contributions: {
152
188
  get<T>(pointId: string): Contribution<T>[];
@@ -293,10 +329,16 @@ interface LeaveResult {
293
329
  decision: LeaveDecision;
294
330
  reason?: string;
295
331
  }
332
+ interface ToolSessionServiceDependencies {
333
+ commandService?: CommandService;
334
+ toolRegistry?: ToolRegistryService;
335
+ }
296
336
  declare class ToolSessionService implements Service {
297
337
  private readonly sessions;
298
338
  private commandService?;
299
339
  private toolRegistry?;
340
+ constructor(dependencies?: ToolSessionServiceDependencies);
341
+ init(context: ServiceContext): void;
300
342
  setCommandService(commandService: CommandService): void;
301
343
  setToolRegistry(toolRegistry: ToolRegistryService): void;
302
344
  registerDirtyTracker(toolId: string, callback: () => boolean): Disposable;
@@ -307,6 +349,8 @@ declare class ToolSessionService implements Service {
307
349
  markDirty(toolId: string, dirty?: boolean): void;
308
350
  private resolveTool;
309
351
  private runCommand;
352
+ private getCommandService;
353
+ private getToolRegistry;
310
354
  begin(toolId: string): Promise<void>;
311
355
  validate(toolId: string): Promise<{
312
356
  ok: boolean;
@@ -334,13 +378,19 @@ interface ToolSwitchResult {
334
378
  reason?: string;
335
379
  }
336
380
  type ToolSwitchGuard = (context: ToolSwitchContext) => boolean | Promise<boolean>;
381
+ interface WorkbenchServiceDependencies {
382
+ eventBus?: EventBus;
383
+ toolRegistry?: ToolRegistryService;
384
+ sessionService?: ToolSessionService;
385
+ }
337
386
  declare class WorkbenchService implements Service {
338
387
  private _activeToolId;
339
388
  private eventBus?;
340
389
  private toolRegistry?;
341
390
  private sessionService?;
342
391
  private guards;
343
- init(): void;
392
+ constructor(dependencies?: WorkbenchServiceDependencies);
393
+ init(context: ServiceContext): void;
344
394
  dispose(): void;
345
395
  setEventBus(bus: EventBus): void;
346
396
  setToolRegistry(toolRegistry: ToolRegistryService): void;
@@ -353,21 +403,50 @@ declare class WorkbenchService implements Service {
353
403
  }): Promise<ToolSwitchResult>;
354
404
  activate(id: string | null): Promise<ToolSwitchResult>;
355
405
  deactivate(): Promise<ToolSwitchResult>;
406
+ private getEventBus;
407
+ private getToolRegistry;
408
+ private getSessionService;
356
409
  }
357
410
 
411
+ declare const COMMAND_SERVICE: ServiceToken<CommandService>;
412
+ declare const CONFIGURATION_SERVICE: ServiceToken<ConfigurationService>;
413
+ declare const TOOL_REGISTRY_SERVICE: ServiceToken<ToolRegistryService>;
414
+ declare const TOOL_SESSION_SERVICE: ServiceToken<ToolSessionService>;
415
+ declare const WORKBENCH_SERVICE: ServiceToken<WorkbenchService>;
416
+ declare const CORE_SERVICE_TOKENS: {
417
+ readonly COMMAND: ServiceToken<CommandService>;
418
+ readonly CONFIGURATION: ServiceToken<ConfigurationService>;
419
+ readonly TOOL_REGISTRY: ServiceToken<ToolRegistryService>;
420
+ readonly TOOL_SESSION: ServiceToken<ToolSessionService>;
421
+ readonly WORKBENCH: ServiceToken<WorkbenchService>;
422
+ };
423
+
358
424
  declare class Pooder {
359
425
  readonly eventBus: EventBus;
360
426
  private readonly services;
427
+ private readonly serviceContext;
361
428
  private readonly contributions;
362
429
  readonly extensionManager: ExtensionManager;
363
430
  constructor();
364
431
  private initDefaultContributionPoints;
365
- registerService(service: Service, id?: string): boolean;
366
- unregisterService(service: Service, id?: string): boolean;
367
- getService<T extends Service>(id: string): T | undefined;
432
+ registerService<T extends Service>(service: T, identifier?: ServiceIdentifier<T>, options?: RegisterServiceOptions): boolean;
433
+ registerServiceAsync<T extends Service>(service: T, identifier?: ServiceIdentifier<T>, options?: RegisterServiceOptions): Promise<boolean>;
434
+ unregisterService(service: Service, id?: ServiceIdentifier<Service>): boolean;
435
+ unregisterService(identifier: ServiceIdentifier<Service>): boolean;
436
+ unregisterServiceAsync(serviceOrIdentifier: Service | ServiceIdentifier<Service>, id?: ServiceIdentifier<Service>): Promise<boolean>;
437
+ getService<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
438
+ getServiceOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
439
+ hasService(identifier: ServiceIdentifier<Service>): boolean;
440
+ dispose(): Promise<void>;
368
441
  registerContributionPoint<T>(point: ContributionPoint<T>): void;
369
442
  registerContribution<T>(pointId: string, contribution: Contribution<T>): Disposable;
370
443
  getContributions<T>(pointId: string): Contribution<T>[];
444
+ private resolveServiceIdentifier;
445
+ private resolveUnregisterIdentifier;
446
+ private getServiceLabel;
447
+ private invokeServiceHook;
448
+ private invokeServiceHookAsync;
449
+ private isPromiseLike;
371
450
  }
372
451
 
373
- 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 ToolCommandBindings, type ToolContribution, type ToolInteraction, ToolRegistryService, type ToolSessionLeavePolicy, ToolSessionService, type ViewContribution, WorkbenchService };
452
+ export { COMMAND_SERVICE, CONFIGURATION_SERVICE, CORE_SERVICE_TOKENS, 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 RegisterServiceOptions, type RegisteredService, type Service, type ServiceContext, type ServiceIdentifier, ServiceRegistry, type ServiceToken, TOOL_REGISTRY_SERVICE, TOOL_SESSION_SERVICE, type ToolCommandBindings, type ToolContribution, type ToolInteraction, ToolRegistryService, type ToolSessionLeavePolicy, ToolSessionService, type ViewContribution, WORKBENCH_SERVICE, WorkbenchService, createServiceToken, isServiceToken };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,3 @@
1
- interface Service {
2
- init?(): void;
3
- dispose?(): void;
4
- }
5
- declare class ServiceRegistry {
6
- private services;
7
- register<T extends Service>(name: string, service: T): T;
8
- get<T extends Service>(serviceName: string): T | undefined;
9
- has(serviceName: string): boolean;
10
- delete(serviceName: string): void;
11
- }
12
-
13
1
  type EventHandler = (...args: any[]) => void | boolean;
14
2
  declare class EventBus {
15
3
  private events;
@@ -20,6 +8,52 @@ declare class EventBus {
20
8
  count(event: string): number;
21
9
  }
22
10
 
11
+ interface Service {
12
+ init?(context: ServiceContext): void | Promise<void>;
13
+ dispose?(context: ServiceContext): void | Promise<void>;
14
+ }
15
+ interface ServiceToken<T extends Service = Service> {
16
+ readonly kind: "service-token";
17
+ readonly key: symbol;
18
+ readonly name: string;
19
+ }
20
+ type ServiceIdentifier<T extends Service = Service> = string | ServiceToken<T>;
21
+ interface ServiceContext {
22
+ readonly eventBus: EventBus;
23
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
24
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
25
+ has(identifier: ServiceIdentifier<Service>): boolean;
26
+ }
27
+ interface RegisterServiceOptions {
28
+ allowOverride?: boolean;
29
+ }
30
+ interface RegisteredService<T extends Service = Service> {
31
+ readonly id: string;
32
+ readonly token?: ServiceToken<T>;
33
+ readonly service: T;
34
+ }
35
+ declare function createServiceToken<T extends Service = Service>(name: string): ServiceToken<T>;
36
+ declare function isServiceToken<T extends Service = Service>(identifier: unknown): identifier is ServiceToken<T>;
37
+ declare class ServiceRegistry {
38
+ private readonly servicesByName;
39
+ private readonly servicesByToken;
40
+ private readonly registrationOrder;
41
+ register<T extends Service>(identifier: ServiceIdentifier<T>, service: T, options?: RegisterServiceOptions): T;
42
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
43
+ get<T extends Service>(identifier: ServiceToken<T>): T | undefined;
44
+ get<T extends Service>(identifier: string): T | undefined;
45
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
46
+ getOrThrow<T extends Service>(identifier: ServiceToken<T>, errorMessage?: string): T;
47
+ getOrThrow<T extends Service>(identifier: string, errorMessage?: string): T;
48
+ has(identifier: ServiceIdentifier<Service>): boolean;
49
+ delete(identifier: ServiceIdentifier<Service>): boolean;
50
+ list(): RegisteredService[];
51
+ clear(): void;
52
+ private findEntry;
53
+ private normalizeIdentifier;
54
+ private removeEntry;
55
+ }
56
+
23
57
  interface ContributionPoint<T = any> {
24
58
  id: string;
25
59
  description?: string;
@@ -146,7 +180,9 @@ interface Contribution<T = any> {
146
180
  interface ExtensionContext {
147
181
  readonly eventBus: EventBus;
148
182
  readonly services: {
149
- get<T extends Service>(serviceName: string): T | undefined;
183
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
184
+ getOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
185
+ has(identifier: ServiceIdentifier<Service>): boolean;
150
186
  };
151
187
  readonly contributions: {
152
188
  get<T>(pointId: string): Contribution<T>[];
@@ -293,10 +329,16 @@ interface LeaveResult {
293
329
  decision: LeaveDecision;
294
330
  reason?: string;
295
331
  }
332
+ interface ToolSessionServiceDependencies {
333
+ commandService?: CommandService;
334
+ toolRegistry?: ToolRegistryService;
335
+ }
296
336
  declare class ToolSessionService implements Service {
297
337
  private readonly sessions;
298
338
  private commandService?;
299
339
  private toolRegistry?;
340
+ constructor(dependencies?: ToolSessionServiceDependencies);
341
+ init(context: ServiceContext): void;
300
342
  setCommandService(commandService: CommandService): void;
301
343
  setToolRegistry(toolRegistry: ToolRegistryService): void;
302
344
  registerDirtyTracker(toolId: string, callback: () => boolean): Disposable;
@@ -307,6 +349,8 @@ declare class ToolSessionService implements Service {
307
349
  markDirty(toolId: string, dirty?: boolean): void;
308
350
  private resolveTool;
309
351
  private runCommand;
352
+ private getCommandService;
353
+ private getToolRegistry;
310
354
  begin(toolId: string): Promise<void>;
311
355
  validate(toolId: string): Promise<{
312
356
  ok: boolean;
@@ -334,13 +378,19 @@ interface ToolSwitchResult {
334
378
  reason?: string;
335
379
  }
336
380
  type ToolSwitchGuard = (context: ToolSwitchContext) => boolean | Promise<boolean>;
381
+ interface WorkbenchServiceDependencies {
382
+ eventBus?: EventBus;
383
+ toolRegistry?: ToolRegistryService;
384
+ sessionService?: ToolSessionService;
385
+ }
337
386
  declare class WorkbenchService implements Service {
338
387
  private _activeToolId;
339
388
  private eventBus?;
340
389
  private toolRegistry?;
341
390
  private sessionService?;
342
391
  private guards;
343
- init(): void;
392
+ constructor(dependencies?: WorkbenchServiceDependencies);
393
+ init(context: ServiceContext): void;
344
394
  dispose(): void;
345
395
  setEventBus(bus: EventBus): void;
346
396
  setToolRegistry(toolRegistry: ToolRegistryService): void;
@@ -353,21 +403,50 @@ declare class WorkbenchService implements Service {
353
403
  }): Promise<ToolSwitchResult>;
354
404
  activate(id: string | null): Promise<ToolSwitchResult>;
355
405
  deactivate(): Promise<ToolSwitchResult>;
406
+ private getEventBus;
407
+ private getToolRegistry;
408
+ private getSessionService;
356
409
  }
357
410
 
411
+ declare const COMMAND_SERVICE: ServiceToken<CommandService>;
412
+ declare const CONFIGURATION_SERVICE: ServiceToken<ConfigurationService>;
413
+ declare const TOOL_REGISTRY_SERVICE: ServiceToken<ToolRegistryService>;
414
+ declare const TOOL_SESSION_SERVICE: ServiceToken<ToolSessionService>;
415
+ declare const WORKBENCH_SERVICE: ServiceToken<WorkbenchService>;
416
+ declare const CORE_SERVICE_TOKENS: {
417
+ readonly COMMAND: ServiceToken<CommandService>;
418
+ readonly CONFIGURATION: ServiceToken<ConfigurationService>;
419
+ readonly TOOL_REGISTRY: ServiceToken<ToolRegistryService>;
420
+ readonly TOOL_SESSION: ServiceToken<ToolSessionService>;
421
+ readonly WORKBENCH: ServiceToken<WorkbenchService>;
422
+ };
423
+
358
424
  declare class Pooder {
359
425
  readonly eventBus: EventBus;
360
426
  private readonly services;
427
+ private readonly serviceContext;
361
428
  private readonly contributions;
362
429
  readonly extensionManager: ExtensionManager;
363
430
  constructor();
364
431
  private initDefaultContributionPoints;
365
- registerService(service: Service, id?: string): boolean;
366
- unregisterService(service: Service, id?: string): boolean;
367
- getService<T extends Service>(id: string): T | undefined;
432
+ registerService<T extends Service>(service: T, identifier?: ServiceIdentifier<T>, options?: RegisterServiceOptions): boolean;
433
+ registerServiceAsync<T extends Service>(service: T, identifier?: ServiceIdentifier<T>, options?: RegisterServiceOptions): Promise<boolean>;
434
+ unregisterService(service: Service, id?: ServiceIdentifier<Service>): boolean;
435
+ unregisterService(identifier: ServiceIdentifier<Service>): boolean;
436
+ unregisterServiceAsync(serviceOrIdentifier: Service | ServiceIdentifier<Service>, id?: ServiceIdentifier<Service>): Promise<boolean>;
437
+ getService<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
438
+ getServiceOrThrow<T extends Service>(identifier: ServiceIdentifier<T>, errorMessage?: string): T;
439
+ hasService(identifier: ServiceIdentifier<Service>): boolean;
440
+ dispose(): Promise<void>;
368
441
  registerContributionPoint<T>(point: ContributionPoint<T>): void;
369
442
  registerContribution<T>(pointId: string, contribution: Contribution<T>): Disposable;
370
443
  getContributions<T>(pointId: string): Contribution<T>[];
444
+ private resolveServiceIdentifier;
445
+ private resolveUnregisterIdentifier;
446
+ private getServiceLabel;
447
+ private invokeServiceHook;
448
+ private invokeServiceHookAsync;
449
+ private isPromiseLike;
371
450
  }
372
451
 
373
- 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 ToolCommandBindings, type ToolContribution, type ToolInteraction, ToolRegistryService, type ToolSessionLeavePolicy, ToolSessionService, type ViewContribution, WorkbenchService };
452
+ export { COMMAND_SERVICE, CONFIGURATION_SERVICE, CORE_SERVICE_TOKENS, 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 RegisterServiceOptions, type RegisteredService, type Service, type ServiceContext, type ServiceIdentifier, ServiceRegistry, type ServiceToken, TOOL_REGISTRY_SERVICE, TOOL_SESSION_SERVICE, type ToolCommandBindings, type ToolContribution, type ToolInteraction, ToolRegistryService, type ToolSessionLeavePolicy, ToolSessionService, type ViewContribution, WORKBENCH_SERVICE, WorkbenchService, createServiceToken, isServiceToken };