@backstage/backend-defaults 0.3.0-next.2 → 0.3.0-next.3

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,26 @@
1
1
  # @backstage/backend-defaults
2
2
 
3
+ ## 0.3.0-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 1897169: Exposed `DefaultSchedulerService`
8
+ - 8aab451: Internal minor refactors of the database connectors
9
+ - b2ee7f3: Moved over all URL reader functionality from `@backstage/backend-common` to `@backstage/backend-defaults/urlReader`. Please update your imports.
10
+ - Updated dependencies
11
+ - @backstage/backend-plugin-api@0.6.19-next.3
12
+ - @backstage/integration@1.12.0-next.1
13
+ - @backstage/plugin-permission-node@0.7.30-next.3
14
+ - @backstage/plugin-events-node@0.3.5-next.2
15
+ - @backstage/backend-common@0.23.0-next.3
16
+ - @backstage/backend-app-api@0.7.6-next.3
17
+ - @backstage/config-loader@1.8.1-next.0
18
+ - @backstage/backend-dev-utils@0.1.4
19
+ - @backstage/config@1.2.0
20
+ - @backstage/errors@1.2.4
21
+ - @backstage/integration-aws-node@0.1.12
22
+ - @backstage/types@1.1.1
23
+
3
24
  ## 0.3.0-next.2
4
25
 
5
26
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults",
3
- "version": "0.3.0-next.2",
3
+ "version": "0.3.0-next.3",
4
4
  "main": "../dist/cache.cjs.js",
5
5
  "types": "../dist/cache.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults",
3
- "version": "0.3.0-next.2",
3
+ "version": "0.3.0-next.3",
4
4
  "main": "../dist/database.cjs.js",
5
5
  "types": "../dist/database.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults",
3
- "version": "0.3.0-next.2",
3
+ "version": "0.3.0-next.3",
4
4
  "main": "../dist/discovery.cjs.js",
5
5
  "types": "../dist/discovery.d.ts"
6
6
  }
@@ -9,15 +9,15 @@ var lodash = require('lodash');
9
9
  var limiterFactory = require('p-limit');
10
10
  var yn = require('yn');
11
11
  var backendDevUtils = require('@backstage/backend-dev-utils');
12
- var fsExtra = require('fs-extra');
13
- var path = require('path');
12
+ var fs = require('fs-extra');
13
+ var platformPath = require('path');
14
14
 
15
15
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
16
16
 
17
17
  var knexFactory__default = /*#__PURE__*/_interopDefaultCompat(knexFactory);
18
18
  var limiterFactory__default = /*#__PURE__*/_interopDefaultCompat(limiterFactory);
19
19
  var yn__default = /*#__PURE__*/_interopDefaultCompat(yn);
20
- var path__default = /*#__PURE__*/_interopDefaultCompat(path);
20
+ var platformPath__default = /*#__PURE__*/_interopDefaultCompat(platformPath);
21
21
 
