Skip to content

Commit

Permalink
Support non-string identifiers in data connector interface and abstra…
Browse files Browse the repository at this point in the history
…ct class.
  • Loading branch information
afshin committed Nov 7, 2017
1 parent 80fb579 commit 7112dda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions packages/coreutils/src/dataconnector.ts
Expand Up @@ -10,7 +10,7 @@ import {
* An abstract class that adheres to the data connector interface.
*/
export
abstract class DataConnector<T, U = T> implements IDataConnector<T, U> {
abstract class DataConnector<T, U = T, V = string> implements IDataConnector<T, U, V> {
/**
* Retrieve an item from the data connector.
*
Expand All @@ -23,10 +23,10 @@ abstract class DataConnector<T, U = T> implements IDataConnector<T, U> {
* occurs in retrieving the data. Non-existence of an `id` will
* succeed with `undefined`.
*/
abstract fetch(id: string): Promise<T | undefined>;
abstract fetch(id: V): Promise<T | undefined>;

/**
* Remove a value from the data connector.
* Remove a value using the data connector.
*
* @param id - The identifier for the data being removed.
*
Expand All @@ -36,8 +36,8 @@ abstract class DataConnector<T, U = T> implements IDataConnector<T, U> {
* This method will always reject, subclasses should reimplement it if they
* support a back-end that can remove resources.
*/
remove(): Promise<void> {
return Promise.reject(new Error('Removing \has not been implemented.'));
remove(id: V): Promise<void> {
return Promise.reject(new Error('Removing has not been implemented.'));
}

/**
Expand All @@ -53,7 +53,7 @@ abstract class DataConnector<T, U = T> implements IDataConnector<T, U> {
* This method will always reject, subclasses should reimplement it if they
* support a back-end that can save resources.
*/
save(id: string, value: U): Promise<void> {
return Promise.reject(new Error('Saving has not been implemented.'));
save(id: V, value: U): Promise<void> {
return Promise.reject(new Error('Saving has not been implemented.'));
}
}
16 changes: 8 additions & 8 deletions packages/coreutils/src/interfaces.ts
Expand Up @@ -28,11 +28,11 @@ interface IChangedArgs<T> {
* The description of a general purpose data connector.
*/
export
interface IDataConnector<T, U = T> {
interface IDataConnector<T, U = T, V = string> {
/**
* Retrieve a saved bundle from the data connector.
* Retrieve an item from the data connector.
*
* @param id - The identifier used to retrieve a data bundle.
* @param id - The identifier used to retrieve an item.
*
* @returns A promise that bears a data payload if available.
*
Expand All @@ -41,25 +41,25 @@ interface IDataConnector<T, U = T> {
* occurs in retrieving the data. Non-existence of an `id` will
* succeed with `undefined`.
*/
fetch(id: string): Promise<T | undefined>;
fetch(id: V): Promise<T | undefined>;

/**
* Remove a value from the data connector.
* Remove a value using the data connector.
*
* @param id - The identifier for the data being removed.
*
* @returns A promise that is rejected if remove fails and succeeds otherwise.
*/
remove(id: string): Promise<void>;
remove(id: V): Promise<void>;

/**
* Save a value in the data connector.
* Save a value using the data connector.
*
* @param id - The identifier for the data being saved.
*
* @param value - The data being saved.
*
* @returns A promise that is rejected if saving fails and succeeds otherwise.
*/
save(id: string, value: U): Promise<void>;
save(id: V, value: U): Promise<void>;
}

0 comments on commit 7112dda

Please sign in to comment.