@backstage/plugin-scaffolder-backend-module-workspace-database 0.1.0-next.1 → 0.1.1-next.0

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,29 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-workspace-database
2
2
 
3
+ ## 0.1.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.13.8-next.0
9
+ - @backstage/backend-plugin-api@1.10.2-next.0
10
+
11
+ ## 0.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - e95b649: Added task recovery feature with new `scaffolder.taskRecovery` config section. When enabled, tasks that crash or timeout are automatically recovered and resume from the last completed step, task secrets are retained until the task reaches a terminal state so recovery can continue, and completed step outputs are persisted. Enabling recovery applies to all scaffolder tasks, so actions used by those tasks should be idempotent or use checkpoints. When recovery is disabled (the default), the previous behavior is unchanged: secrets are cleared as soon as a task is claimed and retries re-run every step. The new config consolidates previous experimental flags (`EXPERIMENTAL_recoverTasks`, `EXPERIMENTAL_workspaceSerialization`, `EXPERIMENTAL_recoverTasksTimeout`) which remain supported as fallbacks. The legacy workspace provider setting continues to select a provider only when `EXPERIMENTAL_workspaceSerialization` is `true`.
16
+
17
+ Workspace serialization for task recovery now requires installing a separate workspace provider module, including when you use the legacy configuration. For development, use `@backstage/plugin-scaffolder-backend-module-workspace-database` (50 MB limit, not recommended for production). On first startup, that module migrates existing database workspace snapshots from the legacy task storage. For production, use `@backstage/plugin-scaffolder-backend-module-gcp` or a similar external storage provider. The scaffolder rejects a configured provider that has not been installed and registered.
18
+
19
+ Enabling crash recovery does not keep completed task event streams open; normal task completion remains terminal for event-stream clients.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+ - @backstage/plugin-scaffolder-node@0.13.7
25
+ - @backstage/backend-plugin-api@1.10.1
26
+
3
27
  ## 0.1.0-next.1
4
28
 
