@backstage/backend-plugin-api 0.0.0-nightly-20230109022518 → 0.0.0-nightly-20230111022819

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,6 +1,6 @@
1
1
  # @backstage/backend-plugin-api
2
2
 
3
- ## 0.0.0-nightly-20230109022518
3
+ ## 0.0.0-nightly-20230111022819
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -8,17 +8,38 @@
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - 6cfd4d7073: Added `RootLifecycleService` and `rootLifecycleServiceRef`, as well as added a `labels` option to the existing `LifecycleServiceShutdownHook`.
11
+ - 6cfd4d7073: Added `RootLifecycleService` and `rootLifecycleServiceRef`, as well as added a `logger` option to the existing `LifecycleServiceShutdownHook`.
12
+ - ecc6bfe4c9: Added `ServiceFactoryOrFunction` type, for use when either a `ServiceFactory` or `() => ServiceFactory` can be used.
12
13
  - 02b119ff93: Added a new `rootHttpRouterServiceRef` and `RootHttpRouterService` interface.
13
14
  - 5e2cebe9a3: Migrate `UrlReader` into this package to gradually remove the dependency on backend-common.
14
15
  - 5437fe488f: Migrated types related to `TokenManagerService`, `CacheService` and `DatabaseService` into backend-plugin-api.
15
16
  - 6f02d23b01: Moved `PluginEndpointDiscovery` type from backend-common to backend-plugin-api.
16
17
  - 16054afdec: Documented `coreServices` an all of its members.
18
+ - 62b04bb865: Updates all `create*` methods to simplify their type definitions and ensure they all have configuration interfaces.
19
+ - Updated dependencies
20
+ - @backstage/backend-tasks@0.0.0-nightly-20230111022819
21
+ - @backstage/config@0.0.0-nightly-20230111022819
22
+ - @backstage/types@1.0.2
23
+ - @backstage/plugin-permission-common@0.0.0-nightly-20230111022819
24
+
25
+ ## 0.3.0-next.1
26
+
27
+ ### Minor Changes
28
+
29
+ - 8e06f3cf00: Moved `loggerToWinstonLogger` to `@backstage/backend-common`.
30
+
31
+ ### Patch Changes
32
+
33
+ - ecc6bfe4c9: Added `ServiceFactoryOrFunction` type, for use when either a `ServiceFactory` or `() => ServiceFactory` can be used.
34
+ - 02b119ff93: Added a new `rootHttpRouterServiceRef` and `RootHttpRouterService` interface.
35
+ - 5437fe488f: Migrated types related to `TokenManagerService`, `CacheService` and `DatabaseService` into backend-plugin-api.
36
+ - 16054afdec: Documented `coreServices` an all of its members.
37
+ - 62b04bb865: Updates all `create*` methods to simplify their type definitions and ensure they all have configuration interfaces.
17
38
  - Updated dependencies
18
- - @backstage/config@0.0.0-nightly-20230109022518
19
- - @backstage/backend-tasks@0.0.0-nightly-20230109022518
39
+ - @backstage/backend-tasks@0.4.1-next.1
40
+ - @backstage/config@1.0.6-next.0
20
41
  - @backstage/types@1.0.2
21
- - @backstage/plugin-permission-common@0.0.0-nightly-20230109022518
42
+ - @backstage/plugin-permission-common@0.7.3-next.0
22
43
 
23
44
  ## 0.2.1-next.0
24
45
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-plugin-api",
3
- "version": "0.0.0-nightly-20230109022518",
3
+ "version": "0.0.0-nightly-20230111022819",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -220,9 +220,11 @@ export declare namespace coreServices {
220
220
  }
221
221
 
222
222
  /**
223
+ * Creates a new backend module for a given plugin.
224
+ *
223
225
  * @public
224
226
  *
225
- * Creates a new backend module for a given plugin.
227
+ * @remarks
226
228
  *
227
229
  * The `moduleId` should be equal to the module-specific prefix of the exported name, such
228
230
  * that the full name is `moduleId + PluginId + "Module"`. For example, a GitHub entity
@@ -231,47 +233,38 @@ export declare namespace coreServices {
231
233
  *
232
234
  * The `pluginId` should exactly match the `id` of the plugin that the module extends.
233
235
  */