22
22
  const databaseServiceFactory = backendPluginApi.createServiceFactory({
23
23
  service: backendPluginApi.coreServices.database,
@@ -174,45 +174,28 @@ async function dropMysqlDatabase(dbConfig, ...databases) {
174
174
  await admin.destroy();
175
175
  }
176
176
  }
177
- const mysqlConnector = Object.freeze({
178
- createClient: createMysqlDatabaseClient,
179
- ensureDatabaseExists: ensureMysqlDatabaseExists,
180
- createNameOverride: defaultNameOverride,
181
- parseConnectionString: parseMysqlConnectionString,
182
- dropDatabase: dropMysqlDatabase
183
- });
184
177
  function pluginPath$3(pluginId) {
185
178
  return `plugin.${pluginId}`;
186
179
  }
187
- function normalizeConnection$2(connection, client) {
180
+ function normalizeConnection$2(connection) {
188
181
  if (typeof connection === "undefined" || connection === null) {
189
182
  return {};
190
183
  }
191
- return typeof connection === "string" || connection instanceof String ? mysqlConnector.parseConnectionString(connection, client) : connection;
192
- }
193
- function createNameOverride$2(client, name) {
194
- try {
195
- return mysqlConnector.createNameOverride(name);
196
- } catch (e) {
197
- throw new errors.InputError(
198
- `Unable to create database name override for '${client}' connector`,
199
- e
200
- );
201
- }
184
+ return typeof connection === "string" || connection instanceof String ? parseMysqlConnectionString(connection) : connection;
202
185
  }
203
186
  class MysqlConnector {
204
187
  constructor(config, prefix) {
205
188
  this.config = config;
206
189
  this.prefix = prefix;
207
190
  }
208
- async getClient(pluginId, deps) {
191
+ async getClient(pluginId, _deps) {
209
192
  const pluginConfig = new config.ConfigReader(
210
193
  this.getConfigForPlugin(pluginId)
211
194
  );
212
195
  const databaseName = this.getDatabaseName(pluginId);
213
196
  if (databaseName && this.getEnsureExistsConfig(pluginId)) {
214
197
  try {
215
- await mysqlConnector.ensureDatabaseExists(pluginConfig, databaseName);
198
+ await ensureMysqlDatabaseExists(pluginConfig, databaseName);
216
199
  } catch (error) {
217
200
  throw new Error(
218
201
  `Failed to connect to the database to make sure that '${databaseName}' exists, ${error}`
@@ -229,10 +212,9 @@ class MysqlConnector {
229
212
  {},
230
213
  this.getDatabaseOverrides(pluginId)
231
214
  );
232
- const client = mysqlConnector.createClient(
215
+ const client = createMysqlDatabaseClient(
233
216
  pluginConfig,
234
- databaseClientOverrides,
235
- deps
217
+ databaseClientOverrides
236
218
  );
237
219
  return client;
238
220
  }
@@ -309,17 +291,13 @@ class MysqlConnector {
309
291
  * unless `pluginDivisionMode` is set to `schema`.
310
292
  */
311
293
  getConnectionConfig(pluginId) {
312
- const { client, overridden } = this.getClientType(pluginId);
313
- let baseConnection = normalizeConnection$2(
314
- this.config.get("connection"),
315
- this.config.getString("client")
316
- );
294
+ const { overridden } = this.getClientType(pluginId);
295
+ let baseConnection = normalizeConnection$2(this.config.get("connection"));
317
296
  if (this.getPluginDivisionModeConfig() !== "schema") {
318
297
  baseConnection = lodash.omit(baseConnection, "database");
319
298
  }
320
299
  const connection = normalizeConnection$2(
321
- this.config.getOptional(`${pluginPath$3(pluginId)}.connection`),
322
- client
300
+ this.config.getOptional(`${pluginPath$3(pluginId)}.connection`)
323
301
  );
324
302
  return {
325
303
  // include base connection if client type has not been overridden
@@ -353,7 +331,7 @@ class MysqlConnector {
353
331
  */
354
332
  getDatabaseOverrides(pluginId) {
355
333
  const databaseName = this.getDatabaseName(pluginId);
356
- return databaseName ? createNameOverride$2(this.getClientType(pluginId).client, databaseName) : {};
334
+ return databaseName ? defaultNameOverride(databaseName) : {};
357
335
  }
358
336
  }
359
337
 
@@ -475,57 +453,28 @@ async function dropPgDatabase(dbConfig, ...databases) {
475
453
  await admin.destroy();
476
454
  }
477
455
  }
478
- const pgConnector = Object.freeze({
479
- createClient: createPgDatabaseClient,
480
- ensureDatabaseExists: ensurePgDatabaseExists,
481
- ensureSchemaExists: ensurePgSchemaExists,
482
- createNameOverride: defaultNameOverride,
483
- createSchemaOverride: defaultSchemaOverride,
484
- parseConnectionString: parsePgConnectionString,
485
- dropDatabase: dropPgDatabase
486
- });
487
456
  function pluginPath$2(pluginId) {
488
457
  return `plugin.${pluginId}`;
489
458
  }
490
- function normalizeConnection$1(connection, client) {
459
+ function normalizeConnection$1(connection) {
491
460
  if (typeof connection === "undefined" || connection === null) {
492
461
  return {};
493
462
  }
494
- return typeof connection === "string" || connection instanceof String ? pgConnector.parseConnectionString(connection, client) : connection;
495
- }
496
- function createSchemaOverride(client, name) {
497
- try {
498
- return pgConnector.createSchemaOverride?.(name);
499
- } catch (e) {
500
- throw new errors.InputError(
501
- `Unable to create database schema override for '${client}' connector`,
502
- e
503
- );
504
- }
505
- }
506
- function createNameOverride$1(client, name) {
507
- try {
508
- return pgConnector.createNameOverride(name);
509
- } catch (e) {
510
- throw new errors.InputError(
511
- `Unable to create database name override for '${client}' connector`,
512
- e
513
- );
514
- }
463
+ return typeof connection === "string" || connection instanceof String ? parsePgConnectionString(connection) : connection;
515
464
  }
516
465
  class PgConnector {
517
466
  constructor(config, prefix) {
518
467
  this.config = config;
519
468
  this.prefix = prefix;
520
469
  }
521
- async getClient(pluginId, deps) {
470
+ async getClient(pluginId, _deps) {
522
471
  const pluginConfig = new config.ConfigReader(
523
472
  this.getConfigForPlugin(pluginId)
524
473
  );
525
474
  const databaseName = this.getDatabaseName(pluginId);
526
475
  if (databaseName && this.getEnsureExistsConfig(pluginId)) {
527
476
  try {
528
- await pgConnector.ensureDatabaseExists(pluginConfig, databaseName);
477
+ await ensurePgDatabaseExists(pluginConfig, databaseName);
529
478
  } catch (error) {
530
479
  throw new Error(
531
480
  `Failed to connect to the database to make sure that '${databaseName}' exists, ${error}`
@@ -534,10 +483,10 @@ class PgConnector {
534
483
  }
535
484
  let schemaOverrides;
536
485
  if (this.getPluginDivisionModeConfig() === "schema") {
537
- schemaOverrides = this.getSchemaOverrides(pluginId);
486
+ schemaOverrides = defaultSchemaOverride(pluginId);
538
487
  if (this.getEnsureSchemaExistsConfig(pluginId) || this.getEnsureExistsConfig(pluginId)) {
539
488
  try {
540
- await pgConnector.ensureSchemaExists(pluginConfig, pluginId);
489
+ await ensurePgSchemaExists(pluginConfig, pluginId);
541
490
  } catch (error) {
542
491
  throw new Error(
543
492
  `Failed to connect to the database to make sure that schema for plugin '${pluginId}' exists, ${error}`
@@ -550,10 +499,9 @@ class PgConnector {
550
499
  this.getDatabaseOverrides(pluginId),
551
500
  schemaOverrides
552
501
  );
553
- const client = pgConnector.createClient(
502
+ const client = createPgDatabaseClient(
554
503
  pluginConfig,
555
- databaseClientOverrides,
556
- deps
504
+ databaseClientOverrides
557
505
  );
558
506
  return client;
559
507
  }
@@ -640,17 +588,13 @@ class PgConnector {
640
588
  * unless `pluginDivisionMode` is set to `schema`.
641
589
  */
642
590
  getConnectionConfig(pluginId) {
643
- const { client, overridden } = this.getClientType(pluginId);
644
- let baseConnection = normalizeConnection$1(
645
- this.config.get("connection"),
646
- this.config.getString("client")
647
- );
591
+ const { overridden } = this.getClientType(pluginId);
592
+ let baseConnection = normalizeConnection$1(this.config.get("connection"));
648
593
  if (this.getPluginDivisionModeConfig() !== "schema") {
649
594
  baseConnection = lodash.omit(baseConnection, "database");
650
595
  }
651
596
  const connection = normalizeConnection$1(
652
- this.config.getOptional(`${pluginPath$2(pluginId)}.connection`),
653
- client
597
+ this.config.getOptional(`${pluginPath$2(pluginId)}.connection`)
654
598
  );
655
599
  baseConnection.application_name ||= `backstage_plugin_${pluginId}`;
656
600
  return {
@@ -677,16 +621,6 @@ class PgConnector {
677
621
  ...role && { role }
678
622
  };
679
623
  }
680
- /**
681
- * Provides a partial `Knex.Config` database schema override for a given
682
- * plugin.
683
- *
684
- * @param pluginId - Target plugin to get database schema override
685
- * @returns Partial `Knex.Config` with database schema override
686
- */
687
- getSchemaOverrides(pluginId) {
688
- return createSchemaOverride(this.getClientType(pluginId).client, pluginId);
689
- }
690
624
  /**
691
625
  * Provides a partial `Knex.Config`• database name override for a given plugin.
692
626
  *
@@ -695,7 +629,7 @@ class PgConnector {
695
629
  */
696
630
  getDatabaseOverrides(pluginId) {
697
631
  const databaseName = this.getDatabaseName(pluginId);
698
- return databaseName ? createNameOverride$1(this.getClientType(pluginId).client, databaseName) : {};
632
+ return databaseName ? defaultNameOverride(databaseName) : {};
699
633
  }
700
634
  }
701
635
 
@@ -704,8 +638,8 @@ function createSqliteDatabaseClient(dbConfig, overrides, deps) {
704
638
  const connConfig = knexConfig.connection;
705
639
  const filename = connConfig.filename ?? ":memory:";
706
640
  if (filename !== ":memory:") {
707
- const directory = path__default.default.dirname(filename);
708
- fsExtra.ensureDirSync(directory);
641
+ const directory = platformPath__default.default.dirname(filename);
642
+ fs.ensureDirSync(directory);
709
643
  }
710
644
  let database;
711
645
  if (deps && filename === ":memory:") {
@@ -773,29 +707,14 @@ function parseSqliteConnectionString(name) {
773
707
  filename: name
774
708
  };
775
709
  }
776
- const sqliteConnector = Object.freeze({
777
- createClient: createSqliteDatabaseClient,
778
- createNameOverride: createSqliteNameOverride,
779
- parseConnectionString: parseSqliteConnectionString
780
- });
781
710
  function pluginPath$1(pluginId) {
782
711
  return `plugin.${pluginId}`;
783
712
  }
784
- function normalizeConnection(connection, client) {
713
+ function normalizeConnection(connection) {
785
714
  if (typeof connection === "undefined" || connection === null) {
786
715
  return {};
787
716
  }
788
- return typeof connection === "string" || connection instanceof String ? sqliteConnector.parseConnectionString(connection, client) : connection;
789
- }
790
- function createNameOverride(client, name) {
791
- try {
792
- return sqliteConnector.createNameOverride(name);
793
- } catch (e) {
794
- throw new errors.InputError(
795
- `Unable to create database name override for '${client}' connector`,
796
- e
797
- );
798
- }
717
+ return typeof connection === "string" || connection instanceof String ? parseSqliteConnectionString(connection) : connection;
799
718
  }
800
719
  class Sqlite3Connector {
801
720
  constructor(config) {
@@ -815,7 +734,7 @@ class Sqlite3Connector {
815
734
  {},
816
735
  this.getDatabaseOverrides(pluginId)
817
736
  );
818
- const client = sqliteConnector.createClient(
737
+ const client = createSqliteDatabaseClient(
819
738
  pluginConfig,
820
739
  databaseClientOverrides,
821
740
  deps
@@ -843,7 +762,7 @@ class Sqlite3Connector {
843
762
  return sqliteFilename;
844
763
  }
845
764
  const sqliteDirectory = connection.directory ?? ".";
846
- return path__default.default.join(sqliteDirectory, sqliteFilename ?? `${pluginId}.sqlite`);
765
+ return platformPath__default.default.join(sqliteDirectory, sqliteFilename ?? `${pluginId}.sqlite`);
847
766
  }
848
767
  /**
849
768
  * Provides the client type which should be used for a given plugin.
@@ -897,10 +816,7 @@ class Sqlite3Connector {
897
816
  */
898
817
  getConnectionConfig(pluginId) {
899
818
  const { client, overridden } = this.getClientType(pluginId);
900
- let baseConnection = normalizeConnection(
901
- this.config.get("connection"),
902
- this.config.getString("client")
903
- );
819
+ let baseConnection = normalizeConnection(this.config.get("connection"));
904
820
  if (client.includes("sqlite3") && "filename" in baseConnection && baseConnection.filename !== ":memory:") {
905
821
  throw new Error(
906
822
  "`connection.filename` is not supported for the base sqlite connection. Prefer `connection.directory` or provide a filename for the plugin connection instead."
@@ -910,8 +826,7 @@ class Sqlite3Connector {
910
826
  baseConnection = lodash.omit(baseConnection, "database");
911
827
  }
912
828
  const connection = normalizeConnection(
913
- this.config.getOptional(`${pluginPath$1(pluginId)}.connection`),
914
- client
829
+ this.config.getOptional(`${pluginPath$1(pluginId)}.connection`)
915
830
  );
916
831
  return {
917
832
  // include base connection if client type has not been overridden
@@ -945,7 +860,7 @@ class Sqlite3Connector {
945
860
  */
946
861
  getDatabaseOverrides(pluginId) {
947
862
  const databaseName = this.getDatabaseName(pluginId);
948
- return databaseName ? createNameOverride(this.getClientType(pluginId).client, databaseName) : {};
863
+ return databaseName ? createSqliteNameOverride(databaseName) : {};
949
864
  }
950
865
  }
951
866