Skip to content

Commit

Permalink
Fix Collections type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mircea Cosbuc committed Jun 25, 2019
1 parent 29cbf1d commit bb5aefd
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 68 deletions.
1 change: 1 addition & 0 deletions bin/travis.sh
Expand Up @@ -9,6 +9,7 @@ fi
./bin/coveralls.sh
if [ "${RUN_LINTERS:='no'}" == "yes" ]; then
npm run lint
npm run dtslint
fi
npm install -g bower
bower install getstream
80 changes: 76 additions & 4 deletions types/getstream/index.d.ts
@@ -1,4 +1,4 @@
// TypeScript Version: 2.2
// TypeScript Version: 2.4

export as namespace stream;

Expand All @@ -12,9 +12,81 @@ export function connect(
options?: object,
): stream.Client;

export class CollectionEntry {
constructor(store: Collections, collection: string, id: string, data: object);

// Get the entry from the Collection
get(): Promise<object>;
get(
callback: (err: object, httpResponse: object, body: object) => void,
): void;

// Add the entry to the Collection
add(): Promise<object>;
add(
callback: (err: object, httpResponse: object, body: object) => void,
): void;

// Update the entry in the object storage
update(): Promise<object>;
update(
callback: (err: object, httpResponse: object, body: object) => void,
): void;

// Delete the entry from the collection
delete(): Promise<object>;
delete(
callback: (err: object, httpResponse: object, body: object) => void,
): void;
}

export class Collections {
/** Construct Collections. */
constructor(client: StreamClient);
constructor(client: StreamClient, token: string);

// Build the URL for a collection or collection item
buildURL(collection: string, itemId?: string): string;

// Instantiate a collection entry object
entry(
collection: string,
itemId?: string,
itemData?: object,
): CollectionEntry;

// Get a collection entry
get(collection: string, itemId: string): Promise<object>;
get(
collection: string,
itemId: string,
callback: (err: object, httpResponse: object, body: object) => void,
): void;

// Add a single entry to a collection
add(collection: string, itemId: string, itemData?: object): Promise<object>;
add(
collection: string,
itemId: string,
itemData?: object,
callback?: (err: object, httpResponse: object, body: object) => void,
): void;

// Update a single collection entry
update(collection: string, entryId: string, data?: object): Promise<object>;
update(
collection: string,
entryId: string,
data?: object,
callback?: (err: object, httpResponse: object, body: object) => void,
): void;

// Delete a single collection entry
delete(collection: string, entryId: string): Promise<object>;
delete(
collection: string,
entryId: string,
callback: (err: object, httpResponse: object, body: object) => void,
): void;

// Upsert one or more items within a collection.
upsert(
Expand All @@ -33,12 +105,12 @@ export class Collections {
select(collectionName: string, ids: object | object[]): Promise<object>;

// Remove all objects by id from the collection.
delete(
deleteMany(
collectionName: string,
ids: object | object[],
callback: (err: object, httpResponse: object, body: object) => void,
): void;
delete(collectionName: string, ids: object | object[]): Promise<object>;
deleteMany(collectionName: string, ids: object | object[]): Promise<object>;
}

export class Personalization {
Expand Down
47 changes: 0 additions & 47 deletions types/getstream/tests-getstream.ts

This file was deleted.

42 changes: 42 additions & 0 deletions types/getstream/testsGetstream.ts
@@ -0,0 +1,42 @@
new stream.Client('key', undefined, 'apiSecret');

stream.connect('abc', 'def', 'ghi'); // $ExpectType StreamClient

const client = stream.connect('abc', 'def', 'ghi');
client.feed('feedSlug', 'user'); // $ExpectType Feed

let callback = (err: object, httpResponse: object, body: object) => {};

let feed = client.feed('feedSlug', 'user');
feed.follow('feedSlug', 'user'); // $ExpectType Promise<object>
feed.follow('feedSlug', 'user', { activity_copy_limit: 10 }); // $ExpectType Promise<object>

feed.follow('feedSlug', 'user', { activity_copy_limit: 10 }, callback); // $ExpectType void
feed.follow('feedSlug', 'user', callback); // $ExpectType void

feed.unfollow('feedSlug', 'user'); // $ExpectType Promise<object>
feed.unfollow('feedSlug', 'user', { keep_history: true }); // $ExpectType Promise<object>
feed.unfollow('feedSlug', 'user', { keep_history: true }, callback); // $ExpectType void
feed.unfollow('feedSlug', 'user', callback); // $ExpectType void

let collections = client.collections; // $ExpectType Collections
collections.buildURL('events', 'login-134'); // $ExpectType string
collections.entry('events', 'login-134', { user: 'john', source: 'website' }); // $ExpectType CollectionEntry
collections.get('events', 'login-134'); // $ExpectType Promise<object>
collections.get('events', 'login-134', callback); // $ExpectType void
collections.add('events', 'login-123', { user: 'john' }); // $ExpectType Promise<object>
collections.add('events', 'login-1', { user: 'mo' }, callback); // $ExpectType void
collections.update('events', 'login-2', { user: 'jo' }); // $ExpectType Promise<object>
collections.update('events', 'login-2', { user: 'jo' }, callback); // $ExpectType void
collections.delete('events', 'login-134'); // $ExpectType Promise<object>
collections.delete('events', 'login-134', callback); // $ExpectType void
collections.upsert('events', { id: 'login-1', user: 'jo' }); // $ExpectType Promise<object>
collections.upsert('events', { id: 'login-1', source: 'cart' }, callback); // $ExpectType void
collections.select('events', ['login-1', 'login-123']); // $ExpectType Promise<object>
collections.select('events', ['login-1', 'login-123'], callback); // $ExpectType void
collections.deleteMany('events', ['login-2', 'login-234']); // $ExpectType Promise<object>
collections.deleteMany('events', ['login-2', 'login-234'], callback); // $ExpectType void

new stream.errors.MissingSchemaError(); // $ExpectType MissingSchemaError
new stream.errors.FeedError(); // $ExpectType FeedError
new stream.errors.SiteError(); // $ExpectType SiteError
34 changes: 17 additions & 17 deletions types/getstream/tsconfig.json
@@ -1,19 +1,19 @@
{
"compileOnSave": false,
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": true,
"preserveConstEnums": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"sourceMap": true,
"baseUrl": "../",
"types": [],
"paths": {"getstream": ["getstream/"] }
}
"compileOnSave": false,
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": true,
"preserveConstEnums": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"sourceMap": true,
"baseUrl": "../",
"types": [],
"paths": { "getstream": ["getstream/"] }
}
}

0 comments on commit bb5aefd

Please sign in to comment.