234
- export declare function createBackendModule<TOptions extends object | undefined = undefined>(config: BackendModuleConfig<TOptions>): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
236
+ export declare function createBackendModule<TOptions extends MaybeOptions = undefined>(config: BackendModuleConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
235
237
 
236
238
  /** @public */
237
- export declare function createBackendPlugin<TOptions extends object | undefined = undefined>(config: {
238
- id: string;
239
- register(reg: BackendRegistrationPoints, options: TOptions): void;
240
- }): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
239
+ export declare function createBackendPlugin<TOptions extends MaybeOptions = undefined>(config: BackendPluginConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
241
240
 
242
241
  /** @public */
243
- export declare function createExtensionPoint<T>(options: {
244
- id: string;
245
- }): ExtensionPoint<T>;
242
+ export declare function createExtensionPoint<T>(config: ExtensionPointConfig): ExtensionPoint<T>;
246
243
 
247
244
  /**
248
245
  * @public
249
246
  */
250
247
  export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
251
248
  [name in string]: ServiceRef<unknown>;
252
- }, TOpts extends object | undefined = undefined>(config: {
253
- service: ServiceRef<TService, TScope>;
254
- deps: TDeps;
255
- factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
256
- }): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
249
+ }, TOpts extends MaybeOptions = undefined>(config: ServiceFactoryConfig<TService, TScope, TImpl, TDeps, TOpts>): FactoryFunctionWithOptions<ServiceFactory<TService>, TOpts>;
257
250
 
258
- /** @public */
259
- export declare function createServiceRef<T>(options: {
260
- id: string;
261
- scope?: 'plugin';
262
- defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
263
- }): ServiceRef<T, 'plugin'>;
251
+ /**
252
+ * Creates a new service definition. This overload is used to create plugin scoped services.
253
+ *
254
+ * @public
255
+ */
256
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'plugin'>): ServiceRef<TService, 'plugin'>;
264
257
 
265
- /** @public */
266
- export declare function createServiceRef<T>(options: {
267
- id: string;
268
- scope: 'root';
269
- defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
270
- }): ServiceRef<T, 'root'>;
258
+ /**
259
+ * Creates a new service definition. This overload is used to create root scoped services.
260
+ *
261
+ * @public
262
+ */
263
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'root'>): ServiceRef<TService, 'root'>;
271
264
 
272
265
  /**
273
266
  * The DatabaseService manages access to databases that Plugins get.
274
- *gs
267
+ *
275
268
  * @public
276
269
  */
277
270
  export declare interface DatabaseService {
@@ -358,6 +351,18 @@ export declare type ExtensionPoint<T> = {
358
351
  $$ref: 'extension-point';
359
352
  };
360
353
 
354
+ /** @public */
355
+ export declare interface ExtensionPointConfig {
356
+ id: string;
357
+ }
358
+
359
+ /**
360
+ * Helper type that makes the options argument optional if options are not required.
361
+ *
362
+ * @ignore
363
+ */
364
+ declare type FactoryFunctionWithOptions<TResult, TOptions> = undefined extends TOptions ? (options?: TOptions) => TResult : (options: TOptions) => TResult;
365
+
361
366
  /**
362
367
  * @public
363
368
  */
@@ -380,8 +385,10 @@ export declare interface LifecycleService {
380
385
  **/
381
386
  export declare type LifecycleServiceShutdownHook = {
382
387
  fn: () => void | Promise<void>;
383
- /** Labels to help identify the shutdown hook */
384
- labels?: Record<string, string>;
388
+ /**
389
+ * Optional {@link LoggerService} that will be used for logging instead of the default logger.
390
+ */
391
+ logger?: LoggerService;
385
392
  };
386
393
 
387
394
  /**
@@ -404,6 +411,13 @@ export declare type LogMeta = {
404
411
  [name: string]: unknown;
405
412
  };
406
413
 
414
+ /**
415
+ * Base type for options objects that aren't required.
416
+ *
417
+ * @ignore
418
+ */
419
+ declare type MaybeOptions = object | undefined;
420
+
407
421
  /** @public */
408
422
  export declare interface PermissionsService extends PermissionEvaluator {
409
423
  }
@@ -694,6 +708,22 @@ export declare type ServiceFactory<TService = unknown> = {
694
708
  }) => Promise<TService>>;
695
709
  };
696
710
 
711
+ /** @public */
712
+ export declare interface ServiceFactoryConfig<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
713
+ [name in string]: ServiceRef<unknown>;
714
+ }, TOpts extends MaybeOptions = undefined> {
715
+ service: ServiceRef<TService, TScope>;
716
+ deps: TDeps;
717
+ factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
718
+ }
719
+
720
+ /**
721
+ * Represents either a {@link ServiceFactory} or a function that returns one.
722
+ *
723
+ * @public
724
+ */
725
+ export declare type ServiceFactoryOrFunction<TService = unknown> = ServiceFactory<TService> | (() => ServiceFactory<TService>);
726
+
697
727
  /**
698
728
  * TODO
699
729
  *
@@ -720,6 +750,13 @@ export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'roo
720
750
  $$ref: 'service';
721
751
  };
722
752
 
753
+ /** @public */
754
+ export declare interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
755
+ id: string;
756
+ scope?: TScope;
757
+ defaultFactory?: (service: ServiceRef<TService, TScope>) => Promise<ServiceFactoryOrFunction<TService>>;
758
+ }
759
+
723
760
  /** @ignore */
