Skip to content

Commit

Permalink
feat(type): define chat type
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 29, 2022
1 parent 4652d02 commit e4a345a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 15 deletions.
3 changes: 3 additions & 0 deletions core/type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"homepage": "https://github.com/AliMD/alwatr/tree/main/core/type#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
},
"dependencies": {
"@alwatr/storage-client": "~0.26.0"
}
}
2 changes: 1 addition & 1 deletion services/comment/src/lib/type.ts → core/type/src/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AlwatrDocumentObject} from '@alwatr/storage-client';

type CommonMessage = AlwatrDocumentObject & {
user: unknown;
from: unknown;
replyId?: string;
};

Expand Down
1 change: 1 addition & 0 deletions core/type/src/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './chat.js';
4 changes: 3 additions & 1 deletion core/type/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
// files, include and exclude from the inheriting config are always overwritten.
"include": ["src/**/*.ts"],
"exclude": [],
"references": []
"references": [
{"path": "../storage-client"}
]
}
4 changes: 3 additions & 1 deletion services/comment/src/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -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/chat.js';


export const storageClient = new AlwatrStorageClient<Message>(config.storage);
2 changes: 1 addition & 1 deletion services/comment/src/route/patch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +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, AlwatrServiceResponse} from '@alwatr/nano-server';
import type {Message} from '@alwatr/type/chat.js';

nanoServer.route('PATCH', '/', setComment);

Expand Down
9 changes: 9 additions & 0 deletions ui/demo-pwa/src/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {AlwatrDocumentStorage} from '@alwatr/storage-engine';
import type {TextMessage} from '@alwatr/type/chat.js';


declare global {
interface AlwatrSignals {
'comment-document-storage': AlwatrDocumentStorage<TextMessage>;
}
}
5 changes: 4 additions & 1 deletion ui/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
},
"dependencies": {
"@alwatr/element": "~0.26.0",
"@alwatr/fetch": "~0.26.0",
"@alwatr/fetch": "~0.26.0"
},
"devDependencies": {
"@alwatr/type": "~0.26.0",
"tslib": "~2.4.1"
}
}
7 changes: 3 additions & 4 deletions ui/ui-kit/src/chat/chat-list.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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/fetch/type.js';
import type {ChatMessage} from './chat-message.js';
import type {AlwatrDocumentStorage} from '@alwatr/fetch/type.js';

declare global {
interface HTMLElementTagNameMap {
'alwatr-chat-list': AlwatrChatList;
}
}

export type ChatMessage = AlwatrDocumentObject & _ChatMessage;
export type ChatStorage = AlwatrDocumentStorage<ChatMessage>;

export function* map<T>(
Expand Down Expand Up @@ -46,7 +45,7 @@ export class AlwatrChatList extends AlwatrDummyElement {
@property({type: Object, attribute: false})
storage?: ChatStorage;

@property({type: Object, attribute: false})
@property({type: String, attribute: false})
currentUser?: string;

override render(): unknown {
Expand Down
12 changes: 6 additions & 6 deletions ui/ui-kit/src/chat/chat-message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {AlwatrDummyElement, css, customElement, html, nothing, property, DirectionMixin} from '@alwatr/element';

import type {TextMessage} from '@alwatr/type/chat.js';

import './chat-avatar.js';
import './chat-bubble.js';

Expand All @@ -8,14 +11,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.
*
Expand Down Expand Up @@ -63,7 +63,7 @@ export class AlwatrChatMessage extends DirectionMixin(AlwatrDummyElement) {
`;

@property({type: Object, attribute: false})
message?: ChatTextMessage;
message?: ChatMessage;

@property({type: Boolean, attribute: 'self', reflect: true})
self = false;
Expand Down
1 change: 1 addition & 0 deletions ui/ui-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
{"path": "../element"},
{"path": "../icon"},
{"path": "../../core/fetch"},
{"path": "../../core/type"},
]
}

0 comments on commit e4a345a

Please sign in to comment.