@backstage/backend-app-api 1.0.0 → 1.0.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,240 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var errors = require('@backstage/errors');
5
+ var DependencyGraph = require('../lib/DependencyGraph.cjs.js');
6
+
7
+ function toInternalServiceFactory(factory) {
8
+ const f = factory;
9
+ if (f.$$type !== "@backstage/BackendFeature") {
10
+ throw new Error(`Invalid service factory, bad type '${f.$$type}'`);
11
+ }
12
+ if (f.version !== "v1") {
13
+ throw new Error(`Invalid service factory, bad version '${f.version}'`);
14
+ }
15
+ return f;
16
+ }
17
+ function createPluginMetadataServiceFactory(pluginId) {
18
+ return backendPluginApi.createServiceFactory({
19
+ service: backendPluginApi.coreServices.pluginMetadata,
20
+ deps: {},
21
+ factory: async () => ({ getId: () => pluginId })
22
+ });
23
+ }
24
+ class ServiceRegistry {
25
+ static create(factories) {
26
+ const factoryMap = /* @__PURE__ */ new Map();
27
+ for (const factory of factories) {
28
+ if (factory.service.multiton) {
29
+ const existing = factoryMap.get(factory.service.id) ?? [];
30
+ factoryMap.set(
31
+ factory.service.id,
32
+ existing.concat(toInternalServiceFactory(factory))
33
+ );
34
+ } else {
35
+ factoryMap.set(factory.service.id, [toInternalServiceFactory(factory)]);
36
+ }
37
+ }
38
+ const registry = new ServiceRegistry(factoryMap);
39
+ registry.checkForCircularDeps();
40
+ return registry;
41
+ }
42
+ #providedFactories;
43
+ #loadedDefaultFactories;
44
+ #implementations;
45
+ #rootServiceImplementations = /* @__PURE__ */ new Map();
46
+ #addedFactoryIds = /* @__PURE__ */ new Set();
47
+ #instantiatedFactories = /* @__PURE__ */ new Set();
48
+ constructor(factories) {
49
+ this.#providedFactories = factories;
50
+ this.#loadedDefaultFactories = /* @__PURE__ */ new Map();
51
+ this.#implementations = /* @__PURE__ */ new Map();
52
+ }
53
+ #resolveFactory(ref, pluginId) {
54
+ if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
55
+ return Promise.resolve([
56
+ toInternalServiceFactory(createPluginMetadataServiceFactory(pluginId))
57
+ ]);
58
+ }
59
+ let resolvedFactory = this.#providedFactories.get(ref.id);
60
+ const { __defaultFactory: defaultFactory } = ref;
61
+ if (!resolvedFactory && !defaultFactory) {
62
+ return void 0;
63
+ }
64
+ if (!resolvedFactory) {
65
+ let loadedFactory = this.#loadedDefaultFactories.get(defaultFactory);
66
+ if (!loadedFactory) {
67
+ loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
68
+ (f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
69
+ );
70
+ this.#loadedDefaultFactories.set(defaultFactory, loadedFactory);
71
+ }
72
+ resolvedFactory = loadedFactory.then(
73
+ (factory) => [factory],
74
+ (error) => {
75
+ throw new Error(
76
+ `Failed to instantiate service '${ref.id}' because the default factory loader threw an error, ${errors.stringifyError(
77
+ error
78
+ )}`
79
+ );
80
+ }
81
+ );
82
+ }
83
+ return Promise.resolve(resolvedFactory);
84
+ }
85
+ #checkForMissingDeps(factory, pluginId) {
86
+ const missingDeps = Object.values(factory.deps).filter((ref) => {
87
+ if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
88
+ return false;
89
+ }
90
+ if (this.#providedFactories.get(ref.id)) {
91
+ return false;
92
+ }
93
+ if (ref.multiton) {
94
+ return false;
95
+ }
96
+ return !ref.__defaultFactory;
97
+ });
98
+ if (missingDeps.length) {
99
+ const missing = missingDeps.map((r) => `'${r.id}'`).join(", ");
100
+ throw new Error(
101
+ `Failed to instantiate service '${factory.service.id}' for '${pluginId}' because the following dependent services are missing: ${missing}`
102
+ );
103
+ }
104
+ }
105
+ checkForCircularDeps() {
106
+ const graph = DependencyGraph.DependencyGraph.fromIterable(
107
+ Array.from(this.#providedFactories).map(([serviceId, factories]) => ({
108
+ value: serviceId,
109
+ provides: [serviceId],
110
+ consumes: factories.flatMap(
111
+ (factory) => Object.values(factory.deps).map((d) => d.id)
112
+ )
113
+ }))
114
+ );
115
+ const circularDependencies = Array.from(graph.detectCircularDependencies());
116
+ if (circularDependencies.length) {
117
+ const cycles = circularDependencies.map((c) => c.map((id) => `'${id}'`).join(" -> ")).join("\n ");
118
+ throw new errors.ConflictError(`Circular dependencies detected:
119
+ ${cycles}`);
120
+ }
121
+ }
122
+ add(factory) {
123
+ const factoryId = factory.service.id;
124
+ if (factoryId === backendPluginApi.coreServices.pluginMetadata.id) {
125
+ throw new Error(
126
+ `The ${backendPluginApi.coreServices.pluginMetadata.id} service cannot be overridden`
127
+ );
128
+ }
129
+ if (this.#instantiatedFactories.has(factoryId)) {
130
+ throw new Error(
131
+ `Unable to set service factory with id ${factoryId}, service has already been instantiated`
132
+ );
133
+ }
134
+ if (factory.service.multiton) {
135
+ const newFactories = (this.#providedFactories.get(factoryId) ?? []).concat(toInternalServiceFactory(factory));
136
+ this.#providedFactories.set(factoryId, newFactories);
137
+ } else {
138
+ if (this.#addedFactoryIds.has(factoryId)) {
139
+ throw new Error(
140
+ `Duplicate service implementations provided for ${factoryId}`
141
+ );
142
+ }
143
+ this.#addedFactoryIds.add(factoryId);
144
+ this.#providedFactories.set(factoryId, [
145
+ toInternalServiceFactory(factory)
146
+ ]);
147
+ }
148
+ }
149
+ async initializeEagerServicesWithScope(scope, pluginId = "root") {
150
+ for (const [factory] of this.#providedFactories.values()) {
151
+ if (factory.service.scope === scope) {
152
+ if (scope === "root" && factory.initialization !== "lazy") {
153
+ await this.get(factory.service, pluginId);
154
+ } else if (scope === "plugin" && factory.initialization === "always") {
155
+ await this.get(factory.service, pluginId);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ get(ref, pluginId) {
161
+ this.#instantiatedFactories.add(ref.id);
162
+ const resolvedFactory = this.#resolveFactory(ref, pluginId);
163
+ if (!resolvedFactory) {
164
+ return ref.multiton ? Promise.resolve([]) : void 0;
165
+ }
166
+ return resolvedFactory.then((factories) => {
167
+ return Promise.all(
168
+ factories.map((factory) => {
169
+ if (factory.service.scope === "root") {
170
+ let existing = this.#rootServiceImplementations.get(factory);
171
+ if (!existing) {
172
+ this.#checkForMissingDeps(factory, pluginId);
173
+ const rootDeps = new Array();
174
+ for (const [name, serviceRef] of Object.entries(factory.deps)) {
175
+ if (serviceRef.scope !== "root") {
176
+ throw new Error(
177
+ `Failed to instantiate 'root' scoped service '${ref.id}' because it depends on '${serviceRef.scope}' scoped service '${serviceRef.id}'.`
178
+ );
179
+ }
180
+ const target = this.get(serviceRef, pluginId);
181
+ rootDeps.push(target.then((impl) => [name, impl]));
182
+ }
183
+ existing = Promise.all(rootDeps).then(
184
+ (entries) => factory.factory(Object.fromEntries(entries), void 0)
185
+ );
186
+ this.#rootServiceImplementations.set(factory, existing);
187
+ }
188
+ return existing;
189
+ }
190
+ let implementation = this.#implementations.get(factory);
191
+ if (!implementation) {
192
+ this.#checkForMissingDeps(factory, pluginId);
193
+ const rootDeps = new Array();
194
+ for (const [name, serviceRef] of Object.entries(factory.deps)) {
195
+ if (serviceRef.scope === "root") {
196
+ const target = this.get(serviceRef, pluginId);
197
+ rootDeps.push(target.then((impl) => [name, impl]));
198
+ }
199
+ }
200
+ implementation = {
201
+ context: Promise.all(rootDeps).then(
202
+ (entries) => factory.createRootContext?.(Object.fromEntries(entries))
203
+ ).catch((error) => {
204
+ const cause = errors.stringifyError(error);
205
+ throw new Error(
206
+ `Failed to instantiate service '${ref.id}' because createRootContext threw an error, ${cause}`
207
+ );
208
+ }),
209
+ byPlugin: /* @__PURE__ */ new Map()
210
+ };
211
+ this.#implementations.set(factory, implementation);
212
+ }
213
+ let result = implementation.byPlugin.get(pluginId);
214
+ if (!result) {
215
+ const allDeps = new Array();
216
+ for (const [name, serviceRef] of Object.entries(factory.deps)) {
217
+ const target = this.get(serviceRef, pluginId);
218
+ allDeps.push(target.then((impl) => [name, impl]));
219
+ }
220
+ result = implementation.context.then(
221
+ (context) => Promise.all(allDeps).then(
222
+ (entries) => factory.factory(Object.fromEntries(entries), context)
223
+ )
224
+ ).catch((error) => {
225
+ const cause = errors.stringifyError(error);
226
+ throw new Error(
227
+ `Failed to instantiate service '${ref.id}' for '${pluginId}' because the factory function threw an error, ${cause}`
228
+ );
229
+ });
230
+ implementation.byPlugin.set(pluginId, result);
231
+ }
232
+ return result;
233
+ })
234
+ );
235
+ }).then((results) => ref.multiton ? results : results[0]);
236
+ }
237
+ }
238
+
239
+ exports.ServiceRegistry = ServiceRegistry;
240
+ //# sourceMappingURL=ServiceRegistry.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceRegistry.cjs.js","sources":["../../src/wiring/ServiceRegistry.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 {\n ServiceFactory,\n ServiceRef,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { ConflictError, stringifyError } from '@backstage/errors';\n// Direct internal import to avoid duplication\n// eslint-disable-next-line @backstage/no-forbidden-package-imports\nimport { InternalServiceFactory } from '@backstage/backend-plugin-api/src/services/system/types';\nimport { DependencyGraph } from '../lib/DependencyGraph';\n/**\n * Keep in sync with `@backstage/backend-plugin-api/src/services/system/types.ts`\n * @internal\n */\nexport type InternalServiceRef = ServiceRef<unknown> & {\n __defaultFactory?: (\n service: ServiceRef<unknown>,\n ) => Promise<ServiceFactory | (() => ServiceFactory)>;\n};\n\nfunction toInternalServiceFactory<TService, TScope extends 'plugin' | 'root'>(\n factory: ServiceFactory<TService, TScope>,\n): InternalServiceFactory<TService, TScope> {\n const f = factory as InternalServiceFactory<TService, TScope>;\n if (f.$$type !== '@backstage/BackendFeature') {\n throw new Error(`Invalid service factory, bad type '${f.$$type}'`);\n }\n if (f.version !== 'v1') {\n throw new Error(`Invalid service factory, bad version '${f.version}'`);\n }\n return f;\n}\n\nfunction createPluginMetadataServiceFactory(pluginId: string) {\n return createServiceFactory({\n service: coreServices.pluginMetadata,\n deps: {},\n factory: async () => ({ getId: () => pluginId }),\n });\n}\n\nexport class ServiceRegistry {\n static create(factories: Array<ServiceFactory>): ServiceRegistry {\n const factoryMap = new Map<string, InternalServiceFactory[]>();\n for (const factory of factories) {\n if (factory.service.multiton) {\n const existing = factoryMap.get(factory.service.id) ?? [];\n factoryMap.set(\n factory.service.id,\n existing.concat(toInternalServiceFactory(factory)),\n );\n } else {\n factoryMap.set(factory.service.id, [toInternalServiceFactory(factory)]);\n }\n }\n const registry = new ServiceRegistry(factoryMap);\n registry.checkForCircularDeps();\n return registry;\n }\n\n readonly #providedFactories: Map<string, InternalServiceFactory[]>;\n readonly #loadedDefaultFactories: Map<\n Function,\n Promise<InternalServiceFactory>\n >;\n readonly #implementations: Map<\n InternalServiceFactory,\n {\n context: Promise<unknown>;\n byPlugin: Map<string, Promise<unknown>>;\n }\n >;\n readonly #rootServiceImplementations = new Map<\n InternalServiceFactory,\n Promise<unknown>\n >();\n readonly #addedFactoryIds = new Set<string>();\n readonly #instantiatedFactories = new Set<string>();\n\n private constructor(factories: Map<string, InternalServiceFactory[]>) {\n this.#providedFactories = factories;\n this.#loadedDefaultFactories = new Map();\n this.#implementations = new Map();\n }\n\n #resolveFactory(\n ref: ServiceRef<unknown>,\n pluginId: string,\n ): Promise<InternalServiceFactory[]> | undefined {\n // Special case handling of the plugin metadata service, generating a custom factory for it each time\n if (ref.id === coreServices.pluginMetadata.id) {\n return Promise.resolve([\n toInternalServiceFactory(createPluginMetadataServiceFactory(pluginId)),\n ]);\n }\n\n let resolvedFactory:\n | Promise<InternalServiceFactory[]>\n | InternalServiceFactory[]\n | undefined = this.#providedFactories.get(ref.id);\n const { __defaultFactory: defaultFactory } = ref as InternalServiceRef;\n if (!resolvedFactory && !defaultFactory) {\n return undefined;\n }\n\n if (!resolvedFactory) {\n let loadedFactory = this.#loadedDefaultFactories.get(defaultFactory!);\n if (!loadedFactory) {\n loadedFactory = Promise.resolve()\n .then(() => defaultFactory!(ref))\n .then(f =>\n toInternalServiceFactory(typeof f === 'function' ? f() : f),\n );\n this.#loadedDefaultFactories.set(defaultFactory!, loadedFactory);\n }\n resolvedFactory = loadedFactory.then(\n factory => [factory],\n error => {\n throw new Error(\n `Failed to instantiate service '${\n ref.id\n }' because the default factory loader threw an error, ${stringifyError(\n error,\n )}`,\n );\n },\n );\n }\n\n return Promise.resolve(resolvedFactory);\n }\n\n #checkForMissingDeps(factory: InternalServiceFactory, pluginId: string) {\n const missingDeps = Object.values(factory.deps).filter(ref => {\n if (ref.id === coreServices.pluginMetadata.id) {\n return false;\n }\n if (this.#providedFactories.get(ref.id)) {\n return false;\n }\n if (ref.multiton) {\n return false;\n }\n\n return !(ref as InternalServiceRef).__defaultFactory;\n });\n\n if (missingDeps.length) {\n const missing = missingDeps.map(r => `'${r.id}'`).join(', ');\n throw new Error(\n `Failed to instantiate service '${factory.service.id}' for '${pluginId}' because the following dependent services are missing: ${missing}`,\n );\n }\n }\n\n checkForCircularDeps(): void {\n const graph = DependencyGraph.fromIterable(\n Array.from(this.#providedFactories).map(([serviceId, factories]) => ({\n value: serviceId,\n provides: [serviceId],\n consumes: factories.flatMap(factory =>\n Object.values(factory.deps).map(d => d.id),\n ),\n })),\n );\n const circularDependencies = Array.from(graph.detectCircularDependencies());\n\n if (circularDependencies.length) {\n const cycles = circularDependencies\n .map(c => c.map(id => `'${id}'`).join(' -> '))\n .join('\\n ');\n\n throw new ConflictError(`Circular dependencies detected:\\n ${cycles}`);\n }\n }\n\n add(factory: ServiceFactory) {\n const factoryId = factory.service.id;\n if (factoryId === coreServices.pluginMetadata.id) {\n throw new Error(\n `The ${coreServices.pluginMetadata.id} service cannot be overridden`,\n );\n }\n\n if (this.#instantiatedFactories.has(factoryId)) {\n throw new Error(\n `Unable to set service factory with id ${factoryId}, service has already been instantiated`,\n );\n }\n\n if (factory.service.multiton) {\n const newFactories = (\n this.#providedFactories.get(factoryId) ?? []\n ).concat(toInternalServiceFactory(factory));\n this.#providedFactories.set(factoryId, newFactories);\n } else {\n if (this.#addedFactoryIds.has(factoryId)) {\n throw new Error(\n `Duplicate service implementations provided for ${factoryId}`,\n );\n }\n\n this.#addedFactoryIds.add(factoryId);\n this.#providedFactories.set(factoryId, [\n toInternalServiceFactory(factory),\n ]);\n }\n }\n\n async initializeEagerServicesWithScope(\n scope: 'root' | 'plugin',\n pluginId: string = 'root',\n ) {\n for (const [factory] of this.#providedFactories.values()) {\n if (factory.service.scope === scope) {\n // Root-scoped services are eager by default, plugin-scoped are lazy by default\n if (scope === 'root' && factory.initialization !== 'lazy') {\n await this.get(factory.service, pluginId);\n } else if (scope === 'plugin' && factory.initialization === 'always') {\n await this.get(factory.service, pluginId);\n }\n }\n }\n }\n\n get<T, TInstances extends 'singleton' | 'multiton'>(\n ref: ServiceRef<T, 'plugin' | 'root', TInstances>,\n pluginId: string,\n ): Promise<TInstances extends 'multiton' ? T[] : T> | undefined {\n this.#instantiatedFactories.add(ref.id);\n\n const resolvedFactory = this.#resolveFactory(ref, pluginId);\n\n if (!resolvedFactory) {\n return ref.multiton\n ? (Promise.resolve([]) as\n | Promise<TInstances extends 'multiton' ? T[] : T>\n | undefined)\n : undefined;\n }\n\n return resolvedFactory\n .then(factories => {\n return Promise.all(\n factories.map(factory => {\n if (factory.service.scope === 'root') {\n let existing = this.#rootServiceImplementations.get(factory);\n if (!existing) {\n this.#checkForMissingDeps(factory, pluginId);\n const rootDeps = new Array<\n Promise<[name: string, impl: unknown]>\n >();\n\n for (const [name, serviceRef] of Object.entries(factory.deps)) {\n if (serviceRef.scope !== 'root') {\n throw new Error(\n `Failed to instantiate 'root' scoped service '${ref.id}' because it depends on '${serviceRef.scope}' scoped service '${serviceRef.id}'.`,\n );\n }\n const target = this.get(serviceRef, pluginId)!;\n rootDeps.push(target.then(impl => [name, impl]));\n }\n\n existing = Promise.all(rootDeps).then(entries =>\n factory.factory(Object.fromEntries(entries), undefined),\n );\n this.#rootServiceImplementations.set(factory, existing);\n }\n return existing as Promise<T>;\n }\n\n let implementation = this.#implementations.get(factory);\n if (!implementation) {\n this.#checkForMissingDeps(factory, pluginId);\n const rootDeps = new Array<\n Promise<[name: string, impl: unknown]>\n >();\n\n for (const [name, serviceRef] of Object.entries(factory.deps)) {\n if (serviceRef.scope === 'root') {\n const target = this.get(serviceRef, pluginId)!;\n rootDeps.push(target.then(impl => [name, impl]));\n }\n }\n\n implementation = {\n context: Promise.all(rootDeps)\n .then(entries =>\n factory.createRootContext?.(Object.fromEntries(entries)),\n )\n .catch(error => {\n const cause = stringifyError(error);\n throw new Error(\n `Failed to instantiate service '${ref.id}' because createRootContext threw an error, ${cause}`,\n );\n }),\n byPlugin: new Map(),\n };\n\n this.#implementations.set(factory, implementation);\n }\n\n let result = implementation.byPlugin.get(pluginId) as Promise<any>;\n if (!result) {\n const allDeps = new Array<\n Promise<[name: string, impl: unknown]>\n >();\n\n for (const [name, serviceRef] of Object.entries(factory.deps)) {\n const target = this.get(serviceRef, pluginId)!;\n allDeps.push(target.then(impl => [name, impl]));\n }\n\n result = implementation.context\n .then(context =>\n Promise.all(allDeps).then(entries =>\n factory.factory(Object.fromEntries(entries), context),\n ),\n )\n .catch(error => {\n const cause = stringifyError(error);\n throw new Error(\n `Failed to instantiate service '${ref.id}' for '${pluginId}' because the factory function threw an error, ${cause}`,\n );\n });\n implementation.byPlugin.set(pluginId, result);\n }\n return result;\n }),\n );\n })\n .then(results => (ref.multiton ? results : results[0]));\n }\n}\n"],"names":["createServiceFactory","coreServices","stringifyError","DependencyGraph","ConflictError"],"mappings":";;;;;;AAqCA,SAAS,yBACP,OAC0C,EAAA;AAC1C,EAAA,MAAM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LOGGER_INTERVAL_MAX = 6e4;
4
+ function joinIds(ids) {
5
+ return [...ids].map((id) => `'${id}'`).join(", ");
6
+ }
7
+ function createInitializationLogger(pluginIds, rootLogger) {
8
+ const logger = rootLogger?.child({ type: "initialization" });
9
+ const starting = new Set(pluginIds);
10
+ const started = /* @__PURE__ */ new Set();
11
+ logger?.info(`Plugin initialization started: ${joinIds(pluginIds)}`);
12
+ const getInitStatus = () => {
13
+ let status = "";
14
+ if (started.size > 0) {
15
+ status = `, newly initialized: ${joinIds(started)}`;
16
+ started.clear();
17
+ }
18
+ if (starting.size > 0) {
19
+ status += `, still initializing: ${joinIds(starting)}`;
20
+ }
21
+ return status;
22
+ };
23
+ let interval = 1e3;
24
+ let prevInterval = 0;
25
+ let timeout;
26
+ const onTimeout = () => {
27
+ logger?.info(`Plugin initialization in progress${getInitStatus()}`);
28
+ const nextInterval = Math.min(interval + prevInterval, LOGGER_INTERVAL_MAX);
29
+ prevInterval = interval;
30
+ interval = nextInterval;
31
+ timeout = setTimeout(onTimeout, nextInterval);
32
+ };
33
+ timeout = setTimeout(onTimeout, interval);
34
+ return {
35
+ onPluginStarted(pluginId) {
36
+ starting.delete(pluginId);
37
+ started.add(pluginId);
38
+ },
39
+ onPluginFailed(pluginId) {
40
+ starting.delete(pluginId);
41
+ const status = starting.size > 0 ? `, waiting for ${starting.size} other plugins to finish before shutting down the process` : "";
42
+ logger?.error(
43
+ `Plugin '${pluginId}' thew an error during startup${status}`
44
+ );
45
+ },
46
+ onAllStarted() {
47
+ logger?.info(`Plugin initialization complete${getInitStatus()}`);
48
+ if (timeout) {
49
+ clearTimeout(timeout);
50
+ timeout = void 0;
51
+ }
52
+ }
53
+ };
54
+ }
55
+
56
+ exports.createInitializationLogger = createInitializationLogger;
57
+ //# sourceMappingURL=createInitializationLogger.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInitializationLogger.cjs.js","sources":["../../src/wiring/createInitializationLogger.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { RootLoggerService } from '@backstage/backend-plugin-api';\n\nconst LOGGER_INTERVAL_MAX = 60_000;\n\nfunction joinIds(ids: Iterable<string>): string {\n return [...ids].map(id => `'${id}'`).join(', ');\n}\n\nexport function createInitializationLogger(\n pluginIds: string[],\n rootLogger?: RootLoggerService,\n): {\n onPluginStarted(pluginId: string): void;\n onPluginFailed(pluginId: string): void;\n onAllStarted(): void;\n} {\n const logger = rootLogger?.child({ type: 'initialization' });\n const starting = new Set(pluginIds);\n const started = new Set<string>();\n\n logger?.info(`Plugin initialization started: ${joinIds(pluginIds)}`);\n\n const getInitStatus = () => {\n let status = '';\n if (started.size > 0) {\n status = `, newly initialized: ${joinIds(started)}`;\n started.clear();\n }\n if (starting.size > 0) {\n status += `, still initializing: ${joinIds(starting)}`;\n }\n return status;\n };\n\n // Periodically log the initialization status with a fibonacci backoff\n let interval = 1000;\n let prevInterval = 0;\n let timeout: NodeJS.Timeout | undefined;\n const onTimeout = () => {\n logger?.info(`Plugin initialization in progress${getInitStatus()}`);\n\n const nextInterval = Math.min(interval + prevInterval, LOGGER_INTERVAL_MAX);\n prevInterval = interval;\n interval = nextInterval;\n\n timeout = setTimeout(onTimeout, nextInterval);\n };\n timeout = setTimeout(onTimeout, interval);\n\n return {\n onPluginStarted(pluginId: string) {\n starting.delete(pluginId);\n started.add(pluginId);\n },\n onPluginFailed(pluginId: string) {\n starting.delete(pluginId);\n const status =\n starting.size > 0\n ? `, waiting for ${starting.size} other plugins to finish before shutting down the process`\n : '';\n logger?.error(\n `Plugin '${pluginId}' thew an error during startup${status}`,\n );\n },\n onAllStarted() {\n logger?.info(`Plugin initialization complete${getInitStatus()}`);\n\n if (timeout) {\n clearTimeout(timeout);\n timeout = undefined;\n }\n },\n };\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,mBAAsB,GAAA,GAAA,CAAA;AAE5B,SAAS,QAAQ,GAA+B,EAAA;AAC9C,EAAO,OAAA,CAAC,GAAG,GAAG,CAAE,CAAA,GAAA,CAAI,CAAM,EAAA,KAAA,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAChD,CAAA;AAEgB,SAAA,0BAAA,CACd,WACA,UAKA,EAAA;AACA,EAAA,MAAM,SAAS,UAAY,EAAA,KAAA,CAAM,EAAE,IAAA,EAAM,kBAAkB,CAAA,CAAA;AAC3D,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,SAAS,CAAA,CAAA;AAClC,EAAM,MAAA,OAAA,uBAAc,GAAY,EAAA,CAAA;AAEhC,EAAA,MAAA,EAAQ,IAAK,CAAA,CAAA,+BAAA,EAAkC,OAAQ,CAAA,SAAS,CAAC,CAAE,CAAA,CAAA,CAAA;AAEnE,EAAA,MAAM,gBAAgB,MAAM;AAC1B,IAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,IAAI,IAAA,OAAA,CAAQ,OAAO,CAAG,EAAA;AACpB,MAAS,MAAA,GAAA,CAAA,qBAAA,EAAwB,OAAQ,CAAA,OAAO,CAAC,CAAA,CAAA,CAAA;AACjD,MAAA,OAAA,CAAQ,KAAM,EAAA,CAAA;AAAA,KAChB;AACA,IAAI,IAAA,QAAA,CAAS,OAAO,CAAG,EAAA;AACrB,MAAU,MAAA,IAAA,CAAA,sBAAA,EAAyB,OAAQ,CAAA,QAAQ,CAAC,CAAA,CAAA,CAAA;AAAA,KACtD;AACA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT,CAAA;AAGA,EAAA,IAAI,QA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A,GAAA,KAAA,CAAA,CAAA;AAAA,OACZ;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;"}
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var BackstageBackend = require('./BackstageBackend.cjs.js');
5
+
6
+ function createSpecializedBackend(options) {
7
+ const exists = /* @__PURE__ */ new Set();
8
+ const duplicates = /* @__PURE__ */ new Set();
9
+ for (const { service } of options.defaultServiceFactories) {
10
+ if (exists.has(service.id)) {
11
+ duplicates.add(service.id);
12
+ } else {
13
+ exists.add(service.id);
14
+ }
15
+ }
16
+ if (duplicates.size > 0) {
17
+ const ids = Array.from(duplicates).join(", ");
18
+ throw new Error(`Duplicate service implementations provided for ${ids}`);
19
+ }
20
+ if (exists.has(backendPluginApi.coreServices.pluginMetadata.id)) {
21
+ throw new Error(
22
+ `The ${backendPluginApi.coreServices.pluginMetadata.id} service cannot be overridden`
23
+ );
24
+ }
25
+ return new BackstageBackend.BackstageBackend(options.defaultServiceFactories);
26
+ }
27
+
28
+ exports.createSpecializedBackend = createSpecializedBackend;
29
+ //# sourceMappingURL=createSpecializedBackend.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSpecializedBackend.cjs.js","sources":["../../src/wiring/createSpecializedBackend.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 { coreServices } from '@backstage/backend-plugin-api';\nimport { BackstageBackend } from './BackstageBackend';\nimport { Backend, CreateSpecializedBackendOptions } from './types';\n\n/**\n * @public\n */\nexport function createSpecializedBackend(\n options: CreateSpecializedBackendOptions,\n): Backend {\n const exists = new Set<string>();\n const duplicates = new Set<string>();\n for (const { service } of options.defaultServiceFactories) {\n if (exists.has(service.id)) {\n duplicates.add(service.id);\n } else {\n exists.add(service.id);\n }\n }\n if (duplicates.size > 0) {\n const ids = Array.from(duplicates).join(', ');\n throw new Error(`Duplicate service implementations provided for ${ids}`);\n }\n if (exists.has(coreServices.pluginMetadata.id)) {\n throw new Error(\n `The ${coreServices.pluginMetadata.id} service cannot be overridden`,\n );\n }\n\n return new BackstageBackend(options.defaultServiceFactories);\n}\n"],"names":["coreServices","BackstageBackend"],"mappings":";;;;;AAuBO,SAAS,yBACd,OACS,EAAA;AACT,EAAM,MAAA,MAAA,uBAAa,GAAY,EAAA,CAAA;AAC/B,EAAM,MAAA,UAAA,uBAAiB,GAAY,EAAA,CAAA;AACnC,EAAA,KAAA,MAAW,EAAE,OAAA,EAAa,IAAA,OAAA,CAAQ,uBAAyB,EAAA;AACzD,IAAA,IAAI,MAAO,CAAA,GAAA,CAAI,OAAQ,CAAA,EAAE,CAAG,EAAA;AAC1B,MAAW,UAAA,CAAA,GAAA,CAAI,QAAQ,EAAE,CAAA,CAAA;AAAA,KACpB,MAAA;AACL,MAAO,MAAA,CAAA,GAAA,CAAI,QAAQ,EAAE,CAAA,CAAA;AAAA,KACvB;AAAA,GACF;AACA,EAAI,IAAA,UAAA,CAAW,OAAO,CAAG,EAAA;AACvB,IAAA,MAAM,MAAM,KAAM,CAAA,IAAA,CAAK,UAAU,CAAA,CAAE,KAAK,IAAI,CAAA,CAAA;AAC5C,IAAA,MAAM,IAAI,KAAA,CAAM,CAAkD,+CAAA,EAAA,GAAG,CAAE,CAAA,CAAA,CAAA;AAAA,GACzE;AACA,EAAA,IAAI,MAAO,CAAA,GAAA,CAAIA,6BAAa,CAAA,cAAA,CAAe,EAAE,CAAG,EAAA;AAC9C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,IAAA,EAAOA,6BAAa,CAAA,cAAA,CAAe,EAAE,CAAA,6BAAA,CAAA;AAAA,KACvC,CAAA;AAAA,GACF;AAEA,EAAO,OAAA,IAAIC,iCAAiB,CAAA,OAAA,CAAQ,uBAAuB,CAAA,CAAA;AAC7D;;;;"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ function unwrapFeature(feature) {
4
+ if ("$$type" in feature) {
5
+ return feature;
6
+ }
7
+ if ("default" in feature) {
8
+ return feature.default;
9
+ }
10
+ return feature;
11
+ }
12
+
13
+ exports.unwrapFeature = unwrapFeature;
14
+ //# sourceMappingURL=helpers.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../../src/wiring/helpers.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { BackendFeature } from '@backstage/backend-plugin-api';\n\n/** @internal */\nexport function unwrapFeature(\n feature: BackendFeature | { default: BackendFeature },\n): BackendFeature {\n if ('$$type' in feature) {\n return feature;\n }\n\n // This is a workaround where default exports get transpiled to `exports['default'] = ...`\n // in CommonJS modules, which in turn results in a double `{ default: { default: ... } }` nesting\n // when importing using a dynamic import.\n // TODO: This is a broader issue than just this piece of code, and should move away from CommonJS.\n if ('default' in feature) {\n return feature.default;\n }\n\n return feature;\n}\n"],"names":[],"mappings":";;AAmBO,SAAS,cACd,OACgB,EAAA;AAChB,EAAA,IAAI,YAAY,OAAS,EAAA;AACvB,IAAO,OAAA,OAAA,CAAA;AAAA,GACT;AAMA,EAAA,IAAI,aAAa,OAAS,EAAA;AACxB,IAAA,OAAO,OAAQ,CAAA,OAAA,CAAA;AAAA,GACjB;AAEA,EAAO,OAAA,OAAA,CAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-app-api",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-next.1",
4
4
  "description": "Core API used by Backstage backend apps",
5
5
  "backstage": {
6
6
  "role": "node-library"
@@ -50,17 +50,17 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@backstage/backend-common": "^0.25.0",
53
- "@backstage/backend-plugin-api": "^1.0.0",
54
- "@backstage/cli-common": "^0.1.14",
55
- "@backstage/config": "^1.2.0",
56
- "@backstage/config-loader": "^1.9.1",
57
- "@backstage/errors": "^1.2.4",
58
- "@backstage/plugin-auth-node": "^0.5.2",
59
- "@backstage/plugin-permission-node": "^0.8.3",
60
- "@backstage/types": "^1.1.1",
53
+ "@backstage/backend-plugin-api": "1.0.1-next.1",
54
+ "@backstage/cli-common": "0.1.14",
55
+ "@backstage/config": "1.2.0",
56
+ "@backstage/config-loader": "1.9.1",
57
+ "@backstage/errors": "1.2.4",
58
+ "@backstage/plugin-auth-node": "0.5.3-next.1",
59
+ "@backstage/plugin-permission-node": "0.8.4-next.1",
60
+ "@backstage/types": "1.1.1",
61
61
  "@manypkg/get-packages": "^1.1.3",
62
62
  "compression": "^1.7.4",
63
- "cookie": "^0.6.0",
63
+ "cookie": "^0.7.0",
64
64
  "cors": "^2.8.5",
65
65
  "express": "^4.17.1",
66
66
  "express-promise-router": "^4.1.0",
@@ -84,9 +84,9 @@
84
84
  "winston-transport": "^4.5.0"
85
85
  },
86
86
  "devDependencies": {
87
- "@backstage/backend-defaults": "^0.5.0",
88
- "@backstage/backend-test-utils": "^1.0.0",
89
- "@backstage/cli": "^0.27.1",
87
+ "@backstage/backend-defaults": "0.5.1-next.2",
88
+ "@backstage/backend-test-utils": "1.0.1-next.2",
89
+ "@backstage/cli": "0.28.0-next.2",
90
90
  "@types/compression": "^1.7.0",
91
91
  "@types/http-errors": "^2.0.0",
92
92
  "@types/minimist": "^1.2.0",