@backstage/backend-test-utils 1.9.1 → 1.10.0-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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @backstage/backend-test-utils
2
2
 
3
+ ## 1.10.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/backend-defaults@0.13.1-next.1
9
+ - @backstage/backend-plugin-api@1.5.0-next.1
10
+ - @backstage/backend-app-api@1.3.0-next.1
11
+ - @backstage/plugin-permission-common@0.9.3-next.1
12
+ - @backstage/plugin-auth-node@0.6.9-next.1
13
+ - @backstage/plugin-events-node@0.4.17-next.1
14
+
15
+ ## 1.10.0-next.0
16
+
17
+ ### Minor Changes
18
+
19
+ - d57b13b: Added support for Postgres 18 to the available `TestDatabases`.
20
+
21
+ Note that the set of _default_ databases to test against for users of the `TestDatabases` class was also updated to include Postgres 14 and 18, instead of 13 and 17. If you need to override this, you can pass in an explicit `ids` argument, for example `ids: ['POSTGRES_17', 'POSTGRES_13', 'SQLITE_3']`.
22
+
23
+ ### Patch Changes
24
+
25
+ - 05f60e1: Refactored constructor parameter properties to explicit property declarations for compatibility with TypeScript's `erasableSyntaxOnly` setting. This internal refactoring maintains all existing functionality while ensuring TypeScript compilation compatibility.
26
+ - Updated dependencies
27
+ - @backstage/backend-defaults@0.13.1-next.0
28
+ - @backstage/plugin-events-node@0.4.17-next.0
29
+ - @backstage/plugin-auth-node@0.6.9-next.0
30
+ - @backstage/backend-app-api@1.2.9-next.0
31
+ - @backstage/config@1.3.6-next.0
32
+ - @backstage/backend-plugin-api@1.4.5-next.0
33
+ - @backstage/errors@1.2.7
34
+ - @backstage/types@1.2.2
35
+ - @backstage/plugin-permission-common@0.9.3-next.0
36
+
3
37
  ## 1.9.1
4
38
 
5
39
  ### Patch Changes
@@ -11,6 +11,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
11
11
  var zodToJsonSchema__default = /*#__PURE__*/_interopDefaultCompat(zodToJsonSchema);
12
12
 
