This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { SyncedState } from '../state/SyncedState.js';
|
||||
import type { RudderContext } from '../core/context.js';
|
||||
import { api } from '../generated/api.js';
|
||||
import type {
|
||||
GetProjectStorageResponse,
|
||||
ProjectStorageUpdateItem,
|
||||
} from '../generated/project-storage.js';
|
||||
|
||||
/**
|
||||
* ProjectStorageDomain — project-wide key/value storage as an observable
|
||||
* entity, plus its mutations. Synced under revision key `projectStorage`;
|
||||
* mutations invalidate it so subscribers observe fresh data.
|
||||
*/
|
||||
export class ProjectStorageDomain extends SyncedState<GetProjectStorageResponse> {
|
||||
readonly syncKey = 'projectStorage';
|
||||
|
||||
constructor(private readonly ctx: RudderContext) {
|
||||
super(() => api.getProjectStorage(ctx, { limit: 100 }));
|
||||
}
|
||||
|
||||
/** Saves project storage items, then invalidates. */
|
||||
async save(items: ProjectStorageUpdateItem[]): Promise<void> {
|
||||
await api.updateProjectStorage(this.ctx, { items });
|
||||
this.invalidate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user