vkontakte-api
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -5,2 +5,4 @@ # Changelog | ||
### [1.3.4](https://github.com/wolframdeus/vk-api/compare/v1.3.3...v1.3.4) (2020-06-14) | ||
### [1.3.3](https://github.com/wolframdeus/vk-api/compare/v1.3.2...v1.3.3) (2020-06-11) | ||
@@ -7,0 +9,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./VKAPIMaster")),__export(require("./VKAPISlave")),__export(require("./types")); | ||
"use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./VKAPIMaster")),__export(require("./VKAPISlave")); |
@@ -1,2 +0,2 @@ | ||
import { ProcessRequestConfig } from '../types'; | ||
import { RequestConfig } from '../types'; | ||
export interface VKAPIMessage { | ||
@@ -11,4 +11,4 @@ processId: number; | ||
export interface VKAPIProcessRequestMessage extends VKAPIMessage { | ||
type: MessageTypeEnum.ProcessRequest; | ||
config: ProcessRequestConfig; | ||
type: 'process-request'; | ||
config: RequestConfig; | ||
} | ||
@@ -19,9 +19,5 @@ /** | ||
export interface VKAPIRequestProcessedMessage extends VKAPIMessage { | ||
type: MessageTypeEnum.RequestProcessed; | ||
type: 'request-processed'; | ||
error: Error | null; | ||
data: any; | ||
} | ||
export declare enum MessageTypeEnum { | ||
ProcessRequest = "process-request", | ||
RequestProcessed = "request-processed" | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var MessageTypeEnum;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.ProcessRequest="process-request",e.RequestProcessed="request-processed"}(MessageTypeEnum=exports.MessageTypeEnum||(exports.MessageTypeEnum={})); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}); |
@@ -8,7 +8,7 @@ /// <reference types="node" /> | ||
*/ | ||
threads: Worker[]; | ||
workers: Worker[]; | ||
/** | ||
* API client which performs requests | ||
*/ | ||
client: VKAPIInterface; | ||
instance: VKAPIInterface; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var types_1=require("../types");function isVKAPIProcessRequestMessage(e){return"object"==typeof e&&"number"==typeof e.processId&&"string"==typeof e.requestId&&!0===e.isVKAPIMessage&&e.type===types_1.MessageTypeEnum.ProcessRequest&&"object"==typeof e.config&&"string"==typeof e.config.method&&"object"==typeof e.config.options}exports.isVKAPIProcessRequestMessage=isVKAPIProcessRequestMessage; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var utils_1=require("../utils");function isVKAPIProcessRequestMessage(e){return utils_1.extendsVKAPIMessage(e)&&"process-request"===e.type&&utils_1.isNonNullObject(e.config)&&"string"==typeof e.config.method&&utils_1.isNonNullObject(e.config.params)}exports.isVKAPIProcessRequestMessage=isVKAPIProcessRequestMessage; |
@@ -9,7 +9,7 @@ import { VKAPIMasterConstructorProps } from './types'; | ||
*/ | ||
private readonly threads; | ||
private readonly workers; | ||
/** | ||
* API client which executes requests | ||
*/ | ||
private readonly client; | ||
private readonly instance; | ||
constructor(props: VKAPIMasterConstructorProps); | ||
@@ -16,0 +16,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(s,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function o(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,o)}u((n=n.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){var r,n,s,i,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return i={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function o(i){return function(o){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(s=2&i[0]?n.return:i[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,i[1])).done)return s;switch(n=0,s&&(i=[2&i[0],s.value]),i[0]){case 0:case 1:s=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(s=(s=a.trys).length>0&&s[s.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!s||i[1]>s[0]&&i[1]<s[3])){a.label=i[1];break}if(6===i[0]&&a.label<s[1]){a.label=s[1],s=i;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(i);break}s[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=s=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,o])}}};Object.defineProperty(exports,"__esModule",{value:!0});var utils_1=require("./utils"),types_1=require("../types"),VKAPIMaster=function(){function e(e){var t=e.client,r=e.threads;this.client=t,this.threads=r,this.init()}return e.prototype.init=function(){var e=this;this.threads.forEach(function(t){t.on("message",function(r){return __awaiter(e,void 0,void 0,function(){var e,n,s,i,a,o,u;return __generator(this,function(c){switch(c.label){case 0:if(!utils_1.isVKAPIProcessRequestMessage(r))return[3,5];e=r.requestId,n=r.processId,s=r.config,i=null,a=null,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.client.processRequest(s)];case 2:return a=c.sent(),[3,4];case 3:return o=c.sent(),i=o,[3,4];case 4:u={processId:n,requestId:e,isVKAPIMessage:!0,type:types_1.MessageTypeEnum.RequestProcessed,error:i,data:a},t.send(u),c.label=5;case 5:return[2]}})})})})},e}();exports.VKAPIMaster=VKAPIMaster; | ||
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(s,a){function o(e){try{u(n.next(e))}catch(e){a(e)}}function i(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,i)}u((n=n.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){var r,n,s,a,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(s=(s=o.trys).length>0&&s[s.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){o.label=a[1];break}if(6===a[0]&&o.label<s[1]){o.label=s[1],s=a;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(a);break}s[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}};Object.defineProperty(exports,"__esModule",{value:!0});var utils_1=require("./utils"),VKAPIMaster=function(){function e(e){var t=e.instance,r=e.workers;this.instance=t,this.workers=r}return e.prototype.init=function(){var e=this;this.workers.forEach(function(t){t.on("message",function(r){return __awaiter(e,void 0,void 0,function(){var e,n,s,a,o,i,u;return __generator(this,function(c){switch(c.label){case 0:if(!utils_1.isVKAPIProcessRequestMessage(r))return[3,5];e=r.requestId,n=r.processId,s=r.config,a=null,o=null,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.instance.addRequestToQueue(s)];case 2:return o=c.sent(),[3,4];case 3:return i=c.sent(),a=i,[3,4];case 4:u={processId:n,requestId:e,isVKAPIMessage:!0,type:"request-processed",error:a,data:o},t.send(u),c.label=5;case 5:return[2]}})})})})},e}();exports.VKAPIMaster=VKAPIMaster; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var types_1=require("../types");function isVKAPIRequestProcessedMessage(e){return"object"==typeof e&&"number"==typeof e.processId&&"string"==typeof e.requestId&&!0===e.isVKAPIMessage&&e.type===types_1.MessageTypeEnum.RequestProcessed&&(e.error instanceof Error||null===e.error)&&"data"in e}exports.isVKAPIRequestProcessedMessage=isVKAPIRequestProcessedMessage; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var utils_1=require("../utils");function isVKAPIRequestProcessedMessage(e){return utils_1.extendsVKAPIMessage(e)&&"request-processed"===e.type&&(void 0!==e.error||null===e.error)&&"data"in e}exports.isVKAPIRequestProcessedMessage=isVKAPIRequestProcessedMessage; |
import { VKAPIInterface } from '../../VKAPI'; | ||
import { MessagesRepository, NotificationsRepository, UsersRepository } from '../../repositories'; | ||
import { ProcessRequest } from '../../types'; | ||
import { UsersRepository, MessagesRepository, NotificationsRepository } from '../../repositories'; | ||
import { SendRequest } from '../../types'; | ||
/** | ||
@@ -10,4 +10,4 @@ * Stub class which wants to get data from API VKontakte and has to | ||
users: UsersRepository; | ||
messages: MessagesRepository; | ||
notifications: NotificationsRepository; | ||
messages: MessagesRepository; | ||
/** | ||
@@ -19,3 +19,3 @@ * Internal request counter. Required to send and get answers from master | ||
constructor(); | ||
processRequest: ProcessRequest; | ||
addRequestToQueue: SendRequest; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var repositories_1=require("../../repositories"),types_1=require("../types"),utils_1=require("./utils"),VKAPISlave=function(){return function(){var e=this;if(this.requestId="0",this.processRequest=function(s){if(!process.send)throw new Error('Unable to process VKAPI request from slave due to there is no "process.send" method available. It looks like it was created in main thread, but not in fork');var r=(parseInt(e.requestId)+1).toString(16),t=process.pid,o={processId:t,requestId:r,isVKAPIMessage:!0,type:types_1.MessageTypeEnum.ProcessRequest,config:s};return process.send(o),e.requestId=r,new Promise(function(e,s){var o=function(i){if(utils_1.isVKAPIRequestProcessedMessage(i)&&i.requestId===r&&i.processId===t){if(process.off("message",o),i.error)return s(i.error);e(i.data)}};process.on("message",o)})},!process.send)throw new Error('Unable to create VKAPISlave due to there is no "process.send" method available. It looks like it was created in main thread, but not in fork');this.users=new repositories_1.UsersRepository({processRequest:this.processRequest}),this.notifications=new repositories_1.NotificationsRepository({processRequest:this.processRequest}),this.messages=new repositories_1.MessagesRepository({processRequest:this.processRequest})}}();exports.VKAPISlave=VKAPISlave; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var utils_1=require("./utils"),repositories_1=require("../../repositories"),VKAPISlave=function(){return function(){var e=this;if(this.requestId="0",this.addRequestToQueue=function(s){if(!process.send)throw new Error('Unable to process VKAPI request from slave due to there is no "process.send" method available. It looks like it was created in main thread, but not in fork');var r=(parseInt(e.requestId)+1).toString(16),t=process.pid,o={processId:t,requestId:r,isVKAPIMessage:!0,type:"process-request",config:s};return process.send(o),e.requestId=r,new Promise(function(e,s){var o=function(i){if(utils_1.isVKAPIRequestProcessedMessage(i)&&i.requestId===r&&i.processId===t){if(process.off("message",o),i.error)return s(i.error);e(i.data)}};process.on("message",o)})},!process.send)throw new Error('Unable to create VKAPISlave due to there is no "process.send" method available. It looks like it was created in main thread, but not in fork');this.users=new repositories_1.UsersRepository(this.addRequestToQueue),this.messages=new repositories_1.MessagesRepository(this.addRequestToQueue),this.notifications=new repositories_1.NotificationsRepository(this.addRequestToQueue)}}();exports.VKAPISlave=VKAPISlave; |
@@ -1,9 +0,15 @@ | ||
import { SendMethod, MessagesRepositoryConstructorProps, MessagesRepositoryInterface } from './types'; | ||
import { Repository } from '../../Repository'; | ||
import { Repository } from '../Repository'; | ||
import { RepositoryMethod, SendRequest } from '../../types'; | ||
import { SendParams, SendResult } from './types'; | ||
/** | ||
* Repository to work with users | ||
*/ | ||
export declare class MessagesRepository extends Repository implements MessagesRepositoryInterface { | ||
constructor(props: MessagesRepositoryConstructorProps); | ||
send: SendMethod; | ||
export declare class MessagesRepository extends Repository { | ||
constructor(sendRequest: SendRequest); | ||
/** | ||
* @see https://vk.com/dev/messages.send | ||
* @param {SendParams & RequestOptionalParams} params | ||
* @returns {Promise<any>} | ||
*/ | ||
send: RepositoryMethod<SendParams, SendResult>; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,o){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(t,o)};return function(t,o){function s(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(s.prototype=o.prototype,new s)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../../Repository"),MessagesRepository=function(e){function t(t){var o=e.call(this,{processRequest:t.processRequest,name:"messages"})||this;return o.send=function(e){return o.processRequest({method:"send",options:e})},o}return __extends(t,e),t}(Repository_1.Repository);exports.MessagesRepository=MessagesRepository; | ||
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,o){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(t,o)};return function(t,o){function r(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../Repository"),MessagesRepository=function(e){function t(t){var o=e.call(this,"messages",t)||this;return o.send=function(e){return o.sendRequest({method:"send",params:e})},o}return __extends(t,e),t}(Repository_1.Repository);exports.MessagesRepository=MessagesRepository; |
@@ -1,6 +0,10 @@ | ||
import { ProcessRequest, RequestOptionalParams } from '../../types'; | ||
export interface MessagesRepositoryConstructorProps { | ||
processRequest: ProcessRequest; | ||
} | ||
interface SendMethodOptions extends RequestOptionalParams { | ||
/** | ||
* @see https://vk.com/dev/messages.send | ||
*/ | ||
export declare type SendResult = number | Array<{ | ||
peerId: number; | ||
messageId: number; | ||
error?: string; | ||
}>; | ||
export interface SendParams { | ||
userId?: number; | ||
@@ -26,11 +30,1 @@ randomId?: number; | ||
} | ||
export declare type SendMethodResult = number | Array<{ | ||
peerId: number; | ||
messageId: number; | ||
error?: string; | ||
}>; | ||
export declare type SendMethod = (options: SendMethodOptions) => Promise<SendMethodResult>; | ||
export interface MessagesRepositoryInterface { | ||
send: SendMethod; | ||
} | ||
export {}; |
@@ -1,20 +0,20 @@ | ||
import { NotificationsRepositoryInterface, NotificationsRepositoryConstructorProps, SendMessageMethod, MarkAsViewedMethod } from './types'; | ||
import { Repository } from '../../Repository'; | ||
import { MarkAsViewedResult, SendMessageResult, SendMessageParams, MarkAsViewedParams } from './types'; | ||
import { Repository } from '../Repository'; | ||
import { RepositoryMethod, SendRequest } from '../../types'; | ||
/** | ||
* Repository to work with notifications | ||
*/ | ||
export declare class NotificationsRepository extends Repository implements NotificationsRepositoryInterface { | ||
constructor(props: NotificationsRepositoryConstructorProps); | ||
export declare class NotificationsRepository extends Repository { | ||
constructor(sendRequest: SendRequest); | ||
/** | ||
* Marks notifications as viewed | ||
* @param {RequestOptionalParams | undefined} options | ||
* @returns {Promise<MarkAsViewedResultType>} | ||
* @see https://vk.com/dev/notifications.markAsViewed | ||
* @returns {Promise<any>} | ||
*/ | ||
markAsViewed: MarkAsViewedMethod; | ||
markAsViewed: RepositoryMethod<MarkAsViewedParams, MarkAsViewedResult>; | ||
/** | ||
* Sends notification | ||
* @param options | ||
* @returns {Promise<SendMessageResultType[]>} | ||
* @see https://vk.com/dev/notifications.sendMessage | ||
* @param {SendMessageParams & RequestOptionalParams} params | ||
* @returns {Promise<any>} | ||
*/ | ||
sendMessage: SendMessageMethod; | ||
sendMessage: RepositoryMethod<SendMessageParams, SendMessageResult>; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var __extends=this&&this.__extends||function(){var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(e,o)};return function(e,o){function s(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(s.prototype=o.prototype,new s)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../../Repository"),NotificationsRepository=function(t){function e(e){var o=t.call(this,{processRequest:e.processRequest,name:"notifications"})||this;return o.markAsViewed=function(t){return o.processRequest({method:"sendMessage",options:t||{}})},o.sendMessage=function(t){return o.processRequest({method:"sendMessage",options:t})},o}return __extends(e,t),e}(Repository_1.Repository);exports.NotificationsRepository=NotificationsRepository; | ||
"use strict";var __extends=this&&this.__extends||function(){var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(e,o)};return function(e,o){function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../Repository"),NotificationsRepository=function(t){function e(e){var o=t.call(this,"notifications",e)||this;return o.markAsViewed=function(){return o.sendRequest({method:"markAsViewed",params:{}})},o.sendMessage=function(t){return o.sendRequest({method:"sendMessage",params:t})},o}return __extends(e,t),e}(Repository_1.Repository);exports.NotificationsRepository=NotificationsRepository; |
@@ -1,18 +0,16 @@ | ||
import { ProcessRequest, RequestOptionalParams } from '../../types'; | ||
export interface NotificationsRepositoryConstructorProps { | ||
processRequest: ProcessRequest; | ||
import { PseudoBooleanType } from '../../types'; | ||
/** | ||
* @see https://vk.com/dev/notifications.markAsViewed | ||
*/ | ||
export declare type MarkAsViewedResult = PseudoBooleanType; | ||
export interface MarkAsViewedParams { | ||
} | ||
export declare type MarkAsViewedResultType = 0 | 1; | ||
export declare type MarkAsViewedMethod = (options?: RequestOptionalParams) => Promise<MarkAsViewedResultType>; | ||
interface SendMessageOptions extends RequestOptionalParams { | ||
userIds: Array<string | number>; | ||
message: string; | ||
fragment?: string; | ||
groupId?: number; | ||
} | ||
interface SendMessageResultOk { | ||
/** | ||
* @see https://vk.com/dev/notifications.sendMessage | ||
*/ | ||
export interface SendMessageResultOk { | ||
userId: number; | ||
status: true; | ||
} | ||
interface SendMessageResultError { | ||
export interface SendMessageResultError { | ||
userId: number; | ||
@@ -25,8 +23,8 @@ status: false; | ||
} | ||
export declare type SendMessageResultType = SendMessageResultOk | SendMessageResultError; | ||
export declare type SendMessageMethod = (options: SendMessageOptions) => Promise<SendMessageResultType[]>; | ||
export interface NotificationsRepositoryInterface { | ||
markAsViewed: MarkAsViewedMethod; | ||
sendMessage: SendMessageMethod; | ||
export declare type SendMessageResult = Array<SendMessageResultOk | SendMessageResultError>; | ||
export interface SendMessageParams { | ||
userIds: Array<string | number>; | ||
message: string; | ||
fragment?: string; | ||
groupId?: number; | ||
} | ||
export {}; |
@@ -1,14 +0,10 @@ | ||
import { ProcessRequest, RequestOptionalParams, User, UserFieldType, NameCaseType } from '../../types'; | ||
export interface UsersRepositoryConstructorProps { | ||
processRequest: ProcessRequest; | ||
} | ||
interface GetMethodOptions extends RequestOptionalParams { | ||
import { NameCaseType, User, UserFieldType } from '../../types'; | ||
/** | ||
* @see https://vk.com/dev/users.get | ||
*/ | ||
export interface GetParams { | ||
userIds: Array<string | number>; | ||
fields: UserFieldType[]; | ||
fields?: UserFieldType[]; | ||
nameCase?: NameCaseType; | ||
} | ||
export declare type GetMethod = (options: GetMethodOptions) => Promise<User[]>; | ||
export interface UsersRepositoryInterface { | ||
get: GetMethod; | ||
} | ||
export {}; | ||
export declare type GetResult = User[]; |
@@ -1,14 +0,15 @@ | ||
import { GetMethod, UsersRepositoryInterface, UsersRepositoryConstructorProps } from './types'; | ||
import { Repository } from '../../Repository'; | ||
import { Repository } from '../Repository'; | ||
import { RepositoryMethod, SendRequest } from '../../types'; | ||
import { GetParams, GetResult } from './types'; | ||
/** | ||
* Repository to work with users | ||
*/ | ||
export declare class UsersRepository extends Repository implements UsersRepositoryInterface { | ||
constructor(props: UsersRepositoryConstructorProps); | ||
export declare class UsersRepository extends Repository { | ||
constructor(sendRequest: SendRequest); | ||
/** | ||
* Returns info about users | ||
* @param {GetMethodOptions} options | ||
* @returns {Promise<User[]>} | ||
* @see https://vk.com/dev/users.get | ||
* @param {GetParams & RequestOptionalParams} params | ||
* @returns {Promise<any>} | ||
*/ | ||
get: GetMethod; | ||
get: RepositoryMethod<GetParams, GetResult>; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var __extends=this&&this.__extends||function(){var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(e,o)};return function(e,o){function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../../Repository"),UsersRepository=function(t){function e(e){var o=t.call(this,{processRequest:e.processRequest,name:"users"})||this;return o.get=function(t){return o.processRequest({method:"get",options:t})},o}return __extends(e,t),e}(Repository_1.Repository);exports.UsersRepository=UsersRepository; | ||
"use strict";var __extends=this&&this.__extends||function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Repository_1=require("../Repository"),UsersRepository=function(t){function e(e){var r=t.call(this,"users",e)||this;return r.get=function(t){return r.sendRequest({method:"get",params:t})},r}return __extends(e,t),e}(Repository_1.Repository);exports.UsersRepository=UsersRepository; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* Enum of available languages | ||
*/ | ||
export declare enum LangEnum { | ||
@@ -11,3 +14,14 @@ RU = 0, | ||
} | ||
/** | ||
* Type which describes available languages | ||
* @see https://vk.com/dev/api_requests?f=2.%20Общие%20параметры | ||
*/ | ||
export declare type LangType = 'ru' | 'uk' | 'be' | 'en' | 'es' | 'fi' | 'de' | 'it' | LangEnum; | ||
/** | ||
* Pseudo boolean type. Means boolean converted to number | ||
*/ | ||
export declare type PseudoBooleanType = 0 | 1; | ||
/** | ||
* Shared optional request parameters. | ||
*/ | ||
export interface RequestOptionalParams { | ||
@@ -20,2 +34,3 @@ /** | ||
* Language | ||
* @default "ru" | ||
*/ | ||
@@ -25,2 +40,3 @@ lang?: LangType; | ||
* API version | ||
* @default "5.110" | ||
*/ | ||
@@ -30,13 +46,21 @@ v?: string; | ||
/** | ||
* Pseudo boolean type | ||
* Config to execute request | ||
*/ | ||
export declare type PseudoBooleanType = 0 | 1; | ||
export interface RequestConfig<M extends string = string, P extends {} = any> { | ||
/** | ||
* API method name | ||
*/ | ||
method: M; | ||
/** | ||
* List of params for passed method | ||
*/ | ||
params: P; | ||
} | ||
/** | ||
* Config to perform request | ||
* Function that sends request | ||
*/ | ||
export interface ProcessRequestConfig { | ||
method: string; | ||
options: object; | ||
} | ||
export declare type ProcessRequest = <T>(config: ProcessRequestConfig) => Promise<T>; | ||
export declare type SendRequest = ProcessRequest; | ||
export declare type SendRequest = <M extends string = string, P extends {} = any, R = any>(config: RequestConfig<M, P>) => Promise<R>; | ||
/** | ||
* Describes repository method | ||
*/ | ||
export declare type RepositoryMethod<P extends {} = any, R = any> = (params: P & RequestOptionalParams) => Promise<R>; |
/** | ||
* Creates query converting camel case field names to snake case | ||
* @param {Record<string, any>} query | ||
* Converts text to snake case | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
export declare function formatQuery(query: Record<string, any>): string; | ||
export declare function toSnakeCase(text: string): string; | ||
export declare const recursiveToSnakeCase: (value: any) => any; | ||
/** | ||
* Converts text to camel case | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
export declare function toCamelCase(text: string): string; | ||
export declare const recursiveToCamelCase: (value: any) => any; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var VKAPI_1=require("./VKAPI"),querystring_1=require("querystring");function formatQuery(r){var e=Object.keys(r).reduce(function(e,t){return e[VKAPI_1.toSnakeCase(t)]=Array.isArray(r[t])?r[t].join(","):r[t],e},{});return querystring_1.stringify(e)}exports.formatQuery=formatQuery; | ||
"use strict";function createRecursiveKeysFormatter(e){var r=function(t){return null===t?null:Array.isArray(t)?t.map(r):"object"==typeof t?Object.keys(t).reduce(function(a,o){return a[e(o)]=r(t[o]),a},{}):t};return r}function toSnakeCase(e){return e.replace(/[A-Z]/g,function(e){return"_"+e.toLowerCase()})}function toCamelCase(e){return e.replace(/_./g,function(e){return e.slice(1).toUpperCase()})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.toSnakeCase=toSnakeCase,exports.recursiveToSnakeCase=createRecursiveKeysFormatter(toSnakeCase),exports.toCamelCase=toCamelCase,exports.recursiveToCamelCase=createRecursiveKeysFormatter(toCamelCase); |
export * from './types'; | ||
export * from './utils'; | ||
export * from './VKAPI'; |
@@ -1,1 +0,1 @@ | ||
"use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./utils")),__export(require("./VKAPI")); | ||
"use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./VKAPI")); |
@@ -1,40 +0,31 @@ | ||
import { UsersRepositoryInterface } from '../repositories/UsersRepository'; | ||
import { NotificationsRepositoryInterface } from '../repositories/NotificationsRepository'; | ||
import { ProcessRequest } from '../types'; | ||
import { MessagesRepositoryInterface } from '../repositories/MessagesRepository'; | ||
export interface VKAPIConstructorProps { | ||
import { RequestConfig, RequestOptionalParams, SendRequest } from '../types'; | ||
import { UsersRepository } from '../repositories/UsersRepository'; | ||
import { MessagesRepository } from '../repositories/MessagesRepository'; | ||
import { NotificationsRepository } from '../repositories/NotificationsRepository'; | ||
export interface QueueRequest { | ||
/** | ||
* Requests per second, API instance can perform | ||
* Request config | ||
*/ | ||
requestsPerSecond: number; | ||
config: RequestConfig; | ||
/** | ||
* Access token which will be used for each request | ||
* Reference required to detect which request was performed | ||
*/ | ||
accessToken?: string; | ||
ref: symbol; | ||
} | ||
export interface VKAPIConstructorProps extends RequestOptionalParams { | ||
/** | ||
* API version | ||
* Requests per second instance can perform. Required to prevent block from | ||
* VKontakte API | ||
* @default 3 | ||
*/ | ||
version?: string; | ||
rps?: number; | ||
} | ||
/** | ||
* VKAPI class interface | ||
*/ | ||
export interface VKAPIInterface { | ||
users: UsersRepository; | ||
messages: MessagesRepository; | ||
notifications: NotificationsRepository; | ||
/** | ||
* Notifications repository | ||
* Adds request to queue and performs it after some time | ||
*/ | ||
notifications: NotificationsRepositoryInterface; | ||
/** | ||
* Users repository | ||
*/ | ||
users: UsersRepositoryInterface; | ||
/** | ||
* Messages repository | ||
*/ | ||
messages: MessagesRepositoryInterface; | ||
/** | ||
* In outer context, executes a request. Internally, places a request into | ||
* the requests queue and executes it after it becomes available | ||
*/ | ||
processRequest: ProcessRequest; | ||
addRequestToQueue: SendRequest; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { ProcessRequest } from '../types'; | ||
import { SendRequest } from '../types'; | ||
import { VKAPIInterface, VKAPIConstructorProps } from './types'; | ||
import { MessagesRepositoryInterface, NotificationsRepositoryInterface, UsersRepositoryInterface } from '../repositories'; | ||
import { UsersRepository, MessagesRepository, NotificationsRepository } from '../repositories'; | ||
/** | ||
@@ -8,12 +8,27 @@ * Class to perform request to VKontakte API | ||
export declare class VKAPI implements VKAPIInterface { | ||
notifications: NotificationsRepositoryInterface; | ||
users: UsersRepositoryInterface; | ||
messages: MessagesRepositoryInterface; | ||
users: UsersRepository; | ||
messages: MessagesRepository; | ||
notifications: NotificationsRepository; | ||
/** | ||
* Queue of requests | ||
* @type {any[]} | ||
*/ | ||
private requestsQueue; | ||
private readonly queue; | ||
/** | ||
* Mutex which states if queue is currently processing | ||
* @type {boolean} | ||
*/ | ||
private isQueueProcessing; | ||
/** | ||
* Event emitter which notifies about completed requests | ||
* @type {EventEmitter} | ||
*/ | ||
private eventEmitter; | ||
/** | ||
* Timeout between requests | ||
*/ | ||
private readonly timeout; | ||
/** | ||
* Access token to perform requests | ||
* @type {null} | ||
* @type {string | null} | ||
*/ | ||
@@ -24,9 +39,17 @@ private readonly accessToken; | ||
*/ | ||
private readonly version; | ||
constructor(props: VKAPIConstructorProps); | ||
processRequest: ProcessRequest; | ||
private readonly v; | ||
/** | ||
* Executes request with http client | ||
* Language | ||
*/ | ||
private readonly lang; | ||
constructor(props?: VKAPIConstructorProps); | ||
/** | ||
* Sends request via http client | ||
*/ | ||
private sendRequest; | ||
/** | ||
* Processes queue of requests | ||
*/ | ||
private processQueue; | ||
addRequestToQueue: SendRequest; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,t,r,s){return new(r||(r=Promise))(function(n,o){function i(e){try{a(s.next(e))}catch(e){o(e)}}function u(e){try{a(s.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,u)}a((s=s.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){var r,s,n,o,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,s&&(n=2&o[0]?s.return:o[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,o[1])).done)return n;switch(s=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,s=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(n=(n=i.trys).length>0&&n[n.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){i.label=o[1];break}if(6===o[0]&&i.label<n[1]){i.label=n[1],n=o;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(o);break}n[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],s=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var isomorphic_fetch_1=__importDefault(require("isomorphic-fetch")),RequestsQueue_1=require("../RequestsQueue"),repositories_1=require("../repositories"),VKError_1=require("../VKError"),utils_1=require("./utils"),utils_2=require("../utils"),VKAPI=function(){return function(e){var t=this;this.accessToken=null,this.processRequest=function(e){return t.requestsQueue.add(e)},this.sendRequest=function(e){return __awaiter(t,void 0,void 0,function(){var t,r,s,n;return __generator(this,function(o){switch(o.label){case 0:return t=e.method,r=e.options,s=utils_2.formatQuery(__assign({v:this.version,accessToken:this.accessToken},r)),[4,isomorphic_fetch_1.default("https://api.vk.com/method/"+t+"?"+s).then(function(e){return e.json()})];case 1:if((n=o.sent()).error)throw new VKError_1.VKError(n.error);return[2,utils_1.recursiveToCamelCase(n.response)]}})})};var r=e.requestsPerSecond,s=e.accessToken,n=e.version;this.accessToken=s||null,this.version=n||"5.122",this.requestsQueue=new RequestsQueue_1.RequestsQueue({requestsPerSecond:r,sendRequest:this.sendRequest}),this.users=new repositories_1.UsersRepository({processRequest:this.processRequest}),this.notifications=new repositories_1.NotificationsRepository({processRequest:this.processRequest}),this.messages=new repositories_1.MessagesRepository({processRequest:this.processRequest})}}();exports.VKAPI=VKAPI; | ||
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,s){function o(e){try{a(n.next(e))}catch(e){s(e)}}function u(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,u)}a((n=n.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var isomorphic_fetch_1=__importDefault(require("isomorphic-fetch")),VKError_1=require("../VKError"),EventEmitter_1=require("../EventEmitter"),utils_1=require("../utils"),repositories_1=require("../repositories"),VKAPI=function(){function e(e){var t=this;void 0===e&&(e={}),this.queue=[],this.isQueueProcessing=!1,this.eventEmitter=new EventEmitter_1.EventEmitter,this.accessToken=null,this.sendRequest=function(e){return __awaiter(t,void 0,void 0,function(){var t,r,n,i,s;return __generator(this,function(o){switch(o.label){case 0:return t=e.method,r=e.params,n=utils_1.recursiveToSnakeCase(__assign({v:this.v,accessToken:this.accessToken,lang:this.lang},r)),i=Object.keys(n).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(n[e])}).join("&"),[4,isomorphic_fetch_1.default("https://api.vk.com/method/"+t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:i})];case 1:return[4,o.sent().json()];case 2:if((s=o.sent()).error)throw new VKError_1.VKError(utils_1.recursiveToCamelCase(s.error));return[2,utils_1.recursiveToCamelCase(s.response)]}})})},this.addRequestToQueue=function(e){var r=Symbol();t.queue.push({config:e,ref:r});var n=new Promise(function(e,n){var i=function(s,o,u){if(r===s){if(t.eventEmitter.off("request-performed",i),o)return n(o);e(u)}};t.eventEmitter.on("request-performed",i)});return t.processQueue(),n};var r=e.rps,n=void 0===r?3:r,i=e.accessToken,s=e.v,o=void 0===s?"5.110":s,u=e.lang,a=void 0===u?"ru":u;this.accessToken=i||null,this.v=o,this.lang=a,this.timeout=Math.ceil(1e3/n),this.users=new repositories_1.UsersRepository(this.addRequestToQueue),this.messages=new repositories_1.MessagesRepository(this.addRequestToQueue),this.notifications=new repositories_1.NotificationsRepository(this.addRequestToQueue)}return e.prototype.processQueue=function(){return __awaiter(this,void 0,void 0,function(){var e=this;return __generator(this,function(t){switch(t.label){case 0:return this.isQueueProcessing||0===this.queue.length?[2]:(this.isQueueProcessing=!0,[4,Promise.all(this.queue.map(function(t,r){return new Promise(function(n){setTimeout(function(){return __awaiter(e,void 0,void 0,function(){var e,r,i,s,o;return __generator(this,function(u){switch(u.label){case 0:e=t.config,r=t.ref,i=null,s=null,u.label=1;case 1:return u.trys.push([1,3,,4]),[4,this.sendRequest(e)];case 2:return s=u.sent(),[3,4];case 3:return o=u.sent(),i=o,[3,4];case 4:return this.eventEmitter.emit("request-performed",r,i,s),this.queue.splice(this.queue.indexOf(t),1),n(),[2]}})})},r*e.timeout)})}))]);case 1:return t.sent(),this.isQueueProcessing=!1,this.processQueue(),[2]}})})},e}();exports.VKAPI=VKAPI; |
{ | ||
"name": "vkontakte-api", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"main": "dist/index.js", | ||
@@ -27,4 +27,4 @@ "types": "dist/index.d.ts", | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@types/event-emitter": "^0.3.3", | ||
"@types/isomorphic-fetch": "^0.0.35", | ||
"@types/isomorphic-form-data": "^2.0.0", | ||
"@types/node": "^13.13.5", | ||
@@ -48,6 +48,6 @@ "@typescript-eslint/eslint-plugin": "^2.31.0", | ||
"standard-version": "^8.0.0", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"event-emitter": "^0.3.5", | ||
"isomorphic-fetch": "^2.2.1" | ||
@@ -54,0 +54,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 4 instances in 1 package
52717
1
76
843
24
22
- Removedevent-emitter@^0.3.5
- Removedd@1.0.2(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@2.0.3(transitive)
- Removedes6-symbol@3.1.4(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removednext-tick@1.1.0(transitive)
- Removedtype@2.7.3(transitive)