@backstage/backend-plugin-api 0.1.2-next.1 → 0.1.2
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 +28 -0
- package/alpha/package.json +1 -1
- package/dist/index.alpha.d.ts +81 -33
- package/dist/index.beta.d.ts +81 -33
- package/dist/index.cjs.js +24 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +81 -33
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @backstage/backend-plugin-api
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2c57c0c499: Made `ApiRef.defaultFactory` internal.
|
|
8
|
+
- 91eed37a39: Updated `createBackendPlugin` and `createBackendModule` to properly forward lack of options.
|
|
9
|
+
- 409ed984e8: Service are now scoped to either `'plugin'` or `'root'` scope. Service factories have been updated to provide dependency instances directly rather than factory functions.
|
|
10
|
+
- eef91a2558: Simplified the `ServiceFactory` type and removed `AnyServiceFactory`.
|
|
11
|
+
- 854ba37357: The `createServiceFactory` method has been updated to return a higher-order factory that can accept options.
|
|
12
|
+
- 68513f169a: When defining a new `ServiceRef` you can now also include a `defaultFactory`, which will be used to construct instances of the service in case there is no explicit factory defined.
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @backstage/backend-common@0.15.1
|
|
15
|
+
- @backstage/backend-tasks@0.3.5
|
|
16
|
+
- @backstage/config@1.0.2
|
|
17
|
+
- @backstage/plugin-permission-common@0.6.4
|
|
18
|
+
|
|
19
|
+
## 0.1.2-next.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 409ed984e8: Service are now scoped to either `'plugin'` or `'root'` scope. Service factories have been updated to provide dependency instances directly rather than factory functions.
|
|
24
|
+
- 854ba37357: The `createServiceFactory` method has been updated to return a higher-order factory that can accept options.
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- @backstage/config@1.0.2-next.0
|
|
27
|
+
- @backstage/plugin-permission-common@0.6.4-next.2
|
|
28
|
+
- @backstage/backend-common@0.15.1-next.3
|
|
29
|
+
- @backstage/backend-tasks@0.3.5-next.1
|
|
30
|
+
|
|
3
31
|
## 0.1.2-next.1
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.alpha.d.ts
CHANGED
|
@@ -52,12 +52,12 @@ export declare interface BackendRegistrationPoints {
|
|
|
52
52
|
/**
|
|
53
53
|
* @public
|
|
54
54
|
*/
|
|
55
|
-
export declare const cacheServiceRef: ServiceRef<PluginCacheManager>;
|
|
55
|
+
export declare const cacheServiceRef: ServiceRef<PluginCacheManager, "plugin">;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* @public
|
|
59
59
|
*/
|
|
60
|
-
export declare const configServiceRef: ServiceRef<Config>;
|
|
60
|
+
export declare const configServiceRef: ServiceRef<Config, "root">;
|
|
61
61
|
|
|
62
62
|
/** @public */
|
|
63
63
|
export declare function createBackendModule<TOptions extends {
|
|
@@ -77,36 +77,39 @@ export declare function createExtensionPoint<T>(options: {
|
|
|
77
77
|
/**
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
|
-
export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
|
|
80
|
+
export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
|
|
81
|
+
[name in string]: ServiceRef<unknown>;
|
|
82
|
+
}, TOpts extends {
|
|
81
83
|
[name in string]: unknown;
|
|
82
|
-
}>(
|
|
83
|
-
service: ServiceRef<TService>;
|
|
84
|
-
deps:
|
|
85
|
-
factory(deps:
|
|
86
|
-
}): ServiceFactory<TService>;
|
|
84
|
+
} | undefined = undefined>(config: {
|
|
85
|
+
service: ServiceRef<TService, TScope>;
|
|
86
|
+
deps: TDeps;
|
|
87
|
+
factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
|
|
88
|
+
}): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
|
|
87
89
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/** @public */
|
|
91
|
+
export declare function createServiceRef<T>(options: {
|
|
92
|
+
id: string;
|
|
93
|
+
scope?: 'plugin';
|
|
94
|
+
defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
95
|
+
}): ServiceRef<T, 'plugin'>;
|
|
96
|
+
|
|
97
|
+
/** @public */
|
|
91
98
|
export declare function createServiceRef<T>(options: {
|
|
92
99
|
id: string;
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
scope: 'root';
|
|
101
|
+
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
102
|
+
}): ServiceRef<T, 'root'>;
|
|
95
103
|
|
|
96
104
|
/**
|
|
97
105
|
* @public
|
|
98
106
|
*/
|
|
99
|
-
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager>;
|
|
100
|
-
|
|
101
|
-
/** @public */
|
|
102
|
-
export declare type DepsToDepFactories<T> = {
|
|
103
|
-
[key in keyof T]: (pluginId: string) => Promise<T[key]>;
|
|
104
|
-
};
|
|
107
|
+
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
|
|
105
108
|
|
|
106
109
|
/**
|
|
107
110
|
* @public
|
|
108
111
|
*/
|
|
109
|
-
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery>;
|
|
112
|
+
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
|
|
110
113
|
|
|
111
114
|
/**
|
|
112
115
|
* TODO
|
|
@@ -124,9 +127,6 @@ export declare type ExtensionPoint<T> = {
|
|
|
124
127
|
$$ref: 'extension-point';
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
/** @public */
|
|
128
|
-
export declare type FactoryFunc<Impl> = (pluginId: string) => Promise<Impl>;
|
|
129
|
-
|
|
130
130
|
/**
|
|
131
131
|
* @public
|
|
132
132
|
*/
|
|
@@ -137,7 +137,7 @@ export declare interface HttpRouterService {
|
|
|
137
137
|
/**
|
|
138
138
|
* @public
|
|
139
139
|
*/
|
|
140
|
-
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService>;
|
|
140
|
+
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService, "plugin">;
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* @public
|
|
@@ -152,7 +152,7 @@ export declare interface Logger {
|
|
|
152
152
|
/**
|
|
153
153
|
* @public
|
|
154
154
|
*/
|
|
155
|
-
export declare const loggerServiceRef: ServiceRef<Logger>;
|
|
155
|
+
export declare const loggerServiceRef: ServiceRef<Logger, "plugin">;
|
|
156
156
|
|
|
157
157
|
/** @public */
|
|
158
158
|
export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportStreamOptions): Logger_2;
|
|
@@ -160,22 +160,51 @@ export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportSt
|
|
|
160
160
|
/**
|
|
161
161
|
* @public
|
|
162
162
|
*/
|
|
163
|
-
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator>;
|
|
163
|
+
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator, "plugin">;
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* @public
|
|
167
167
|
*/
|
|
168
|
-
export declare
|
|
168
|
+
export declare interface PluginMetadata {
|
|
169
|
+
getId(): string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export declare const pluginMetadataServiceRef: ServiceRef<PluginMetadata, "plugin">;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare const rootLoggerServiceRef: ServiceRef<Logger, "root">;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
|
|
169
186
|
|
|
170
187
|
/** @public */
|
|
171
188
|
export declare type ServiceFactory<TService = unknown> = {
|
|
172
|
-
|
|
189
|
+
scope: 'root';
|
|
190
|
+
service: ServiceRef<TService, 'root'>;
|
|
191
|
+
deps: {
|
|
192
|
+
[key in string]: ServiceRef<unknown>;
|
|
193
|
+
};
|
|
194
|
+
factory(deps: {
|
|
195
|
+
[key in string]: unknown;
|
|
196
|
+
}): Promise<TService>;
|
|
197
|
+
} | {
|
|
198
|
+
scope: 'plugin';
|
|
199
|
+
service: ServiceRef<TService, 'plugin'>;
|
|
173
200
|
deps: {
|
|
174
201
|
[key in string]: ServiceRef<unknown>;
|
|
175
202
|
};
|
|
176
203
|
factory(deps: {
|
|
177
204
|
[key in string]: unknown;
|
|
178
|
-
}): Promise<
|
|
205
|
+
}): Promise<(deps: {
|
|
206
|
+
[key in string]: unknown;
|
|
207
|
+
}) => Promise<TService>>;
|
|
179
208
|
};
|
|
180
209
|
|
|
181
210
|
/**
|
|
@@ -183,21 +212,40 @@ export declare type ServiceFactory<TService = unknown> = {
|
|
|
183
212
|
*
|
|
184
213
|
* @public
|
|
185
214
|
*/
|
|
186
|
-
export declare type ServiceRef<
|
|
215
|
+
export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
187
216
|
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* This determines the scope at which this service is available.
|
|
219
|
+
*
|
|
220
|
+
* Root scoped services are available to all other services but
|
|
221
|
+
* may only depend on other root scoped services.
|
|
222
|
+
*
|
|
223
|
+
* Plugin scoped services are only available to other plugin scoped
|
|
224
|
+
* services but may depend on all other services.
|
|
225
|
+
*/
|
|
226
|
+
scope: TScope;
|
|
188
227
|
/**
|
|
189
228
|
* Utility for getting the type of the service, using `typeof serviceRef.T`.
|
|
190
229
|
* Attempting to actually read this value will result in an exception.
|
|
191
230
|
*/
|
|
192
|
-
T:
|
|
231
|
+
T: TService;
|
|
193
232
|
toString(): string;
|
|
194
233
|
$$ref: 'service';
|
|
195
234
|
};
|
|
196
235
|
|
|
236
|
+
/** @ignore */
|
|
237
|
+
declare type ServiceRefsToInstances<T extends {
|
|
238
|
+
[key in string]: ServiceRef<unknown>;
|
|
239
|
+
}, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
240
|
+
[name in {
|
|
241
|
+
[key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;
|
|
242
|
+
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
243
|
+
};
|
|
244
|
+
|
|
197
245
|
/**
|
|
198
246
|
* @public
|
|
199
247
|
*/
|
|
200
|
-
export declare const tokenManagerServiceRef: ServiceRef<TokenManager>;
|
|
248
|
+
export declare const tokenManagerServiceRef: ServiceRef<TokenManager, "plugin">;
|
|
201
249
|
|
|
202
250
|
/** @public */
|
|
203
251
|
export declare type TypesToServiceRef<T> = {
|
|
@@ -207,6 +255,6 @@ export declare type TypesToServiceRef<T> = {
|
|
|
207
255
|
/**
|
|
208
256
|
* @public
|
|
209
257
|
*/
|
|
210
|
-
export declare const urlReaderServiceRef: ServiceRef<UrlReader>;
|
|
258
|
+
export declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
|
|
211
259
|
|
|
212
260
|
export { }
|
package/dist/index.beta.d.ts
CHANGED
|
@@ -52,12 +52,12 @@ export declare interface BackendRegistrationPoints {
|
|
|
52
52
|
/**
|
|
53
53
|
* @public
|
|
54
54
|
*/
|
|
55
|
-
export declare const cacheServiceRef: ServiceRef<PluginCacheManager>;
|
|
55
|
+
export declare const cacheServiceRef: ServiceRef<PluginCacheManager, "plugin">;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* @public
|
|
59
59
|
*/
|
|
60
|
-
export declare const configServiceRef: ServiceRef<Config>;
|
|
60
|
+
export declare const configServiceRef: ServiceRef<Config, "root">;
|
|
61
61
|
|
|
62
62
|
/** @public */
|
|
63
63
|
export declare function createBackendModule<TOptions extends {
|
|
@@ -77,36 +77,39 @@ export declare function createExtensionPoint<T>(options: {
|
|
|
77
77
|
/**
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
|
-
export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
|
|
80
|
+
export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
|
|
81
|
+
[name in string]: ServiceRef<unknown>;
|
|
82
|
+
}, TOpts extends {
|
|
81
83
|
[name in string]: unknown;
|
|
82
|
-
}>(
|
|
83
|
-
service: ServiceRef<TService>;
|
|
84
|
-
deps:
|
|
85
|
-
factory(deps:
|
|
86
|
-
}): ServiceFactory<TService>;
|
|
84
|
+
} | undefined = undefined>(config: {
|
|
85
|
+
service: ServiceRef<TService, TScope>;
|
|
86
|
+
deps: TDeps;
|
|
87
|
+
factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
|
|
88
|
+
}): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
|
|
87
89
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/** @public */
|
|
91
|
+
export declare function createServiceRef<T>(options: {
|
|
92
|
+
id: string;
|
|
93
|
+
scope?: 'plugin';
|
|
94
|
+
defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
95
|
+
}): ServiceRef<T, 'plugin'>;
|
|
96
|
+
|
|
97
|
+
/** @public */
|
|
91
98
|
export declare function createServiceRef<T>(options: {
|
|
92
99
|
id: string;
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
scope: 'root';
|
|
101
|
+
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
102
|
+
}): ServiceRef<T, 'root'>;
|
|
95
103
|
|
|
96
104
|
/**
|
|
97
105
|
* @public
|
|
98
106
|
*/
|
|
99
|
-
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager>;
|
|
100
|
-
|
|
101
|
-
/** @public */
|
|
102
|
-
export declare type DepsToDepFactories<T> = {
|
|
103
|
-
[key in keyof T]: (pluginId: string) => Promise<T[key]>;
|
|
104
|
-
};
|
|
107
|
+
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
|
|
105
108
|
|
|
106
109
|
/**
|
|
107
110
|
* @public
|
|
108
111
|
*/
|
|
109
|
-
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery>;
|
|
112
|
+
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
|
|
110
113
|
|
|
111
114
|
/**
|
|
112
115
|
* TODO
|
|
@@ -124,9 +127,6 @@ export declare type ExtensionPoint<T> = {
|
|
|
124
127
|
$$ref: 'extension-point';
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
/** @public */
|
|
128
|
-
export declare type FactoryFunc<Impl> = (pluginId: string) => Promise<Impl>;
|
|
129
|
-
|
|
130
130
|
/**
|
|
131
131
|
* @public
|
|
132
132
|
*/
|
|
@@ -137,7 +137,7 @@ export declare interface HttpRouterService {
|
|
|
137
137
|
/**
|
|
138
138
|
* @public
|
|
139
139
|
*/
|
|
140
|
-
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService>;
|
|
140
|
+
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService, "plugin">;
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* @public
|
|
@@ -152,7 +152,7 @@ export declare interface Logger {
|
|
|
152
152
|
/**
|
|
153
153
|
* @public
|
|
154
154
|
*/
|
|
155
|
-
export declare const loggerServiceRef: ServiceRef<Logger>;
|
|
155
|
+
export declare const loggerServiceRef: ServiceRef<Logger, "plugin">;
|
|
156
156
|
|
|
157
157
|
/** @public */
|
|
158
158
|
export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportStreamOptions): Logger_2;
|
|
@@ -160,22 +160,51 @@ export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportSt
|
|
|
160
160
|
/**
|
|
161
161
|
* @public
|
|
162
162
|
*/
|
|
163
|
-
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator>;
|
|
163
|
+
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator, "plugin">;
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* @public
|
|
167
167
|
*/
|
|
168
|
-
export declare
|
|
168
|
+
export declare interface PluginMetadata {
|
|
169
|
+
getId(): string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export declare const pluginMetadataServiceRef: ServiceRef<PluginMetadata, "plugin">;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare const rootLoggerServiceRef: ServiceRef<Logger, "root">;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
|
|
169
186
|
|
|
170
187
|
/** @public */
|
|
171
188
|
export declare type ServiceFactory<TService = unknown> = {
|
|
172
|
-
|
|
189
|
+
scope: 'root';
|
|
190
|
+
service: ServiceRef<TService, 'root'>;
|
|
191
|
+
deps: {
|
|
192
|
+
[key in string]: ServiceRef<unknown>;
|
|
193
|
+
};
|
|
194
|
+
factory(deps: {
|
|
195
|
+
[key in string]: unknown;
|
|
196
|
+
}): Promise<TService>;
|
|
197
|
+
} | {
|
|
198
|
+
scope: 'plugin';
|
|
199
|
+
service: ServiceRef<TService, 'plugin'>;
|
|
173
200
|
deps: {
|
|
174
201
|
[key in string]: ServiceRef<unknown>;
|
|
175
202
|
};
|
|
176
203
|
factory(deps: {
|
|
177
204
|
[key in string]: unknown;
|
|
178
|
-
}): Promise<
|
|
205
|
+
}): Promise<(deps: {
|
|
206
|
+
[key in string]: unknown;
|
|
207
|
+
}) => Promise<TService>>;
|
|
179
208
|
};
|
|
180
209
|
|
|
181
210
|
/**
|
|
@@ -183,21 +212,40 @@ export declare type ServiceFactory<TService = unknown> = {
|
|
|
183
212
|
*
|
|
184
213
|
* @public
|
|
185
214
|
*/
|
|
186
|
-
export declare type ServiceRef<
|
|
215
|
+
export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
187
216
|
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* This determines the scope at which this service is available.
|
|
219
|
+
*
|
|
220
|
+
* Root scoped services are available to all other services but
|
|
221
|
+
* may only depend on other root scoped services.
|
|
222
|
+
*
|
|
223
|
+
* Plugin scoped services are only available to other plugin scoped
|
|
224
|
+
* services but may depend on all other services.
|
|
225
|
+
*/
|
|
226
|
+
scope: TScope;
|
|
188
227
|
/**
|
|
189
228
|
* Utility for getting the type of the service, using `typeof serviceRef.T`.
|
|
190
229
|
* Attempting to actually read this value will result in an exception.
|
|
191
230
|
*/
|
|
192
|
-
T:
|
|
231
|
+
T: TService;
|
|
193
232
|
toString(): string;
|
|
194
233
|
$$ref: 'service';
|
|
195
234
|
};
|
|
196
235
|
|
|
236
|
+
/** @ignore */
|
|
237
|
+
declare type ServiceRefsToInstances<T extends {
|
|
238
|
+
[key in string]: ServiceRef<unknown>;
|
|
239
|
+
}, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
240
|
+
[name in {
|
|
241
|
+
[key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;
|
|
242
|
+
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
243
|
+
};
|
|
244
|
+
|
|
197
245
|
/**
|
|
198
246
|
* @public
|
|
199
247
|
*/
|
|
200
|
-
export declare const tokenManagerServiceRef: ServiceRef<TokenManager>;
|
|
248
|
+
export declare const tokenManagerServiceRef: ServiceRef<TokenManager, "plugin">;
|
|
201
249
|
|
|
202
250
|
/** @public */
|
|
203
251
|
export declare type TypesToServiceRef<T> = {
|
|
@@ -207,6 +255,6 @@ export declare type TypesToServiceRef<T> = {
|
|
|
207
255
|
/**
|
|
208
256
|
* @public
|
|
209
257
|
*/
|
|
210
|
-
export declare const urlReaderServiceRef: ServiceRef<UrlReader>;
|
|
258
|
+
export declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
|
|
211
259
|
|
|
212
260
|
export { }
|
package/dist/index.cjs.js
CHANGED
|
@@ -10,9 +10,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
var Transport__default = /*#__PURE__*/_interopDefaultLegacy(Transport);
|
|
11
11
|
|
|
12
12
|
function createServiceRef(options) {
|
|
13
|
-
const { id, defaultFactory } = options;
|
|
13
|
+
const { id, scope = "plugin", defaultFactory } = options;
|
|
14
14
|
return {
|
|
15
15
|
id,
|
|
16
|
+
scope,
|
|
16
17
|
get T() {
|
|
17
18
|
throw new Error(`tried to read ServiceRef.T of ${this}`);
|
|
18
19
|
},
|
|
@@ -23,12 +24,20 @@ function createServiceRef(options) {
|
|
|
23
24
|
__defaultFactory: defaultFactory
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
function createServiceFactory(
|
|
27
|
-
return
|
|
27
|
+
function createServiceFactory(config) {
|
|
28
|
+
return (options) => ({
|
|
29
|
+
scope: config.service.scope,
|
|
30
|
+
service: config.service,
|
|
31
|
+
deps: config.deps,
|
|
32
|
+
factory(deps) {
|
|
33
|
+
return config.factory(deps, options);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
const configServiceRef = createServiceRef({
|
|
31
|
-
id: "core.config"
|
|
39
|
+
id: "core.root.config",
|
|
40
|
+
scope: "root"
|
|
32
41
|
});
|
|
33
42
|
|
|
34
43
|
const httpRouterServiceRef = createServiceRef({
|
|
@@ -67,6 +76,15 @@ const schedulerServiceRef = createServiceRef({
|
|
|
67
76
|
id: "core.scheduler"
|
|
68
77
|
});
|
|
69
78
|
|
|
79
|
+
const rootLoggerServiceRef = createServiceRef({
|
|
80
|
+
id: "core.root.logger",
|
|
81
|
+
scope: "root"
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const pluginMetadataServiceRef = createServiceRef({
|
|
85
|
+
id: "core.plugin-metadata"
|
|
86
|
+
});
|
|
87
|
+
|
|
70
88
|
class BackstageLoggerTransport extends Transport__default["default"] {
|
|
71
89
|
constructor(backstageLogger, opts) {
|
|
72
90
|
super(opts);
|
|
@@ -125,6 +143,8 @@ exports.httpRouterServiceRef = httpRouterServiceRef;
|
|
|
125
143
|
exports.loggerServiceRef = loggerServiceRef;
|
|
126
144
|
exports.loggerToWinstonLogger = loggerToWinstonLogger;
|
|
127
145
|
exports.permissionsServiceRef = permissionsServiceRef;
|
|
146
|
+
exports.pluginMetadataServiceRef = pluginMetadataServiceRef;
|
|
147
|
+
exports.rootLoggerServiceRef = rootLoggerServiceRef;
|
|
128
148
|
exports.schedulerServiceRef = schedulerServiceRef;
|
|
129
149
|
exports.tokenManagerServiceRef = tokenManagerServiceRef;
|
|
130
150
|
exports.urlReaderServiceRef = urlReaderServiceRef;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/configServiceRef.ts","../src/services/definitions/httpRouterServiceRef.ts","../src/services/definitions/loggerServiceRef.ts","../src/services/definitions/urlReaderServiceRef.ts","../src/services/definitions/cacheServiceRef.ts","../src/services/definitions/databaseServiceRef.ts","../src/services/definitions/discoveryServiceRef.ts","../src/services/definitions/tokenManagerServiceRef.ts","../src/services/definitions/permissionsServiceRef.ts","../src/services/definitions/schedulerServiceRef.ts","../src/services/helpers/loggerToWinstonLogger.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<T> = {\n id: string;\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: T;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/**\n * @internal\n */\nexport type InternalServiceRef<T> = ServiceRef<T> & {\n /**\n * The default factory that will be used to create service\n * instances if no other factory is provided.\n */\n __defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type DepsToDepFactories<T> = {\n [key in keyof T]: (pluginId: string) => Promise<T[key]>;\n};\n\n/** @public */\nexport type FactoryFunc<Impl> = (pluginId: string) => Promise<Impl>;\n\n/** @public */\nexport type ServiceFactory<TService = unknown> = {\n service: ServiceRef<TService>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<FactoryFunc<TService>>;\n};\n\n/**\n * @public\n */\nexport function createServiceRef<T>(options: {\n id: string;\n defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;\n}): ServiceRef<T> {\n const { id, defaultFactory } = options;\n return {\n id,\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 InternalServiceRef<T>;\n}\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TImpl extends TService,\n TDeps extends { [name in string]: unknown },\n>(factory: {\n service: ServiceRef<TService>;\n deps: TypesToServiceRef<TDeps>;\n factory(deps: DepsToDepFactories<TDeps>): Promise<FactoryFunc<TImpl>>;\n}): ServiceFactory<TService> {\n return factory 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 { Config } from '@backstage/config';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport const configServiceRef = createServiceRef<Config>({\n id: 'core.config',\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/types';\nimport { Handler } from 'express';\n\n/**\n * @public\n */\nexport interface HttpRouterService {\n use(handler: Handler): void;\n}\n\n/**\n * @public\n */\nexport const httpRouterServiceRef = createServiceRef<HttpRouterService>({\n id: 'core.httpRouter',\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/types';\n\n/**\n * @public\n */\nexport interface Logger {\n info(message: string): void;\n child(fields: { [name: string]: string }): Logger;\n}\n\n/**\n * @public\n */\nexport const loggerServiceRef = createServiceRef<Logger>({\n id: 'core.logger',\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/types';\nimport { UrlReader } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const urlReaderServiceRef = createServiceRef<UrlReader>({\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 { createServiceRef } from '../system/types';\nimport { PluginCacheManager } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const cacheServiceRef = createServiceRef<PluginCacheManager>({\n id: 'core.cache',\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 { PluginDatabaseManager } from '@backstage/backend-common';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport const databaseServiceRef = createServiceRef<PluginDatabaseManager>({\n id: 'core.database',\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/types';\nimport { PluginEndpointDiscovery } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const discoveryServiceRef = createServiceRef<PluginEndpointDiscovery>({\n id: 'core.discovery',\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/types';\nimport { TokenManager } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const tokenManagerServiceRef = createServiceRef<TokenManager>({\n id: 'core.tokenManager',\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/types';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n} from '@backstage/plugin-permission-common';\n\n/**\n * @public\n */\nexport const permissionsServiceRef = createServiceRef<\n PermissionEvaluator | PermissionAuthorizer\n>({\n id: 'core.permissions',\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/types';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\n\n/**\n * @public\n */\nexport const schedulerServiceRef = createServiceRef<PluginTaskScheduler>({\n id: 'core.scheduler',\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 { Logger as BackstageLogger } from '../definitions';\nimport { Logger as WinstonLogger, createLogger } from 'winston';\nimport Transport, { TransportStreamOptions } from 'winston-transport';\n\nclass BackstageLoggerTransport extends Transport {\n constructor(\n private readonly backstageLogger: BackstageLogger,\n opts?: TransportStreamOptions,\n ) {\n super(opts);\n }\n\n log(info: { message: string }, callback: VoidFunction) {\n // TODO: add support for levels and fields\n this.backstageLogger.info(info.message);\n callback();\n }\n}\n\n/** @public */\nexport function loggerToWinstonLogger(\n logger: BackstageLogger,\n opts?: TransportStreamOptions,\n): WinstonLogger {\n return createLogger({\n transports: [new BackstageLoggerTransport(logger, opts)],\n });\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 { [name: string]: unknown } | undefined = undefined,\n>(\n config: BackendPluginConfig<TOptions>,\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/** @public */\nexport function createBackendModule<\n TOptions extends { [name: string]: unknown } | 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":["Transport","createLogger"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/configServiceRef.ts","../src/services/definitions/httpRouterServiceRef.ts","../src/services/definitions/loggerServiceRef.ts","../src/services/definitions/urlReaderServiceRef.ts","../src/services/definitions/cacheServiceRef.ts","../src/services/definitions/databaseServiceRef.ts","../src/services/definitions/discoveryServiceRef.ts","../src/services/definitions/tokenManagerServiceRef.ts","../src/services/definitions/permissionsServiceRef.ts","../src/services/definitions/schedulerServiceRef.ts","../src/services/definitions/rootLoggerServiceRef.ts","../src/services/definitions/pluginMetadataServiceRef.ts","../src/services/helpers/loggerToWinstonLogger.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 { [name in string]: unknown } | 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 { Config } from '@backstage/config';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport const configServiceRef = createServiceRef<Config>({\n id: 'core.root.config',\n scope: 'root',\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/types';\nimport { Handler } from 'express';\n\n/**\n * @public\n */\nexport interface HttpRouterService {\n use(handler: Handler): void;\n}\n\n/**\n * @public\n */\nexport const httpRouterServiceRef = createServiceRef<HttpRouterService>({\n id: 'core.httpRouter',\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/types';\n\n/**\n * @public\n */\nexport interface Logger {\n info(message: string): void;\n child(fields: { [name: string]: string }): Logger;\n}\n\n/**\n * @public\n */\nexport const loggerServiceRef = createServiceRef<Logger>({\n id: 'core.logger',\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/types';\nimport { UrlReader } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const urlReaderServiceRef = createServiceRef<UrlReader>({\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 { createServiceRef } from '../system/types';\nimport { PluginCacheManager } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const cacheServiceRef = createServiceRef<PluginCacheManager>({\n id: 'core.cache',\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 { PluginDatabaseManager } from '@backstage/backend-common';\nimport { createServiceRef } from '../system/types';\n\n/**\n * @public\n */\nexport const databaseServiceRef = createServiceRef<PluginDatabaseManager>({\n id: 'core.database',\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/types';\nimport { PluginEndpointDiscovery } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const discoveryServiceRef = createServiceRef<PluginEndpointDiscovery>({\n id: 'core.discovery',\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/types';\nimport { TokenManager } from '@backstage/backend-common';\n\n/**\n * @public\n */\nexport const tokenManagerServiceRef = createServiceRef<TokenManager>({\n id: 'core.tokenManager',\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/types';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n} from '@backstage/plugin-permission-common';\n\n/**\n * @public\n */\nexport const permissionsServiceRef = createServiceRef<\n PermissionEvaluator | PermissionAuthorizer\n>({\n id: 'core.permissions',\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/types';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\n\n/**\n * @public\n */\nexport const schedulerServiceRef = createServiceRef<PluginTaskScheduler>({\n id: 'core.scheduler',\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/types';\nimport { Logger } from './loggerServiceRef';\n\n/**\n * @public\n */\nexport const rootLoggerServiceRef = createServiceRef<Logger>({\n id: 'core.root.logger',\n scope: 'root',\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/types';\n\n/**\n * @public\n */\nexport interface PluginMetadata {\n getId(): string;\n}\n\n/**\n * @public\n */\nexport const pluginMetadataServiceRef = createServiceRef<PluginMetadata>({\n id: 'core.plugin-metadata',\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 { Logger as BackstageLogger } from '../definitions';\nimport { Logger as WinstonLogger, createLogger } from 'winston';\nimport Transport, { TransportStreamOptions } from 'winston-transport';\n\nclass BackstageLoggerTransport extends Transport {\n constructor(\n private readonly backstageLogger: BackstageLogger,\n opts?: TransportStreamOptions,\n ) {\n super(opts);\n }\n\n log(info: { message: string }, callback: VoidFunction) {\n // TODO: add support for levels and fields\n this.backstageLogger.info(info.message);\n callback();\n }\n}\n\n/** @public */\nexport function loggerToWinstonLogger(\n logger: BackstageLogger,\n opts?: TransportStreamOptions,\n): WinstonLogger {\n return createLogger({\n transports: [new BackstageLoggerTransport(logger, opts)],\n });\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 { [name: string]: unknown } | undefined = undefined,\n>(\n config: BackendPluginConfig<TOptions>,\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/** @public */\nexport function createBackendModule<\n TOptions extends { [name: string]: unknown } | 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":["Transport","createLogger"],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -52,12 +52,12 @@ export declare interface BackendRegistrationPoints {
|
|
|
52
52
|
/**
|
|
53
53
|
* @public
|
|
54
54
|
*/
|
|
55
|
-
export declare const cacheServiceRef: ServiceRef<PluginCacheManager>;
|
|
55
|
+
export declare const cacheServiceRef: ServiceRef<PluginCacheManager, "plugin">;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* @public
|
|
59
59
|
*/
|
|
60
|
-
export declare const configServiceRef: ServiceRef<Config>;
|
|
60
|
+
export declare const configServiceRef: ServiceRef<Config, "root">;
|
|
61
61
|
|
|
62
62
|
/** @public */
|
|
63
63
|
export declare function createBackendModule<TOptions extends {
|
|
@@ -77,36 +77,39 @@ export declare function createExtensionPoint<T>(options: {
|
|
|
77
77
|
/**
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
|
-
export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
|
|
80
|
+
export declare function createServiceFactory<TService, TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends {
|
|
81
|
+
[name in string]: ServiceRef<unknown>;
|
|
82
|
+
}, TOpts extends {
|
|
81
83
|
[name in string]: unknown;
|
|
82
|
-
}>(
|
|
83
|
-
service: ServiceRef<TService>;
|
|
84
|
-
deps:
|
|
85
|
-
factory(deps:
|
|
86
|
-
}): ServiceFactory<TService>;
|
|
84
|
+
} | undefined = undefined>(config: {
|
|
85
|
+
service: ServiceRef<TService, TScope>;
|
|
86
|
+
deps: TDeps;
|
|
87
|
+
factory(deps: ServiceRefsToInstances<TDeps, 'root'>, options: TOpts): TScope extends 'root' ? Promise<TImpl> : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;
|
|
88
|
+
}): undefined extends TOpts ? (options?: TOpts) => ServiceFactory<TService> : (options: TOpts) => ServiceFactory<TService>;
|
|
87
89
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/** @public */
|
|
91
|
+
export declare function createServiceRef<T>(options: {
|
|
92
|
+
id: string;
|
|
93
|
+
scope?: 'plugin';
|
|
94
|
+
defaultFactory?: (service: ServiceRef<T, 'plugin'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
95
|
+
}): ServiceRef<T, 'plugin'>;
|
|
96
|
+
|
|
97
|
+
/** @public */
|
|
91
98
|
export declare function createServiceRef<T>(options: {
|
|
92
99
|
id: string;
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
scope: 'root';
|
|
101
|
+
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
102
|
+
}): ServiceRef<T, 'root'>;
|
|
95
103
|
|
|
96
104
|
/**
|
|
97
105
|
* @public
|
|
98
106
|
*/
|
|
99
|
-
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager>;
|
|
100
|
-
|
|
101
|
-
/** @public */
|
|
102
|
-
export declare type DepsToDepFactories<T> = {
|
|
103
|
-
[key in keyof T]: (pluginId: string) => Promise<T[key]>;
|
|
104
|
-
};
|
|
107
|
+
export declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
|
|
105
108
|
|
|
106
109
|
/**
|
|
107
110
|
* @public
|
|
108
111
|
*/
|
|
109
|
-
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery>;
|
|
112
|
+
export declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
|
|
110
113
|
|
|
111
114
|
/**
|
|
112
115
|
* TODO
|
|
@@ -124,9 +127,6 @@ export declare type ExtensionPoint<T> = {
|
|
|
124
127
|
$$ref: 'extension-point';
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
/** @public */
|
|
128
|
-
export declare type FactoryFunc<Impl> = (pluginId: string) => Promise<Impl>;
|
|
129
|
-
|
|
130
130
|
/**
|
|
131
131
|
* @public
|
|
132
132
|
*/
|
|
@@ -137,7 +137,7 @@ export declare interface HttpRouterService {
|
|
|
137
137
|
/**
|
|
138
138
|
* @public
|
|
139
139
|
*/
|
|
140
|
-
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService>;
|
|
140
|
+
export declare const httpRouterServiceRef: ServiceRef<HttpRouterService, "plugin">;
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* @public
|
|
@@ -152,7 +152,7 @@ export declare interface Logger {
|
|
|
152
152
|
/**
|
|
153
153
|
* @public
|
|
154
154
|
*/
|
|
155
|
-
export declare const loggerServiceRef: ServiceRef<Logger>;
|
|
155
|
+
export declare const loggerServiceRef: ServiceRef<Logger, "plugin">;
|
|
156
156
|
|
|
157
157
|
/** @public */
|
|
158
158
|
export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportStreamOptions): Logger_2;
|
|
@@ -160,22 +160,51 @@ export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportSt
|
|
|
160
160
|
/**
|
|
161
161
|
* @public
|
|
162
162
|
*/
|
|
163
|
-
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator>;
|
|
163
|
+
export declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator, "plugin">;
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* @public
|
|
167
167
|
*/
|
|
168
|
-
export declare
|
|
168
|
+
export declare interface PluginMetadata {
|
|
169
|
+
getId(): string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export declare const pluginMetadataServiceRef: ServiceRef<PluginMetadata, "plugin">;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare const rootLoggerServiceRef: ServiceRef<Logger, "root">;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
|
|
169
186
|
|
|
170
187
|
/** @public */
|
|
171
188
|
export declare type ServiceFactory<TService = unknown> = {
|
|
172
|
-
|
|
189
|
+
scope: 'root';
|
|
190
|
+
service: ServiceRef<TService, 'root'>;
|
|
191
|
+
deps: {
|
|
192
|
+
[key in string]: ServiceRef<unknown>;
|
|
193
|
+
};
|
|
194
|
+
factory(deps: {
|
|
195
|
+
[key in string]: unknown;
|
|
196
|
+
}): Promise<TService>;
|
|
197
|
+
} | {
|
|
198
|
+
scope: 'plugin';
|
|
199
|
+
service: ServiceRef<TService, 'plugin'>;
|
|
173
200
|
deps: {
|
|
174
201
|
[key in string]: ServiceRef<unknown>;
|
|
175
202
|
};
|
|
176
203
|
factory(deps: {
|
|
177
204
|
[key in string]: unknown;
|
|
178
|
-
}): Promise<
|
|
205
|
+
}): Promise<(deps: {
|
|
206
|
+
[key in string]: unknown;
|
|
207
|
+
}) => Promise<TService>>;
|
|
179
208
|
};
|
|
180
209
|
|
|
181
210
|
/**
|
|
@@ -183,21 +212,40 @@ export declare type ServiceFactory<TService = unknown> = {
|
|
|
183
212
|
*
|
|
184
213
|
* @public
|
|
185
214
|
*/
|
|
186
|
-
export declare type ServiceRef<
|
|
215
|
+
export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
187
216
|
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* This determines the scope at which this service is available.
|
|
219
|
+
*
|
|
220
|
+
* Root scoped services are available to all other services but
|
|
221
|
+
* may only depend on other root scoped services.
|
|
222
|
+
*
|
|
223
|
+
* Plugin scoped services are only available to other plugin scoped
|
|
224
|
+
* services but may depend on all other services.
|
|
225
|
+
*/
|
|
226
|
+
scope: TScope;
|
|
188
227
|
/**
|
|
189
228
|
* Utility for getting the type of the service, using `typeof serviceRef.T`.
|
|
190
229
|
* Attempting to actually read this value will result in an exception.
|
|
191
230
|
*/
|
|
192
|
-
T:
|
|
231
|
+
T: TService;
|
|
193
232
|
toString(): string;
|
|
194
233
|
$$ref: 'service';
|
|
195
234
|
};
|
|
196
235
|
|
|
236
|
+
/** @ignore */
|
|
237
|
+
declare type ServiceRefsToInstances<T extends {
|
|
238
|
+
[key in string]: ServiceRef<unknown>;
|
|
239
|
+
}, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
|
|
240
|
+
[name in {
|
|
241
|
+
[key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;
|
|
242
|
+
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
243
|
+
};
|
|
244
|
+
|
|
197
245
|
/**
|
|
198
246
|
* @public
|
|
199
247
|
*/
|
|
200
|
-
export declare const tokenManagerServiceRef: ServiceRef<TokenManager>;
|
|
248
|
+
export declare const tokenManagerServiceRef: ServiceRef<TokenManager, "plugin">;
|
|
201
249
|
|
|
202
250
|
/** @public */
|
|
203
251
|
export declare type TypesToServiceRef<T> = {
|
|
@@ -207,6 +255,6 @@ export declare type TypesToServiceRef<T> = {
|
|
|
207
255
|
/**
|
|
208
256
|
* @public
|
|
209
257
|
*/
|
|
210
|
-
export declare const urlReaderServiceRef: ServiceRef<UrlReader>;
|
|
258
|
+
export declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
|
|
211
259
|
|
|
212
260
|
export { }
|
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.1.2
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"start": "backstage-cli package start"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-common": "^0.15.1
|
|
37
|
-
"@backstage/backend-tasks": "^0.3.5
|
|
38
|
-
"@backstage/config": "^1.0.
|
|
39
|
-
"@backstage/plugin-permission-common": "^0.6.4
|
|
36
|
+
"@backstage/backend-common": "^0.15.1",
|
|
37
|
+
"@backstage/backend-tasks": "^0.3.5",
|
|
38
|
+
"@backstage/config": "^1.0.2",
|
|
39
|
+
"@backstage/plugin-permission-common": "^0.6.4",
|
|
40
40
|
"@types/express": "^4.17.6",
|
|
41
41
|
"express": "^4.17.1",
|
|
42
42
|
"winston": "^3.2.1",
|
|
43
43
|
"winston-transport": "^4.5.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@backstage/cli": "^0.19.0
|
|
46
|
+
"@backstage/cli": "^0.19.0"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"dist",
|
|
50
50
|
"alpha"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "25b94e63455f1fb170506f9e84e3f430f4b79406"
|
|
53
53
|
}
|