724
761
  declare type ServiceRefsToInstances<T extends {
725
762
  [key in string]: ServiceRef<unknown>;
@@ -220,9 +220,11 @@ export declare namespace coreServices {
220
220
  }
221
221
 
222
222
  /**
223
+ * Creates a new backend module for a given plugin.
224
+ *
223
225
  * @public
224
226
  *
225
- * Creates a new backend module for a given plugin.
227
+ * @remarks
226
228
  *
227
229
  * The `moduleId` should be equal to the module-specific prefix of the exported name, such
228
230
  * that the full name is `moduleId + PluginId + "Module"`. For example, a GitHub entity
@@ -231,47 +233,38 @@ export declare namespace coreServices {
231
233
  *
232
234
  * The `pluginId` should exactly match the `id` of the plugin that the module extends.
233
235
  */
234
- export declare function createBackendModule<TOptions extends object | undefined = undefined>(config: BackendModuleConfig<TOptions>): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
236
+ export declare function createBackendModule<TOptions extends MaybeOptions = undefined>(config: BackendModuleConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
235
237
 
236
238
  /** @public */
237
- export declare function createBackendPlugin<TOptions extends object | undefined = undefined>(config: {
238
- id: string;
239
- register(reg: BackendRegistrationPoints, options: TOptions): void;
240
- }): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
239
+ export declare function createBackendPlugin<TOptions extends MaybeOptions = undefined>(config: BackendPluginConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
241
240
 
242
241
  /** @public */
243
- export declare function createExtensionPoint<T>(options: {
244
- id: string;
245
- }): ExtensionPoint<T>;
242
+ export declare function createExtensionPoint<T>(config: ExtensionPointConfig): ExtensionPoint<T>;
246
243
 
247
244
  /**
248
245
  * @public
249
246
  */
250
247
  export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
251
248
  [name in string]: ServiceRef<unknown>;
252
- }, TOpts extends object | undefined = undefined>(config: {
253
- service: ServiceRef<TService, TScope>;
254
- deps: TDeps;
255
- factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
256
- }): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
249
+ }, TOpts extends MaybeOptions = undefined>(config: ServiceFactoryConfig<TService, TScope, TImpl, TDeps, TOpts>): FactoryFunctionWithOptions<ServiceFactory<TService>, TOpts>;
257
250
 
258
- /** @public */
259
- export declare function createServiceRef<T>(options: {
260
- id: string;
261
- scope?: 'plugin';
262
- defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
263
- }): ServiceRef<T, 'plugin'>;
251
+ /**
252
+ * Creates a new service definition. This overload is used to create plugin scoped services.
253
+ *
254
+ * @public
255
+ */
256
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'plugin'>): ServiceRef<TService, 'plugin'>;
264
257
 
265
- /** @public */
266
- export declare function createServiceRef<T>(options: {
267
- id: string;
268
- scope: 'root';
269
- defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
270
- }): ServiceRef<T, 'root'>;
258
+ /**
259
+ * Creates a new service definition. This overload is used to create root scoped services.
260
+ *
261
+ * @public
262
+ */
263
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'root'>): ServiceRef<TService, 'root'>;
271
264
 
272
265
  /**
273
266
  * The DatabaseService manages access to databases that Plugins get.
274
- *gs
267
+ *
275
268
  * @public
276
269
  */
277
270
  export declare interface DatabaseService {
@@ -358,6 +351,18 @@ export declare type ExtensionPoint<T> = {
358
351
  $$ref: 'extension-point';
359
352
  };
360
353
 
354
+ /** @public */
355
+ export declare interface ExtensionPointConfig {
356
+ id: string;
357
+ }
358
+
359
+ /**
360
+ * Helper type that makes the options argument optional if options are not required.
361
+ *
362
+ * @ignore
363
+ */
364
+ declare type FactoryFunctionWithOptions<TResult, TOptions> = undefined extends TOptions ? (options?: TOptions) => TResult : (options: TOptions) => TResult;
365
+
361
366
  /**
362
367
  * @public
363
368
  */
@@ -380,8 +385,10 @@ export declare interface LifecycleService {
380
385
  **/
381
386
  export declare type LifecycleServiceShutdownHook = {
382
387
  fn: () => void | Promise<void>;
383
- /** Labels to help identify the shutdown hook */
384
- labels?: Record<string, string>;
388
+ /**
389
+ * Optional {@link LoggerService} that will be used for logging instead of the default logger.
390
+ */
391
+ logger?: LoggerService;
385
392
  };
386
393
 
387
394
  /**
@@ -404,6 +411,13 @@ export declare type LogMeta = {
404
411
  [name: string]: unknown;
405
412
  };
406
413
 
414
+ /**
415
+ * Base type for options objects that aren't required.
416
+ *
417
+ * @ignore
418
+ */
419
+ declare type MaybeOptions = object | undefined;
420
+
407
421
  /** @public */
408
422
  export declare interface PermissionsService extends PermissionEvaluator {
409
423
  }
@@ -694,6 +708,22 @@ export declare type ServiceFactory<TService = unknown> = {
694
708
  }) => Promise<TService>>;
695
709
  };
