227 lines
9.4 KiB
TypeScript
227 lines
9.4 KiB
TypeScript
|
|
import UserNode from './UserNode';
|
||
|
|
import Model from './Model';
|
||
|
|
import Node from './Node';
|
||
|
|
export declare type ErrCallback = (err) => void;
|
||
|
|
export declare type UsersCallback = (err, users?: UserNode[]) => void;
|
||
|
|
export declare type UserCallback = (err: string, user?: UserNode) => void;
|
||
|
|
export declare type UserNameCallback = (err: string, userName?: string) => void;
|
||
|
|
export interface EnrollmentParams {
|
||
|
|
memberId: string;
|
||
|
|
loopId?: string;
|
||
|
|
voice?: boolean;
|
||
|
|
face?: boolean;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Jibo KB Loop API
|
||
|
|
* @namespace jibo.kb.loop
|
||
|
|
*/
|
||
|
|
/** LoopModel Class. The Loop Model subclass
|
||
|
|
*
|
||
|
|
* @class LoopModel
|
||
|
|
* @extends jibo.kb.Model
|
||
|
|
* @memberof jibo.kb.loop
|
||
|
|
* @example
|
||
|
|
* let model = jibo.kb.loop.createModel('/skillname');
|
||
|
|
*/
|
||
|
|
export default class LoopModel extends Model {
|
||
|
|
/** Load status `accepted` loop members. These are the current
|
||
|
|
* loop members. If callback is omitted a promise is returned
|
||
|
|
* instead.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#loadLoop
|
||
|
|
* @param {Function} [callback] Called with (err, loop). If callback
|
||
|
|
* is omitted a promise that resolves to `loop` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `loop` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
loadLoop(callback: UsersCallback): any;
|
||
|
|
loadLoop(): Promise<UserNode[]>;
|
||
|
|
/** Load status `invited` loop members. These are loop the
|
||
|
|
* members who have not yet accepted their invitation to join the
|
||
|
|
* loop. If callback is omitted a promise is returned instead.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#loadLoopInvited
|
||
|
|
* @param {Function} [callback] Called with (err, loop). If callback
|
||
|
|
* is omitted a promise that resolves to `loop` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `loop` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
loadLoopInvited(callback: UsersCallback): any;
|
||
|
|
loadLoopInvited(): Promise<UserNode[]>;
|
||
|
|
/** Load `isActive` loop members.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#loadLoopActive
|
||
|
|
* @param {Function} [callback] Called with (err, loop). If callback
|
||
|
|
* is omitted a promise that resolves to `loop` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `loop` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
loadLoopActive(callback: UsersCallback): any;
|
||
|
|
loadLoopActive(): Promise<any>;
|
||
|
|
/** Load all loop members, including where `status` is `deleted`.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#loadLoopAll
|
||
|
|
* @param {Function} [callback] Called with (err, loop). If callback
|
||
|
|
* is omitted a promise that resolves to `loop` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `loop` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
loadLoopAll(callback: UsersCallback): any;
|
||
|
|
loadLoopAll(): Promise<UserNode[]>;
|
||
|
|
/** Retrieve loop member's node.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#getUserNodeById
|
||
|
|
* @param {String} id The loop member's ID.
|
||
|
|
* @param {Function} [callback] Called with (err, node). If callback
|
||
|
|
* is omitted a promise that resolves to `node` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `node` if the callback is omitted.
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
getUserNodeById(id: string, callback: UserCallback): any;
|
||
|
|
getUserNodeById(id: string): Promise<UserNode>;
|
||
|
|
/** Retrieve loop member's written name.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#getWrittenNameById
|
||
|
|
* @param {String} id The loop member's ID.
|
||
|
|
* @param {Function} [callback] Called with (err, name). If
|
||
|
|
* callback is omitted a promise that resolves to `name` is
|
||
|
|
* returned instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `name` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
getWrittenNameById(id: string, callback: UserNameCallback): any;
|
||
|
|
getWrittenNameById(id: string): Promise<string>;
|
||
|
|
/** Retrieve loop member's spoken name.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#getSpokenNameById
|
||
|
|
* @param {String} id The loop member's ID.
|
||
|
|
* @param {Function} [callback] Called with (err, name). If callback
|
||
|
|
* is omitted a promise that resolves to `name` is returned
|
||
|
|
* instead.
|
||
|
|
* @returns {Promise} A promise that resolves with the value of
|
||
|
|
* `name` if the callback is omitted.
|
||
|
|
*/
|
||
|
|
getSpokenNameById(id: string, callback: UserNameCallback): any;
|
||
|
|
getSpokenNameById(id: string): Promise<string>;
|
||
|
|
/** Fetch status `accepted` loop members from the
|
||
|
|
* cache. These are the current loop members.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#fetchLoop
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Array of loop members.
|
||
|
|
*/
|
||
|
|
fetchLoop(): UserNode[];
|
||
|
|
/** Fetch status `invited` loop members from the
|
||
|
|
* cache. These are the loop members who have not yet accepted
|
||
|
|
* their invitation to join the loop.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#fetchLoopInvited
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Array of invited loop members.
|
||
|
|
*/
|
||
|
|
fetchLoopInvited(): UserNode[];
|
||
|
|
/** Fetch `isActive` loop members from the cache.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#fetchLoopActive
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Array of active loop members.
|
||
|
|
*/
|
||
|
|
fetchLoopActive(): UserNode[];
|
||
|
|
/** Fetch all loop members from the cache, including where status
|
||
|
|
* is `deleted`.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#fetchLoopAll
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Array of all loop members.
|
||
|
|
*/
|
||
|
|
fetchLoopAll(): UserNode[];
|
||
|
|
/** Set the phonetic name of a loop member in the cloud.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#setPhoneticName
|
||
|
|
* @param {string|jibo.kb.Node} idOrNode The loop member's
|
||
|
|
* ID or Node.
|
||
|
|
* @param {String} phoneticName The phonetic name value.
|
||
|
|
* @param {Function} [callback] Called when done. If callback is
|
||
|
|
* omitted a promise is returned instead.
|
||
|
|
* @returns {Promise} A promise if the callback is omitted.
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
setPhoneticName(idOrNode: string | Node, phoneticName: string, callback: ErrCallback): any;
|
||
|
|
setPhoneticName(idOrNode: string | Node, phoneticName: string): Promise<any>;
|
||
|
|
/** Set the face enrollment flag of a loop member in the cloud.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#setEnrollmentFace
|
||
|
|
* @param {string|jibo.kb.Node} idOrNode The loop member's
|
||
|
|
* ID or Node.
|
||
|
|
* @param {boolean} face The face enrollment flag.
|
||
|
|
* @param {Function} [callback] Called when done. If callback is
|
||
|
|
* omitted a promise is returned instead.
|
||
|
|
* @returns {Promise} A promise if the callback is omitted.
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
setEnrollmentFace(idOrNode: string | Node, face: boolean, callback: ErrCallback): any;
|
||
|
|
setEnrollmentFace(idOrNode: string | Node, face: boolean): Promise<any>;
|
||
|
|
/** Set the voice enrollment flag of a loop member in the cloud.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#setEnrollmentVoice
|
||
|
|
* @param {string|jibo.kb.Node} idOrNode The loop member's
|
||
|
|
* ID or Node.
|
||
|
|
* @param {boolean} voice The voice enrollment flag.
|
||
|
|
* @param {Function} [callback] Called when done. If callback is
|
||
|
|
* omitted a promise is returned instead.
|
||
|
|
* @returns {Promise} A promise if the callback is omitted.
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
setEnrollmentVoice(idOrNode: string | Node, voice: boolean, callback: ErrCallback): any;
|
||
|
|
setEnrollmentVoice(idOrNode: string | Node, voice: boolean): Promise<any>;
|
||
|
|
/** Set the enrollment flag(s) of a loop member in the cloud.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#setEnrollment
|
||
|
|
* @param {Object} params Enrollment
|
||
|
|
* parameters (memberId and face/voice flags)
|
||
|
|
* @param {Function} [callback] Called when done. If callback is
|
||
|
|
* omitted a promise is returned instead.
|
||
|
|
* @returns {Promise} A promise if the callback is omitted.
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
setEnrollment(params: EnrollmentParams, callback: ErrCallback): any;
|
||
|
|
setEnrollment(params: EnrollmentParams): Promise<any>;
|
||
|
|
/** Filter out loop members that have not accepted yet.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#_onlyAccepted
|
||
|
|
* @param {jibo.kb.loop.UserNode[]} loop Loop nodes to filter.
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Loop nodes where `status` is 'accepted'.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private _onlyAccepted(loop);
|
||
|
|
/** Filter out loop members that don't have a pending invitation.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#_onlyInvited
|
||
|
|
* @param {jibo.kb.loop.UserNode[]} loop Loop nodes to filter.
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Loop nodes where `status` is 'invited'.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private _onlyInvited(loop);
|
||
|
|
/** Filter out loop members that are not `isActive`.
|
||
|
|
*
|
||
|
|
* @method jibo.kb.loop.LoopModel#_onlyActive
|
||
|
|
* @param {jibo.kb.loop.UserNode[]} loop Loop nodes to filter.
|
||
|
|
* @returns {jibo.kb.loop.UserNode[]} Loop nodes where `isActive` is true.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private _onlyActive(loop);
|
||
|
|
/** Check http request result for null error object and 2xx result code and
|
||
|
|
* generate an error object if not (or pass through non null error object).
|
||
|
|
*
|
||
|
|
* @method jibo.kb.WebClient#_checkStatusCode
|
||
|
|
* @param {Error} err Error object returned from request.
|
||
|
|
* @param {Object} res Http request result object.
|
||
|
|
* @param {string} [message] Message to add to error object.
|
||
|
|
* @returns {Error} Error object or null.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private _checkStatusCode(err, res, message?);
|
||
|
|
}
|