From 5cd453704479f52ad03392bc1383250c6cefd072 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 11 Nov 2021 17:29:13 +0000 Subject: [PATCH] Server: Rename "ReadOnly" mode to "ReadAndClear" to avoid any confusion --- packages/server/src/models/ItemModel.ts | 4 ++-- .../models/items/storage/StorageDriverBase.ts | 2 +- .../storage/StorageDriverDatabase.test.ts | 2 +- .../storage/parseStorageConnectionString.ts | 4 ++-- .../items/storage/serializeStorageConfig.ts | 4 ++-- .../src/models/items/storage/testUtils.ts | 2 +- packages/server/src/utils/types.ts | 20 +++++++++---------- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/server/src/models/ItemModel.ts b/packages/server/src/models/ItemModel.ts index e57739f0225..e348ac2c2d1 100644 --- a/packages/server/src/models/ItemModel.ts +++ b/packages/server/src/models/ItemModel.ts @@ -172,9 +172,9 @@ export default class ItemModel extends BaseModel { await storageDriver.write(itemId, content, context); if (storageDriverFallback) { - if (storageDriverFallback.mode === StorageDriverMode.ReadWrite) { + if (storageDriverFallback.mode === StorageDriverMode.ReadAndWrite) { await storageDriverFallback.write(itemId, content, context); - } else if (storageDriverFallback.mode === StorageDriverMode.ReadOnly) { + } else if (storageDriverFallback.mode === StorageDriverMode.ReadAndClear) { await storageDriverFallback.write(itemId, Buffer.from(''), context); } else { throw new Error(`Unsupported fallback mode: ${storageDriverFallback.mode}`); diff --git a/packages/server/src/models/items/storage/StorageDriverBase.ts b/packages/server/src/models/items/storage/StorageDriverBase.ts index 195485f862c..1d5608a2d80 100644 --- a/packages/server/src/models/items/storage/StorageDriverBase.ts +++ b/packages/server/src/models/items/storage/StorageDriverBase.ts @@ -28,7 +28,7 @@ export default class StorageDriverBase { } public get mode(): StorageDriverMode { - return this.config.mode || StorageDriverMode.ReadOnly; + return this.config.mode || StorageDriverMode.ReadAndClear; } public async write(_itemId: string, _content: Buffer, _context: Context): Promise { throw new Error('Not implemented'); } diff --git a/packages/server/src/models/items/storage/StorageDriverDatabase.test.ts b/packages/server/src/models/items/storage/StorageDriverDatabase.test.ts index f4aeaab642d..c2706917023 100644 --- a/packages/server/src/models/items/storage/StorageDriverDatabase.test.ts +++ b/packages/server/src/models/items/storage/StorageDriverDatabase.test.ts @@ -61,7 +61,7 @@ describe('StorageDriverDatabase', function() { }); test('should support fallback content drivers in rw mode', async function() { - await shouldSupportFallbackDriverInReadWriteMode(newConfig(), { type: StorageDriverType.Memory, mode: StorageDriverMode.ReadWrite }); + await shouldSupportFallbackDriverInReadWriteMode(newConfig(), { type: StorageDriverType.Memory, mode: StorageDriverMode.ReadAndWrite }); }); test('should update content storage ID after switching driver', async function() { diff --git a/packages/server/src/models/items/storage/parseStorageConnectionString.ts b/packages/server/src/models/items/storage/parseStorageConnectionString.ts index 5dd3e1b7553..cd6ad206d17 100644 --- a/packages/server/src/models/items/storage/parseStorageConnectionString.ts +++ b/packages/server/src/models/items/storage/parseStorageConnectionString.ts @@ -11,8 +11,8 @@ const parseType = (type: string): StorageDriverType => { }; const parseMode = (mode: string): StorageDriverMode => { - if (mode === 'rw') return StorageDriverMode.ReadWrite; - if (mode === 'r') return StorageDriverMode.ReadOnly; + if (mode === 'ReadAndWrite') return StorageDriverMode.ReadAndWrite; + if (mode === 'ReadAndClear') return StorageDriverMode.ReadAndClear; throw new Error(`Invalid type: "${mode}"`); }; diff --git a/packages/server/src/models/items/storage/serializeStorageConfig.ts b/packages/server/src/models/items/storage/serializeStorageConfig.ts index 4afa2060763..c3c96fbda6e 100644 --- a/packages/server/src/models/items/storage/serializeStorageConfig.ts +++ b/packages/server/src/models/items/storage/serializeStorageConfig.ts @@ -9,8 +9,8 @@ const serializeType = (type: StorageDriverType): string => { }; const serializeMode = (mode: StorageDriverMode): string => { - if (mode === StorageDriverMode.ReadWrite) return 'rw'; - if (mode === StorageDriverMode.ReadOnly) return 'r'; + if (mode === StorageDriverMode.ReadAndWrite) return 'ReadAndWrite'; + if (mode === StorageDriverMode.ReadAndClear) return 'ReadAndClear'; throw new Error(`Invalid type: "${mode}"`); }; diff --git a/packages/server/src/models/items/storage/testUtils.ts b/packages/server/src/models/items/storage/testUtils.ts index 55224e8664a..3147bb9d71b 100644 --- a/packages/server/src/models/items/storage/testUtils.ts +++ b/packages/server/src/models/items/storage/testUtils.ts @@ -197,7 +197,7 @@ export async function shouldSupportFallbackDriver(driverConfig: StorageDriverCon } export async function shouldSupportFallbackDriverInReadWriteMode(driverConfig: StorageDriverConfig, fallbackDriverConfig: StorageDriverConfig) { - if (fallbackDriverConfig.mode !== StorageDriverMode.ReadWrite) throw new Error('Content driver must be configured in RW mode for this test'); + if (fallbackDriverConfig.mode !== StorageDriverMode.ReadAndWrite) throw new Error('Content driver must be configured in RW mode for this test'); const { user } = await createUserAndSession(1); diff --git a/packages/server/src/utils/types.ts b/packages/server/src/utils/types.ts index 652f9bfa9d0..bd46c128825 100644 --- a/packages/server/src/utils/types.ts +++ b/packages/server/src/utils/types.ts @@ -104,19 +104,19 @@ export enum StorageDriverType { // When writing, the app writes to the main driver. Then the mode determines how // it writes to the fallback driver: // -// - In read-only mode, it's going to clear the fallback driver content. This is -// used to migrate from one driver to another. It means that over time the old -// storage will be cleared and all content will be on the new storage. +// - In ReadAndClear mode, it's going to clear the fallback driver content. This +// is used to migrate from one driver to another. It means that over time the +// old storage will be cleared and all content will be on the new storage. // -// - In read/write mode, it's going to write the content to the fallback driver. -// This is purely for safey - it allows deploying the new storage (such as the -// filesystem or S3) but still keep the old content up-to-date. So if -// something goes wrong it's possible to go back to the old storage until the -// new one is working. +// - In ReadAndWrite mode, it's going to write the content to the fallback +// driver too. This is purely for safey - it allows deploying the new storage +// (such as the filesystem or S3) but still keep the old content up-to-date. +// So if something goes wrong it's possible to go back to the old storage +// until the new one is working. export enum StorageDriverMode { - ReadWrite = 1, - ReadOnly = 2, + ReadAndWrite = 1, + ReadAndClear = 2, } export interface StorageDriverConfig {