696
710
 
711
+ /** @public */
712
+ export declare interface ServiceFactoryConfig<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
713
+ [name in string]: ServiceRef<unknown>;
714
+ }, TOpts extends MaybeOptions = undefined> {
715
+ service: ServiceRef<TService, TScope>;
716
+ deps: TDeps;
717
+ factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
718
+ }
719
+
720
+ /**
721
+ * Represents either a {@link ServiceFactory} or a function that returns one.
722
+ *
723
+ * @public
724
+ */
725
+ export declare type ServiceFactoryOrFunction<TService = unknown> = ServiceFactory<TService> | (() => ServiceFactory<TService>);
726
+
697
727
  /**
698
728
  * TODO
699
729
  *
@@ -720,6 +750,13 @@ export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'roo
720
750
  $$ref: 'service';
721
751
  };
722
752
 
753
+ /** @public */
754
+ export declare interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
755
+ id: string;
756
+ scope?: TScope;
757
+ defaultFactory?: (service: ServiceRef<TService, TScope>) => Promise<ServiceFactoryOrFunction<TService>>;
758
+ }
759
+
723
760
  /** @ignore */
724
761
  declare type ServiceRefsToInstances<T extends {
725
762
  [key in string]: ServiceRef<unknown>;
package/dist/index.cjs.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function createServiceRef(options) {
6
- const { id, scope = "plugin", defaultFactory } = options;
5
+ function createServiceRef(config) {
6
+ const { id, scope = "plugin", defaultFactory } = config;
7
7
  return {
8
8
  id,
9
9
  scope,
@@ -11,7 +11,7 @@ function createServiceRef(options) {
11
11
  throw new Error(`tried to read ServiceRef.T of ${this}`);
12
12
  },
13
13
  toString() {
14
- return `serviceRef{${options.id}}`;
14
+ return `serviceRef{${config.id}}`;
15
15
  },
16
16
  $$ref: "service",
17
17
  // TODO: declare
@@ -50,14 +50,14 @@ exports.coreServices = void 0;
50
50
  coreServices2.urlReader = createServiceRef({ id: "core.urlReader" });
51
51
  })(exports.coreServices || (exports.coreServices = {}));
52
52
 
53
- function createExtensionPoint(options) {
53
+ function createExtensionPoint(config) {
54
54
  return {
55
- id: options.id,
55
+ id: config.id,
56
56
  get T() {
57
57
  throw new Error(`tried to read ExtensionPoint.T of ${this}`);
58
58
  },
59
59
  toString() {
60
- return `extensionPoint{${options.id}}`;
60
+ return `extensionPoint{${config.id}}`;
61
61
  },
62
62
  $$ref: "extension-point"
63
63
  // TODO: declare
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/coreServices.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin';\n defaultFactory?: (\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'plugin'>;\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope: 'root';\n defaultFactory?: (\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'root'>;\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin' | 'root';\n defaultFactory?:\n | ((\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>)\n | ((\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>);\n}): ServiceRef<T> {\n const { id, scope = 'plugin', defaultFactory } = options;\n return {\n id,\n scope,\n get T(): T {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${options.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<T, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<T>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends object | undefined = undefined,\n>(config: {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}): undefined extends TOpts\n ? (options?: TOpts) => ServiceFactory<TService>\n : (options: TOpts) => ServiceFactory<TService> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system';\n\n/**\n * All core services references\n *\n * @public\n */\nexport namespace coreServices {\n /**\n * The service reference for the plugin scoped {@link CacheService}.\n *\n * @public\n */\n export const cache = createServiceRef<import('./CacheService').CacheService>({\n id: 'core.cache',\n });\n\n /**\n * The service reference for the root scoped {@link ConfigService}.\n *\n * @public\n */\n export const config = createServiceRef<\n import('./ConfigService').ConfigService\n >({ id: 'core.config', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link DatabaseService}.\n *\n * @public\n */\n export const database = createServiceRef<\n import('./DatabaseService').DatabaseService\n >({ id: 'core.database' });\n\n /**\n * The service reference for the plugin scoped {@link DiscoveryService}.\n *\n * @public\n */\n export const discovery = createServiceRef<\n import('./DiscoveryService').DiscoveryService\n >({ id: 'core.discovery' });\n\n /**\n * The service reference for the plugin scoped {@link HttpRouterService}.\n *\n * @public\n */\n export const httpRouter = createServiceRef<\n import('./HttpRouterService').HttpRouterService\n >({ id: 'core.httpRouter' });\n\n /**\n * The service reference for the plugin scoped {@link LifecycleService}.\n *\n * @public\n */\n export const lifecycle = createServiceRef<\n import('./LifecycleService').LifecycleService\n >({ id: 'core.lifecycle' });\n\n /**\n * The service reference for the plugin scoped {@link LoggerService}.\n *\n * @public\n */\n export const logger = createServiceRef<\n import('./LoggerService').LoggerService\n >({ id: 'core.logger' });\n\n /**\n * The service reference for the plugin scoped {@link PermissionsService}.\n *\n * @public\n */\n export const permissions = createServiceRef<\n import('./PermissionsService').PermissionsService\n >({ id: 'core.permissions' });\n\n /**\n * The service reference for the plugin scoped {@link PluginMetadataService}.\n *\n * @public\n */\n export const pluginMetadata = createServiceRef<\n import('./PluginMetadataService').PluginMetadataService\n >({ id: 'core.pluginMetadata' });\n\n /**\n * The service reference for the root scoped {@link RootHttpRouterService}.\n *\n * @public\n */\n export const rootHttpRouter = createServiceRef<\n import('./RootHttpRouterService').RootHttpRouterService\n >({ id: 'core.rootHttpRouter', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLifecycleService}.\n *\n * @public\n */\n export const rootLifecycle = createServiceRef<\n import('./RootLifecycleService').RootLifecycleService\n >({ id: 'core.rootLifecycle', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLoggerService}.\n *\n * @public\n */\n export const rootLogger = createServiceRef<\n import('./RootLoggerService').RootLoggerService\n >({ id: 'core.rootLogger', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link SchedulerService}.\n *\n * @public\n */\n export const scheduler = createServiceRef<\n import('./SchedulerService').SchedulerService\n >({ id: 'core.scheduler' });\n\n /**\n * The service reference for the plugin scoped {@link TokenManagerService}.\n *\n * @public\n */\n export const tokenManager = createServiceRef<\n import('./TokenManagerService').TokenManagerService\n >({ id: 'core.tokenManager' });\n\n /**\n * The service reference for the plugin scoped {@link UrlReaderService}.\n *\n * @public\n */\n export const urlReader = createServiceRef<\n import('./UrlReaderService').UrlReaderService\n >({ id: 'core.urlReader' });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport function createExtensionPoint<T>(options: {\n id: string;\n}): ExtensionPoint<T> {\n return {\n id: options.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${options.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<\n TOptions extends object | undefined = undefined,\n>(config: {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * @public\n *\n * Creates a new backend module for a given plugin.\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<\n TOptions extends object | undefined = undefined,\n>(\n config: BackendModuleConfig<TOptions>,\n): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["coreServices"],"mappings":";;;;AAuFO,SAAS,iBAAoB,OAUlB,EAAA;AAChB,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,OAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAO,GAAA;AACT,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,cAAc,OAAQ,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KAC/B;AAAA,IACA,KAAO,EAAA,SAAA;AAAA;AAAA,IACP,gBAAkB,EAAA,cAAA;AAAA,GACpB,CAAA;AAKF,CAAA;AAeO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AAwBO,SAAS,oBAGd,MAGwC,EAAA;AACxC,EAAA,OAAO,CAAC,OAAwB,MAAA;AAAA,IAC9B,EAAI,EAAA,CAAA,EAAG,MAAO,CAAA,QAAA,CAAA,CAAA,EAAY,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,IACjC,SAAS,QAAqC,EAAA;AAE5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/coreServices.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FactoryFunctionWithOptions, MaybeOptions } from '../../types';\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/**\n * Represents either a {@link ServiceFactory} or a function that returns one.\n *\n * @public\n */\nexport type ServiceFactoryOrFunction<TService = unknown> =\n | ServiceFactory<TService>\n | (() => ServiceFactory<TService>);\n\n/** @public */\nexport interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {\n id: string;\n scope?: TScope;\n defaultFactory?: (\n service: ServiceRef<TService, TScope>,\n ) => Promise<ServiceFactoryOrFunction<TService>>;\n}\n\n/**\n * Creates a new service definition. This overload is used to create plugin scoped services.\n *\n * @public\n */\nexport function createServiceRef<TService>(\n config: ServiceRefConfig<TService, 'plugin'>,\n): ServiceRef<TService, 'plugin'>;\n\n/**\n * Creates a new service definition. This overload is used to create root scoped services.\n *\n * @public\n */\nexport function createServiceRef<TService>(\n config: ServiceRefConfig<TService, 'root'>,\n): ServiceRef<TService, 'root'>;\nexport function createServiceRef<TService>(\n config: ServiceRefConfig<TService, any>,\n): ServiceRef<TService, any> {\n const { id, scope = 'plugin', defaultFactory } = config;\n return {\n id,\n scope,\n get T(): TService {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${config.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<TService, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<TService>,\n ) => Promise<ServiceFactory<TService> | (() => ServiceFactory<TService>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/** @public */\nexport interface ServiceFactoryConfig<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends MaybeOptions = undefined,\n> {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends MaybeOptions = undefined,\n>(\n config: ServiceFactoryConfig<TService, TScope, TImpl, TDeps, TOpts>,\n): FactoryFunctionWithOptions<ServiceFactory<TService>, TOpts> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system';\n\n/**\n * All core services references\n *\n * @public\n */\nexport namespace coreServices {\n /**\n * The service reference for the plugin scoped {@link CacheService}.\n *\n * @public\n */\n export const cache = createServiceRef<import('./CacheService').CacheService>({\n id: 'core.cache',\n });\n\n /**\n * The service reference for the root scoped {@link ConfigService}.\n *\n * @public\n */\n export const config = createServiceRef<\n import('./ConfigService').ConfigService\n >({ id: 'core.config', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link DatabaseService}.\n *\n * @public\n */\n export const database = createServiceRef<\n import('./DatabaseService').DatabaseService\n >({ id: 'core.database' });\n\n /**\n * The service reference for the plugin scoped {@link DiscoveryService}.\n *\n * @public\n */\n export const discovery = createServiceRef<\n import('./DiscoveryService').DiscoveryService\n >({ id: 'core.discovery' });\n\n /**\n * The service reference for the plugin scoped {@link HttpRouterService}.\n *\n * @public\n */\n export const httpRouter = createServiceRef<\n import('./HttpRouterService').HttpRouterService\n >({ id: 'core.httpRouter' });\n\n /**\n * The service reference for the plugin scoped {@link LifecycleService}.\n *\n * @public\n */\n export const lifecycle = createServiceRef<\n import('./LifecycleService').LifecycleService\n >({ id: 'core.lifecycle' });\n\n /**\n * The service reference for the plugin scoped {@link LoggerService}.\n *\n * @public\n */\n export const logger = createServiceRef<\n import('./LoggerService').LoggerService\n >({ id: 'core.logger' });\n\n /**\n * The service reference for the plugin scoped {@link PermissionsService}.\n *\n * @public\n */\n export const permissions = createServiceRef<\n import('./PermissionsService').PermissionsService\n >({ id: 'core.permissions' });\n\n /**\n * The service reference for the plugin scoped {@link PluginMetadataService}.\n *\n * @public\n */\n export const pluginMetadata = createServiceRef<\n import('./PluginMetadataService').PluginMetadataService\n >({ id: 'core.pluginMetadata' });\n\n /**\n * The service reference for the root scoped {@link RootHttpRouterService}.\n *\n * @public\n */\n export const rootHttpRouter = createServiceRef<\n import('./RootHttpRouterService').RootHttpRouterService\n >({ id: 'core.rootHttpRouter', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLifecycleService}.\n *\n * @public\n */\n export const rootLifecycle = createServiceRef<\n import('./RootLifecycleService').RootLifecycleService\n >({ id: 'core.rootLifecycle', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLoggerService}.\n *\n * @public\n */\n export const rootLogger = createServiceRef<\n import('./RootLoggerService').RootLoggerService\n >({ id: 'core.rootLogger', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link SchedulerService}.\n *\n * @public\n */\n export const scheduler = createServiceRef<\n import('./SchedulerService').SchedulerService\n >({ id: 'core.scheduler' });\n\n /**\n * The service reference for the plugin scoped {@link TokenManagerService}.\n *\n * @public\n */\n export const tokenManager = createServiceRef<\n import('./TokenManagerService').TokenManagerService\n >({ id: 'core.tokenManager' });\n\n /**\n * The service reference for the plugin scoped {@link UrlReaderService}.\n *\n * @public\n */\n export const urlReader = createServiceRef<\n import('./UrlReaderService').UrlReaderService\n >({ id: 'core.urlReader' });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FactoryFunctionWithOptions, MaybeOptions } from '../types';\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport interface ExtensionPointConfig {\n id: string;\n}\n\n/** @public */\nexport function createExtensionPoint<T>(\n config: ExtensionPointConfig,\n): ExtensionPoint<T> {\n return {\n id: config.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${config.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<TOptions extends MaybeOptions = undefined>(\n config: BackendPluginConfig<TOptions>,\n): FactoryFunctionWithOptions<BackendFeature, TOptions> {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * Creates a new backend module for a given plugin.\n *\n * @public\n *\n * @remarks\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<TOptions extends MaybeOptions = undefined>(\n config: BackendModuleConfig<TOptions>,\n): FactoryFunctionWithOptions<BackendFeature, TOptions> {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["coreServices"],"mappings":";;;;AA4GO,SAAS,iBACd,MAC2B,EAAA;AAC3B,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,MAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAc,GAAA;AAChB,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,cAAc,MAAO,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KAC9B;AAAA,IACA,KAAO,EAAA,SAAA;AAAA;AAAA,IACP,gBAAkB,EAAA,cAAA;AAAA,GACpB,CAAA;AAKF,CAAA;AAiCO,SAAS,qBAOd,MAC6D,EAAA;AAC7D,EA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AO,CAAC,OAAwB,MAAA;AAAA,IAC9B,EAAI,EAAA,CAAA,EAAG,MAAO,CAAA,QAAA,CAAA,CAAA,EAAY,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,IACjC,SAAS,QAAqC,EAAA;AAE5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -220,9 +220,11 @@ export declare namespace coreServices {
220
220
  }
221
221
 
222
222
  /**
223
+ * Creates a new backend module for a given plugin.
224
+ *
223
225
  * @public
224
226
  *
225
- * Creates a new backend module for a given plugin.
227
+ * @remarks
226
228
  *
227
229
  * The `moduleId` should be equal to the module-specific prefix of the exported name, such
228
230
  * that the full name is `moduleId + PluginId + "Module"`. For example, a GitHub entity
@@ -231,47 +233,38 @@ export declare namespace coreServices {
231
233
  *
232
234
  * The `pluginId` should exactly match the `id` of the plugin that the module extends.
233
235
  */
234
- export declare function createBackendModule<TOptions extends object | undefined = undefined>(config: BackendModuleConfig<TOptions>): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
236
+ export declare function createBackendModule<TOptions extends MaybeOptions = undefined>(config: BackendModuleConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
235
237
 
236
238
  /** @public */
237
- export declare function createBackendPlugin<TOptions extends object | undefined = undefined>(config: {
238
- id: string;
239
- register(reg: BackendRegistrationPoints, options: TOptions): void;
240
- }): undefined extends TOptions ? (options?: TOptions) => BackendFeature : (options: TOptions) => BackendFeature;
239
+ export declare function createBackendPlugin<TOptions extends MaybeOptions = undefined>(config: BackendPluginConfig<TOptions>): FactoryFunctionWithOptions<BackendFeature, TOptions>;
241
240
 
242
241
  /** @public */
243
- export declare function createExtensionPoint<T>(options: {
244
- id: string;
245
- }): ExtensionPoint<T>;
242
+ export declare function createExtensionPoint<T>(config: ExtensionPointConfig): ExtensionPoint<T>;
246
243
 
247
244
  /**
248
245
  * @public
249
246
  */
250
247
  export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
251
248
  [name in string]: ServiceRef<unknown>;
252
- }, TOpts extends object | undefined = undefined>(config: {
253
- service: ServiceRef<TService, TScope>;
254
- deps: TDeps;
255
- factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
256
- }): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
249
+ }, TOpts extends MaybeOptions = undefined>(config: ServiceFactoryConfig<TService, TScope, TImpl, TDeps, TOpts>): FactoryFunctionWithOptions<ServiceFactory<TService>, TOpts>;
257
250
 
258
- /** @public */
259
- export declare function createServiceRef<T>(options: {
260
- id: string;
261
- scope?: 'plugin';
262
- defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
263
- }): ServiceRef<T, 'plugin'>;
251
+ /**
252
+ * Creates a new service definition. This overload is used to create plugin scoped services.
253
+ *
254
+ * @public
255
+ */
256
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'plugin'>): ServiceRef<TService, 'plugin'>;
264
257
 
265
- /** @public */
266
- export declare function createServiceRef<T>(options: {
267
- id: string;
268
- scope: 'root';
269
- defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
270
- }): ServiceRef<T, 'root'>;
258
+ /**
259
+ * Creates a new service definition. This overload is used to create root scoped services.
260
+ *
261
+ * @public
262
+ */
263
+ export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'root'>): ServiceRef<TService, 'root'>;
271
264
 
272
265
  /**
273
266
  * The DatabaseService manages access to databases that Plugins get.
274
- *gs
267
+ *
275
268
  * @public
276
269
  */
277
270
  export declare interface DatabaseService {
@@ -358,6 +351,18 @@ export declare type ExtensionPoint<T> = {
358
351
  $$ref: 'extension-point';
359
352
  };
360
353
 
354
+ /** @public */
355
+ export declare interface ExtensionPointConfig {
356
+ id: string;
357
+ }
358
+
359
+ /**
360
+ * Helper type that makes the options argument optional if options are not required.
361
+ *
362
+ * @ignore
363
+ */
364
+ declare type FactoryFunctionWithOptions<TResult, TOptions> = undefined extends TOptions ? (options?: TOptions) => TResult : (options: TOptions) => TResult;
365
+
361
366
  /**
362
367
  * @public
363
368
  */
@@ -380,8 +385,10 @@ export declare interface LifecycleService {
380
385
  **/
381
386
  export declare type LifecycleServiceShutdownHook = {
382
387
  fn: () => void | Promise<void>;
383
- /** Labels to help identify the shutdown hook */
384
- labels?: Record<string, string>;
388
+ /**
389
+ * Optional {@link LoggerService} that will be used for logging instead of the default logger.
390
+ */
391
+ logger?: LoggerService;
385
392
  };
386
393
 
387
394
  /**
@@ -404,6 +411,13 @@ export declare type LogMeta = {
404
411
  [name: string]: unknown;
405
412
  };
406
413
 
414
+ /**
415
+ * Base type for options objects that aren't required.
416
+ *
417
+ * @ignore
418
+ */
419
+ declare type MaybeOptions = object | undefined;
420
+
407
421
  /** @public */
408
422
  export declare interface PermissionsService extends PermissionEvaluator {
409
423
  }
@@ -694,6 +708,22 @@ export declare type ServiceFactory<TService = unknown> = {
694
708
  }) => Promise<TService>>;
695
709
  };
696
710
 
711
+ /** @public */
712
+ export declare interface ServiceFactoryConfig<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
713
+ [name in string]: ServiceRef<unknown>;
714
+ }, TOpts extends MaybeOptions = undefined> {
715
+ service: ServiceRef<TService, TScope>;
716
+ deps: TDeps;
717
+ factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
718
+ }
719
+
720
+ /**
721
+ * Represents either a {@link ServiceFactory} or a function that returns one.
722
+ *
723
+ * @public
724
+ */
725
+ export declare type ServiceFactoryOrFunction<TService = unknown> = ServiceFactory<TService> | (() => ServiceFactory<TService>);
726
+
697
727
  /**
698
728
  * TODO
699
729
  *
@@ -720,6 +750,13 @@ export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'roo
720
750
  $$ref: 'service';
721
751
  };
722
752
 
753
+ /** @public */
754
+ export declare interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
755
+ id: string;
756
+ scope?: TScope;
757
+ defaultFactory?: (service: ServiceRef<TService, TScope>) => Promise<ServiceFactoryOrFunction<TService>>;
758
+ }
759
+
723
760
  /** @ignore */
724
761
  declare type ServiceRefsToInstances<T extends {
725
762
  [key in string]: ServiceRef<unknown>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/backend-plugin-api",
3
3
  "description": "Core API used by Backstage backend plugins",
4
- "version": "0.0.0-nightly-20230109022518",
4
+ "version": "0.0.0-nightly-20230111022819",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
@@ -33,16 +33,16 @@
33
33
  "start": "backstage-cli package start"
34
34
  },
35
35
  "dependencies": {
36
- "@backstage/backend-tasks": "^0.0.0-nightly-20230109022518",
37
- "@backstage/config": "^0.0.0-nightly-20230109022518",
38
- "@backstage/plugin-permission-common": "^0.0.0-nightly-20230109022518",
36
+ "@backstage/backend-tasks": "^0.0.0-nightly-20230111022819",
37
+ "@backstage/config": "^0.0.0-nightly-20230111022819",
38
+ "@backstage/plugin-permission-common": "^0.0.0-nightly-20230111022819",
39
39
  "@backstage/types": "^1.0.2",
40
40
  "@types/express": "^4.17.6",
41
41
  "express": "^4.17.1",
42
42
  "knex": "^2.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@backstage/cli": "^0.0.0-nightly-20230109022518"
45
+ "@backstage/cli": "^0.0.0-nightly-20230111022819"
46
46
  },
47
47
  "files": [
48
48
  "dist",