13
13
  class MockActionsRegistry {
14
+ logger;
14
15
  constructor(logger) {
15
16
  this.logger = logger;
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MockActionsRegistry.cjs.js","sources":["../../../src/alpha/services/MockActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport {\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport { ForwardedError, InputError, NotFoundError } from '@backstage/errors';\nimport { JsonObject, JsonValue } from '@backstage/types';\nimport { z, AnyZodObject } from 'zod';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { mockCredentials } from '../../services';\nimport {\n ActionsRegistryActionOptions,\n ActionsRegistryService,\n ActionsService,\n ActionsServiceAction,\n} from '@backstage/backend-plugin-api/alpha';\n\n/**\n * A mock implementation of the ActionsRegistryService and ActionsService that can be used in tests.\n *\n * This is useful for testing actions that are registered with the ActionsRegistryService and ActionsService.\n *\n * The plugin ID is hardcoded to `testing` in the mock implementation.\n *\n * @example\n * ```ts\n * const actionsRegistry = mockServices.actionsRegistry();\n *\n * actionsRegistry.register({\n * name: 'test',\n * title: 'Test',\n * description: 'Test',\n * schema: {\n * input: z.object({ name: z.string() }),\n * output: z.object({ name: z.string() }),\n * },\n * action: async ({ input }) => ({ output: { name: input.name } }),\n * });\n *\n *\n * const result = await actionsRegistry.invoke({\n * id: 'testing:test',\n * input: { name: 'test' },\n * });\n *\n * expect(result).toEqual({ output: { name: 'test' } });\n * ```\n *\n * @alpha\n */\nexport class MockActionsRegistry\n implements ActionsRegistryService, ActionsService\n{\n private constructor(private readonly logger: LoggerService) {}\n\n static create(opts: { logger: LoggerService }) {\n return new MockActionsRegistry(opts.logger);\n }\n\n readonly actions: Map<string, ActionsRegistryActionOptions<any, any>> =\n new Map();\n\n async list(): Promise<{ actions: ActionsServiceAction[] }> {\n return {\n actions: Array.from(this.actions.entries()).map(([id, action]) => ({\n id,\n name: action.name,\n title: action.title,\n description: action.description,\n attributes: {\n destructive: action.attributes?.destructive ?? true,\n idempotent: action.attributes?.idempotent ?? false,\n readOnly: action.attributes?.readOnly ?? false,\n },\n schema: {\n input: action.schema?.input\n ? zodToJsonSchema(action.schema.input(z))\n : zodToJsonSchema(z.object({})),\n output: action.schema?.output\n ? zodToJsonSchema(action.schema.output(z))\n : zodToJsonSchema(z.object({})),\n } as ActionsServiceAction['schema'],\n })),\n };\n }\n\n async invoke(opts: {\n id: string;\n input?: JsonObject;\n credentials?: BackstageCredentials;\n }): Promise<{ output: JsonValue }> {\n const action = this.actions.get(opts.id);\n\n if (!action) {\n const availableActionIds = Array.from(this.actions.keys()).join(', ');\n throw new NotFoundError(\n `Action \"${opts.id}\" not found, available actions: ${\n availableActionIds ? `\"${availableActionIds}\"` : 'none'\n }`,\n );\n }\n\n const input = action.schema?.input\n ? action.schema.input(z).safeParse(opts.input)\n : ({ success: true, data: undefined } as const);\n\n if (!input.success) {\n throw new InputError(`Invalid input to action \"${opts.id}\"`, input.error);\n }\n\n try {\n const result = await action.action({\n input: input.data,\n credentials: opts.credentials ?? mockCredentials.none(),\n logger: this.logger,\n });\n\n const output = action.schema?.output\n ? action.schema.output(z).safeParse(result?.output)\n : ({ success: true, data: result?.output } as const);\n\n if (!output.success) {\n throw new InputError(\n `Invalid output from action \"${opts.id}\"`,\n output.error,\n );\n }\n\n return { output: output.data };\n } catch (error) {\n throw new ForwardedError(\n `Failed execution of action \"${opts.id}\"`,\n error,\n );\n }\n }\n\n register<\n TInputSchema extends AnyZodObject,\n TOutputSchema extends AnyZodObject,\n >(options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>): void {\n // hardcode test: prefix similar to how the default actions registry does it\n // and other places around the testing ecosystem:\n // https://github.com/backstage/backstage/blob/a9219496d5c073aaa0b8caf32ece10455cf65e61/packages/backend-test-utils/src/next/services/mockServices.ts#L321\n // https://github.com/backstage/backstage/blob/861f162b4a39117b824669d67a951ed1db142e3d/packages/backend-test-utils/src/next/wiring/ServiceFactoryTester.ts#L99\n const id = `test:${options.name}`;\n\n if (this.actions.has(id)) {\n throw new Error(`Action with id \"${id}\" is already registered`);\n }\n\n this.actions.set(id, options);\n }\n}\n"],"names":["zodToJsonSchema","z","NotFoundError","InputError","mockCredentials","ForwardedError"],"mappings":";;;;;;;;;;;;AAgEO,MAAM,mBAAA,CAEb;AAAA,EACU,YAA6B,MAAA,EAAuB;AAAvB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAAwB;AAAA,EAE7D,OAAO,OAAO,IAAA,EAAiC;AAC7C,IAAA,OAAO,IAAI,mBAAA,CAAoB,IAAA,CAAK,MAAM,CAAA;AAAA,EAC5C;AAAA,EAES,OAAA,uBACH,GAAA,EAAI;AAAA,EAEV,MAAM,IAAA,GAAqD;AACzD,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,OAAA,EAAS,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,EAAA,EAAI,MAAM,CAAA,MAAO;AAAA,QACjE,EAAA;AAAA,QACA,MAAM,MAAA,CAAO,IAAA;AAAA,QACb,OAAO,MAAA,CAAO,KAAA;AAAA,QACd,aAAa,MAAA,CAAO,WAAA;AAAA,QACpB,UAAA,EAAY;AAAA,UACV,WAAA,EAAa,MAAA,CAAO,UAAA,EAAY,WAAA,IAAe,IAAA;AAAA,UAC/C,UAAA,EAAY,MAAA,CAAO,UAAA,EAAY,UAAA,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AEA,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,EAAA,EAAI,OAAO,CAAA;AAAA,EAC9B;AACF;;;;"}
1
+ {"version":3,"file":"MockActionsRegistry.cjs.js","sources":["../../../src/alpha/services/MockActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport {\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport { ForwardedError, InputError, NotFoundError } from '@backstage/errors';\nimport { JsonObject, JsonValue } from '@backstage/types';\nimport { z, AnyZodObject } from 'zod';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { mockCredentials } from '../../services';\nimport {\n ActionsRegistryActionOptions,\n ActionsRegistryService,\n ActionsService,\n ActionsServiceAction,\n} from '@backstage/backend-plugin-api/alpha';\n\n/**\n * A mock implementation of the ActionsRegistryService and ActionsService that can be used in tests.\n *\n * This is useful for testing actions that are registered with the ActionsRegistryService and ActionsService.\n *\n * The plugin ID is hardcoded to `testing` in the mock implementation.\n *\n * @example\n * ```ts\n * const actionsRegistry = mockServices.actionsRegistry();\n *\n * actionsRegistry.register({\n * name: 'test',\n * title: 'Test',\n * description: 'Test',\n * schema: {\n * input: z.object({ name: z.string() }),\n * output: z.object({ name: z.string() }),\n * },\n * action: async ({ input }) => ({ output: { name: input.name } }),\n * });\n *\n *\n * const result = await actionsRegistry.invoke({\n * id: 'testing:test',\n * input: { name: 'test' },\n * });\n *\n * expect(result).toEqual({ output: { name: 'test' } });\n * ```\n *\n * @alpha\n */\nexport class MockActionsRegistry\n implements ActionsRegistryService, ActionsService\n{\n private readonly logger: LoggerService;\n\n private constructor(logger: LoggerService) {\n this.logger = logger;\n }\n\n static create(opts: { logger: LoggerService }) {\n return new MockActionsRegistry(opts.logger);\n }\n\n readonly actions: Map<string, ActionsRegistryActionOptions<any, any>> =\n new Map();\n\n async list(): Promise<{ actions: ActionsServiceAction[] }> {\n return {\n actions: Array.from(this.actions.entries()).map(([id, action]) => ({\n id,\n name: action.name,\n title: action.title,\n description: action.description,\n attributes: {\n destructive: action.attributes?.destructive ?? true,\n idempotent: action.attributes?.idempotent ?? false,\n readOnly: action.attributes?.readOnly ?? false,\n },\n schema: {\n input: action.schema?.input\n ? zodToJsonSchema(action.schema.input(z))\n : zodToJsonSchema(z.object({})),\n output: action.schema?.output\n ? zodToJsonSchema(action.schema.output(z))\n : zodToJsonSchema(z.object({})),\n } as ActionsServiceAction['schema'],\n })),\n };\n }\n\n async invoke(opts: {\n id: string;\n input?: JsonObject;\n credentials?: BackstageCredentials;\n }): Promise<{ output: JsonValue }> {\n const action = this.actions.get(opts.id);\n\n if (!action) {\n const availableActionIds = Array.from(this.actions.keys()).join(', ');\n throw new NotFoundError(\n `Action \"${opts.id}\" not found, available actions: ${\n availableActionIds ? `\"${availableActionIds}\"` : 'none'\n }`,\n );\n }\n\n const input = action.schema?.input\n ? action.schema.input(z).safeParse(opts.input)\n : ({ success: true, data: undefined } as const);\n\n if (!input.success) {\n throw new InputError(`Invalid input to action \"${opts.id}\"`, input.error);\n }\n\n try {\n const result = await action.action({\n input: input.data,\n credentials: opts.credentials ?? mockCredentials.none(),\n logger: this.logger,\n });\n\n const output = action.schema?.output\n ? action.schema.output(z).safeParse(result?.output)\n : ({ success: true, data: result?.output } as const);\n\n if (!output.success) {\n throw new InputError(\n `Invalid output from action \"${opts.id}\"`,\n output.error,\n );\n }\n\n return { output: output.data };\n } catch (error) {\n throw new ForwardedError(\n `Failed execution of action \"${opts.id}\"`,\n error,\n );\n }\n }\n\n register<\n TInputSchema extends AnyZodObject,\n TOutputSchema extends AnyZodObject,\n >(options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>): void {\n // hardcode test: prefix similar to how the default actions registry does it\n // and other places around the testing ecosystem:\n // https://github.com/backstage/backstage/blob/a9219496d5c073aaa0b8caf32ece10455cf65e61/packages/backend-test-utils/src/next/services/mockServices.ts#L321\n // https://github.com/backstage/backstage/blob/861f162b4a39117b824669d67a951ed1db142e3d/packages/backend-test-utils/src/next/wiring/ServiceFactoryTester.ts#L99\n const id = `test:${options.name}`;\n\n if (this.actions.has(id)) {\n throw new Error(`Action with id \"${id}\" is already registered`);\n }\n\n this.actions.set(id, options);\n }\n}\n"],"names":["zodToJsonSchema","z","NotFoundError","InputError","mockCredentials","ForwardedError"],"mappings":";;;;;;;;;;;;AAgEO,MAAM,mBAAA,CAEb;AAAA,EACmB,MAAA;AAAA,EAET,YAAY,MAAA,EAAuB;AACzC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EAEA,OAAO,OAAO,IAAA,EAAiC;AAC7C,IAAA,OAAO,IAAI,mBAAA,CAAoB,IAAA,CAAK,MAAM,CAAA;AAAA,EAC5C;AAAA,EAES,OAAA,uBACH,GAAA,EAAI;AAAA,EAEV,MAAM,IAAA,GAAqD;AACzD,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,OAAA,EAAS,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,EAAA,EAAI,MAAM,CAAA,MAAO;AAAA,QACjE,EAAA;AAAA,QACA,MAAM,MAAA,CAAO,IAAA;AAAA,QACb,OAAO,MAAA,CAAO,KAAA;AAAA,QACd,aAAa,MAAA,CAAO,WAAA;AAAA,QACpB,UAAA,EAAY;AAAA,UACV,WAAA,EAAa,MAAA,CAAO,UAAA,EAAY,WAAA,IAAe,IAAA;AAAA,UAC/C,UAAA,EAAY,MAAA,CAAO,UAAA,EAAY,UAAA,IAAc,KAAA;AA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A,CAAK,OAAA,CAAQ,GAAA,CAAI,EAAA,EAAI,OAAO,CAAA;AAAA,EAC9B;AACF;;;;"}
@@ -1,11 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  class Node {
4
- constructor(value, consumes, provides) {
5
- this.value = value;
6
- this.consumes = consumes;
7
- this.provides = provides;
8
- }
9
4
  static from(input) {
10
5
  return new Node(
11
6
  input.value,
@@ -13,6 +8,14 @@ class Node {
13
8
  input.provides ? new Set(input.provides) : /* @__PURE__ */ new Set()
14
9
  );
15
10
  }
11
+ value;
12
+ consumes;
13
+ provides;
14
+ constructor(value, consumes, provides) {
15
+ this.value = value;
16
+ this.consumes = consumes;
17
+ this.provides = provides;
18
+ }
16
19
  }
17
20
  class CycleKeySet {
18
21
  static from(nodes) {
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyGraph.cjs.js","sources":["../../../../../backend-app-api/src/lib/DependencyGraph.ts"],"sourcesContent":["/*\n * Copyright 2023 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\ninterface NodeInput<T> {\n value: T;\n consumes?: Iterable<string>;\n provides?: Iterable<string>;\n}\n\n/** @internal */\nclass Node<T> {\n static from<T>(input: NodeInput<T>) {\n return new Node<T>(\n input.value,\n input.consumes ? new Set(input.consumes) : new Set(),\n input.provides ? new Set(input.provides) : new Set(),\n );\n }\n\n private constructor(\n readonly value: T,\n readonly consumes: Set<string>,\n readonly provides: Set<string>,\n ) {}\n}\n\n/** @internal */\nclass CycleKeySet<T> {\n static from<T>(nodes: Array<Node<T>>) {\n return new CycleKeySet<T>(nodes);\n }\n\n #nodeIds: Map<T, number>;\n #cycleKeys: Set<string>;\n\n private constructor(nodes: Array<Node<T>>) {\n this.#nodeIds = new Map(nodes.map((n, i) => [n.value, i]));\n this.#cycleKeys = new Set<string>();\n }\n\n tryAdd(path: T[]): boolean {\n const cycleKey = this.#getCycleKey(path);\n if (this.#cycleKeys.has(cycleKey)) {\n return false;\n }\n this.#cycleKeys.add(cycleKey);\n return true;\n }\n\n #getCycleKey(path: T[]): string {\n return path\n .map(n => this.#nodeIds.get(n)!)\n .sort()\n .join(',');\n }\n}\n\n/**\n * Internal helper to help validate and traverse a dependency graph.\n * @internal\n */\nexport class DependencyGraph<T> {\n static fromMap(\n nodes: Record<string, Omit<NodeInput<unknown>, 'value'>>,\n ): DependencyGraph<string> {\n return this.fromIterable(\n Object.entries(nodes).map(([key, node]) => ({\n value: String(key),\n ...node,\n })),\n );\n }\n\n static fromIterable<T>(\n nodeInputs: Iterable<NodeInput<T>>,\n ): DependencyGraph<T> {\n const nodes = new Array<Node<T>>();\n for (const nodeInput of nodeInputs) {\n nodes.push(Node.from(nodeInput));\n }\n\n return new DependencyGraph(nodes);\n }\n\n #nodes: Array<Node<T>>;\n #allProvided: Set<string>;\n\n private constructor(nodes: Array<Node<T>>) {\n this.#nodes = nodes;\n this.#allProvided = new Set();\n\n for (const node of this.#nodes.values()) {\n for (const produced of node.provides) {\n this.#allProvided.add(produced);\n }\n }\n }\n\n /**\n * Find all nodes that consume dependencies that are not provided by any other node.\n */\n findUnsatisfiedDeps(): Array<{ value: T; unsatisfied: string[] }> {\n const unsatisfiedDependencies = [];\n for (const node of this.#nodes.values()) {\n const unsatisfied = Array.from(node.consumes).filter(\n id => !this.#allProvided.has(id),\n );\n if (unsatisfied.length > 0) {\n unsatisfiedDependencies.push({ value: node.value, unsatisfied });\n }\n }\n return unsatisfiedDependencies;\n }\n\n /**\n * Detect the first circular dependency within the graph, returning the path of nodes that\n * form a cycle, with the same node as the first and last element of the array.\n */\n detectCircularDependency(): T[] | undefined {\n return this.detectCircularDependencies().next().value;\n }\n\n /**\n * Detect circular dependencies within the graph, returning the path of nodes that\n * form a cycle, with the same node as the first and last element of the array.\n */\n *detectCircularDependencies(): Generator<T[], undefined> {\n const cycleKeys = CycleKeySet.from(this.#nodes);\n\n for (const startNode of this.#nodes) {\n const visited = new Set<Node<T>>();\n const stack = new Array<[node: Node<T>, path: T[]]>([\n startNode,\n [startNode.value],\n ]);\n\n while (stack.length > 0) {\n const [node, path] = stack.pop()!;\n if (visited.has(node)) {\n continue;\n }\n visited.add(node);\n for (const consumed of node.consumes) {\n const providerNodes = this.#nodes.filter(other =>\n other.provides.has(consumed),\n );\n for (const provider of providerNodes) {\n if (provider === startNode) {\n if (cycleKeys.tryAdd(path)) {\n yield [...path, startNode.value];\n }\n\n break;\n }\n if (!visited.has(provider)) {\n stack.push([provider, [...path, provider.value]]);\n }\n }\n }\n }\n }\n return undefined;\n }\n\n /**\n * Traverses the dependency graph in topological order, calling the provided\n * function for each node and waiting for it to resolve.\n *\n * The nodes are traversed in parallel, but in such a way that no node is\n * visited before all of its dependencies.\n *\n * Dependencies of nodes that are not produced by any other nodes will be ignored.\n */\n async parallelTopologicalTraversal<TResult>(\n fn: (value: T) => Promise<TResult>,\n ): Promise<TResult[]> {\n const allProvided = this.#allProvided;\n const waiting = new Set(this.#nodes.values());\n const visited = new Set<Node<T>>();\n const results = new Array<TResult>();\n let inFlight = 0; // Keep track of how many callbacks are in flight, so that we know if we got stuck\n\n // This keeps track of a counter of how many providers there are still left\n // to be visited for each dependency. This needs to be a counter instead of\n // a flag for the special case where there are several providers of a given\n // value, even though there may be only one consumer of it.\n const producedRemaining = new Map<string, number>();\n for (const node of this.#nodes) {\n for (const provided of node.provides) {\n producedRemaining.set(\n provided,\n (producedRemaining.get(provided) ?? 0) + 1,\n );\n }\n }\n\n // Find all nodes that have no dependencies that have not already been produced by visited nodes\n async function processMoreNodes() {\n if (waiting.size === 0) {\n return;\n }\n const nodesToProcess = [];\n for (const node of waiting) {\n let ready = true;\n for (const consumed of node.consumes) {\n if (\n allProvided.has(consumed) &&\n producedRemaining.get(consumed) !== 0\n ) {\n ready = false;\n continue;\n }\n }\n if (ready) {\n nodesToProcess.push(node);\n }\n }\n\n for (const node of nodesToProcess) {\n waiting.delete(node);\n }\n\n if (nodesToProcess.length === 0 && inFlight === 0) {\n // We expect the caller to check for circular dependencies before\n // traversal, so this error should never happen\n throw new Error('Circular dependency detected');\n }\n\n await Promise.all(nodesToProcess.map(processNode));\n }\n\n // Process an individual node, and then add its produced dependencies to the set of available products\n async function processNode(node: Node<T>) {\n visited.add(node);\n inFlight += 1;\n\n const result = await fn(node.value);\n results.push(result);\n\n node.provides.forEach(produced => {\n const remaining = producedRemaining.get(produced);\n if (!remaining) {\n // This should be impossible, if the code that generates the map is correct\n throw new Error(\n `Internal error: Node provided superfluous dependency '${produced}'`,\n );\n }\n producedRemaining.set(produced, remaining - 1);\n });\n\n inFlight -= 1;\n await processMoreNodes();\n }\n\n await processMoreNodes();\n\n return results;\n }\n}\n"],"names":[],"mappings":";;AAuBA,MAAM,IAAA,CAAQ;AAAA,EASJ,WAAA,CACG,KAAA,EACA,QAAA,EACA,QAAA,EACT;AAHS,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA,EACR;AAAA,EAZH,OAAO,KAAQ,KAAA,EAAqB;AAClC,IAAA,OAAO,IAAI,IAAA;AAAA,MACT,KAAA,CAAM,KAAA;AAAA,MACN,KAAA,CAAM,WAAW,IAAI,GAAA,CAAI,MAAM,QAAQ,CAAA,uBAAQ,GAAA,EAAI;AAAA,MACnD,KAAA,CAAM,WAAW,IAAI,GAAA,CAAI,MAAM,QAAQ,CAAA,uBAAQ,GAAA;AAAI,KACrD;AAAA,EACF;AAOF;AAGA,MAAM,WAAA,CAAe;AAAA,EACnB,OAAO,KAAQ,KAAA,EAAuB;AACpC,IAAA,OAAO,IAAI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;AAAA,MACF;AAEA,MAAA,KAAA,MAAW,QAAQ,cAAA,EAAgB;AACjC,QAAA,OAAA,CAAQ,OAAO,IAAI,CAAA;AAAA,MACrB;AAEA,MAAA,IAAI,cAAA,CAAe,MAAA,KAAW,CAAA,IAAK,QAAA,KAAa,CAAA,EAAG;AAGjD,QAAA,MAAM,IAAI,MAAM,8BAA8B,CAAA;AAAA,MAChD;AAEA,MAAA,MAAM,OAAA,CAAQ,GAAA,CAAI,cAAA,CAAe,GAAA,CAAI,WAAW,CAAC,CAAA;AAAA,IACnD;AAGA,IAAA,eAAe,YAAY,IAAA,EAAe;AACxC,MAAA,OAAA,CAAQ,IAAI,IAAI,CAAA;AAChB,MAAA,QAAA,IAAY,CAAA;AAEZ,MAAA,MAAM,MAAA,GAAS,MAAM,EAAA,CAAG,IAAA,CAAK,KAAK,CAAA;AAClC,MAAA,OAAA,CAAQ,KAAK,MAAM,CAAA;AAEnB,MAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,QAAA,KAAY;AAChC,QAAA,MAAM,SAAA,GAAY,iBAAA,CAAkB,GAAA,CAAI,QAAQ,CAAA;AAChD,QAAA,IAAI,CAAC,SAAA,EAAW;AAEd,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,yDAAyD,QAAQ,CAAA,CAAA;AAAA,WACnE;AAAA,QACF;AACA,QAAA,iBAAA,CAAkB,GAAA,CAAI,QAAA,EAAU,SAAA,GAAY,CAAC,CAAA;AAAA,MAC/C,CAAC,CAAA;AAED,MAAA,QAAA,IAAY,CAAA;AACZ,MAAA,MAAM,gBAAA,EAAiB;AAAA,IACzB;AAEA,IAAA,MAAM,gBAAA,EAAiB;AAEvB,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;;"}
1
+ {"version":3,"file":"DependencyGraph.cjs.js","sources":["../../../../../backend-app-api/src/lib/DependencyGraph.ts"],"sourcesContent":["/*\n * Copyright 2023 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\ninterface NodeInput<T> {\n value: T;\n consumes?: Iterable<string>;\n provides?: Iterable<string>;\n}\n\n/** @internal */\nclass Node<T> {\n static from<T>(input: NodeInput<T>) {\n return new Node<T>(\n input.value,\n input.consumes ? new Set(input.consumes) : new Set(),\n input.provides ? new Set(input.provides) : new Set(),\n );\n }\n\n readonly value: T;\n readonly consumes: Set<string>;\n readonly provides: Set<string>;\n\n private constructor(value: T, consumes: Set<string>, provides: Set<string>) {\n this.value = value;\n this.consumes = consumes;\n this.provides = provides;\n }\n}\n\n/** @internal */\nclass CycleKeySet<T> {\n static from<T>(nodes: Array<Node<T>>) {\n return new CycleKeySet<T>(nodes);\n }\n\n #nodeIds: Map<T, number>;\n #cycleKeys: Set<string>;\n\n private constructor(nodes: Array<Node<T>>) {\n this.#nodeIds = new Map(nodes.map((n, i) => [n.value, i]));\n this.#cycleKeys = new Set<string>();\n }\n\n tryAdd(path: T[]): boolean {\n const cycleKey = this.#getCycleKey(path);\n if (this.#cycleKeys.has(cycleKey)) {\n return false;\n }\n this.#cycleKeys.add(cycleKey);\n return true;\n }\n\n #getCycleKey(path: T[]): string {\n return path\n .map(n => this.#nodeIds.get(n)!)\n .sort()\n .join(',');\n }\n}\n\n/**\n * Internal helper to help validate and traverse a dependency graph.\n * @internal\n */\nexport class DependencyGraph<T> {\n static fromMap(\n nodes: Record<string, Omit<NodeInput<unknown>, 'value'>>,\n ): DependencyGraph<string> {\n return this.fromIterable(\n Object.entries(nodes).map(([key, node]) => ({\n value: String(key),\n ...node,\n })),\n );\n }\n\n static fromIterable<T>(\n nodeInputs: Iterable<NodeInput<T>>,\n ): DependencyGraph<T> {\n const nodes = new Array<Node<T>>();\n for (const nodeInput of nodeInputs) {\n nodes.push(Node.from(nodeInput));\n }\n\n return new DependencyGraph(nodes);\n }\n\n #nodes: Array<Node<T>>;\n #allProvided: Set<string>;\n\n private constructor(nodes: Array<Node<T>>) {\n this.#nodes = nodes;\n this.#allProvided = new Set();\n\n for (const node of this.#nodes.values()) {\n for (const produced of node.provides) {\n this.#allProvided.add(produced);\n }\n }\n }\n\n /**\n * Find all nodes that consume dependencies that are not provided by any other node.\n */\n findUnsatisfiedDeps(): Array<{ value: T; unsatisfied: string[] }> {\n const unsatisfiedDependencies = [];\n for (const node of this.#nodes.values()) {\n const unsatisfied = Array.from(node.consumes).filter(\n id => !this.#allProvided.has(id),\n );\n if (unsatisfied.length > 0) {\n unsatisfiedDependencies.push({ value: node.value, unsatisfied });\n }\n }\n return unsatisfiedDependencies;\n }\n\n /**\n * Detect the first circular dependency within the graph, returning the path of nodes that\n * form a cycle, with the same node as the first and last element of the array.\n */\n detectCircularDependency(): T[] | undefined {\n return this.detectCircularDependencies().next().value;\n }\n\n /**\n * Detect circular dependencies within the graph, returning the path of nodes that\n * form a cycle, with the same node as the first and last element of the array.\n */\n *detectCircularDependencies(): Generator<T[], undefined> {\n const cycleKeys = CycleKeySet.from(this.#nodes);\n\n for (const startNode of this.#nodes) {\n const visited = new Set<Node<T>>();\n const stack = new Array<[node: Node<T>, path: T[]]>([\n startNode,\n [startNode.value],\n ]);\n\n while (stack.length > 0) {\n const [node, path] = stack.pop()!;\n if (visited.has(node)) {\n continue;\n }\n visited.add(node);\n for (const consumed of node.consumes) {\n const providerNodes = this.#nodes.filter(other =>\n other.provides.has(consumed),\n );\n for (const provider of providerNodes) {\n if (provider === startNode) {\n if (cycleKeys.tryAdd(path)) {\n yield [...path, startNode.value];\n }\n\n break;\n }\n if (!visited.has(provider)) {\n stack.push([provider, [...path, provider.value]]);\n }\n }\n }\n }\n }\n return undefined;\n }\n\n /**\n * Traverses the dependency graph in topological order, calling the provided\n * function for each node and waiting for it to resolve.\n *\n * The nodes are traversed in parallel, but in such a way that no node is\n * visited before all of its dependencies.\n *\n * Dependencies of nodes that are not produced by any other nodes will be ignored.\n */\n async parallelTopologicalTraversal<TResult>(\n fn: (value: T) => Promise<TResult>,\n ): Promise<TResult[]> {\n const allProvided = this.#allProvided;\n const waiting = new Set(this.#nodes.values());\n const visited = new Set<Node<T>>();\n const results = new Array<TResult>();\n let inFlight = 0; // Keep track of how many callbacks are in flight, so that we know if we got stuck\n\n // This keeps track of a counter of how many providers there are still left\n // to be visited for each dependency. This needs to be a counter instead of\n // a flag for the special case where there are several providers of a given\n // value, even though there may be only one consumer of it.\n const producedRemaining = new Map<string, number>();\n for (const node of this.#nodes) {\n for (const provided of node.provides) {\n producedRemaining.set(\n provided,\n (producedRemaining.get(provided) ?? 0) + 1,\n );\n }\n }\n\n // Find all nodes that have no dependencies that have not already been produced by visited nodes\n async function processMoreNodes() {\n if (waiting.size === 0) {\n return;\n }\n const nodesToProcess = [];\n for (const node of waiting) {\n let ready = true;\n for (const consumed of node.consumes) {\n if (\n allProvided.has(consumed) &&\n producedRemaining.get(consumed) !== 0\n ) {\n ready = false;\n continue;\n }\n }\n if (ready) {\n nodesToProcess.push(node);\n }\n }\n\n for (const node of nodesToProcess) {\n waiting.delete(node);\n }\n\n if (nodesToProcess.length === 0 && inFlight === 0) {\n // We expect the caller to check for circular dependencies before\n // traversal, so this error should never happen\n throw new Error('Circular dependency detected');\n }\n\n await Promise.all(nodesToProcess.map(processNode));\n }\n\n // Process an individual node, and then add its produced dependencies to the set of available products\n async function processNode(node: Node<T>) {\n visited.add(node);\n inFlight += 1;\n\n const result = await fn(node.value);\n results.push(result);\n\n node.provides.forEach(produced => {\n const remaining = producedRemaining.get(produced);\n if (!remaining) {\n // This should be impossible, if the code that generates the map is correct\n throw new Error(\n `Internal error: Node provided superfluous dependency '${produced}'`,\n );\n }\n producedRemaining.set(produced, remaining - 1);\n });\n\n inFlight -= 1;\n await processMoreNod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AK,CAAA;AAClC,MAAA,OAAA,CAAQ,KAAK,MAAM,CAAA;AAEnB,MAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,QAAA,KAAY;AAChC,QAAA,MAAM,SAAA,GAAY,iBAAA,CAAkB,GAAA,CAAI,QAAQ,CAAA;AAChD,QAAA,IAAI,CAAC,SAAA,EAAW;AAEd,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,yDAAyD,QAAQ,CAAA,CAAA;AAAA,WACnE;AAAA,QACF;AACA,QAAA,iBAAA,CAAkB,GAAA,CAAI,QAAA,EAAU,SAAA,GAAY,CAAC,CAAA;AAAA,MAC/C,CAAC,CAAA;AAED,MAAA,QAAA,IAAY,CAAA;AACZ,MAAA,MAAM,gBAAA,EAAiB;AAAA,IACzB;AAEA,IAAA,MAAM,gBAAA,EAAiB;AAEvB,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;;"}
@@ -8,6 +8,14 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
8
8
  var isEqual__default = /*#__PURE__*/_interopDefaultCompat(isEqual);
9
9
 
10
10
  class ObservableConfigProxy {
11
+ config = new config.ConfigReader({});
12
+ subscribers = [];
13
+ static create(abortController) {
14
+ return new ObservableConfigProxy(void 0, void 0, abortController);
15
+ }
16
+ parent;
17
+ parentKey;
18
+ abortController;
11
19
  constructor(parent, parentKey, abortController) {
12
20
  this.parent = parent;
13
21
  this.parentKey = parentKey;
@@ -16,11 +24,6 @@ class ObservableConfigProxy {
16
24
  throw new Error("parentKey is required if parent is set");
17
25
  }
18
26
  }
19
- config = new config.ConfigReader({});
20
- subscribers = [];
21
- static create(abortController) {
22
- return new ObservableConfigProxy(void 0, void 0, abortController);
23
- }
24
27
  setConfig(config) {
25
28
  if (this.parent) {
26
29
  throw new Error("immutable");
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableConfigProxy.cjs.js","sources":["../../../../../config-loader/src/sources/ObservableConfigProxy.ts"],"sourcesContent":["/*\n * Copyright 2023 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, ConfigReader } from '@backstage/config';\nimport { JsonValue } from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\n\nexport class ObservableConfigProxy implements Config {\n private config: Config = new ConfigReader({});\n\n private readonly subscribers: (() => void)[] = [];\n\n static create(abortController: AbortController): ObservableConfigProxy {\n return new ObservableConfigProxy(undefined, undefined, abortController);\n }\n\n private constructor(\n private readonly parent?: ObservableConfigProxy,\n private readonly parentKey?: string,\n private readonly abortController?: AbortController,\n ) {\n if (parent && !parentKey) {\n throw new Error('parentKey is required if parent is set');\n }\n }\n\n setConfig(config: Config) {\n if (this.parent) {\n throw new Error('immutable');\n }\n\n // We only notify subscribers if the data contents of the config actually\n // changed. If they didn't, there's no point in callers trying to re-read\n // them. However we still want to replace the local config object, since its\n // runtime implementation could be entirely different.\n const changed = !isEqual(this.config.get(), config.get());\n\n this.config = config;\n\n if (changed) {\n for (const subscriber of this.subscribers) {\n try {\n subscriber();\n } catch (error) {\n console.error(`Config subscriber threw error, ${error}`);\n }\n }\n }\n }\n\n close() {\n if (!this.abortController) {\n throw new Error('Only the root config can be closed');\n }\n this.abortController.abort();\n }\n\n subscribe(onChange: () => void): { unsubscribe: () => void } {\n if (this.parent) {\n return this.parent.subscribe(onChange);\n }\n\n this.subscribers.push(onChange);\n return {\n unsubscribe: () => {\n const index = this.subscribers.indexOf(onChange);\n if (index >= 0) {\n this.subscribers.splice(index, 1);\n }\n },\n };\n }\n\n private select(required: true): Config;\n private select(required: false): Config | undefined;\n private select(required: boolean): Config | undefined {\n if (this.parent && this.parentKey) {\n if (required) {\n return this.parent.select(true).getConfig(this.parentKey);\n }\n return this.parent.select(false)?.getOptionalConfig(this.parentKey);\n }\n\n return this.config;\n }\n\n has(key: string): boolean {\n return this.select(false)?.has(key) ?? false;\n }\n keys(): string[] {\n return this.select(false)?.keys() ?? [];\n }\n get<T = JsonValue>(key?: string): T {\n return this.select(true).get(key);\n }\n getOptional<T = JsonValue>(key?: string): T | undefined {\n return this.select(false)?.getOptional(key);\n }\n getConfig(key: string): Config {\n return new ObservableConfigProxy(this, key);\n }\n getOptionalConfig(key: string): Config | undefined {\n if (this.select(false)?.has(key)) {\n return new ObservableConfigProxy(this, key);\n }\n return undefined;\n }\n getConfigArray(key: string): Config[] {\n return this.select(true).getConfigArray(key);\n }\n getOptionalConfigArray(key: string): Config[] | undefined {\n return this.select(false)?.getOptionalConfigArray(key);\n }\n getNumber(key: string): number {\n return this.select(true).getNumber(key);\n }\n getOptionalNumber(key: string): number | undefined {\n return this.select(false)?.getOptionalNumber(key);\n }\n getBoolean(key: string): boolean {\n return this.select(true).getBoolean(key);\n }\n getOptionalBoolean(key: string): boolean | undefined {\n return this.select(false)?.getOptionalBoolean(key);\n }\n getString(key: string): string {\n return this.select(true).getString(key);\n }\n getOptionalString(key: string): string | undefined {\n return this.select(false)?.getOptionalString(key);\n }\n getStringArray(key: string): string[] {\n return this.select(true).getStringArray(key);\n }\n getOptionalStringArray(key: string): string[] | undefined {\n return this.select(false)?.getOptionalStringArray(key);\n }\n}\n"],"names":["ConfigReader","isEqual"],"mappings":";;;;;;;;;AAoBO,MAAM,qBAAA,CAAwC;AAAA,EAS3C,WAAA,CACW,MAAA,EACA,SAAA,EACA,eAAA,EACjB;AAHiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACA,IAAA,IAAA,CAAA,eAAA,GAAA,eAAA;AAEjB,IAAA,IAAI,MAAA,IAAU,CAAC,SAAA,EAAW;AACxB,MAAA,MAAM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Ae,GAAA,EAAuB;AACpC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,CAAE,eAAe,GAAG,CAAA;AAAA,EAC7C;AAAA,EACA,uBAAuB,GAAA,EAAmC;AACxD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,EAAG,uBAAuB,GAAG,CAAA;AAAA,EACvD;AACF;;;;"}
1
+ {"version":3,"file":"ObservableConfigProxy.cjs.js","sources":["../../../../../config-loader/src/sources/ObservableConfigProxy.ts"],"sourcesContent":["/*\n * Copyright 2023 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, ConfigReader } from '@backstage/config';\nimport { JsonValue } from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\n\nexport class ObservableConfigProxy implements Config {\n private config: Config = new ConfigReader({});\n\n private readonly subscribers: (() => void)[] = [];\n\n static create(abortController: AbortController): ObservableConfigProxy {\n return new ObservableConfigProxy(undefined, undefined, abortController);\n }\n\n private readonly parent?: ObservableConfigProxy;\n private readonly parentKey?: string;\n private readonly abortController?: AbortController;\n\n private constructor(\n parent?: ObservableConfigProxy,\n parentKey?: string,\n abortController?: AbortController,\n ) {\n this.parent = parent;\n this.parentKey = parentKey;\n this.abortController = abortController;\n if (parent && !parentKey) {\n throw new Error('parentKey is required if parent is set');\n }\n }\n\n setConfig(config: Config) {\n if (this.parent) {\n throw new Error('immutable');\n }\n\n // We only notify subscribers if the data contents of the config actually\n // changed. If they didn't, there's no point in callers trying to re-read\n // them. However we still want to replace the local config object, since its\n // runtime implementation could be entirely different.\n const changed = !isEqual(this.config.get(), config.get());\n\n this.config = config;\n\n if (changed) {\n for (const subscriber of this.subscribers) {\n try {\n subscriber();\n } catch (error) {\n console.error(`Config subscriber threw error, ${error}`);\n }\n }\n }\n }\n\n close() {\n if (!this.abortController) {\n throw new Error('Only the root config can be closed');\n }\n this.abortController.abort();\n }\n\n subscribe(onChange: () => void): { unsubscribe: () => void } {\n if (this.parent) {\n return this.parent.subscribe(onChange);\n }\n\n this.subscribers.push(onChange);\n return {\n unsubscribe: () => {\n const index = this.subscribers.indexOf(onChange);\n if (index >= 0) {\n this.subscribers.splice(index, 1);\n }\n },\n };\n }\n\n private select(required: true): Config;\n private select(required: false): Config | undefined;\n private select(required: boolean): Config | undefined {\n if (this.parent && this.parentKey) {\n if (required) {\n return this.parent.select(true).getConfig(this.parentKey);\n }\n return this.parent.select(false)?.getOptionalConfig(this.parentKey);\n }\n\n return this.config;\n }\n\n has(key: string): boolean {\n return this.select(false)?.has(key) ?? false;\n }\n keys(): string[] {\n return this.select(false)?.keys() ?? [];\n }\n get<T = JsonValue>(key?: string): T {\n return this.select(true).get(key);\n }\n getOptional<T = JsonValue>(key?: string): T | undefined {\n return this.select(false)?.getOptional(key);\n }\n getConfig(key: string): Config {\n return new ObservableConfigProxy(this, key);\n }\n getOptionalConfig(key: string): Config | undefined {\n if (this.select(false)?.has(key)) {\n return new ObservableConfigProxy(this, key);\n }\n return undefined;\n }\n getConfigArray(key: string): Config[] {\n return this.select(true).getConfigArray(key);\n }\n getOptionalConfigArray(key: string): Config[] | undefined {\n return this.select(false)?.getOptionalConfigArray(key);\n }\n getNumber(key: string): number {\n return this.select(true).getNumber(key);\n }\n getOptionalNumber(key: string): number | undefined {\n return this.select(false)?.getOptionalNumber(key);\n }\n getBoolean(key: string): boolean {\n return this.select(true).getBoolean(key);\n }\n getOptionalBoolean(key: string): boolean | undefined {\n return this.select(false)?.getOptionalBoolean(key);\n }\n getString(key: string): string {\n return this.select(true).getString(key);\n }\n getOptionalString(key: string): string | undefined {\n return this.select(false)?.getOptionalString(key);\n }\n getStringArray(key: string): string[] {\n return this.select(true).getStringArray(key);\n }\n getOptionalStringArray(key: string): string[] | undefined {\n return this.select(false)?.getOptionalStringArray(key);\n }\n}\n"],"names":["ConfigReader","isEqual"],"mappings":";;;;;;;;;AAoBO,MAAM,qBAAA,CAAwC;AAAA,EAC3C,MAAA,GAAiB,IAAIA,mBAAA,CAAa,EAAE,CAAA;AAAA,EAE3B,cAA8B,EAAC;AAAA,EAEhD,OAAO,OAAO,eAAA,EAAyD;AACrE,IAAA,OAAO,IAAI,qBAAA,CAAsB,MAAA,EAAW,MAAA,EAAW,eAAe,CAAA;AAAA,EACxE;AAAA,EAEiB,MAAA;AAAA,EACA,SAAA;AAAA,EACA,eAAA;AAAA,EAET,WAAA,CACN,MAAA,EACA,SAAA,EACA,eAAA,EACA;AACA,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,eAAA,GAAkB,eAAA;AACvB,IAAA,IAAI,MAAA,IAAU,CAAC,SAAA,EAAW;AACxB,MAAA,MAAM,IAAI,MAAM,wCAAwC,CAAA;AAAA,IAC1D;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAgB;AACxB,IAAA,IAAI,KAAK,MAAA,EAAQ;AACf,MAAA,MAAM,IAAI,MAAM,WAAW,CAAA;AAAA,IAC7B;AAMA,IAAA,MAAM,OAAA,GAAU,CAACC,wBAAA,CAAQ,IAAA,CAAK,OAAO,GAAA,EAAI,EAAG,MAAA,CAAO,GAAA,EAAK,CAAA;AAExD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAEd,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,KAAA,MAAW,UAAA,IAAc,KAAK,WAAA,EAAa;AACzC,QAAA,IAAI;AACF,UAAA,UAAA,EAAW;AAAA,QACb,SAAS,KAAA,EAAO;AACd,UAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,+BAAA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A,EAAsB;AAC/B,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,CAAE,WAAW,GAAG,CAAA;AAAA,EACzC;AAAA,EACA,mBAAmB,GAAA,EAAkC;AACnD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,EAAG,mBAAmB,GAAG,CAAA;AAAA,EACnD;AAAA,EACA,UAAU,GAAA,EAAqB;AAC7B,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,CAAE,UAAU,GAAG,CAAA;AAAA,EACxC;AAAA,EACA,kBAAkB,GAAA,EAAiC;AACjD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,EAAG,kBAAkB,GAAG,CAAA;AAAA,EAClD;AAAA,EACA,eAAe,GAAA,EAAuB;AACpC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,CAAE,eAAe,GAAG,CAAA;AAAA,EAC7C;AAAA,EACA,uBAAuB,GAAA,EAAmC;AACxD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,EAAG,uBAAuB,GAAG,CAAA;AAAA,EACvD;AACF;;;;"}
@@ -80,7 +80,7 @@ class TestDatabases {
80
80
  * Returns a fresh, unique, empty logical database on an instance of the
81
81
  * given database ID platform.
82
82
  *
83
- * @param id - The ID of the database platform to use, e.g. 'POSTGRES_13'
83
+ * @param id - The ID of the database platform to use, e.g. 'POSTGRES_14'
84
84
  * @returns A `Knex` connection object
85
85
  */
86
86
  async init(id) {
@@ -1 +1 @@
1
- {"version":3,"file":"TestDatabases.cjs.js","sources":["../../src/database/TestDatabases.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Knex } from 'knex';\nimport { isDockerDisabledForTests } from '../util/isDockerDisabledForTests';\nimport { MysqlEngine } from './mysql';\nimport { PostgresEngine } from './postgres';\nimport { SqliteEngine } from './sqlite';\nimport {\n Engine,\n TestDatabaseId,\n TestDatabaseProperties,\n allDatabases,\n} from './types';\n\n/**\n * Encapsulates the creation of ephemeral test database instances for use\n * inside unit or integration tests.\n *\n * @public\n */\nexport class TestDatabases {\n private readonly engineFactoryByDriver: Record<\n string,\n (properties: TestDatabaseProperties) => Promise<Engine>\n > = {\n pg: PostgresEngine.create,\n mysql: MysqlEngine.create,\n mysql2: MysqlEngine.create,\n 'better-sqlite3': SqliteEngine.create,\n sqlite3: SqliteEngine.create,\n };\n private readonly engineByTestDatabaseId: Map<string, Engine>;\n private readonly supportedIds: TestDatabaseId[];\n private static defaultIds?: TestDatabaseId[];\n\n /**\n * Creates an empty `TestDatabases` instance, and sets up Jest to clean up\n * all of its acquired resources after all tests finish.\n *\n * You typically want to create just a single instance like this at the top\n * of your test file or `describe` block, and then call `init` many times on\n * that instance inside the individual tests. Spinning up a \"physical\"\n * database instance takes a considerable amount of time, slowing down tests.\n * But initializing a new logical database inside that instance using `init`\n * is very fast.\n */\n static create(options?: {\n ids?: TestDatabaseId[];\n disableDocker?: boolean;\n }): TestDatabases {\n const ids = options?.ids;\n const disableDocker = options?.disableDocker ?? isDockerDisabledForTests();\n\n let testDatabaseIds: TestDatabaseId[];\n if (ids) {\n testDatabaseIds = ids;\n } else if (TestDatabases.defaultIds) {\n testDatabaseIds = TestDatabases.defaultIds;\n } else {\n testDatabaseIds = Object.keys(allDatabases) as TestDatabaseId[];\n }\n\n const supportedIds = testDatabaseIds.filter(id => {\n const properties = allDatabases[id];\n if (!properties) {\n return false;\n }\n // If the caller has set up the env with an explicit connection string,\n // we'll assume that this database will work\n if (\n properties.connectionStringEnvironmentVariableName &&\n process.env[properties.connectionStringEnvironmentVariableName]\n ) {\n return true;\n }\n // If the database doesn't require docker at all, there's nothing to worry\n // about\n if (!properties.dockerImageName) {\n return true;\n }\n // If the database requires docker, but docker is disabled, we will fail.\n if (disableDocker) {\n return false;\n }\n return true;\n });\n\n const databases = new TestDatabases(supportedIds);\n\n if (supportedIds.length > 0) {\n afterAll(async () => {\n await databases.shutdown();\n });\n }\n\n return databases;\n }\n\n static setDefaults(options: { ids?: TestDatabaseId[] }) {\n TestDatabases.defaultIds = options.ids;\n }\n\n private constructor(supportedIds: TestDatabaseId[]) {\n this.engineByTestDatabaseId = new Map();\n this.supportedIds = supportedIds;\n }\n\n supports(id: TestDatabaseId): boolean {\n return this.supportedIds.includes(id);\n }\n\n eachSupportedId(): [TestDatabaseId][] {\n return this.supportedIds.map(id => [id]);\n }\n\n /**\n * Returns a fresh, unique, empty logical database on an instance of the\n * given database ID platform.\n *\n * @param id - The ID of the database platform to use, e.g. 'POSTGRES_13'\n * @returns A `Knex` connection object\n */\n async init(id: TestDatabaseId): Promise<Knex> {\n const properties = allDatabases[id];\n if (!properties) {\n const candidates = Object.keys(allDatabases).join(', ');\n throw new Error(\n `Unknown test database ${id}, possible values are ${candidates}`,\n );\n }\n if (!this.supportedIds.includes(id)) {\n const candidates = this.supportedIds.join(', ');\n throw new Error(\n `Unsupported test database ${id} for this environment, possible values are ${candidates}`,\n );\n }\n\n let engine = this.engineByTestDatabaseId.get(id);\n if (!engine) {\n const factory = this.engineFactoryByDriver[properties.driver];\n if (!factory) {\n throw new Error(`Unknown database driver ${properties.driver}`);\n }\n engine = await factory(properties);\n this.engineByTestDatabaseId.set(id, engine);\n }\n\n return await engine.createDatabaseInstance();\n }\n\n private async shutdown() {\n const engines = [...this.engineByTestDatabaseId.values()];\n this.engineByTestDatabaseId.clear();\n\n for (const engine of engines) {\n try {\n await engine.shutdown();\n } catch (error) {\n console.warn(`TestDatabases: Failed to shutdown engine`, {\n engine,\n error,\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ACH;AAAA,IACF;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"TestDatabases.cjs.js","sources":["../../src/database/TestDatabases.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Knex } from 'knex';\nimport { isDockerDisabledForTests } from '../util/isDockerDisabledForTests';\nimport { MysqlEngine } from './mysql';\nimport { PostgresEngine } from './postgres';\nimport { SqliteEngine } from './sqlite';\nimport {\n Engine,\n TestDatabaseId,\n TestDatabaseProperties,\n allDatabases,\n} from './types';\n\n/**\n * Encapsulates the creation of ephemeral test database instances for use\n * inside unit or integration tests.\n *\n * @public\n */\nexport class TestDatabases {\n private readonly engineFactoryByDriver: Record<\n string,\n (properties: TestDatabaseProperties) => Promise<Engine>\n > = {\n pg: PostgresEngine.create,\n mysql: MysqlEngine.create,\n mysql2: MysqlEngine.create,\n 'better-sqlite3': SqliteEngine.create,\n sqlite3: SqliteEngine.create,\n };\n private readonly engineByTestDatabaseId: Map<string, Engine>;\n private readonly supportedIds: TestDatabaseId[];\n private static defaultIds?: TestDatabaseId[];\n\n /**\n * Creates an empty `TestDatabases` instance, and sets up Jest to clean up\n * all of its acquired resources after all tests finish.\n *\n * You typically want to create just a single instance like this at the top\n * of your test file or `describe` block, and then call `init` many times on\n * that instance inside the individual tests. Spinning up a \"physical\"\n * database instance takes a considerable amount of time, slowing down tests.\n * But initializing a new logical database inside that instance using `init`\n * is very fast.\n */\n static create(options?: {\n ids?: TestDatabaseId[];\n disableDocker?: boolean;\n }): TestDatabases {\n const ids = options?.ids;\n const disableDocker = options?.disableDocker ?? isDockerDisabledForTests();\n\n let testDatabaseIds: TestDatabaseId[];\n if (ids) {\n testDatabaseIds = ids;\n } else if (TestDatabases.defaultIds) {\n testDatabaseIds = TestDatabases.defaultIds;\n } else {\n testDatabaseIds = Object.keys(allDatabases) as TestDatabaseId[];\n }\n\n const supportedIds = testDatabaseIds.filter(id => {\n const properties = allDatabases[id];\n if (!properties) {\n return false;\n }\n // If the caller has set up the env with an explicit connection string,\n // we'll assume that this database will work\n if (\n properties.connectionStringEnvironmentVariableName &&\n process.env[properties.connectionStringEnvironmentVariableName]\n ) {\n return true;\n }\n // If the database doesn't require docker at all, there's nothing to worry\n // about\n if (!properties.dockerImageName) {\n return true;\n }\n // If the database requires docker, but docker is disabled, we will fail.\n if (disableDocker) {\n return false;\n }\n return true;\n });\n\n const databases = new TestDatabases(supportedIds);\n\n if (supportedIds.length > 0) {\n afterAll(async () => {\n await databases.shutdown();\n });\n }\n\n return databases;\n }\n\n static setDefaults(options: { ids?: TestDatabaseId[] }) {\n TestDatabases.defaultIds = options.ids;\n }\n\n private constructor(supportedIds: TestDatabaseId[]) {\n this.engineByTestDatabaseId = new Map();\n this.supportedIds = supportedIds;\n }\n\n supports(id: TestDatabaseId): boolean {\n return this.supportedIds.includes(id);\n }\n\n eachSupportedId(): [TestDatabaseId][] {\n return this.supportedIds.map(id => [id]);\n }\n\n /**\n * Returns a fresh, unique, empty logical database on an instance of the\n * given database ID platform.\n *\n * @param id - The ID of the database platform to use, e.g. 'POSTGRES_14'\n * @returns A `Knex` connection object\n */\n async init(id: TestDatabaseId): Promise<Knex> {\n const properties = allDatabases[id];\n if (!properties) {\n const candidates = Object.keys(allDatabases).join(', ');\n throw new Error(\n `Unknown test database ${id}, possible values are ${candidates}`,\n );\n }\n if (!this.supportedIds.includes(id)) {\n const candidates = this.supportedIds.join(', ');\n throw new Error(\n `Unsupported test database ${id} for this environment, possible values are ${candidates}`,\n );\n }\n\n let engine = this.engineByTestDatabaseId.get(id);\n if (!engine) {\n const factory = this.engineFactoryByDriver[properties.driver];\n if (!factory) {\n throw new Error(`Unknown database driver ${properties.driver}`);\n }\n engine = await factory(properties);\n this.engineByTestDatabaseId.set(id, engine);\n }\n\n return await engine.createDatabaseInstance();\n }\n\n private async shutdown() {\n const engines = [...this.engineByTestDatabaseId.values()];\n this.engineByTestDatabaseId.clear();\n\n for (const engine of engines) {\n try {\n await engine.shutdown();\n } catch (error) {\n console.warn(`TestDatabases: Failed to shutdown engine`, {\n engine,\n error,\n });\n }\n }\n }\n}\n"],"names":["PostgresEngine","MysqlEngine","SqliteEngine","isDockerDisabledForTests","allDatabases"],"mappings":";;;;;;;;AAkCO,MAAM,aAAA,CAAc;AAAA,EACR,qBAAA,GAGb;AAAA,IACF,IAAIA,uBAAA,CAAe,MAAA;AAAA,IACnB,OAAOC,iBAAA,CAAY,MAAA;AAAA,IACnB,QAAQA,iBAAA,CAAY,MAAA;AAAA,IACpB,kBAAkBC,mBAAA,CAAa,MAAA;AAAA,IAC/B,SAASA,mBAAA,CAAa;AAAA,GACxB;AAAA,EACiB,sBAAA;AAAA,EACA,YAAA;AAAA,EACjB,OAAe,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaf,OAAO,OAAO,OAAA,EAGI;AAChB,IAAA,MAAM,MAAM,OAAA,EAAS,GAAA;AACrB,IAAA,MAAM,aAAA,GAAgB,OAAA,EAAS,aAAA,IAAiBC,iDAAA,EAAyB;AAEzE,IAAA,IAAI,eAAA;AACJ,IAAA,IAAI,GAAA,EAAK;AACP,MAAA,eAAA,GAAkB,GAAA;AAAA,IACpB,CAAA,MAAA,IAAW,cAAc,UAAA,EAAY;AACnC,MAAA,eAAA,GAAkB,aAAA,CAAc,UAAA;AAAA,IAClC,CAAA,MAAO;AACL,MAAA,eAAA,GAAkB,MAAA,CAAO,KAAKC,kBAAY,CAAA;AAAA,IAC5C;AAEA,IAAA,MAAM,YAAA,GAAe,eAAA,CA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A,CAAuB,QAAQ,CAAA;AACxD,IAAA,IAAA,CAAK,uBAAuB,KAAA,EAAM;AAElC,IAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,MAAA,IAAI;AACF,QAAA,MAAM,OAAO,QAAA,EAAS;AAAA,MACxB,SAAS,KAAA,EAAO;AACd,QAAA,OAAA,CAAQ,KAAK,CAAA,wCAAA,CAAA,EAA4C;AAAA,UACvD,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;;"}
@@ -3,6 +3,12 @@
3
3
  var getDockerImageForName = require('../util/getDockerImageForName.cjs.js');
4
4
 
5
5
  const allDatabases = Object.freeze({
6
+ POSTGRES_18: {
7
+ name: "Postgres 18.x",
8
+ driver: "pg",
9
+ dockerImageName: getDockerImageForName.getDockerImageForName("postgres:18"),
10
+ connectionStringEnvironmentVariableName: "BACKSTAGE_TEST_DATABASE_POSTGRES18_CONNECTION_STRING"
11
+ },
6
12
  POSTGRES_17: {
7
13
  name: "Postgres 17.x",
8
14
  driver: "pg",
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs.js","sources":["../../src/database/types.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Knex } from 'knex';\nimport { getDockerImageForName } from '../util/getDockerImageForName';\n\nexport interface Engine {\n createDatabaseInstance(): Promise<Knex>;\n shutdown(): Promise<void>;\n}\n\n/**\n * The possible databases to test against.\n *\n * @public\n */\nexport type TestDatabaseId =\n | 'POSTGRES_17'\n | 'POSTGRES_16'\n | 'POSTGRES_15'\n | 'POSTGRES_14'\n | 'POSTGRES_13'\n | 'POSTGRES_12'\n | 'POSTGRES_11'\n | 'POSTGRES_9'\n | 'MYSQL_8'\n | 'SQLITE_3';\n\nexport type TestDatabaseProperties = {\n name: string;\n driver: string;\n dockerImageName?: string;\n connectionStringEnvironmentVariableName?: string;\n};\n\nexport const allDatabases: Record<TestDatabaseId, TestDatabaseProperties> =\n Object.freeze({\n POSTGRES_17: {\n name: 'Postgres 17.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:17'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES17_CONNECTION_STRING',\n },\n POSTGRES_16: {\n name: 'Postgres 16.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:16'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES16_CONNECTION_STRING',\n },\n POSTGRES_15: {\n name: 'Postgres 15.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:15'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES15_CONNECTION_STRING',\n },\n POSTGRES_14: {\n name: 'Postgres 14.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:14'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES14_CONNECTION_STRING',\n },\n POSTGRES_13: {\n name: 'Postgres 13.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:13'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING',\n },\n POSTGRES_12: {\n name: 'Postgres 12.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:12'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING',\n },\n POSTGRES_11: {\n name: 'Postgres 11.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:11'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING',\n },\n POSTGRES_9: {\n name: 'Postgres 9.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:9'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING',\n },\n MYSQL_8: {\n name: 'MySQL 8.x',\n driver: 'mysql2',\n dockerImageName: getDockerImageForName('mysql:8'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING',\n },\n SQLITE_3: {\n name: 'SQLite 3.x',\n driver: 'better-sqlite3',\n },\n });\n\nexport const LARGER_POOL_CONFIG = {\n pool: {\n min: 0,\n max: 50,\n },\n};\n"],"names":["getDockerImageForName"],"mappings":";;;;AAgDO,MAAM,YAAA,GACX,OAAO,MAAA,CAAO;AAAA,EACZ,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,cAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,YAAY,CAAA;AAAA,IACnD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,WAAA;AAAA,IACN,MAAA,EAAQ,QAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,SAAS,CAAA;AAAA,IAChD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,YAAA;AAAA,IACN,MAAA,EAAQ;AAAA;AAEZ,CAAC;AAEI,MAAM,kBAAA,GAAqB;AAAA,EAChC,IAAA,EAAM;AAAA,IACJ,GAAA,EAAK,CAAA;AAAA,IACL,GAAA,EAAK;AAAA;AAET;;;;;"}
1
+ {"version":3,"file":"types.cjs.js","sources":["../../src/database/types.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Knex } from 'knex';\nimport { getDockerImageForName } from '../util/getDockerImageForName';\n\nexport interface Engine {\n createDatabaseInstance(): Promise<Knex>;\n shutdown(): Promise<void>;\n}\n\n/**\n * The possible databases to test against.\n *\n * @public\n */\nexport type TestDatabaseId =\n | 'POSTGRES_18'\n | 'POSTGRES_17'\n | 'POSTGRES_16'\n | 'POSTGRES_15'\n | 'POSTGRES_14'\n | 'POSTGRES_13'\n | 'POSTGRES_12'\n | 'POSTGRES_11'\n | 'POSTGRES_9'\n | 'MYSQL_8'\n | 'SQLITE_3';\n\nexport type TestDatabaseProperties = {\n name: string;\n driver: string;\n dockerImageName?: string;\n connectionStringEnvironmentVariableName?: string;\n};\n\nexport const allDatabases: Record<TestDatabaseId, TestDatabaseProperties> =\n Object.freeze({\n POSTGRES_18: {\n name: 'Postgres 18.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:18'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES18_CONNECTION_STRING',\n },\n POSTGRES_17: {\n name: 'Postgres 17.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:17'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES17_CONNECTION_STRING',\n },\n POSTGRES_16: {\n name: 'Postgres 16.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:16'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES16_CONNECTION_STRING',\n },\n POSTGRES_15: {\n name: 'Postgres 15.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:15'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES15_CONNECTION_STRING',\n },\n POSTGRES_14: {\n name: 'Postgres 14.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:14'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES14_CONNECTION_STRING',\n },\n POSTGRES_13: {\n name: 'Postgres 13.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:13'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES13_CONNECTION_STRING',\n },\n POSTGRES_12: {\n name: 'Postgres 12.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:12'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES12_CONNECTION_STRING',\n },\n POSTGRES_11: {\n name: 'Postgres 11.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:11'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES11_CONNECTION_STRING',\n },\n POSTGRES_9: {\n name: 'Postgres 9.x',\n driver: 'pg',\n dockerImageName: getDockerImageForName('postgres:9'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_POSTGRES9_CONNECTION_STRING',\n },\n MYSQL_8: {\n name: 'MySQL 8.x',\n driver: 'mysql2',\n dockerImageName: getDockerImageForName('mysql:8'),\n connectionStringEnvironmentVariableName:\n 'BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING',\n },\n SQLITE_3: {\n name: 'SQLite 3.x',\n driver: 'better-sqlite3',\n },\n });\n\nexport const LARGER_POOL_CONFIG = {\n pool: {\n min: 0,\n max: 50,\n },\n};\n"],"names":["getDockerImageForName"],"mappings":";;;;AAiDO,MAAM,YAAA,GACX,OAAO,MAAA,CAAO;AAAA,EACZ,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,aAAa,CAAA;AAAA,IACpD,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MAAA,EAAQ,IAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,YAAY,CAAA;AAAA,IACnD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,WAAA;AAAA,IACN,MAAA,EAAQ,QAAA;AAAA,IACR,eAAA,EAAiBA,4CAAsB,SAAS,CAAA;AAAA,IAChD,uCAAA,EACE;AAAA,GACJ;AAAA,EACA,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,YAAA;AAAA,IACN,MAAA,EAAQ;AAAA;AAEZ,CAAC;AAEI,MAAM,kBAAA,GAAqB;AAAA,EAChC,IAAA,EAAM;AAAA,IACJ,GAAA,EAAK,CAAA;AAAA,IACL,GAAA,EAAK;AAAA;AAET;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import Keyv from 'keyv';
2
2
  import { Knex } from 'knex';
3
3
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
4
- import { ServiceFactory, RootConfigService, LoggerService, AuthService, DiscoveryService, BackstageCredentials, HttpAuthService, BackstageUserInfo, UserInfoService, DatabaseService, PermissionsService, SchedulerService, BackstageNonePrincipal, BackstageUserPrincipal, BackstagePrincipalAccessRestrictions, BackstageServicePrincipal, ServiceRef, ExtensionPoint, BackendFeature } from '@backstage/backend-plugin-api';
4
+ import { ServiceFactory, RootConfigService, LoggerService, AuthService, DiscoveryService, BackstageCredentials, HttpAuthService, BackstageUserInfo, UserInfoService, DatabaseService, PermissionsService, SchedulerService, RootInstanceMetadataService, BackstageNonePrincipal, BackstageUserPrincipal, BackstagePrincipalAccessRestrictions, BackstageServicePrincipal, ServiceRef, ExtensionPoint, BackendFeature } from '@backstage/backend-plugin-api';
5
5
  import { EventsService } from '@backstage/plugin-events-node';
6
6
  import { AuthorizeResult } from '@backstage/plugin-permission-common';
7
7
  import { JsonObject } from '@backstage/types';
@@ -71,7 +71,7 @@ declare class TestCaches {
71
71
  *
72
72
  * @public
73
73
  */
74
- type TestDatabaseId = 'POSTGRES_17' | 'POSTGRES_16' | 'POSTGRES_15' | 'POSTGRES_14' | 'POSTGRES_13' | 'POSTGRES_12' | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3';
74
+ type TestDatabaseId = 'POSTGRES_18' | 'POSTGRES_17' | 'POSTGRES_16' | 'POSTGRES_15' | 'POSTGRES_14' | 'POSTGRES_13' | 'POSTGRES_12' | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3';
75
75
 
76
76
  /**
77
77
  * Encapsulates the creation of ephemeral test database instances for use
@@ -109,7 +109,7 @@ declare class TestDatabases {
109
109
  * Returns a fresh, unique, empty logical database on an instance of the
110
110
  * given database ID platform.
111
111
  *
112
- * @param id - The ID of the database platform to use, e.g. 'POSTGRES_13'
112
+ * @param id - The ID of the database platform to use, e.g. 'POSTGRES_14'
113
113
  * @returns A `Knex` connection object
114
114
  */
115
115
  init(id: TestDatabaseId): Promise<Knex>;
@@ -572,6 +572,11 @@ declare namespace mockServices {
572
572
  */
573
573
  const mock: (partialImpl?: Partial<EventsService> | undefined) => ServiceMock<EventsService>;
574
574
  }
575
+ function rootInstanceMetadata(): RootInstanceMetadataService;
576
+ namespace rootInstanceMetadata {
577
+ const mock: (partialImpl?: Partial<RootInstanceMetadataService> | undefined) => ServiceMock<RootInstanceMetadataService>;
578
+ const factory: () => ServiceFactory<RootInstanceMetadataService, "plugin", "singleton" | "multiton">;
579
+ }
575
580
  }
576
581
 
577
582
  /**
@@ -333,5 +333,20 @@ exports.mockServices = void 0;
333
333
  subscribe: jest.fn()
334
334
  }));
335
335
  })(events = mockServices2.events || (mockServices2.events = {}));
336
+ function rootInstanceMetadata() {
337
+ return {
338
+ getInstalledPlugins: () => Promise.resolve([])
339
+ };
340
+ }
341
+ mockServices2.rootInstanceMetadata = rootInstanceMetadata;
342
+ ((rootInstanceMetadata2) => {
343
+ rootInstanceMetadata2.mock = simpleMock.simpleMock(backendPluginApi.coreServices.rootInstanceMetadata, () => ({
344
+ getInstalledPlugins: jest.fn()
345
+ }));
346
+ rootInstanceMetadata2.factory = simpleFactoryWithOptions(
347
+ backendPluginApi.coreServices.rootInstanceMetadata,
348
+ rootInstanceMetadata2
349
+ );
350
+ })(rootInstanceMetadata = mockServices2.rootInstanceMetadata || (mockServices2.rootInstanceMetadata = {}));
336
351
  })(exports.mockServices || (exports.mockServices = {}));
337
352
  //# sourceMappingURL=mockServices.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockServices.cjs.js","sources":["../../src/services/mockServices.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { auditorServiceFactory } from '@backstage/backend-defaults/auditor';\nimport { cacheServiceFactory } from '@backstage/backend-defaults/cache';\nimport { databaseServiceFactory } from '@backstage/backend-defaults/database';\nimport { HostDiscovery } from '@backstage/backend-defaults/discovery';\nimport { httpRouterServiceFactory } from '@backstage/backend-defaults/httpRouter';\nimport { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';\nimport { loggerServiceFactory } from '@backstage/backend-defaults/logger';\nimport { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';\nimport { permissionsRegistryServiceFactory } from '@backstage/backend-defaults/permissionsRegistry';\nimport { rootHealthServiceFactory } from '@backstage/backend-defaults/rootHealth';\nimport { rootHttpRouterServiceFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { rootLifecycleServiceFactory } from '@backstage/backend-defaults/rootLifecycle';\nimport { urlReaderServiceFactory } from '@backstage/backend-defaults/urlReader';\nimport {\n AuthService,\n BackstageCredentials,\n BackstageUserInfo,\n DatabaseService,\n DiscoveryService,\n HttpAuthService,\n LoggerService,\n PermissionsService,\n RootConfigService,\n SchedulerService,\n ServiceFactory,\n ServiceRef,\n UserInfoService,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { ConfigReader } from '@backstage/config';\nimport { EventsService, eventsServiceRef } from '@backstage/plugin-events-node';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\nimport { JsonObject } from '@backstage/types';\nimport { Knex } from 'knex';\nimport { MockAuthService } from './MockAuthService';\nimport { MockHttpAuthService } from './MockHttpAuthService';\nimport { MockRootLoggerService } from './MockRootLoggerService';\nimport { MockUserInfoService } from './MockUserInfoService';\nimport { mockCredentials } from './mockCredentials';\nimport { MockEventsService } from './MockEventsService';\nimport { MockPermissionsService } from './MockPermissionsService';\nimport { simpleMock } from './simpleMock';\nimport { MockSchedulerService } from './MockSchedulerService';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { ObservableConfigProxy } from '../../../config-loader/src/sources/ObservableConfigProxy';\n\n/** @internal */\nfunction createLoggerMock() {\n return {\n child: jest.fn().mockImplementation(createLoggerMock),\n debug: jest.fn(),\n error: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n };\n}\n\n/** @internal */\nfunction simpleFactoryWithOptions<\n TService,\n TScope extends 'root' | 'plugin',\n TOptions extends [options?: object] = [],\n>(\n ref: ServiceRef<TService, TScope>,\n factory: (...options: TOptions) => TService,\n): (...options: TOptions) => ServiceFactory<TService, TScope> {\n const factoryWithOptions = (...options: TOptions) =>\n createServiceFactory({\n service: ref as ServiceRef<TService, any>,\n deps: {},\n async factory() {\n return factory(...options);\n },\n });\n return Object.assign(\n factoryWithOptions,\n factoryWithOptions(...([undefined] as unknown as TOptions)),\n ) as ServiceFactory<TService, TScope> &\n ((...options: TOptions) => ServiceFactory<TService, TScope>);\n}\n\n/**\n * Mock implementations of the core services, to be used in tests.\n *\n * @public\n * @remarks\n *\n * There are some variations among the services depending on what needs tests\n * might have, but overall there are three main usage patterns:\n *\n * 1. Creating an actual fake service instance, often with a simplified version\n * of functionality, by calling the mock service itself as a function.\n *\n * ```ts\n * // The function often accepts parameters that control its behavior\n * const foo = mockServices.foo();\n * ```\n *\n * 2. Creating a mock service, where all methods are replaced with jest mocks, by\n * calling the service's `mock` function.\n *\n * ```ts\n * // You can optionally supply a subset of its methods to implement\n * const foo = mockServices.foo.mock({\n * someMethod: () => 'mocked result',\n * });\n * // After exercising your test, you can make assertions on the mock:\n * expect(foo.someMethod).toHaveBeenCalledTimes(2);\n * expect(foo.otherMethod).toHaveBeenCalledWith(testData);\n * ```\n *\n * 3. Creating a service factory that behaves similarly to the mock as per above.\n *\n * ```ts\n * await startTestBackend({\n * features: [\n * mockServices.foo.factory({\n * someMethod: () => 'mocked result',\n * })\n * ],\n * });\n * ```\n */\nexport namespace mockServices {\n export function rootConfig(\n options?: rootConfig.Options,\n ): RootConfigService & { update(options: { data: JsonObject }): void } {\n const config = ObservableConfigProxy.create(new AbortController());\n config.setConfig(new ConfigReader(options?.data ?? {}, 'mock-config'));\n return Object.assign(config, {\n update({ data }: { data: JsonObject }): void {\n config.setConfig(new ConfigReader(data, 'mock-config'));\n },\n });\n }\n export namespace rootConfig {\n export type Options = { data?: JsonObject };\n\n export const factory = simpleFactoryWithOptions(\n coreServices.rootConfig,\n rootConfig,\n );\n export const mock = simpleMock(coreServices.rootConfig, () => ({\n get: jest.fn(),\n getBoolean: jest.fn(),\n getConfig: jest.fn(),\n getConfigArray: jest.fn(),\n getNumber: jest.fn(),\n getOptional: jest.fn(),\n getOptionalBoolean: jest.fn(),\n getOptionalConfig: jest.fn(),\n getOptionalConfigArray: jest.fn(),\n getOptionalNumber: jest.fn(),\n getOptionalString: jest.fn(),\n getOptionalStringArray: jest.fn(),\n getString: jest.fn(),\n getStringArray: jest.fn(),\n has: jest.fn(),\n keys: jest.fn(),\n }));\n }\n\n export function rootLogger(options?: rootLogger.Options): LoggerService {\n return MockRootLoggerService.create(options);\n }\n export namespace rootLogger {\n export type Options = {\n level?: 'none' | 'error' | 'warn' | 'info' | 'debug';\n };\n\n export const factory = simpleFactoryWithOptions(\n coreServices.rootLogger,\n rootLogger,\n );\n export const mock = simpleMock(coreServices.rootLogger, () => ({\n child: jest.fn(),\n debug: jest.fn(),\n error: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n }));\n }\n\n export namespace auditor {\n export const factory = () => auditorServiceFactory;\n\n export const mock = simpleMock(coreServices.auditor, () => ({\n createEvent: jest.fn(async _ => {\n return {\n success: jest.fn(),\n fail: jest.fn(),\n };\n }),\n }));\n }\n\n export function auth(options?: {\n pluginId?: string;\n disableDefaultAuthPolicy?: boolean;\n }): AuthService {\n return new MockAuthService({\n pluginId: options?.pluginId ?? 'test',\n disableDefaultAuthPolicy: Boolean(options?.disableDefaultAuthPolicy),\n });\n }\n export namespace auth {\n export const factory = () =>\n createServiceFactory({\n service: coreServices.auth,\n deps: {\n plugin: coreServices.pluginMetadata,\n config: coreServices.rootConfig,\n },\n factory({ plugin, config }) {\n const disableDefaultAuthPolicy = Boolean(\n config.getOptionalBoolean(\n 'backend.auth.dangerouslyDisableDefaultAuthPolicy',\n ),\n );\n return new MockAuthService({\n pluginId: plugin.getId(),\n disableDefaultAuthPolicy,\n });\n },\n });\n export const mock = simpleMock(coreServices.auth, () => ({\n authenticate: jest.fn(),\n getNoneCredentials: jest.fn(),\n getOwnServiceCredentials: jest.fn(),\n isPrincipal: jest.fn() as any,\n getPluginRequestToken: jest.fn(),\n getLimitedUserToken: jest.fn(),\n listPublicServiceKeys: jest.fn(),\n }));\n }\n\n export function discovery(): DiscoveryService {\n return HostDiscovery.fromConfig(\n new ConfigReader({\n backend: {\n // Invalid port to make sure that requests are always mocked\n baseUrl: 'http://localhost:0',\n listen: { port: 0 },\n },\n }),\n );\n }\n export namespace discovery {\n export const factory = () =>\n createServiceFactory({\n service: coreServices.discovery,\n deps: {},\n factory: () => discovery(),\n });\n export const mock = simpleMock(coreServices.discovery, () => ({\n getBaseUrl: jest.fn(),\n getExternalBaseUrl: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the `HttpAuthService`.\n *\n * By default all requests without credentials are treated as requests from\n * the default mock user principal. This behavior can be configured with the\n * `defaultCredentials` option.\n */\n export function httpAuth(options?: {\n pluginId?: string;\n /**\n * The default credentials to use if there are no credentials present in the\n * incoming request.\n *\n * By default all requests without credentials are treated as authenticated\n * as the default mock user as returned from `mockCredentials.user()`.\n */\n defaultCredentials?: BackstageCredentials;\n }): HttpAuthService {\n return new MockHttpAuthService(\n options?.pluginId ?? 'test',\n options?.defaultCredentials ?? mockCredentials.user(),\n );\n }\n export namespace httpAuth {\n /**\n * Creates a mock service factory for the `HttpAuthService`.\n *\n * By default all requests without credentials are treated as requests from\n * the default mock user principal. This behavior can be configured with the\n * `defaultCredentials` option.\n */\n export const factory = (options?: {\n defaultCredentials?: BackstageCredentials;\n }) =>\n createServiceFactory({\n service: coreServices.httpAuth,\n deps: { plugin: coreServices.pluginMetadata },\n factory: ({ plugin }) =>\n new MockHttpAuthService(\n plugin.getId(),\n options?.defaultCredentials ?? mockCredentials.user(),\n ),\n });\n export const mock = simpleMock(coreServices.httpAuth, () => ({\n credentials: jest.fn(),\n issueUserCookie: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the `UserInfoService`.\n *\n * By default it extracts the user's entity ref from a user principal and\n * returns that as the only ownership entity ref, but this can be overridden\n * by passing in a custom set of user info.\n */\n export function userInfo(\n customInfo?: Partial<BackstageUserInfo>,\n ): UserInfoService {\n return new MockUserInfoService(customInfo);\n }\n export namespace userInfo {\n /**\n * Creates a mock service factory for the `UserInfoService`.\n *\n * By default it extracts the user's entity ref from a user principal and\n * returns that as the only ownership entity ref.\n */\n export const factory = () =>\n createServiceFactory({\n service: coreServices.userInfo,\n deps: {},\n factory() {\n return new MockUserInfoService();\n },\n });\n export const mock = simpleMock(coreServices.userInfo, () => ({\n getUserInfo: jest.fn(),\n }));\n }\n\n // TODO(Rugvip): Not all core services have implementations available here yet.\n // some may need a bit more refactoring for it to be simpler to\n // re-implement functioning mock versions here.\n export namespace cache {\n export const factory = () => cacheServiceFactory;\n export const mock = simpleMock(coreServices.cache, () => ({\n delete: jest.fn(),\n get: jest.fn(),\n set: jest.fn(),\n withOptions: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the\n * {@link @backstage/backend-plugin-api#coreServices.database}. Just returns\n * the given `knex` instance, which is useful in combination with the\n * {@link TestDatabases} facility.\n */\n export function database(options: {\n knex: Knex;\n migrations?: { skip?: boolean };\n }): DatabaseService {\n return {\n getClient: async () => options.knex,\n migrations: options.migrations,\n };\n }\n export namespace database {\n /**\n * Creates a mock factory for the\n * {@link @backstage/backend-plugin-api#coreServices.database}. Just returns\n * the given `knex` instance if you supply one, which is useful in\n * combination with the {@link TestDatabases} facility. Otherwise, it\n * returns the regular default database factory which reads config settings.\n */\n export const factory = (options?: {\n knex: Knex;\n migrations?: { skip?: boolean };\n }) =>\n options\n ? createServiceFactory({\n service: coreServices.database,\n deps: {},\n factory: () => database(options),\n })\n : databaseServiceFactory;\n /**\n * Creates a mock of the\n * {@link @backstage/backend-plugin-api#coreServices.database}, optionally\n * with some given method implementations.\n */\n export const mock = simpleMock(coreServices.database, () => ({\n getClient: jest.fn(),\n }));\n }\n\n export namespace rootHealth {\n export const factory = () => rootHealthServiceFactory;\n export const mock = simpleMock(coreServices.rootHealth, () => ({\n getLiveness: jest.fn(),\n getReadiness: jest.fn(),\n }));\n }\n\n export namespace httpRouter {\n export const factory = () => httpRouterServiceFactory;\n export const mock = simpleMock(coreServices.httpRouter, () => ({\n use: jest.fn(),\n addAuthPolicy: jest.fn(),\n }));\n }\n\n export namespace rootHttpRouter {\n export const factory = () => rootHttpRouterServiceFactory();\n export const mock = simpleMock(coreServices.rootHttpRouter, () => ({\n use: jest.fn(),\n }));\n }\n\n export namespace lifecycle {\n export const factory = () => lifecycleServiceFactory;\n export const mock = simpleMock(coreServices.lifecycle, () => ({\n addShutdownHook: jest.fn(),\n addStartupHook: jest.fn(),\n }));\n }\n\n export namespace logger {\n export const factory = () => loggerServiceFactory;\n export const mock = simpleMock(coreServices.logger, () =>\n createLoggerMock(),\n );\n }\n\n /**\n * Creates a functional mock implementation of the\n * {@link @backstage/backend-plugin-api#PermissionsService}.\n */\n export function permissions(options?: {\n result: AuthorizeResult.ALLOW | AuthorizeResult.DENY;\n }): PermissionsService {\n return new MockPermissionsService(options);\n }\n export namespace permissions {\n /**\n * Creates a mock factory for the\n * {@link @backstage/backend-plugin-api#coreServices.permissions}. Just\n * returns the given `result` if you supply one. Otherwise, it returns the\n * regular default permissions factory.\n */\n export const factory = (options?: {\n result: AuthorizeResult.ALLOW | AuthorizeResult.DENY;\n }) =>\n options?.result\n ? createServiceFactory({\n service: coreServices.permissions,\n deps: {},\n factory: () => new MockPermissionsService(options),\n })\n : permissionsServiceFactory;\n /**\n * Creates a mock of the\n * {@link @backstage/backend-plugin-api#coreServices.permissions},\n * optionally with some given method implementations.\n */\n export const mock = simpleMock(coreServices.permissions, () => ({\n authorize: jest.fn(),\n authorizeConditional: jest.fn(),\n }));\n }\n\n export namespace permissionsRegistry {\n export const factory = () => permissionsRegistryServiceFactory;\n export const mock = simpleMock(coreServices.permissionsRegistry, () => ({\n addPermissionRules: jest.fn(),\n addPermissions: jest.fn(),\n addResourceType: jest.fn(),\n getPermissionRuleset: jest.fn(),\n }));\n }\n\n export namespace rootLifecycle {\n export const factory = () => rootLifecycleServiceFactory;\n export const mock = simpleMock(coreServices.rootLifecycle, () => ({\n addShutdownHook: jest.fn(),\n addBeforeShutdownHook: jest.fn(),\n addStartupHook: jest.fn(),\n }));\n }\n\n export function scheduler(): SchedulerService {\n return new MockSchedulerService();\n }\n export namespace scheduler {\n export const factory = (options?: {\n skipTaskRunOnStartup?: boolean;\n includeManualTasksOnStartup?: boolean;\n includeInitialDelayedTasksOnStartup?: boolean;\n }) => new MockSchedulerService().factory(options);\n export const mock = simpleMock(coreServices.scheduler, () => ({\n createScheduledTaskRunner: jest.fn(),\n getScheduledTasks: jest.fn(),\n scheduleTask: jest.fn(),\n triggerTask: jest.fn(),\n }));\n }\n\n export namespace urlReader {\n export const factory = () => urlReaderServiceFactory;\n export const mock = simpleMock(coreServices.urlReader, () => ({\n readTree: jest.fn(),\n readUrl: jest.fn(),\n search: jest.fn(),\n }));\n }\n\n /**\n * Creates a functional mock implementation of the\n * {@link @backstage/backend-events-node#eventsServiceRef}.\n */\n export function events(): EventsService {\n return new MockEventsService();\n }\n export namespace events {\n /**\n * Creates a functional mock factory for the\n * {@link @backstage/backend-events-node#eventsServiceRef}.\n */\n export const factory = simpleFactoryWithOptions(eventsServiceRef, events);\n /**\n * Creates a mock of the\n * {@link @backstage/backend-events-node#eventsServiceRef}, optionally\n * with some given method implementations.\n */\n export const mock = simpleMock(eventsServiceRef, () => ({\n publish: jest.fn(),\n subscribe: jest.fn(),\n }));\n }\n}\n"],"names":["createServiceFactory","mockServices","config","ObservableConfigProxy","ConfigReader","rootConfig","coreServices","simpleMock","MockRootLoggerService","rootLogger","auditor","auditorServiceFactory","MockAuthService","auth","discovery","HostDiscovery","MockHttpAuthService","mockCredentials","httpAuth","MockUserInfoService","userInfo","cache","cacheServiceFactory","database","databaseServiceFactory","rootHealth","rootHealthServiceFactory","httpRouter","httpRouterServiceFactory","rootHttpRouter","rootHttpRouterServiceFactory","lifecycle","lifecycleServiceFactory","logger","loggerServiceFactory","permissions","MockPermissionsService","permissionsServiceFactory","permissionsRegistry","permissionsRegistryServiceFactory","rootLifecycle","rootLifecycleServiceFactory","MockSchedulerService","scheduler","urlReader","urlReaderServiceFactory","MockEventsService","events","eventsServiceRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAS,gBAAA,GAAmB;AAC1B,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,IAAA,CAAK,EAAA,EAAG,CAAE,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5D,QAAA,EAAU,KAAK,EAAA,EAAG;AAAA,MAClB,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,MAAA,EAAQ,KAAK,EAAA;AAAG,KAClB,CAAE,CAAA;AAAA,EAAA,CAAA,EANaL,aAAAA,CAAA,SAAA,KAAAA,aAAAA,CAAA,SAAA,GAAA,EAAA,CAAA,CAAA;AAaV,EAAA,SAAS,MAAA,GAAwB;AACtC,IAAA,OAAO,IAAI6C,mCAAA,EAAkB;AAAA,EAC/B;AAFO,EAAA7C,aAAAA,CAAS,MAAA,GAAA,MAAA;AAGT,EAAA,CAAA,CAAU8C,OAAAA,KAAV;AAKE,IAAMA,OAAAA,CAAA,OAAA,GAAU,wBAAA,CAAyBC,iCAAA,EAAkBD,OAAM,CAAA;AAMjE,IAAMA,OAAAA,CAAA,IAAA,GAAOxC,qBAAA,CAAWyC,iCAAA,EAAkB,OAAO;AAAA,MACtD,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,SAAA,EAAW,KAAK,EAAA;AAAG,KACrB,CAAE,CAAA;AAAA,EAAA,CAAA,EAda,MAAA,GAAA/C,aAAAA,CAAA,MAAA,KAAAA,aAAAA,CAAA,MAAA,GAAA,EAAA,CAAA,CAAA;AAAA,CAAA,EAlZFA,oBAAA,KAAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;"}
1
+ {"version":3,"file":"mockServices.cjs.js","sources":["../../src/services/mockServices.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { auditorServiceFactory } from '@backstage/backend-defaults/auditor';\nimport { cacheServiceFactory } from '@backstage/backend-defaults/cache';\nimport { databaseServiceFactory } from '@backstage/backend-defaults/database';\nimport { HostDiscovery } from '@backstage/backend-defaults/discovery';\nimport { httpRouterServiceFactory } from '@backstage/backend-defaults/httpRouter';\nimport { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';\nimport { loggerServiceFactory } from '@backstage/backend-defaults/logger';\nimport { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';\nimport { permissionsRegistryServiceFactory } from '@backstage/backend-defaults/permissionsRegistry';\nimport { rootHealthServiceFactory } from '@backstage/backend-defaults/rootHealth';\nimport { rootHttpRouterServiceFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { rootLifecycleServiceFactory } from '@backstage/backend-defaults/rootLifecycle';\nimport { urlReaderServiceFactory } from '@backstage/backend-defaults/urlReader';\nimport {\n AuthService,\n BackstageCredentials,\n BackstageUserInfo,\n DatabaseService,\n DiscoveryService,\n HttpAuthService,\n RootInstanceMetadataService,\n LoggerService,\n PermissionsService,\n RootConfigService,\n SchedulerService,\n ServiceFactory,\n ServiceRef,\n UserInfoService,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { ConfigReader } from '@backstage/config';\nimport { EventsService, eventsServiceRef } from '@backstage/plugin-events-node';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\nimport { JsonObject } from '@backstage/types';\nimport { Knex } from 'knex';\nimport { MockAuthService } from './MockAuthService';\nimport { MockHttpAuthService } from './MockHttpAuthService';\nimport { MockRootLoggerService } from './MockRootLoggerService';\nimport { MockUserInfoService } from './MockUserInfoService';\nimport { mockCredentials } from './mockCredentials';\nimport { MockEventsService } from './MockEventsService';\nimport { MockPermissionsService } from './MockPermissionsService';\nimport { simpleMock } from './simpleMock';\nimport { MockSchedulerService } from './MockSchedulerService';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { ObservableConfigProxy } from '../../../config-loader/src/sources/ObservableConfigProxy';\n\n/** @internal */\nfunction createLoggerMock() {\n return {\n child: jest.fn().mockImplementation(createLoggerMock),\n debug: jest.fn(),\n error: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n };\n}\n\n/** @internal */\nfunction simpleFactoryWithOptions<\n TService,\n TScope extends 'root' | 'plugin',\n TOptions extends [options?: object] = [],\n>(\n ref: ServiceRef<TService, TScope>,\n factory: (...options: TOptions) => TService,\n): (...options: TOptions) => ServiceFactory<TService, TScope> {\n const factoryWithOptions = (...options: TOptions) =>\n createServiceFactory({\n service: ref as ServiceRef<TService, any>,\n deps: {},\n async factory() {\n return factory(...options);\n },\n });\n return Object.assign(\n factoryWithOptions,\n factoryWithOptions(...([undefined] as unknown as TOptions)),\n ) as ServiceFactory<TService, TScope> &\n ((...options: TOptions) => ServiceFactory<TService, TScope>);\n}\n\n/**\n * Mock implementations of the core services, to be used in tests.\n *\n * @public\n * @remarks\n *\n * There are some variations among the services depending on what needs tests\n * might have, but overall there are three main usage patterns:\n *\n * 1. Creating an actual fake service instance, often with a simplified version\n * of functionality, by calling the mock service itself as a function.\n *\n * ```ts\n * // The function often accepts parameters that control its behavior\n * const foo = mockServices.foo();\n * ```\n *\n * 2. Creating a mock service, where all methods are replaced with jest mocks, by\n * calling the service's `mock` function.\n *\n * ```ts\n * // You can optionally supply a subset of its methods to implement\n * const foo = mockServices.foo.mock({\n * someMethod: () => 'mocked result',\n * });\n * // After exercising your test, you can make assertions on the mock:\n * expect(foo.someMethod).toHaveBeenCalledTimes(2);\n * expect(foo.otherMethod).toHaveBeenCalledWith(testData);\n * ```\n *\n * 3. Creating a service factory that behaves similarly to the mock as per above.\n *\n * ```ts\n * await startTestBackend({\n * features: [\n * mockServices.foo.factory({\n * someMethod: () => 'mocked result',\n * })\n * ],\n * });\n * ```\n */\nexport namespace mockServices {\n export function rootConfig(\n options?: rootConfig.Options,\n ): RootConfigService & { update(options: { data: JsonObject }): void } {\n const config = ObservableConfigProxy.create(new AbortController());\n config.setConfig(new ConfigReader(options?.data ?? {}, 'mock-config'));\n return Object.assign(config, {\n update({ data }: { data: JsonObject }): void {\n config.setConfig(new ConfigReader(data, 'mock-config'));\n },\n });\n }\n export namespace rootConfig {\n export type Options = { data?: JsonObject };\n\n export const factory = simpleFactoryWithOptions(\n coreServices.rootConfig,\n rootConfig,\n );\n export const mock = simpleMock(coreServices.rootConfig, () => ({\n get: jest.fn(),\n getBoolean: jest.fn(),\n getConfig: jest.fn(),\n getConfigArray: jest.fn(),\n getNumber: jest.fn(),\n getOptional: jest.fn(),\n getOptionalBoolean: jest.fn(),\n getOptionalConfig: jest.fn(),\n getOptionalConfigArray: jest.fn(),\n getOptionalNumber: jest.fn(),\n getOptionalString: jest.fn(),\n getOptionalStringArray: jest.fn(),\n getString: jest.fn(),\n getStringArray: jest.fn(),\n has: jest.fn(),\n keys: jest.fn(),\n }));\n }\n\n export function rootLogger(options?: rootLogger.Options): LoggerService {\n return MockRootLoggerService.create(options);\n }\n export namespace rootLogger {\n export type Options = {\n level?: 'none' | 'error' | 'warn' | 'info' | 'debug';\n };\n\n export const factory = simpleFactoryWithOptions(\n coreServices.rootLogger,\n rootLogger,\n );\n export const mock = simpleMock(coreServices.rootLogger, () => ({\n child: jest.fn(),\n debug: jest.fn(),\n error: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n }));\n }\n\n export namespace auditor {\n export const factory = () => auditorServiceFactory;\n\n export const mock = simpleMock(coreServices.auditor, () => ({\n createEvent: jest.fn(async _ => {\n return {\n success: jest.fn(),\n fail: jest.fn(),\n };\n }),\n }));\n }\n\n export function auth(options?: {\n pluginId?: string;\n disableDefaultAuthPolicy?: boolean;\n }): AuthService {\n return new MockAuthService({\n pluginId: options?.pluginId ?? 'test',\n disableDefaultAuthPolicy: Boolean(options?.disableDefaultAuthPolicy),\n });\n }\n export namespace auth {\n export const factory = () =>\n createServiceFactory({\n service: coreServices.auth,\n deps: {\n plugin: coreServices.pluginMetadata,\n config: coreServices.rootConfig,\n },\n factory({ plugin, config }) {\n const disableDefaultAuthPolicy = Boolean(\n config.getOptionalBoolean(\n 'backend.auth.dangerouslyDisableDefaultAuthPolicy',\n ),\n );\n return new MockAuthService({\n pluginId: plugin.getId(),\n disableDefaultAuthPolicy,\n });\n },\n });\n export const mock = simpleMock(coreServices.auth, () => ({\n authenticate: jest.fn(),\n getNoneCredentials: jest.fn(),\n getOwnServiceCredentials: jest.fn(),\n isPrincipal: jest.fn() as any,\n getPluginRequestToken: jest.fn(),\n getLimitedUserToken: jest.fn(),\n listPublicServiceKeys: jest.fn(),\n }));\n }\n\n export function discovery(): DiscoveryService {\n return HostDiscovery.fromConfig(\n new ConfigReader({\n backend: {\n // Invalid port to make sure that requests are always mocked\n baseUrl: 'http://localhost:0',\n listen: { port: 0 },\n },\n }),\n );\n }\n export namespace discovery {\n export const factory = () =>\n createServiceFactory({\n service: coreServices.discovery,\n deps: {},\n factory: () => discovery(),\n });\n export const mock = simpleMock(coreServices.discovery, () => ({\n getBaseUrl: jest.fn(),\n getExternalBaseUrl: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the `HttpAuthService`.\n *\n * By default all requests without credentials are treated as requests from\n * the default mock user principal. This behavior can be configured with the\n * `defaultCredentials` option.\n */\n export function httpAuth(options?: {\n pluginId?: string;\n /**\n * The default credentials to use if there are no credentials present in the\n * incoming request.\n *\n * By default all requests without credentials are treated as authenticated\n * as the default mock user as returned from `mockCredentials.user()`.\n */\n defaultCredentials?: BackstageCredentials;\n }): HttpAuthService {\n return new MockHttpAuthService(\n options?.pluginId ?? 'test',\n options?.defaultCredentials ?? mockCredentials.user(),\n );\n }\n export namespace httpAuth {\n /**\n * Creates a mock service factory for the `HttpAuthService`.\n *\n * By default all requests without credentials are treated as requests from\n * the default mock user principal. This behavior can be configured with the\n * `defaultCredentials` option.\n */\n export const factory = (options?: {\n defaultCredentials?: BackstageCredentials;\n }) =>\n createServiceFactory({\n service: coreServices.httpAuth,\n deps: { plugin: coreServices.pluginMetadata },\n factory: ({ plugin }) =>\n new MockHttpAuthService(\n plugin.getId(),\n options?.defaultCredentials ?? mockCredentials.user(),\n ),\n });\n export const mock = simpleMock(coreServices.httpAuth, () => ({\n credentials: jest.fn(),\n issueUserCookie: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the `UserInfoService`.\n *\n * By default it extracts the user's entity ref from a user principal and\n * returns that as the only ownership entity ref, but this can be overridden\n * by passing in a custom set of user info.\n */\n export function userInfo(\n customInfo?: Partial<BackstageUserInfo>,\n ): UserInfoService {\n return new MockUserInfoService(customInfo);\n }\n export namespace userInfo {\n /**\n * Creates a mock service factory for the `UserInfoService`.\n *\n * By default it extracts the user's entity ref from a user principal and\n * returns that as the only ownership entity ref.\n */\n export const factory = () =>\n createServiceFactory({\n service: coreServices.userInfo,\n deps: {},\n factory() {\n return new MockUserInfoService();\n },\n });\n export const mock = simpleMock(coreServices.userInfo, () => ({\n getUserInfo: jest.fn(),\n }));\n }\n\n // TODO(Rugvip): Not all core services have implementations available here yet.\n // some may need a bit more refactoring for it to be simpler to\n // re-implement functioning mock versions here.\n export namespace cache {\n export const factory = () => cacheServiceFactory;\n export const mock = simpleMock(coreServices.cache, () => ({\n delete: jest.fn(),\n get: jest.fn(),\n set: jest.fn(),\n withOptions: jest.fn(),\n }));\n }\n\n /**\n * Creates a mock implementation of the\n * {@link @backstage/backend-plugin-api#coreServices.database}. Just returns\n * the given `knex` instance, which is useful in combination with the\n * {@link TestDatabases} facility.\n */\n export function database(options: {\n knex: Knex;\n migrations?: { skip?: boolean };\n }): DatabaseService {\n return {\n getClient: async () => options.knex,\n migrations: options.migrations,\n };\n }\n export namespace database {\n /**\n * Creates a mock factory for the\n * {@link @backstage/backend-plugin-api#coreServices.database}. Just returns\n * the given `knex` instance if you supply one, which is useful in\n * combination with the {@link TestDatabases} facility. Otherwise, it\n * returns the regular default database factory which reads config settings.\n */\n export const factory = (options?: {\n knex: Knex;\n migrations?: { skip?: boolean };\n }) =>\n options\n ? createServiceFactory({\n service: coreServices.database,\n deps: {},\n factory: () => database(options),\n })\n : databaseServiceFactory;\n /**\n * Creates a mock of the\n * {@link @backstage/backend-plugin-api#coreServices.database}, optionally\n * with some given method implementations.\n */\n export const mock = simpleMock(coreServices.database, () => ({\n getClient: jest.fn(),\n }));\n }\n\n export namespace rootHealth {\n export const factory = () => rootHealthServiceFactory;\n export const mock = simpleMock(coreServices.rootHealth, () => ({\n getLiveness: jest.fn(),\n getReadiness: jest.fn(),\n }));\n }\n\n export namespace httpRouter {\n export const factory = () => httpRouterServiceFactory;\n export const mock = simpleMock(coreServices.httpRouter, () => ({\n use: jest.fn(),\n addAuthPolicy: jest.fn(),\n }));\n }\n\n export namespace rootHttpRouter {\n export const factory = () => rootHttpRouterServiceFactory();\n export const mock = simpleMock(coreServices.rootHttpRouter, () => ({\n use: jest.fn(),\n }));\n }\n\n export namespace lifecycle {\n export const factory = () => lifecycleServiceFactory;\n export const mock = simpleMock(coreServices.lifecycle, () => ({\n addShutdownHook: jest.fn(),\n addStartupHook: jest.fn(),\n }));\n }\n\n export namespace logger {\n export const factory = () => loggerServiceFactory;\n export const mock = simpleMock(coreServices.logger, () =>\n createLoggerMock(),\n );\n }\n\n /**\n * Creates a functional mock implementation of the\n * {@link @backstage/backend-plugin-api#PermissionsService}.\n */\n export function permissions(options?: {\n result: AuthorizeResult.ALLOW | AuthorizeResult.DENY;\n }): PermissionsService {\n return new MockPermissionsService(options);\n }\n export namespace permissions {\n /**\n * Creates a mock factory for the\n * {@link @backstage/backend-plugin-api#coreServices.permissions}. Just\n * returns the given `result` if you supply one. Otherwise, it returns the\n * regular default permissions factory.\n */\n export const factory = (options?: {\n result: AuthorizeResult.ALLOW | AuthorizeResult.DENY;\n }) =>\n options?.result\n ? createServiceFactory({\n service: coreServices.permissions,\n deps: {},\n factory: () => new MockPermissionsService(options),\n })\n : permissionsServiceFactory;\n /**\n * Creates a mock of the\n * {@link @backstage/backend-plugin-api#coreServices.permissions},\n * optionally with some given method implementations.\n */\n export const mock = simpleMock(coreServices.permissions, () => ({\n authorize: jest.fn(),\n authorizeConditional: jest.fn(),\n }));\n }\n\n export namespace permissionsRegistry {\n export const factory = () => permissionsRegistryServiceFactory;\n export const mock = simpleMock(coreServices.permissionsRegistry, () => ({\n addPermissionRules: jest.fn(),\n addPermissions: jest.fn(),\n addResourceType: jest.fn(),\n getPermissionRuleset: jest.fn(),\n }));\n }\n\n export namespace rootLifecycle {\n export const factory = () => rootLifecycleServiceFactory;\n export const mock = simpleMock(coreServices.rootLifecycle, () => ({\n addShutdownHook: jest.fn(),\n addBeforeShutdownHook: jest.fn(),\n addStartupHook: jest.fn(),\n }));\n }\n\n export function scheduler(): SchedulerService {\n return new MockSchedulerService();\n }\n export namespace scheduler {\n export const factory = (options?: {\n skipTaskRunOnStartup?: boolean;\n includeManualTasksOnStartup?: boolean;\n includeInitialDelayedTasksOnStartup?: boolean;\n }) => new MockSchedulerService().factory(options);\n export const mock = simpleMock(coreServices.scheduler, () => ({\n createScheduledTaskRunner: jest.fn(),\n getScheduledTasks: jest.fn(),\n scheduleTask: jest.fn(),\n triggerTask: jest.fn(),\n }));\n }\n\n export namespace urlReader {\n export const factory = () => urlReaderServiceFactory;\n export const mock = simpleMock(coreServices.urlReader, () => ({\n readTree: jest.fn(),\n readUrl: jest.fn(),\n search: jest.fn(),\n }));\n }\n\n /**\n * Creates a functional mock implementation of the\n * {@link @backstage/backend-events-node#eventsServiceRef}.\n */\n export function events(): EventsService {\n return new MockEventsService();\n }\n export namespace events {\n /**\n * Creates a functional mock factory for the\n * {@link @backstage/backend-events-node#eventsServiceRef}.\n */\n export const factory = simpleFactoryWithOptions(eventsServiceRef, events);\n /**\n * Creates a mock of the\n * {@link @backstage/backend-events-node#eventsServiceRef}, optionally\n * with some given method implementations.\n */\n export const mock = simpleMock(eventsServiceRef, () => ({\n publish: jest.fn(),\n subscribe: jest.fn(),\n }));\n }\n\n export function rootInstanceMetadata(): RootInstanceMetadataService {\n return {\n getInstalledPlugins: () => Promise.resolve([]),\n };\n }\n export namespace rootInstanceMetadata {\n export const mock = simpleMock(coreServices.rootInstanceMetadata, () => ({\n getInstalledPlugins: jest.fn(),\n }));\n export const factory = simpleFactoryWithOptions(\n coreServices.rootInstanceMetadata,\n rootInstanceMetadata,\n );\n }\n}\n"],"names":["createServiceFactory","mockServices","config","ObservableConfigProxy","ConfigReader","rootConfig","coreServices","simpleMock","MockRootLoggerService","rootLogger","auditor","auditorServiceFactory","MockAuthService","auth","discovery","HostDiscovery","MockHttpAuthService","mockCredentials","httpAuth","MockUserInfoService","userInfo","cache","cacheServiceFactory","database","databaseServiceFactory","rootHealth","rootHealthServiceFactory","httpRouter","httpRouterServiceFactory","rootHttpRouter","rootHttpRouterServiceFactory","lifecycle","lifecycleServiceFactory","logger","loggerServiceFactory","permissions","MockPermissionsService","permissionsServiceFactory","permissionsRegistry","permissionsRegistryServiceFactory","rootLifecycle","rootLifecycleServiceFactory","MockSchedulerService","scheduler","urlReader","urlReaderServiceFactory","MockEventsService","events","eventsServiceRef","rootInstanceMetadata"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAS,gBAAA,GAAmB;AAC1B,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,IAAA,CAAK,EAAA,EAAG,CAAE,mBAAmB,gBAAgB,CAAA;AAAA,IACpD,KAAA,EAAO,KAAK,EAAA,EAAG;AAAA,IACf,KAAA,EAAO,KAAK,EAAA,EAAG;AAAA,IACf,IAAA,EAAM,KAAK,EAAA,EAAG;AAAA,IACd,IAAA,EAAM,KAAK,EAAA;AAAG,GAChB;AACF;AAGA,SAAS,wBAAA,CAKP,KACA,OAAA,EAC4D;AAC5D,EAAA,MAAM,kBAAA,GAAqB,CAAA,GAAI,OAAA,KAC7BA,qCAAA,CAAqB;AAAA,IACnB,OAAA,EAAS,GAAA;AAAA,IACT,MAAM,EAAC;AAAA,IACP,MAAM,OAAA,GAAU;AACd,MAAA,OAAO,OAAA,CAAQ,GAAG,OAAO,CAAA;AA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AAyBC,iCAAA,EAAkBD,OAAM,CAAA;AAMjE,IAAMA,OAAAA,CAAA,IAAA,GAAOxC,qBAAA,CAAWyC,iCAAA,EAAkB,OAAO;AAAA,MACtD,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,SAAA,EAAW,KAAK,EAAA;AAAG,KACrB,CAAE,CAAA;AAAA,EAAA,CAAA,EAda,MAAA,GAAA/C,aAAAA,CAAA,MAAA,KAAAA,aAAAA,CAAA,MAAA,GAAA,EAAA,CAAA,CAAA;AAiBV,EAAA,SAAS,oBAAA,GAAoD;AAClE,IAAA,OAAO;AAAA,MACL,mBAAA,EAAqB,MAAM,OAAA,CAAQ,OAAA,CAAQ,EAAE;AAAA,KAC/C;AAAA,EACF;AAJO,EAAAA,aAAAA,CAAS,oBAAA,GAAA,oBAAA;AAKT,EAAA,CAAA,CAAUgD,qBAAAA,KAAV;AACE,IAAMA,qBAAAA,CAAA,IAAA,GAAO1C,qBAAA,CAAWD,6BAAA,CAAa,sBAAsB,OAAO;AAAA,MACvE,mBAAA,EAAqB,KAAK,EAAA;AAAG,KAC/B,CAAE,CAAA;AACK,IAAM2C,sBAAA,OAAA,GAAU,wBAAA;AAAA,MACrB3C,6BAAA,CAAa,oBAAA;AAAA,MACb2C;AAAA,KACF;AAAA,EAAA,CAAA,EAPe,oBAAA,GAAAhD,aAAAA,CAAA,oBAAA,KAAAA,aAAAA,CAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;AAAA,CAAA,EAxaFA,oBAAA,KAAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-test-utils",
3
- "version": "1.9.1",
3
+ "version": "1.10.0-next.1",
4
4
  "description": "Test helpers library for Backstage backends",
5
5
  "backstage": {
6
6
  "role": "node-library"
@@ -57,15 +57,15 @@
57
57
  "test": "backstage-cli package test"
58
58
  },
59
59
  "dependencies": {
60
- "@backstage/backend-app-api": "^1.2.8",
61
- "@backstage/backend-defaults": "^0.13.0",
62
- "@backstage/backend-plugin-api": "^1.4.4",
63
- "@backstage/config": "^1.3.5",
64
- "@backstage/errors": "^1.2.7",
65
- "@backstage/plugin-auth-node": "^0.6.8",
66
- "@backstage/plugin-events-node": "^0.4.16",
67
- "@backstage/plugin-permission-common": "^0.9.2",
68
- "@backstage/types": "^1.2.2",
60
+ "@backstage/backend-app-api": "1.3.0-next.1",
61
+ "@backstage/backend-defaults": "0.13.1-next.1",
62
+ "@backstage/backend-plugin-api": "1.5.0-next.1",
63
+ "@backstage/config": "1.3.6-next.0",
64
+ "@backstage/errors": "1.2.7",
65
+ "@backstage/plugin-auth-node": "0.6.9-next.1",
66
+ "@backstage/plugin-events-node": "0.4.17-next.1",
67
+ "@backstage/plugin-permission-common": "0.9.3-next.1",
68
+ "@backstage/types": "1.2.2",
69
69
  "@keyv/memcache": "^2.0.1",
70
70
  "@keyv/redis": "^4.0.1",
71
71
  "@keyv/valkey": "^1.0.1",
@@ -91,7 +91,7 @@
91
91
  "zod-to-json-schema": "^3.20.4"
92
92
  },
93
93
  "devDependencies": {
94
- "@backstage/cli": "^0.34.4",
94
+ "@backstage/cli": "0.34.5-next.1",
95
95
  "@types/jest": "*",
96
96
  "@types/lodash": "^4.14.151",
97
97
  "@types/supertest": "^2.0.8",