From 5faa4dd1366acca160b6bd0043e993647d4ecb71 Mon Sep 17 00:00:00 2001 From: esindger Date: Sat, 20 Jul 2019 18:13:18 +0800 Subject: [PATCH] Bump to 1.2.0 --- package-lock.json | 64 +++++++++++++++++++++---------------------- package.json | 6 ++-- src/ChatModel.ts | 6 ++-- src/ChatRepository.ts | 26 ++++++++++++------ src/context.ts | 8 +++--- src/index.ts | 4 +-- 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ee1b6a..4bf4d31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,29 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@airgram/api": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@airgram/api/-/api-1.2.0.tgz", + "integrity": "sha512-cbB6P3agVqVdYceUvmBQ6oMYSA1ltz3EC9aRvvabSpBbKIxVbGyFBsvY69zxy1CH+YonDVikHlzS5Qvd1BHdsQ==" + }, + "@airgram/core": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@airgram/core/-/core-1.2.1.tgz", + "integrity": "sha512-okAh7K6YWZ6MBBEKSalKJDD3es/LGNdYypUufGFOTu/lrt4nrsd/iFqlRlXzS15/8byWD381/5ukizdIg8dwwg==", + "requires": { + "@airgram/api": "^1.2.0" + } + }, + "@airgram/use-models": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@airgram/use-models/-/use-models-1.2.0.tgz", + "integrity": "sha512-a7f179M5Kp+6Hvbzw7H2MkY+K5Z5HVnosnSmUnRD3Y/iZUqEnUx52MsIT1AHY1okoSxm+jXQI9DNb9CagOCO6w==", + "requires": { + "@airgram/api": "^1.2.0", + "class-transformer": "^0.2.3", + "reflect-metadata": "^0.1.13" + } + }, "@babel/code-frame": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", @@ -102,37 +125,14 @@ "dev": true }, "airgram": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/airgram/-/airgram-1.1.2.tgz", - "integrity": "sha512-JtRi80xVpYXMgRfihl1sSCRuz/Q7DhV2TzBA9bLg4G5j6vsrYZo2/sdybdtk5LKJtLFsUXgonapvBrE6oj3QUg==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/airgram/-/airgram-1.2.0.tgz", + "integrity": "sha512-tKgzIW1dGE83DS2rloLwmA1apPzNRzgBNowtJvKFTWVqG9HADUvUSXhPv+TTAx8eFQ44ci3oS3FnruiPMlGaxA==", "requires": { - "airgram-api": "^1.1.2", - "airgram-core": "^1.1.5", + "@airgram/api": "^1.2.0", + "@airgram/core": "^1.2.0", "ffi-napi": "^2.4.5", - "lodash": "^4.17.11" - } - }, - "airgram-api": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/airgram-api/-/airgram-api-1.1.2.tgz", - "integrity": "sha512-qdRtUz3xmn9Y7la4lR7nAL8cTdoHTUx5p1c81yA7pSR8enuvmqhQVjjFu4JO9AyABhdSX1pAHntx47N0O3eilA==" - }, - "airgram-core": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/airgram-core/-/airgram-core-1.1.5.tgz", - "integrity": "sha512-XBKJ+5z0nEOV+gcwgCfallneZ06X8v/UOHqFTAoeVRdtzgIeu6FlnkET+kmIR1dW5XRxpT0GkDgYu2Ax8tfnjA==", - "requires": { - "airgram-api": "^1.1.2" - } - }, - "airgram-use-models": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/airgram-use-models/-/airgram-use-models-1.1.0.tgz", - "integrity": "sha512-phz34V7p1240hotZ5k4Gsx0yIvqa2jGNN9vZqwk2r7fzBY9v9HqSJIQYHKrUdnPBgzGP7a8Dxc8EyeKqhq7kgQ==", - "requires": { - "airgram-api": "^1.0.4", - "class-transformer": "^0.2.3", - "reflect-metadata": "^0.1.13" + "lodash": "^4.17.15" } }, "ajv": { @@ -3258,9 +3258,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.zip": { "version": "4.2.0", diff --git a/package.json b/package.json index 8eaaaf7..18b327a 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "license": "GPL-3.0", "repository": "https://github.com/airgram/airgram-ts-example", "dependencies": { - "airgram": "^1.1.2", - "airgram-api": "^1.1.2", - "airgram-use-models": "^1.1.0" + "@airgram/api": "^1.2.0", + "@airgram/use-models": "^1.2.0", + "airgram": "^1.2.0" }, "devDependencies": { "@types/node": "^12.0.10", diff --git a/src/ChatModel.ts b/src/ChatModel.ts index 89aa970..138c5a5 100644 --- a/src/ChatModel.ts +++ b/src/ChatModel.ts @@ -1,5 +1,5 @@ -import { CHAT_TYPE } from 'airgram-api' -import { ChatBaseModel } from 'airgram-use-models' +import { CHAT_TYPE } from '@airgram/api' +import { ChatBaseModel } from '@airgram/use-models' export default class ChatModel extends ChatBaseModel { get isBasicGroup (): boolean { @@ -20,6 +20,6 @@ export default class ChatModel extends ChatBaseModel { } // tslint:disable:no-empty-interface -declare module 'airgram-api/outputs/Chat' { +declare module '@airgram/api/outputs/Chat' { export interface Chat extends ChatModel {} } diff --git a/src/ChatRepository.ts b/src/ChatRepository.ts index 7c750ee..2b78435 100644 --- a/src/ChatRepository.ts +++ b/src/ChatRepository.ts @@ -1,11 +1,10 @@ -import { ag } from 'airgram' -import { UPDATE } from 'airgram-api' +import { UPDATE } from '@airgram/api' import ChatModel from './ChatModel' export default class ChatRepository { private chatMap: Map - constructor (private airgram: ag.Airgram) { + constructor (private airgram: Airgram.AirgramInstance) { this.chatMap = new Map() // Add new chats to the store @@ -30,7 +29,11 @@ export default class ChatRepository { public async isMe (id: number): Promise { const chat = this.get(id) if (chat && 'userId' in chat.type) { - return (await this.airgram.api.getMe()).id === chat.type.userId + const me = await this.airgram.api.getMe() + if (me._ === 'error') { + throw new Error(me.message) + } + return me.id === chat.type.userId } return false } @@ -39,10 +42,15 @@ export default class ChatRepository { this.chatMap.set(id, chat) } - private fetch (id: number): Promise { - return this.airgram.api.getChat({ chatId: id }).then((chat) => { - this.chatMap.set(id, chat) - return chat - }) + private async fetch (id: number): Promise { + const chatOrError = await this.airgram.api.getChat({ chatId: id }) + + if (chatOrError._ === 'error') { + throw new Error(chatOrError.message) + } else { + this.chatMap.set(id, chatOrError) + } + + return chatOrError } } diff --git a/src/context.ts b/src/context.ts index ba4d7d3..0883989 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,14 +1,14 @@ -import { ag, createContext } from 'airgram' +import { createContext } from 'airgram' import ChatRepository from './ChatRepository' -export interface Context extends ag.Context { +export interface Context extends Airgram.Context { chats: ChatRepository } -export const contextFactory: ag.ContextFactory = (airgram: ag.Airgram) => { +export const contextFactory: Airgram.ContextFactory = (airgram: Airgram.AirgramInstance) => { const chats = new ChatRepository(airgram) - return (options: ag.ContextOptions) => ({ + return (options: Airgram.ContextOptions) => ({ ...createContext(options), chats }) diff --git a/src/index.ts b/src/index.ts index 1a27b6a..b5da498 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ +import { UPDATE } from '@airgram/api' +import { useModels } from '@airgram/use-models' import { Airgram, Auth, prompt } from 'airgram' -import { UPDATE } from 'airgram-api' -import { useModels } from 'airgram-use-models' import ChatModel from './ChatModel' import { Context, contextFactory } from './context'