Page MenuHomePhabricator

D11415.diff
No OneTemporary

D11415.diff

diff --git a/lib/ops/synced-metadata-store-ops.js b/lib/ops/synced-metadata-store-ops.js
new file mode 100644
--- /dev/null
+++ b/lib/ops/synced-metadata-store-ops.js
@@ -0,0 +1,98 @@
+// @flow
+
+import type { BaseStoreOpsHandlers } from './base-ops.js';
+import type {
+ SyncedMetadata,
+ SyncedMetadataStore,
+} from '../types/synced-metadata-types.js';
+
+// client types
+export type ReplaceSyncedMetadataEntryOperation = {
+ +type: 'replace_synced_metadata_entry',
+ +payload: {
+ +name: string,
+ +data: string,
+ },
+};
+
+export type RemoveSyncedMetadataOperation = {
+ +type: 'remove_synced_metadata',
+ +payload: { +names: $ReadOnlyArray<string> },
+};
+
+export type RemoveAllSyncedMetadataOperation = {
+ +type: 'remove_all_synced_metadata',
+};
+
+export type SyncedMetadataStoreOperation =
+ | ReplaceSyncedMetadataEntryOperation
+ | RemoveSyncedMetadataOperation
+ | RemoveAllSyncedMetadataOperation;
+
+// SQLite types
+export type ClientDBSyncedMetadataEntry = {
+ +name: string,
+ +data: string,
+};
+
+export type ClientDBSyncedMetadataStoreOperation =
+ | ReplaceSyncedMetadataEntryOperation
+ | RemoveSyncedMetadataOperation
+ | RemoveAllSyncedMetadataOperation;
+
+const syncedMetadataStoreOpsHandlers: BaseStoreOpsHandlers<
+ SyncedMetadataStore,
+ SyncedMetadataStoreOperation,
+ ClientDBSyncedMetadataStoreOperation,
+ SyncedMetadata,
+ ClientDBSyncedMetadataEntry,
+> = {
+ processStoreOperations(
+ syncedMetadataStore: SyncedMetadataStore,
+ ops: $ReadOnlyArray<SyncedMetadataStoreOperation>,
+ ): SyncedMetadataStore {
+ if (ops.length === 0) {
+ return syncedMetadataStore;
+ }
+
+ let processedSyncedMetadata = { ...syncedMetadataStore.syncedMetadata };
+
+ for (const operation of ops) {
+ if (operation.type === 'replace_synced_metadata_entry') {
+ processedSyncedMetadata[operation.payload.name] =
+ operation.payload.data;
+ } else if (operation.type === 'remove_synced_metadata') {
+ for (const name of operation.payload.names) {
+ delete processedSyncedMetadata[name];
+ }
+ } else if (operation.type === 'remove_all_synced_metadata') {
+ processedSyncedMetadata = {};
+ }
+ }
+
+ return {
+ ...syncedMetadataStore,
+ syncedMetadata: processedSyncedMetadata,
+ };
+ },
+
+ convertOpsToClientDBOps(
+ ops: $ReadOnlyArray<SyncedMetadataStoreOperation>,
+ ): $ReadOnlyArray<ClientDBSyncedMetadataStoreOperation> {
+ return ops;
+ },
+
+ translateClientDBData(
+ communites: $ReadOnlyArray<ClientDBSyncedMetadataEntry>,
+ ): SyncedMetadata {
+ const syncedMetadata: { [name: string]: string } = {};
+
+ communites.forEach(dbSyncedMetadata => {
+ syncedMetadata[dbSyncedMetadata.name] = dbSyncedMetadata.data;
+ });
+
+ return syncedMetadata;
+ },
+};
+
+export { syncedMetadataStoreOpsHandlers };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 10:55 AM (21 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2611420
Default Alt Text
D11415.diff (2 KB)

Event Timeline