MCPcopy
hub / github.com/directus/directus / SynchronizationManagerMemory

Class SynchronizationManagerMemory

api/src/synchronization.ts:29–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29class SynchronizationManagerMemory implements SynchronizationManager {
30 private store: Record<string, string>;
31
32 constructor() {
33 this.store = {};
34 }
35
36 public async set(key: string, value: string | number): Promise<void> {
37 this.setSync(key, value);
38 }
39
40 public async get(key: string): Promise<string | null> {
41 return this.getSync(key);
42 }
43
44 public async delete(key: string): Promise<void> {
45 this.deleteSync(key);
46 }
47
48 public async exists(key: string): Promise<boolean> {
49 return this.existsSync(key);
50 }
51
52 public async setGreaterThan(key: string, value: number): Promise<boolean> {
53 if (this.existsSync(key)) {
54 const oldValue = Number(this.getSync(key));
55
56 if (value <= oldValue) {
57 return false;
58 }
59 }
60
61 this.setSync(key, value);
62
63 return true;
64 }
65
66 private setSync(key: string, value: string | number): void {
67 this.store[key] = String(value);
68 }
69
70 private getSync(key: string): string | null {
71 return this.store[key] ?? null;
72 }
73
74 private deleteSync(key: string): void {
75 delete this.store[key];
76 }
77
78 private existsSync(key: string): boolean {
79 return key in this.store;
80 }
81}
82
83const SET_GREATER_THAN_SCRIPT = `
84 local key = KEYS[1]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected