From 174fb02fe287c6fee6e9783f91dfa1928dbaf2ce Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 29 Dec 2022 10:55:26 +0330 Subject: [PATCH] feat(type): define chat type --- .../comment/src/lib/type.ts => core/type/src/chat.ts | 4 ++-- core/type/src/type.ts | 1 + services/comment/src/lib/storage.ts | 4 +++- services/comment/src/route/patch.ts | 3 +-- ui/demo-pwa/src/director/comment-list.ts | 1 - ui/demo-pwa/src/type.ts | 12 ++++-------- ui/ui-kit/src/chat/chat-list.ts | 5 ++--- ui/ui-kit/src/chat/chat-message.ts | 11 +++++------ 8 files changed, 18 insertions(+), 23 deletions(-) rename services/comment/src/lib/type.ts => core/type/src/chat.ts (80%) diff --git a/services/comment/src/lib/type.ts b/core/type/src/chat.ts similarity index 80% rename from services/comment/src/lib/type.ts rename to core/type/src/chat.ts index ebfcd4980..8b8c151d1 100644 --- a/services/comment/src/lib/type.ts +++ b/core/type/src/chat.ts @@ -1,7 +1,7 @@ -import {AlwatrDocumentObject} from '@alwatr/type'; +import type {AlwatrDocumentObject} from './storage.js'; type CommonMessage = AlwatrDocumentObject & { - user: unknown; + from: unknown; replyId?: string; }; diff --git a/core/type/src/type.ts b/core/type/src/type.ts index e8232aed2..81fa3560e 100644 --- a/core/type/src/type.ts +++ b/core/type/src/type.ts @@ -2,6 +2,7 @@ export * from './storage.js'; export * from './service.js'; export * from './alwatr.js'; export * from './math.js'; +export * from './chat.js'; // FIXME: export type MaybePromise = T | Promise diff --git a/services/comment/src/lib/storage.ts b/services/comment/src/lib/storage.ts index a7fe7c4e9..6e8bdc801 100644 --- a/services/comment/src/lib/storage.ts +++ b/services/comment/src/lib/storage.ts @@ -1,6 +1,8 @@ import {AlwatrStorageClient} from '@alwatr/storage-client'; import {config} from '../config.js'; -import {Message} from './type.js'; + +import type {Message} from '@alwatr/type'; + export const storageClient = new AlwatrStorageClient(config.storage); diff --git a/services/comment/src/route/patch.ts b/services/comment/src/route/patch.ts index e00b6f252..8f402b9de 100644 --- a/services/comment/src/route/patch.ts +++ b/services/comment/src/route/patch.ts @@ -1,10 +1,9 @@ import {config, logger} from '../config.js'; import {nanoServer} from '../lib/nano-server.js'; import {storageClient} from '../lib/storage.js'; -import {Message} from '../lib/type.js'; import type {AlwatrConnection} from '@alwatr/nano-server'; -import type {AlwatrServiceResponse} from '@alwatr/type'; +import type {Message, AlwatrServiceResponse} from '@alwatr/type'; nanoServer.route('PATCH', '/', setComment); diff --git a/ui/demo-pwa/src/director/comment-list.ts b/ui/demo-pwa/src/director/comment-list.ts index c7011f778..80cdecd84 100644 --- a/ui/demo-pwa/src/director/comment-list.ts +++ b/ui/demo-pwa/src/director/comment-list.ts @@ -7,7 +7,6 @@ import type {AlwatrDocumentStorage} from '@alwatr/type'; export const commentDocumentStorageSignal = new SignalInterface('comment-document-storage'); - async function requestCommentStorage(cacheStrategy: CacheStrategy): Promise { // logger.logMethod('jobListProvider'); console.log('jobListProvider'); diff --git a/ui/demo-pwa/src/type.ts b/ui/demo-pwa/src/type.ts index c93478802..827cde273 100644 --- a/ui/demo-pwa/src/type.ts +++ b/ui/demo-pwa/src/type.ts @@ -1,4 +1,6 @@ -import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/type'; +import {TextMessage} from '@alwatr/type'; + +import type {AlwatrDocumentStorage} from '@alwatr/type'; declare global { interface AlwatrSignals { @@ -6,12 +8,6 @@ declare global { } } -export type ChatTextMessage = { +export type ChatMessage = TextMessage & { from: string; - type: 'text'; - text: string; }; - -export type _ChatMessage = ChatTextMessage; // TODO: ChatPhotoMessage - -export type ChatMessage = AlwatrDocumentObject & _ChatMessage; diff --git a/ui/ui-kit/src/chat/chat-list.ts b/ui/ui-kit/src/chat/chat-list.ts index c94c6141f..8687fd2e8 100644 --- a/ui/ui-kit/src/chat/chat-list.ts +++ b/ui/ui-kit/src/chat/chat-list.ts @@ -1,8 +1,8 @@ import {AlwatrDummyElement, css, customElement, html, nothing, property} from '@alwatr/element'; import './chat-message.js'; -import type {ChatMessage as _ChatMessage} from './chat-message.js'; -import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/type'; +import type {ChatMessage} from './chat-message.js'; +import type {AlwatrDocumentStorage} from '@alwatr/type'; declare global { interface HTMLElementTagNameMap { @@ -10,7 +10,6 @@ declare global { } } -export type ChatMessage = AlwatrDocumentObject & _ChatMessage; export type ChatStorage = AlwatrDocumentStorage; export function* map( diff --git a/ui/ui-kit/src/chat/chat-message.ts b/ui/ui-kit/src/chat/chat-message.ts index 10a19c9c6..41b5f196b 100644 --- a/ui/ui-kit/src/chat/chat-message.ts +++ b/ui/ui-kit/src/chat/chat-message.ts @@ -1,4 +1,6 @@ import {AlwatrDummyElement, css, customElement, html, nothing, property} from '@alwatr/element'; + +import type {TextMessage} from '@alwatr/type'; import './chat-avatar.js'; import './chat-bubble.js'; @@ -8,14 +10,11 @@ declare global { } } -export type ChatTextMessage = { +// TODO: ChatPhotoMessage +export type ChatMessage = TextMessage & { from: string; - type: 'text'; - text: string; }; -export type ChatMessage = ChatTextMessage; // TODO: ChatPhotoMessage - /** * Alwatr chat message box element. * @@ -63,7 +62,7 @@ export class AlwatrChatMessage extends AlwatrDummyElement { `; @property({type: Object, attribute: false}) - message?: ChatTextMessage; + message?: ChatMessage; @property({type: Boolean, attribute: 'self', reflect: true}) self = false;