Skip to content

Commit

Permalink
Merge pull request #854 from orbitjs/core-interfaces
Browse files Browse the repository at this point in the history
Improve typings for core interfaces
  • Loading branch information
dgeb committed Jul 2, 2021
2 parents 76bafe4 + 1d5c4fa commit 662598b
Show file tree
Hide file tree
Showing 22 changed files with 300 additions and 209 deletions.
10 changes: 5 additions & 5 deletions packages/@orbit/core/src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export interface BucketSettings {
version?: number;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Bucket extends Evented<'upgrade'> {}
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface
export interface Bucket<Item> extends Evented<'upgrade'> {}

/**
* Buckets can persist state. The base `Bucket` class is abstract and should be
Expand All @@ -42,7 +42,7 @@ export interface Bucket extends Evented<'upgrade'> {}
* The upgrade process allows buckets to migrate their data between versions.
*/
@evented
export abstract class Bucket {
export abstract class Bucket<Item = unknown> {
private _name?: string;
private _namespace!: string;
private _version!: number;
Expand All @@ -62,12 +62,12 @@ export abstract class Bucket {
/**
* Retrieves an item from the bucket.
*/
abstract getItem(key: string): Promise<unknown>;
abstract getItem(key: string): Promise<Item>;

/**
* Stores an item in the bucket.
*/
abstract setItem(key: string, value: unknown): Promise<void>;
abstract setItem(key: string, value: Item): Promise<void>;

/**
* Removes an item from the bucket.
Expand Down
6 changes: 3 additions & 3 deletions packages/@orbit/core/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { assert } = Orbit;
export interface LogOptions {
name?: string;
data?: string[];
bucket?: Bucket;
bucket?: Bucket<string[]>;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -25,7 +25,7 @@ export interface Log
@evented
export class Log {
private _name?: string;
private _bucket?: Bucket;
private _bucket?: Bucket<string[]>;
private _data: string[] = [];

public reified!: Promise<void>;
Expand All @@ -45,7 +45,7 @@ export class Log {
return this._name;
}

get bucket(): Bucket | undefined {
get bucket(): Bucket<string[]> | undefined {
return this._bucket;
}

Expand Down
24 changes: 16 additions & 8 deletions packages/@orbit/core/src/task-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@ import { Task, Performer } from './task';
* A task can be re-tried by first calling `reset()` on the processor. This
* will clear the processor's state and allow `process()` to be invoked again.
*/
export class TaskProcessor {
target: Performer;
task: Task;
export class TaskProcessor<
Type = string,
Data = unknown,
Options = unknown,
Result = unknown
> {
target: Performer<Type, Data, Options, Result>;
task: Task<Type, Data, Options>;

private _started!: boolean;
private _settled!: boolean;
private _settlement!: Promise<unknown>;
private _success?: (resolution: unknown) => void;
private _settlement!: Promise<Result>;
private _success?: (resolution: Result) => void;
private _fail?: (e: Error) => void;

/**
* Creates an instance of TaskProcessor.
*/
constructor(target: Performer, task: Task) {
constructor(
target: Performer<Type, Data, Options, Result>,
task: Task<Type, Data, Options>
) {
this.target = target;
this.task = task;

Expand Down Expand Up @@ -67,14 +75,14 @@ export class TaskProcessor {
/**
* The eventual result of processing.
*/
settle(): Promise<any> {
settle(): Promise<Result> {
return this._settlement;
}

/**
* Invokes `perform` on the target.
*/
process(): Promise<any> {
process(): Promise<Result> {
if (!this._started) {
this._started = true;

Expand Down

0 comments on commit 662598b

Please sign in to comment.