delta-store
Version:
An API for a store with change records
147 lines (128 loc) • 3.52 kB
text/typescript
import {SharedChangeList} from './RepositoryApi';
/**
* Created by Papa on 1/10/2016.
*/
export interface ChangeListShareInfo {
name: string;
dbId: string;
}
export interface SharingPlatformSetupInfo {
platformType: PlatformType;
recordIdField: string;
dbIdField: string;
}
export enum PlatformType {
GOOGLE_DOCS,
IN_MEMORY,
OFFLINE,
STUB
}
export namespace deltaStore.platform {
export const GOOGLE = 'GOOGLE';
export const IN_MEMORY = 'IN_MEMORY';
export const STUB = 'STUB';
export function getName(
platformType: PlatformType
): string {
switch (platformType) {
case PlatformType.GOOGLE_DOCS:
return GOOGLE;
case PlatformType.IN_MEMORY:
return IN_MEMORY;
case PlatformType.STUB:
return STUB;
default:
throw `Unsupported Platform Type: ${distributionStrategy}`;
}
}
export function getValue(
platformTypeName: string
): PlatformType {
switch (platformTypeName) {
case GOOGLE:
return PlatformType.GOOGLE_DOCS;
case IN_MEMORY:
return PlatformType.IN_MEMORY;
case STUB:
return PlatformType.STUB;
default:
throw `Unsupported Platform Type name: ${platformTypeName}`;
}
}
}
/**
* Possible distribution strategies for Change List Federations.
*
* A common (and only currently supported) basic setup:
*
* There is always a Single Shared Store (S3).
* There are always at least one or more 'Personal' Stores.
*
* The stores communicate via servers that propagate data from
* personal stores to the shared store.
*
* What differs is how this propagation is accomplished.
*
* In the future, we'll add a truly distributed setup, without any S3s.
*/
export enum DistributionStrategy {
/**
* The server is aware of all Personal Stores and it
* subscribes to any possible changes in any of these stores.
* It is the server's responsibility to update the S3.
*/
S3_SECURE_POLL,
/**
* There is no need for a server, all clients are aware of S3
* and are responsible for pushing their changes to it.
*/
S3_DISTIBUTED_PUSH
}
export namespace deltaStore.distributionStrategy {
export const S3_DISTRIBUTED_PUSH = 'S3_DISTRIBUTED_PUSH';
export const S3_SECURE_POLL = 'S3_SECURE_POLL';
export function getName(
distributionStrategy: DistributionStrategy
): string {
switch (distributionStrategy) {
case DistributionStrategy.S3_DISTIBUTED_PUSH:
return S3_DISTRIBUTED_PUSH;
case DistributionStrategy.S3_SECURE_POLL:
return S3_SECURE_POLL;
default:
throw `Unsupported Distribution Strategy: ${distributionStrategy}`;
}
}
export function getValue(
distributionStrategyName: string
): DistributionStrategy {
switch (distributionStrategyName) {
case S3_DISTRIBUTED_PUSH:
return DistributionStrategy.S3_DISTIBUTED_PUSH;
case S3_SECURE_POLL:
return DistributionStrategy.S3_SECURE_POLL;
default:
throw `Unsupported Distribution Strategy name: ${distributionStrategyName}`;
}
}
}
export interface SharingAdaptor {
setupInfoBelongsTo(
setupInfo: SharingPlatformSetupInfo,
setupInfos: SharingPlatformSetupInfo[]
): boolean;
initialize(
setupInfo: SharingPlatformSetupInfo
): Promise<any>;
findExistingChangeLists(
setupInfo: SharingPlatformSetupInfo
): Promise<ChangeListShareInfo[]>;
createChangeList(
shareInfo: ChangeListShareInfo,
setupInfo: SharingPlatformSetupInfo
): Promise<SharedChangeList>;
loadChangeList(
shareInfo: ChangeListShareInfo,
setupInfo: SharingPlatformSetupInfo
): Promise<SharedChangeList>;
}