5
29
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderWorkspaceProviderExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { DatabaseWorkspaceProvider } from './provider';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-scaffolder-backend-module-workspace-database',\n 'migrations',\n);\nconst migrationsTable = 'scaffolder_workspace_database_migrations';\n\n/**\n * @public\n * Database workspace provider module for the Scaffolder Backend.\n *\n * This module is intended for development use only. In production,\n * use an external storage provider like GCS.\n */\nexport const workspaceDatabaseModule = createBackendModule({\n moduleId: 'workspace-database',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolderWorkspaceProviders: scaffolderWorkspaceProviderExtensionPoint,\n database: coreServices.database,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n },\n async init({ database, logger, scaffolderWorkspaceProviders, config }) {\n if (\n process.env.NODE_ENV === 'production' &&\n !config.getOptionalBoolean(\n 'scaffolder.taskRecovery.database.dangerouslyEnableInProduction',\n )\n ) {\n logger.warn(\n 'Database workspace provider is not supported in production and will not be enabled',\n );\n return;\n }\n\n const db = await database.getClient();\n\n // Run migrations for our table\n if (!database.migrations?.skip) {\n await db.migrate.latest({\n directory: migrationsDir,\n tableName: migrationsTable,\n });\n }\n\n scaffolderWorkspaceProviders.addProviders({\n database: DatabaseWorkspaceProvider.create({ db }),\n });\n },\n });\n },\n});\n"],"names":["resolvePackagePath","createBackendModule","scaffolderWorkspaceProviderExtensionPoint","coreServices","DatabaseWorkspaceProvider"],"mappings":";;;;;;AAwBA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,gEAAA;AAAA,EACA;AACF,CAAA;AACA,MAAM,eAAA,GAAkB,0CAAA;AASjB,MAAM,0BAA0BC,oCAAA,CAAoB;AAAA,EACzD,QAAA,EAAU,oBAAA;AAAA,EACV,QAAA,EAAU,YAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAa,EAAG;AACzB,IAAA,YAAA,CAAa;AAAA,MACX,IAAA,EAAM;AAAA,QACJ,4BAAA,EAA8BC,+CAAA;AAAA,QAC9B,UAAUC,6BAAA,CAAa,QAAA;AAAA,QACvB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa;AAAA,OACvB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAU,MAAA,EAAQ,4BAAA,EAA8B,QAAO,EAAG;AACrE,QAAA,IACE,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,IACzB,CAAC,MAAA,CAAO,kBAAA;AAAA,UACN;AAAA,SACF,EACA;AACA,UAAA,MAAA,CAAO,IAAA;AAAA,YACL;AAAA,WACF;AACA,UAAA;AAAA,QACF;AAEA,QAAA,MAAM,EAAA,GAAK,MAAM,QAAA,CAAS,SAAA,EAAU;AAGpC,QAAA,IAAI,CAAC,QAAA,CAAS,UAAA,EAAY,IAAA,EAAM;AAC9B,UAAA,MAAM,EAAA,CAAG,QAAQ,MAAA,CAAO;AAAA,YACtB,SAAA,EAAW,aAAA;AAAA,YACX,SAAA,EAAW;AAAA,WACZ,CAAA;AAAA,QACH;AAEA,QAAA,4BAAA,CAA6B,YAAA,CAAa;AAAA,UACxC,QAAA,EAAUC,mDAAA,CAA0B,MAAA,CAAO,EAAE,IAAI;AAAA,SAClD,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderWorkspaceProviderExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { DatabaseWorkspaceProvider } from './provider';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-scaffolder-backend-module-workspace-database',\n 'migrations',\n);\nconst migrationsTable = 'scaffolder_workspace_database_migrations';\n\n/**\n * @public\n * Database workspace provider module for the Scaffolder Backend.\n *\n * This module is intended for development use only. In production,\n * use an external storage provider like GCS.\n */\nexport const workspaceDatabaseModule = createBackendModule({\n moduleId: 'workspace-database',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolderWorkspaceProviders: scaffolderWorkspaceProviderExtensionPoint,\n database: coreServices.database,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n },\n async init({ database, logger, scaffolderWorkspaceProviders, config }) {\n if (\n process.env.NODE_ENV === 'production' &&\n !config.getOptionalBoolean(\n 'scaffolder.taskRecovery.database.dangerouslyEnableInProduction',\n )\n ) {\n logger.warn(\n 'Database workspace provider is not supported in production and will not be enabled',\n );\n return;\n }\n\n const db = await database.getClient();\n\n // Run migrations for our table\n if (!database.migrations?.skip) {\n await db.migrate.latest({\n directory: migrationsDir,\n tableName: migrationsTable,\n });\n }\n\n scaffolderWorkspaceProviders.addProviders({\n database: DatabaseWorkspaceProvider.create({ db }),\n });\n },\n });\n },\n});\n"],"names":["resolvePackagePath","createBackendModule","scaffolderWorkspaceProviderExtensionPoint","coreServices","DatabaseWorkspaceProvider"],"mappings":";;;;;;AAwBA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,gEAAA;AAAA,EACA;AACF,CAAA;AACA,MAAM,eAAA,GAAkB,0CAAA;AASjB,MAAM,0BAA0BC,oCAAA,CAAoB;AAAA,EACzD,QAAA,EAAU,oBAAA;AAAA,EACV,QAAA,EAAU,YAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAa,EAAG;AACzB,IAAA,YAAA,CAAa;AAAA,MACX,IAAA,EAAM;AAAA,QACJ,4BAAA,EAA8BC,+CAAA;AAAA,QAC9B,UAAUC,6BAAA,CAAa,QAAA;AAAA,QACvB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa;AAAA,OACvB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAU,MAAA,EAAQ,4BAAA,EAA8B,QAAO,EAAG;AACrE,QAAA,IACE,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,IACzB,CAAC,MAAA,CAAO,kBAAA;AAAA,UACN;AAAA,SACF,EACA;AACA,UAAA,MAAA,CAAO,IAAA;AAAA,YACL;AAAA,WACF;AACA,UAAA;AAAA,QACF;AAEA,QAAA,MAAM,EAAA,GAAK,MAAM,QAAA,CAAS,SAAA,EAAU;AAGpC,QAAA,IAAI,CAAC,QAAA,CAAS,UAAA,EAAY,IAAA,EAAM;AAC9B,UAAA,MAAM,EAAA,CAAG,QAAQ,MAAA,CAAO;AAAA,YACtB,SAAA,EAAW,aAAA;AAAA,YACX,SAAA,EAAW;AAAA,WACZ,CAAA;AAAA,QACH;AAEA,QAAA,4BAAA,CAA6B,YAAA,CAAa;AAAA,UACxC,QAAA,EAAUC,mDAAA,CAA0B,MAAA,CAAO,EAAE,IAAI;AAAA,SAClD,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseWorkspaceProvider.cjs.js","sources":["../../src/provider/DatabaseWorkspaceProvider.ts"],"sourcesContent":["/*\n * Copyright 2026 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 {\n WorkspaceProvider,\n serializeWorkspace,\n restoreWorkspace,\n} from '@backstage/plugin-scaffolder-node/alpha';\n\nconst MAX_WORKSPACE_SIZE_BYTES = 50 * 1024 * 1024; // 50MB\n\ntype RawDbTaskWorkspaceRow = {\n task_id: string;\n workspace: Buffer;\n created_at: Date;\n};\n\n/**\n * A workspace provider that stores serialized workspaces in the database.\n *\n * @remarks\n * This provider is intended for development use only. It has a 50MB size limit\n * and is disabled in production unless explicitly enabled via config.\n *\n * For production use, consider using an external storage provider like GCS.\n */\nexport class DatabaseWorkspaceProvider implements WorkspaceProvider {\n private readonly db: Knex;\n private legacyWorkspaceColumn?: Promise<boolean>;\n\n static create(options: { db: Knex }) {\n return new DatabaseWorkspaceProvider(options.db);\n }\n\n private constructor(db: Knex) {\n this.db = db;\n }\n\n private hasLegacyWorkspaceColumn(): Promise<boolean> {\n this.legacyWorkspaceColumn ??= this.db.schema.hasColumn(\n 'tasks',\n 'workspace',\n );\n return this.legacyWorkspaceColumn;\n }\n\n public async serializeWorkspace(options: {\n path: string;\n taskId: string;\n }): Promise<void> {\n const { contents: workspace } = await serializeWorkspace({\n path: options.path,\n });\n\n if (workspace.length > MAX_WORKSPACE_SIZE_BYTES) {\n throw new Error(\n `Workspace size (${Math.round(\n workspace.length / 1024 / 1024,\n )}MB) exceeds ` +\n `maximum allowed size of 50MB for database storage. ` +\n `Consider using an external storage provider like GCS.`,\n );\n }\n\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({\n task_id: options.taskId,\n workspace,\n })\n .onConflict('task_id')\n .merge(['workspace']);\n\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .whereNotNull('workspace')\n .update({ workspace });\n }\n });\n }\n\n public async rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void> {\n let workspace: Buffer | undefined;\n if (await this.hasLegacyWorkspaceColumn()) {\n const legacyRow = await this.db('tasks')\n .where({ id: options.taskId })\n .select('workspace')\n .first();\n workspace = legacyRow?.workspace ?? undefined;\n }\n\n if (workspace) {\n await this.db<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({ task_id: options.taskId, workspace })\n .onConflict('task_id')\n .merge(['workspace']);\n } else {\n const row = await this.db<RawDbTaskWorkspaceRow>(\n 'scaffolder_task_workspaces',\n )\n .where({ task_id: options.taskId })\n .first();\n workspace = row?.workspace;\n }\n\n if (workspace) {\n await restoreWorkspace({\n path: options.targetPath,\n buffer: workspace,\n });\n }\n }\n\n public async cleanWorkspace(options: { taskId: string }): Promise<void> {\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .where({ task_id: options.taskId })\n .delete();\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .update({ workspace: null });\n }\n });\n }\n}\n"],"names":["serializeWorkspace","restoreWorkspace"],"mappings":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M,IAAA,CAAK,wBAAA,EAAyB;AACrE,IAAA,MAAM,IAAA,CAAK,EAAA,CAAG,WAAA,CAAY,OAAM,EAAA,KAAM;AACpC,MAAA,MAAM,EAAA,CAA0B,4BAA4B,CAAA,CACzD,KAAA,CAAM,EAAE,SAAS,OAAA,CAAQ,MAAA,EAAQ,CAAA,CACjC,MAAA,EAAO;AACV,MAAA,IAAI,wBAAA,EAA0B;AAC5B,QAAA,MAAM,EAAA,CAAG,OAAO,CAAA,CACb,KAAA,CAAM,EAAE,EAAA,EAAI,OAAA,CAAQ,MAAA,EAAQ,CAAA,CAC5B,MAAA,CAAO,EAAE,SAAA,EAAW,MAAM,CAAA;AAAA,MAC/B;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF;;;;"}
1
+ {"version":3,"file":"DatabaseWorkspaceProvider.cjs.js","sources":["../../src/provider/DatabaseWorkspaceProvider.ts"],"sourcesContent":["/*\n * Copyright 2026 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 {\n WorkspaceProvider,\n serializeWorkspace,\n restoreWorkspace,\n} from '@backstage/plugin-scaffolder-node/alpha';\n\nconst MAX_WORKSPACE_SIZE_BYTES = 50 * 1024 * 1024; // 50MB\n\ntype RawDbTaskWorkspaceRow = {\n task_id: string;\n workspace: Buffer;\n created_at: Date;\n};\n\n/**\n * A workspace provider that stores serialized workspaces in the database.\n *\n * @remarks\n * This provider is intended for development use only. It has a 50MB size limit\n * and is disabled in production unless explicitly enabled via config.\n *\n * For production use, consider using an external storage provider like GCS.\n */\nexport class DatabaseWorkspaceProvider implements WorkspaceProvider {\n private readonly db: Knex;\n private legacyWorkspaceColumn?: Promise<boolean>;\n\n static create(options: { db: Knex }) {\n return new DatabaseWorkspaceProvider(options.db);\n }\n\n private constructor(db: Knex) {\n this.db = db;\n }\n\n private hasLegacyWorkspaceColumn(): Promise<boolean> {\n this.legacyWorkspaceColumn ??= this.db.schema.hasColumn(\n 'tasks',\n 'workspace',\n );\n return this.legacyWorkspaceColumn;\n }\n\n public async serializeWorkspace(options: {\n path: string;\n taskId: string;\n }): Promise<void> {\n const { contents: workspace } = await serializeWorkspace({\n path: options.path,\n });\n\n if (workspace.length > MAX_WORKSPACE_SIZE_BYTES) {\n throw new Error(\n `Workspace size (${Math.round(\n workspace.length / 1024 / 1024,\n )}MB) exceeds ` +\n `maximum allowed size of 50MB for database storage. ` +\n `Consider using an external storage provider like GCS.`,\n );\n }\n\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({\n task_id: options.taskId,\n workspace,\n })\n .onConflict('task_id')\n .merge(['workspace']);\n\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .whereNotNull('workspace')\n .update({ workspace });\n }\n });\n }\n\n public async rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void> {\n let workspace: Buffer | undefined;\n if (await this.hasLegacyWorkspaceColumn()) {\n const legacyRow = await this.db('tasks')\n .where({ id: options.taskId })\n .select('workspace')\n .first();\n workspace = legacyRow?.workspace ?? undefined;\n }\n\n if (workspace) {\n await this.db<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({ task_id: options.taskId, workspace })\n .onConflict('task_id')\n .merge(['workspace']);\n } else {\n const row = await this.db<RawDbTaskWorkspaceRow>(\n 'scaffolder_task_workspaces',\n )\n .where({ task_id: options.taskId })\n .first();\n workspace = row?.workspace;\n }\n\n if (workspace) {\n await restoreWorkspace({\n path: options.targetPath,\n buffer: workspace,\n });\n }\n }\n\n public async cleanWorkspace(options: { taskId: string }): Promise<void> {\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .where({ task_id: options.taskId })\n .delete();\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .update({ workspace: null });\n }\n });\n }\n}\n"],"names":["serializeWorkspace","restoreWorkspace"],"mappings":";;;;AAuBA,MAAM,wBAAA,GAA2B,KAAK,IAAA,GAAO,IAAA;AAiBtC,MAAM,yBAAA,CAAuD;AAAA,EACjD,EAAA;AAAA,EACT,qBAAA;AAAA,EAER,OAAO,OAAO,OAAA,EAAuB;AACnC,IAAA,OAAO,IAAI,yBAAA,CAA0B,OAAA,CAAQ,EAAE,CAAA;AAAA,EACjD;AAAA,EAEQ,YAAY,EAAA,EAAU;AAC5B,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AAAA,EACZ;AAAA,EAEQ,wBAAA,GAA6C;AACnD,IAAA,IAAA,CAAK,qBAAA,KAA0B,IAAA,CAAK,EAAA,CAAG,MAAA,CAAO,SAAA;AAAA,MAC5C,OAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,IAAA,CAAK,qBAAA;AAAA,EACd;AAAA,EAEA,MAAa,mBAAmB,OAAA,EAGd;AAChB,IAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAU,GAAI,MAAMA,wBAAA,CAAmB;AAAA,MACvD,MAAM,OAAA,CAAQ;AAAA,KACf,CAAA;AAED,IAAA,IAAI,SAAA,CAAU,SAAS,wBAAA,EAA0B;AAC/C,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,mBAAmB,IAAA,CAAK,KAAA;AAAA,UACtB,SAAA,CAAU,SAAS,IAAA,GAAO;AAAA,SAC3B,CAAA,oHAAA;AAAA,OAGH;AAAA,IACF;AAEA,IAAA,MA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S,QAAQ,MAAA,EAAQ,EACjC,KAAA,EAAM;AACT,MAAA,SAAA,GAAY,GAAA,EAAK,SAAA;AAAA,IACnB;AAEA,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,MAAMC,sBAAA,CAAiB;AAAA,QACrB,MAAM,OAAA,CAAQ,UAAA;AAAA,QACd,MAAA,EAAQ;AAAA,OACT,CAAA;AAAA,IACH;AAAA,EACF;AAAA,EAEA,MAAa,eAAe,OAAA,EAA4C;AACtE,IAAA,MAAM,wBAAA,GAA2B,MAAM,IAAA,CAAK,wBAAA,EAAyB;AACrE,IAAA,MAAM,IAAA,CAAK,EAAA,CAAG,WAAA,CAAY,OAAM,EAAA,KAAM;AACpC,MAAA,MAAM,EAAA,CAA0B,4BAA4B,CAAA,CACzD,KAAA,CAAM,EAAE,SAAS,OAAA,CAAQ,MAAA,EAAQ,CAAA,CACjC,MAAA,EAAO;AACV,MAAA,IAAI,wBAAA,EAA0B;AAC5B,QAAA,MAAM,EAAA,CAAG,OAAO,CAAA,CACb,KAAA,CAAM,EAAE,EAAA,EAAI,OAAA,CAAQ,MAAA,EAAQ,CAAA,CAC5B,MAAA,CAAO,EAAE,SAAA,EAAW,MAAM,CAAA;AAAA,MAC/B;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-workspace-database",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.1-next.0",
4
4
  "description": "Database workspace provider module for @backstage/plugin-scaffolder-backend (development use only)",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -52,15 +52,15 @@
52
52
  "test": "backstage-cli package test"
53
53
  },
54
54
  "dependencies": {
55
- "@backstage/backend-plugin-api": "1.10.1-next.0",
56
- "@backstage/plugin-scaffolder-node": "0.13.7-next.1",
55
+ "@backstage/backend-plugin-api": "1.10.2-next.0",
56
+ "@backstage/plugin-scaffolder-node": "0.13.8-next.0",
57
57
  "knex": "^3.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@backstage/backend-defaults": "0.17.9-next.0",
61
- "@backstage/backend-test-utils": "1.11.7-next.0",
62
- "@backstage/cli": "0.36.6-next.0",
63
- "@backstage/config": "1.3.8",
60
+ "@backstage/backend-defaults": "0.18.1-next.0",
61
+ "@backstage/backend-test-utils": "1.11.8-next.0",
62
+ "@backstage/cli": "0.36.7-next.0",
63
+ "@backstage/config": "1.3.10-next.0",
64
64
  "fs-extra": "^11.0.0"
65
65
  },
66
66
  "configSchema": "config.schema.json"