Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3401203
D11415.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11415.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D11415: [lib] introduce SyncedMetadata store spec
Attached
Detach File
Event Timeline
Log In to Comment