adding aggregating interfaces

This commit is contained in:
balzack 2024-07-01 22:46:44 -07:00
parent b51e3c82e6
commit 9d76ab40c6
9 changed files with 257 additions and 43 deletions

View File

@ -1,8 +1,10 @@
import { DatabagSDK } from '../src/index';
import { type SessionParams } from '../src/types';
test('allocates session correctly', async () => {
const sdk = new DatabagSDK();
const session = await sdk.login('handle', 'password', 'url');
const params: SessionParams = { initialTopicCount: 0, channelTypes: [], topicTypes: [], tagTypes: [] };
const session = await sdk.login('handle', 'password', 'url', params);
const account = session.getAccount();
account.setNotifications(true);
//expect(r).toBe(5);

View File

@ -91,16 +91,21 @@ export interface Contact {
removeChannel(cardId: string, channelId: string): Promise<void>;
addTopic(cardId: string, channelId: string, type: string, message: string, assets: Asset[]): Promise<string>;
removeTopic(cardId: string, channelId: string, topicId: string): Promise<void>;
setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise<void>;
addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise<string>;
removeTag(cardId: string, tagId: string): Promise<void>;
setTopicSubject(cardId: string, channelId: string, topicId: string, subject: string): Promise<void>;
addTag(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise<string>;
removeTag(cardId: string, topicId: string, tagId: string): Promise<void>;
setTagSubject(cardId: string, topicId: string, tagId: string, subject: string): Promise<void>;
getTopics(cardId: string, channelId: string): Promise<Topic[]>;
getMoreTopics(cardId: string, channelId: string): Promise<Topic[]>;
getTags(cardId: string, channelId: string, topicId: string): Promise<Tag[]>;
getMoreTags(cardId: string, channelId: string, topicId: string): Promise<Tag[]>;
viewMoreTopics(cardId: string, channelId: string): Promise<number>;
setUnreadChannel(cardId: string, channelId: string): Promise<void>;
clearUnreadChannel(cardId: string, channelId: string): Promise<void>;
getRegistry(server: string): Promise<Profile[]>;
getRegistryImageUrl(server: string, string: guid): string;
getRegistryImageUrl(server: string, guid: string): string;
getCardImageUrl(cardId: string): string;
getTopicAssetUrl(cardId: string, channelId: string, topicId: string, assetId: string): string;
@ -125,9 +130,9 @@ export interface Alias {
}
export interface Attribute {
addArticle(type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string>;
addArticle(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string>;
removeArticle(articleId: string): Promise<void>;
setArticleSubject(articleId: string, type: string, subject: string): Promise<void>;
setArticleSubject(articleId: string, subject: string): Promise<void>;
setArticleCard(articleId: string, cardId: string): Promise<void>;
clearArticleCard(articleId: string, cardId: string): Promise<void>;
setArticleGroup(articleId: string, groupId: string): Promise<void>;
@ -138,18 +143,19 @@ export interface Attribute {
}
export interface Content {
addChannel(type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string>;
addChannel(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string>;
removeChannel(channelId: string): Promise<void>;
setChannelSubject(channelId: string, type: string, subject: string): Promise<void>;
setChannelSubject(channelId: string, subject: string): Promise<void>;
setChannelCard(channelId: string, cardId: string): Promise<void>;
clearChannelCard(channelId: string, cardId: string): Promise<void>;
setChannelGroup(channelId: string, cardId: string): Promise<void>;
clearChannelGroup(channelId: string, cardId: string): Promise<void>;
addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise<string>;
removeTopic(channelId: string, topicId: string): Promise<void>;
setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise<void>;
setTopicSubject(channelId: string, topicId: string, subject: string): Promise<void>;
addTag(channelId: string, topicId: string, type: string, value: string): Promise<string>;
removeTag(channelId: string, topicId: string, tagId: string): Promise<void>;
setTagSubject(channelId: string, topicId: string, tagId: string, subject: string): Promise<void>;
getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string;
flagTopic(channelId: string, topicId: string): Promise<void>;
@ -161,7 +167,11 @@ export interface Content {
getBlockedTopics(): Promise<{ channelId: string, topicId: string }[]>;
getBlockedTags(): Promise<{ channelId: string, topicId: string, tagId: string }[]>;
viewMoreTopics(channelId: string): Promise<number>;
getTopics(channelId: string): Promise<Topic[]>;
getMoreTopics(channelId: string): Promise<Topic[]>;
getTags(channelId: string, topicId: string): Promise<Tag[]>;
getMoreTags(channelId: string, topicId: string): Promise<Tag[]>;
setUnreadChannel(channelId: string): Promise<void>;
clearUnreadChannel(channelId: string): Promise<void>;
@ -172,6 +182,43 @@ export interface Content {
removeChannelListener(ev: (channels: Channel[]) => void): void;
}
export interface Stream {
addChannelListener(ev: (channels: Channel[]) => void): void;
removeChannelListener(ev: (channels: Channel[]) => void): void;
}
export interface Focus {
blur(): void;
addTopic(type: string, message: string, assets: Asset[]): Promise<string>;
removeTopic(topicId: string): Promise<void>;
setTopicSubject(topicId: string, subject: string): Promise<void>;
addTag(topicId: string, type: string, subject: string): Promise<string>;
removeTag(cardId: string, tagId: string): Promise<void>;
setTagSubject(topicId: string, tagId: string, subject: string): Promise<void>;
viewMoreTopics(): Promise<void>;
viewMoreTags(topicId: string): Promise<void>;
setUnreadChannel(cardId: string, channelId: string): Promise<void>;
clearUnreadChannel(cardId: string, channelId: string): Promise<void>;
getTopicAssetUrl(topicId: string, assetId: string): string;
addRepeaterAccess(name: string): Promise<Repeater>;
removeRepeaterAccess(repeaterId: string): Promise<void>;
flagTopic(topicId: string): Promise<void>;
flagTag(topicId: string, tagId: string): Promise<void>;
setBlockTopic(topicId: string): Promise<void>;
setBlockTag(topicId: string, tagId: string): Promise<void>;
clearBlockTopic(topicId: string): Promise<void>;
clearBlockTag(topicId: string, tagId: string): Promise<void>;
addTopicListener(ev: (topics: Topic[]) => void): void;
removeTopicListener(ev: (topics: Topic[]) => void): void;
}
export interface Node {
getAccounts(): Promise<NodeAccount[]>;
createAccountAccess(): Promise<string>;

View File

@ -1,5 +1,5 @@
import { EventEmitter } from 'events';
import { type Attribute } from './api';
import type { Attribute, Account } from './api';
import type { Article } from './types';
export class AttributeModule implements Attribute {
@ -7,12 +7,14 @@ export class AttributeModule implements Attribute {
private token: string;
private url: string;
private sync: (flag: boolean) => void;
private account: Account;
private emitter: EventEmitter;
constructor(token: string, url: string, sync: (flag: boolean) => void) {
constructor(token: string, url: string, sync: (flag: boolean) => void, account: Account) {
this.token = token;
this.url = url;
this.sync = sync;
this.account = account;
this.emitter = new EventEmitter();
}
@ -30,14 +32,14 @@ export class AttributeModule implements Attribute {
public async resync(): Promise<void> {
}
public async addArticle(type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
public async addArticle(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
return '';
}
public async removeArticle(articleId: string): Promise<void> {
}
public async setArticleSubject(articleId: string, type: string, subject: string): Promise<void> {
public async setArticleSubject(articleId: string, subject: string): Promise<void> {
}
public async setArticleCard(articleId: string, cardId: string): Promise<void> {

View File

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { type Contact } from './api';
import { type Card, type Topic, type Asset, type Profile, type Repeater} from './types';
import type { Contact } from './api';
import type { Card, Topic, Asset, Tag, Profile, Repeater} from './types';
export class ContactModule implements Contact {
@ -133,18 +133,33 @@ export class ContactModule implements Contact {
public async removeTopic(cardId: string, channelId: string, topicId: string): Promise<void> {
}
public async setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise<void> {
public async setTopicSubject(cardId: string, channelId: string, topicId: string, subject: string): Promise<void> {
}
public async addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise<string> {
return '';
}
public async removeTag(cardId: string, tagId: string): Promise<void> {
public async removeTag(cardId: string, topicId: string, tagId: string): Promise<void> {
}
public async viewMoreTopics(cardId: string, channelId: string): Promise<number> {
return 0;
public async setTagSubject(cardId: string, topicId: string, tagId: string, subject: string): Promise<void> {
}
public async getTopics(cardId: string, channelId: string): Promise<Topic[]> {
return [];
}
public async getMoreTopics(cardId: string, channelId: string): Promise<Topic[]> {
return [];
}
public async getTags(cardId: string, channelId: string, topicId: string): Promise<Tag[]> {
return [];
}
public async getMoreTags(cardId: string, channelId: string, topicId: string): Promise<Tag[]> {
return [];
}
public async setUnreadChannel(cardId: string, channelId: string): Promise<void> {
@ -153,11 +168,11 @@ export class ContactModule implements Contact {
public async clearUnreadChannel(cardId: string, channelId: string): Promise<void> {
}
public getRegistry(server: string): Promise<Profile[]> {
public async getRegistry(server: string): Promise<Profile[]> {
return [];
}
public getRegistryImageUrl(server: string, string: guid): string {
public getRegistryImageUrl(server: string, guid: string): string {
return '';
}

View File

@ -1,18 +1,20 @@
import { EventEmitter } from 'events';
import { type Content } from './api';
import type { Channel, Topic, Asset, Repeater } from './types';
import type { Content, Account } from './api';
import type { Channel, Topic, Asset, Tag, Repeater } from './types';
export class ContentModule implements Content {
private token: string;
private url: string;
private sync: (flag: boolean) => void;
private account: Account;
private emitter: EventEmitter;
constructor(token: string, url: string, sync: (flag: boolean) => void) {
constructor(token: string, url: string, sync: (flag: boolean) => void, account: Account) {
this.token = token;
this.url = url;
this.sync = sync;
this.account = account;
this.emitter = new EventEmitter();
}
@ -30,14 +32,14 @@ export class ContentModule implements Content {
public async resync(): Promise<void> {
}
public async addChannel(type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
public async addChannel(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
return '';
}
public async removeChannel(channelId: string): Promise<void> {
}
public async setChannelSubject(channelId: string, type: string, subject: string): Promise<void> {
public async setChannelSubject(channelId: string, subject: string): Promise<void> {
}
public async setChannelCard(channelId: string, cardId: string): Promise<void> {
@ -52,7 +54,7 @@ export class ContentModule implements Content {
public async clearChannelGroup(channelId: string, groupId: string): Promise<void> {
}
public async addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise<string> {
public async addTopic(channelId: string, type: string, subject: string, assets: Asset[]): Promise<string> {
return '';
}
@ -62,7 +64,7 @@ export class ContentModule implements Content {
public async flagTopic(channelId: string, topicId: string): Promise<void> {
}
public async setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise<void> {
public async setTopicSubject(channelId: string, topicId: string, subject: string): Promise<void> {
}
public async addTag(channelId: string, topicId: string, type: string, value: string): Promise<string> {
@ -72,6 +74,9 @@ export class ContentModule implements Content {
public async removeTag(channelId: string, topicId: string, tagId: string): Promise<void> {
}
public async setTagSubject(channelId: string, topicId: string, tagId: string, subject: string): Promise<void> {
}
public async flagTag(channelId: string, topicId: string, tagId: string): Promise<void> {
}
@ -99,14 +104,26 @@ export class ContentModule implements Content {
return '';
}
public async viewMoreTopics(cardId: string, channelId: string): Promise<number> {
return 0;
public async getTopics(channelId: string): Promise<Topic[]> {
return [];
}
public async setUnreadChannel(cardId: string, channelId: string): Promise<void> {
public async getMoreTopics(channelId: string): Promise<Topic[]> {
return [];
}
public async clearUnreadChannel(cardId: string, channelId: string): Promise<void> {
public async getTags(channelId: string, topicId: string): Promise<Tag[]> {
return [];
}
public async getMoreTags(channelId: string, topicId: string): Promise<Tag[]> {
return [];
}
public async setUnreadChannel(channelId: string): Promise<void> {
}
public async clearUnreadChannel(channelId: string): Promise<void> {
}
public async addRepeaterAccess(channelId: string, name: string): Promise<Repeater> {

93
app/sdk/src/focus.ts Normal file
View File

@ -0,0 +1,93 @@
import { EventEmitter } from 'events';
import type { Identity, Contact, Content, Focus } from './api';
import type { Topic, Asset, Repeater } from './types';
export class FocusModule implements Focus {
private identity: Identity;
private contact: Contact;
private content: Content;
private cardId?: string;
private channelId: string;
private emitter: EventEmitter;
constructor(identity: Identity, contact: Contact, content: Content, channelId: string, cardId?: string) {
this.identity = identity;
this.contact = contact;
this.content = content;
this.cardId = cardId;
this.channelId = channelId;
this.emitter = new EventEmitter();
}
public blur(): void {
}
public async addTopic(type: string, message: string, assets: Asset[]): Promise<string> {
return '';
}
public async removeTopic(topicId: string): Promise<void> {
}
public async setTopicSubject(topicId: string, subject: string): Promise<void> {
}
public async addTag(topicId: string, type: string, subject: string): Promise<string> {
return '';
}
public async removeTag(cardId: string, tagId: string): Promise<void> {
}
public async setTagSubject(topicId: string, tagId: string, subject: string): Promise<void> {
}
public async viewMoreTopics(): Promise<void> {
}
public async viewMoreTags(topicId: string): Promise<void> {
}
public async setUnreadChannel(cardId: string, channelId: string): Promise<void> {
}
public async clearUnreadChannel(cardId: string, channelId: string): Promise<void> {
}
public getTopicAssetUrl(topicId: string, assetId: string): string {
return '';
}
public async addRepeaterAccess(name: string): Promise<Repeater> {
return { id: '', guid: '', name: '', server: '', token: '' };
}
public async removeRepeaterAccess(repeaterId: string): Promise<void> {
}
public async flagTopic(topicId: string): Promise<void> {
}
public async flagTag(topicId: string, tagId: string): Promise<void> {
}
public async setBlockTopic(topicId: string): Promise<void> {
}
public async setBlockTag(topicId: string, tagId: string): Promise<void> {
}
public async clearBlockTopic(topicId: string): Promise<void> {
}
public async clearBlockTag(topicId: string, tagId: string): Promise<void> {
}
public addTopicListener(ev: (topics: Topic[]) => void): void {
}
public removeTopicListener(ev: (topics: Topic[]) => void): void {
}
}

View File

@ -6,8 +6,10 @@ import { ContactModule } from './contact';
import { AliasModule } from './alias';
import { AttributeModule } from './attribute';
import { ContentModule } from './content';
import { StreamModule } from './stream';
import { FocusModule } from './focus';
import { type Session, type SqlStore, type WebStore, type Account, type Identity, type Contact, type Alias, type Attribute, type Content } from './api';
import type { Session, SqlStore, WebStore, Account, Identity, Contact, Alias, Attribute, Content, Stream, Focus } from './api';
export class SessionModule implements Session {
@ -23,6 +25,7 @@ export class SessionModule implements Session {
public alias: AliasModule;
public attribute: AttributeModule;
public content: ContentModule;
public stream: StreamModule;
constructor(store: SqlStore | WebStore | null, token: string, url: string) {
this.store = store;
@ -34,8 +37,9 @@ export class SessionModule implements Session {
this.identity = new IdentityModule(token, url, this.setSync);
this.contact = new ContactModule(token, url, this.setSync);
this.alias = new AliasModule(token, url, this.setSync);
this.attribute = new AttributeModule(token, url, this.setSync);
this.content = new ContentModule(token, url, this.setSync);
this.attribute = new AttributeModule(token, url, this.setSync, this.account);
this.content = new ContentModule(token, url, this.setSync, this.account);
this.stream = new StreamModule(this.contact, this.content);
}
public addStatusListener(ev: (status: string) => void): void {
@ -77,4 +81,12 @@ export class SessionModule implements Session {
public getContent(): Content {
return this.content;
}
public getStream(): Stream {
return this.stream;
}
public getFocus(channelId: string, cardId?: string): Focus {
return new FocusModule(this.identity, this.contact, this.content, channelId, cardId);
}
}

25
app/sdk/src/stream.ts Normal file
View File

@ -0,0 +1,25 @@
import { EventEmitter } from 'events';
import type { Contact, Content, Stream } from './api';
import type { Channel } from './types';
export class StreamModule implements Stream {
private contact: Contact;
private content: Content;
private emitter: EventEmitter;
constructor(contact: Contact, content: Content) {
this.contact = contact;
this.content = content;
this.emitter = new EventEmitter();
}
public addChannelListener(ev: (channels: Channel[]) => void): void {
this.emitter.on('channel', ev);
}
public removeChannelListener(ev: (channels: Channel[]) => void): void {
this.emitter.off('channel', ev);
}
}

View File

@ -16,7 +16,7 @@ export type Card = {
export type Channel = {
id: string,
guid: string,
cardId?: string,
lastTopic: {
guid: string,
dataType: string,
@ -27,6 +27,7 @@ export type Channel = {
transform: string
}
unread: boolean,
sealed: boolean,
dataType: string,
data: string,
created: number,
@ -55,7 +56,7 @@ export type Topic = {
updated: number,
status: string,
transform: string,
tags: [ Tag ]
tags: Tag[]
}
export type Tag = {
@ -78,7 +79,7 @@ export type Group = {
data: string,
created: number,
updated: number,
cards: [ string ]
cards: string[]
}
export type Article = {
@ -88,8 +89,8 @@ export type Article = {
created: number,
updated: number,
contacts?: {
cards: [ string ],
groups: [ string ],
cards: string[],
groups: string[],
}
}