@backstage/config-loader 1.10.0 → 1.10.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 +22 -0
- package/dist/index.d.ts +1 -1
- package/dist/sources/RemoteConfigSource.cjs.js.map +1 -1
- package/package.json +10 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @backstage/config-loader
|
|
2
2
|
|
|
3
|
+
## 1.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 72d019d: Removed various typos
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/config@1.3.2
|
|
10
|
+
- @backstage/cli-common@0.1.15
|
|
11
|
+
- @backstage/errors@1.2.7
|
|
12
|
+
- @backstage/types@1.2.1
|
|
13
|
+
|
|
14
|
+
## 1.10.1-next.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 72d019d: Removed various typos
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/cli-common@0.1.15
|
|
21
|
+
- @backstage/config@1.3.2
|
|
22
|
+
- @backstage/errors@1.2.7
|
|
23
|
+
- @backstage/types@1.2.1
|
|
24
|
+
|
|
3
25
|
## 1.10.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -232,7 +232,7 @@ interface ConfigSource {
|
|
|
232
232
|
readConfigData(options?: ReadConfigDataOptions): AsyncConfigSourceGenerator;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
|
-
* A custom function to be used for substitution
|
|
235
|
+
* A custom function to be used for substitution within configuration files.
|
|
236
236
|
*
|
|
237
237
|
* @remarks
|
|
238
238
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteConfigSource.cjs.js","sources":["../../src/sources/RemoteConfigSource.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 { ResponseError } from '@backstage/errors';\nimport {\n HumanDuration,\n JsonObject,\n durationToMilliseconds,\n} from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\nimport { ConfigTransformer, createConfigTransformer } from './transform';\nimport {\n AsyncConfigSourceGenerator,\n ConfigSource,\n SubstitutionFunc,\n ReadConfigDataOptions,\n Parser,\n} from './types';\nimport { parseYamlContent } from './utils';\n\nconst DEFAULT_RELOAD_INTERVAL = { seconds: 60 };\n\n/**\n * Options for {@link RemoteConfigSource.create}.\n *\n * @public\n */\nexport interface RemoteConfigSourceOptions {\n /**\n * The URL to load the config from.\n */\n url: string;\n\n /**\n * How often to reload the config from the remote URL, defaults to 1 minute.\n *\n * Set to Infinity to disable reloading, for example `{ days: Infinity }`.\n */\n reloadInterval?: HumanDuration;\n\n /**\n * A substitution function to use instead of the default environment substitution.\n */\n substitutionFunc?: SubstitutionFunc;\n\n /**\n * A content parsing function to transform string content to configuration values.\n */\n parser?: Parser;\n}\n\n/**\n * A config source that loads configuration from a remote URL.\n *\n * @public\n */\nexport class RemoteConfigSource implements ConfigSource {\n /**\n * Creates a new {@link RemoteConfigSource}.\n *\n * @param options - Options for the source.\n * @returns A new remote config source.\n */\n static create(options: RemoteConfigSourceOptions): ConfigSource {\n try {\n // eslint-disable-next-line no-new\n new URL(options.url);\n } catch (error) {\n throw new Error(\n `Invalid URL provided to remote config source, '${options.url}', ${error}`,\n );\n }\n return new RemoteConfigSource(options);\n }\n\n readonly #url: string;\n readonly #reloadIntervalMs: number;\n readonly #transformer: ConfigTransformer;\n readonly #parser: Parser;\n\n private constructor(options: RemoteConfigSourceOptions) {\n this.#url = options.url;\n this.#reloadIntervalMs = durationToMilliseconds(\n options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL,\n );\n this.#transformer = createConfigTransformer({\n substitutionFunc: options.substitutionFunc,\n });\n this.#parser = options.parser ?? parseYamlContent;\n }\n\n async *readConfigData(\n options?: ReadConfigDataOptions | undefined,\n ): AsyncConfigSourceGenerator {\n let data = await this.#load();\n\n yield { configs: [{ data, context: this.#url }] };\n\n for (;;) {\n await this.#wait(options?.signal);\n\n if (options?.signal?.aborted) {\n return;\n }\n\n try {\n const newData = await this.#load(options?.signal);\n if (newData && !isEqual(data, newData)) {\n data = newData;\n yield { configs: [{ data, context: this.#url }] };\n }\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.error(`Failed to read config from ${this.#url}, ${error}`);\n }\n }\n }\n }\n\n toString() {\n return `RemoteConfigSource{path=\"${this.#url}\"}`;\n }\n\n async #load(signal?: AbortSignal): Promise<JsonObject> {\n const res = await fetch(this.#url, {\n signal: signal as RequestInit['signal'],\n });\n if (!res.ok) {\n throw await ResponseError.fromResponse(res);\n }\n\n const contents = await res.text();\n const { result: rawData } = await this.#parser({ contents });\n if (rawData === undefined) {\n /**\n * This error message is/was coupled to the implementation and with refactoring it is no longer truly accurate\n * This behavior is also inconsistent with {@link FileConfigSource}, which doesn't error on
|
|
1
|
+
{"version":3,"file":"RemoteConfigSource.cjs.js","sources":["../../src/sources/RemoteConfigSource.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 { ResponseError } from '@backstage/errors';\nimport {\n HumanDuration,\n JsonObject,\n durationToMilliseconds,\n} from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\nimport { ConfigTransformer, createConfigTransformer } from './transform';\nimport {\n AsyncConfigSourceGenerator,\n ConfigSource,\n SubstitutionFunc,\n ReadConfigDataOptions,\n Parser,\n} from './types';\nimport { parseYamlContent } from './utils';\n\nconst DEFAULT_RELOAD_INTERVAL = { seconds: 60 };\n\n/**\n * Options for {@link RemoteConfigSource.create}.\n *\n * @public\n */\nexport interface RemoteConfigSourceOptions {\n /**\n * The URL to load the config from.\n */\n url: string;\n\n /**\n * How often to reload the config from the remote URL, defaults to 1 minute.\n *\n * Set to Infinity to disable reloading, for example `{ days: Infinity }`.\n */\n reloadInterval?: HumanDuration;\n\n /**\n * A substitution function to use instead of the default environment substitution.\n */\n substitutionFunc?: SubstitutionFunc;\n\n /**\n * A content parsing function to transform string content to configuration values.\n */\n parser?: Parser;\n}\n\n/**\n * A config source that loads configuration from a remote URL.\n *\n * @public\n */\nexport class RemoteConfigSource implements ConfigSource {\n /**\n * Creates a new {@link RemoteConfigSource}.\n *\n * @param options - Options for the source.\n * @returns A new remote config source.\n */\n static create(options: RemoteConfigSourceOptions): ConfigSource {\n try {\n // eslint-disable-next-line no-new\n new URL(options.url);\n } catch (error) {\n throw new Error(\n `Invalid URL provided to remote config source, '${options.url}', ${error}`,\n );\n }\n return new RemoteConfigSource(options);\n }\n\n readonly #url: string;\n readonly #reloadIntervalMs: number;\n readonly #transformer: ConfigTransformer;\n readonly #parser: Parser;\n\n private constructor(options: RemoteConfigSourceOptions) {\n this.#url = options.url;\n this.#reloadIntervalMs = durationToMilliseconds(\n options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL,\n );\n this.#transformer = createConfigTransformer({\n substitutionFunc: options.substitutionFunc,\n });\n this.#parser = options.parser ?? parseYamlContent;\n }\n\n async *readConfigData(\n options?: ReadConfigDataOptions | undefined,\n ): AsyncConfigSourceGenerator {\n let data = await this.#load();\n\n yield { configs: [{ data, context: this.#url }] };\n\n for (;;) {\n await this.#wait(options?.signal);\n\n if (options?.signal?.aborted) {\n return;\n }\n\n try {\n const newData = await this.#load(options?.signal);\n if (newData && !isEqual(data, newData)) {\n data = newData;\n yield { configs: [{ data, context: this.#url }] };\n }\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.error(`Failed to read config from ${this.#url}, ${error}`);\n }\n }\n }\n }\n\n toString() {\n return `RemoteConfigSource{path=\"${this.#url}\"}`;\n }\n\n async #load(signal?: AbortSignal): Promise<JsonObject> {\n const res = await fetch(this.#url, {\n signal: signal as RequestInit['signal'],\n });\n if (!res.ok) {\n throw await ResponseError.fromResponse(res);\n }\n\n const contents = await res.text();\n const { result: rawData } = await this.#parser({ contents });\n if (rawData === undefined) {\n /**\n * This error message is/was coupled to the implementation and with refactoring it is no longer truly accurate\n * This behavior is also inconsistent with {@link FileConfigSource}, which doesn't error on unparsable or empty\n * content\n *\n * Preserving to not make a breaking change\n */\n throw new Error('configuration data is null');\n }\n\n const data = await this.#transformer(rawData);\n if (typeof data !== 'object') {\n throw new Error('configuration data is not an object');\n } else if (Array.isArray(data)) {\n throw new Error(\n 'configuration data is an array, expected an object instead',\n );\n }\n return data;\n }\n\n async #wait(signal?: AbortSignal) {\n return new Promise<void>(resolve => {\n const timeoutId = setTimeout(onDone, this.#reloadIntervalMs);\n signal?.addEventListener('abort', onDone);\n\n function onDone() {\n clearTimeout(timeoutId);\n signal?.removeEventListener('abort', onDone);\n resolve();\n }\n });\n }\n}\n"],"names":["durationToMilliseconds","createConfigTransformer","parseYamlContent","isEqual","ResponseError"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,uBAAA,GAA0B,EAAE,OAAA,EAAS,EAAG,EAAA;AAoCvC,MAAM,kBAA2C,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtD,OAAO,OAAO,OAAkD,EAAA;AAC9D,IAAI,IAAA;AAEF,MAAI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B,EAAA;AAChC,IAAO,OAAA,IAAI,QAAc,CAAW,OAAA,KAAA;AAClC,MAAA,MAAM,SAAY,GAAA,UAAA,CAAW,MAAQ,EAAA,IAAA,CAAK,iBAAiB,CAAA;AAC3D,MAAQ,MAAA,EAAA,gBAAA,CAAiB,SAAS,MAAM,CAAA;AAExC,MAAA,SAAS,MAAS,GAAA;AAChB,QAAA,YAAA,CAAa,SAAS,CAAA;AACtB,QAAQ,MAAA,EAAA,mBAAA,CAAoB,SAAS,MAAM,CAAA;AAC3C,QAAQ,OAAA,EAAA;AAAA;AACV,KACD,CAAA;AAAA;AAEL;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/config-loader",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Config loading functionality used by Backstage backend, and CLI",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -53,12 +53,19 @@
|
|
|
53
53
|
"yaml": "^2.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@backstage/backend-test-utils": "^1.
|
|
57
|
-
"@backstage/cli": "^0.
|
|
56
|
+
"@backstage/backend-test-utils": "^1.5.0",
|
|
57
|
+
"@backstage/cli": "^0.32.1",
|
|
58
58
|
"@types/json-schema-merge-allof": "^0.6.0",
|
|
59
59
|
"@types/minimist": "^1.2.5",
|
|
60
60
|
"msw": "^1.0.0",
|
|
61
61
|
"zen-observable": "^0.10.0"
|
|
62
62
|
},
|
|
63
|
+
"typesVersions": {
|
|
64
|
+
"*": {
|
|
65
|
+
"package.json": [
|
|
66
|
+
"package.json"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
63
70
|
"module": "dist/index.esm.js"
|
|
64
71
|
}
|