@launchdarkly/js-server-sdk-common
Version:
LaunchDarkly Server SDK for JavaScript - common code
136 lines • 5.46 kB
TypeScript
/**
* When execution is sequential this enum is used to control if execution
* should be in a fixed or random order.
*/
export declare enum LDExecutionOrdering {
Fixed = 0,
Random = 1
}
/**
* Tag used to determine if execution should be serial or concurrent.
* Callers should not need to use this directly.
*/
export declare enum LDExecution {
/**
* Execution will be serial. One read method will be executed fully before
* the other read method.
*/
Serial = 0,
/**
* Execution will be concurrent. The execution of the read methods will be
* started and then resolved concurrently.
*/
Concurrent = 1
}
/**
* Migration methods may return an LDMethodResult.
* The implementation includes methods for creating results conveniently.
*
* An implementation may also throw an exception to represent an error.
*/
export type LDMethodResult<TResult> = {
success: true;
result: TResult;
} | {
success: false;
error: any;
};
/**
* Configuration class for configuring serial execution of a migration.
*/
export declare class LDSerialExecution {
readonly ordering: LDExecutionOrdering;
readonly type: LDExecution;
constructor(ordering: LDExecutionOrdering);
}
/**
* Configuration class for configuring concurrent execution of a migration.
*/
export declare class LDConcurrentExecution {
readonly type: LDExecution;
}
/**
* Configuration for a migration.
*/
export interface LDMigrationOptions<TMigrationRead, TMigrationWrite, TMigrationReadInput, TMigrationWriteInput> {
/**
* Configure how the migration should execute. If omitted the execution will
* be concurrent.
*/
execution?: LDSerialExecution | LDConcurrentExecution;
/**
* Configure the latency tracking for the migration.
*
* Defaults to {@link true}.
*/
latencyTracking?: boolean;
/**
* Configure the error tracking for the migration.
*
* Defaults to {@link true}.
*/
errorTracking?: boolean;
/**
* Implementation which provides a read from the "new" source.
*
* Users are required to provide two different read methods -- one to read from the old migration source, and one to
* read from the new source. Additionally, customers can opt-in to consistency tracking by providing a `check`
* function.
*
* Depending on the migration stage, one or both of these read methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
readNew: (payload?: TMigrationReadInput) => Promise<LDMethodResult<TMigrationRead>>;
/**
* Implementation which provides a write to the "new" source.
*
* Users are required to provide two different write methods -- one to write to the old migration source, and one to
* write to the new source. Not every stage requires
*
*
* Depending on the migration stage, one or both of these write methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
writeNew: (payload?: TMigrationWriteInput) => Promise<LDMethodResult<TMigrationWrite>>;
/**
* Implementation which provides a read from the "old" source.
*
* Users are required to provide two different read methods -- one to read from the old migration source, and one to
* read from the new source. Additionally, customers can opt-in to consistency tracking by providing a `check`
* function.
*
* Depending on the migration stage, one or both of these read methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
*/
readOld: (payload?: TMigrationReadInput) => Promise<LDMethodResult<TMigrationRead>>;
/**
* Implementation which provides a write to the "old" source.
*
* Users are required to provide two different write methods -- one to write to the old migration source, and one to
* write to the new source. Not every stage requires
*
* Depending on the migration stage, one or both of these write methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
writeOld: (payload?: TMigrationWriteInput) => Promise<LDMethodResult<TMigrationWrite>>;
/**
* Method used to do consistency checks for read operations. After a read operation, during which both data sources
* are read from, a check of read consistency may be done using this method.
*/
check?: (a: TMigrationRead, b: TMigrationRead) => boolean;
}
//# sourceMappingURL=LDMigrationOptions.d.ts.map