From 37d131ab2f3a7ee4b60f021db23f70b906125d6c Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 12 Oct 2021 10:33:00 +0200 Subject: [PATCH] Remove unused context package Signed-off-by: Johan Haals --- .../src/next/Context/BackgroundContext.ts | 26 ------------ .../src/next/Context/ContextWithValue.ts | 39 ------------------ .../src/next/Context/TransactionValue.test.ts | 37 ----------------- .../src/next/Context/TransactionValue.ts | 40 ------------------- .../catalog-backend/src/next/Context/index.ts | 21 ---------- .../catalog-backend/src/next/Context/types.ts | 23 ----------- 6 files changed, 186 deletions(-) delete mode 100644 plugins/catalog-backend/src/next/Context/BackgroundContext.ts delete mode 100644 plugins/catalog-backend/src/next/Context/ContextWithValue.ts delete mode 100644 plugins/catalog-backend/src/next/Context/TransactionValue.test.ts delete mode 100644 plugins/catalog-backend/src/next/Context/TransactionValue.ts delete mode 100644 plugins/catalog-backend/src/next/Context/index.ts delete mode 100644 plugins/catalog-backend/src/next/Context/types.ts diff --git a/plugins/catalog-backend/src/next/Context/BackgroundContext.ts b/plugins/catalog-backend/src/next/Context/BackgroundContext.ts deleted file mode 100644 index c41fa8e3c5..0000000000 --- a/plugins/catalog-backend/src/next/Context/BackgroundContext.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Context, ContextKey } from './types'; - -/** - * A base Context implementation that does not hold any value. - */ -export class BackgroundContext implements Context { - getContextValue(key: ContextKey): T { - return key.defaultValue; - } -} diff --git a/plugins/catalog-backend/src/next/Context/ContextWithValue.ts b/plugins/catalog-backend/src/next/Context/ContextWithValue.ts deleted file mode 100644 index cc88c03679..0000000000 --- a/plugins/catalog-backend/src/next/Context/ContextWithValue.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Context, ContextKey } from './types'; - -/** - * A Context implementation that holds a single value, optionally extending an existing context. - */ -export class ContextWithValue implements Context { - static create(parent: Context, key: ContextKey, value: unknown) { - return new ContextWithValue(parent, key, value); - } - - private constructor( - private readonly parent: Context, - private readonly key: ContextKey, - private readonly value: unknown, - ) {} - - getContextValue(key: ContextKey): T { - if (this.key === key) { - return this.value as T; - } - return this.parent.getContextValue(key); - } -} diff --git a/plugins/catalog-backend/src/next/Context/TransactionValue.test.ts b/plugins/catalog-backend/src/next/Context/TransactionValue.test.ts deleted file mode 100644 index 20165eff2f..0000000000 --- a/plugins/catalog-backend/src/next/Context/TransactionValue.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { TransactionValue } from './TransactionValue'; -import { Knex } from 'knex'; -import { BackgroundContext } from './BackgroundContext'; - -describe('TransactionValue Context', () => { - it('should be able to store tx values and retrieve them from a context', () => { - const tx = {} as Knex.Transaction; - const ctx = new BackgroundContext(); - - const nextCtx = TransactionValue.in(ctx, tx); - - expect(TransactionValue.from(nextCtx)).toBe(tx); - }); - - it('should throw when there is no tx value in the context', () => { - const ctx = new BackgroundContext(); - - expect(() => TransactionValue.from(ctx)).toThrow( - /No transaction available in context/, - ); - }); -}); diff --git a/plugins/catalog-backend/src/next/Context/TransactionValue.ts b/plugins/catalog-backend/src/next/Context/TransactionValue.ts deleted file mode 100644 index af069c6d8e..0000000000 --- a/plugins/catalog-backend/src/next/Context/TransactionValue.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Context, ContextKey } from './types'; -import { Knex } from 'knex'; -import { ContextWithValue } from './ContextWithValue'; - -const transactionContextKey = new ContextKey( - undefined, -); - -/** - * TransactionValue handles the wrapping of a knex transaction in a Context. - */ -export class TransactionValue { - static in(parent: Context, tx: Knex.Transaction) { - return ContextWithValue.create(parent, transactionContextKey, tx); - } - - static from(context: Context): Knex.Transaction { - const transaction = context.getContextValue(transactionContextKey); - if (!transaction) { - throw new Error(`No transaction available in context`); - } - return transaction; - } -} diff --git a/plugins/catalog-backend/src/next/Context/index.ts b/plugins/catalog-backend/src/next/Context/index.ts deleted file mode 100644 index 822edba478..0000000000 --- a/plugins/catalog-backend/src/next/Context/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { BackgroundContext } from './BackgroundContext'; -export { ContextWithValue } from './ContextWithValue'; -export { TransactionValue } from './TransactionValue'; -export { ContextKey } from './types'; -export type { Context } from './types'; diff --git a/plugins/catalog-backend/src/next/Context/types.ts b/plugins/catalog-backend/src/next/Context/types.ts deleted file mode 100644 index 062bc884e9..0000000000 --- a/plugins/catalog-backend/src/next/Context/types.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class ContextKey { - constructor(readonly defaultValue: T) {} -} - -export interface Context { - getContextValue(key: ContextKey): T; -}