From 8f91be0b49abc5c07588aaaf9a297272c5ebe47f Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Fri, 21 Jun 2024 22:52:15 -0700 Subject: [PATCH] partitioning sdk api --- app/sdk/src/account.ts | 7 ++++ app/sdk/src/accountSession.ts | 14 ------- app/sdk/src/admin.ts | 14 +++++++ app/sdk/src/adminSession.ts | 5 --- app/sdk/src/attribute.ts | 7 ++++ app/sdk/src/channel.ts | 7 ++++ app/sdk/src/contact.ts | 7 ++++ app/sdk/src/group.ts | 7 ++++ app/sdk/src/index.ts | 39 ++++++++++--------- app/sdk/src/profile.ts | 7 ++++ app/sdk/src/user.ts | 70 +++++++++++++++++++++++++++++++++++ app/sdk/tsup.config.ts | 2 +- 12 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 app/sdk/src/account.ts delete mode 100644 app/sdk/src/accountSession.ts create mode 100644 app/sdk/src/admin.ts delete mode 100644 app/sdk/src/adminSession.ts create mode 100644 app/sdk/src/attribute.ts create mode 100644 app/sdk/src/channel.ts create mode 100644 app/sdk/src/contact.ts create mode 100644 app/sdk/src/group.ts create mode 100644 app/sdk/src/profile.ts create mode 100644 app/sdk/src/user.ts diff --git a/app/sdk/src/account.ts b/app/sdk/src/account.ts new file mode 100644 index 00000000..61e84568 --- /dev/null +++ b/app/sdk/src/account.ts @@ -0,0 +1,7 @@ +export interface Account { +} + +export class AccountModule implements Account { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/accountSession.ts b/app/sdk/src/accountSession.ts deleted file mode 100644 index 20100331..00000000 --- a/app/sdk/src/accountSession.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { SqlStore } from './index'; -import { WebStore } from './index'; - -export class AccountSession { - - private sqlStore: SqlStore | null = null; - private webStore: WebStore | null = null; - - constructor(sql: SqlStore | null, web: WebStore | null) { - this.sqlStore = sql; - this.webStore = web; - } - -} diff --git a/app/sdk/src/admin.ts b/app/sdk/src/admin.ts new file mode 100644 index 00000000..f04aa567 --- /dev/null +++ b/app/sdk/src/admin.ts @@ -0,0 +1,14 @@ +export interface Admin { +} + +export class AdminModule implements Admin { + + private token: string; + private url: string; + + constructor(token: string, url: string) { + this.token = token; + this.url = url; + } + +} diff --git a/app/sdk/src/adminSession.ts b/app/sdk/src/adminSession.ts deleted file mode 100644 index 2b949e72..00000000 --- a/app/sdk/src/adminSession.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class AdminSession { - - constructor() { } - -} diff --git a/app/sdk/src/attribute.ts b/app/sdk/src/attribute.ts new file mode 100644 index 00000000..915f59f3 --- /dev/null +++ b/app/sdk/src/attribute.ts @@ -0,0 +1,7 @@ +export interface Attribute { +} + +export class AttributeModule implements Attribute { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/channel.ts b/app/sdk/src/channel.ts new file mode 100644 index 00000000..cbeade4c --- /dev/null +++ b/app/sdk/src/channel.ts @@ -0,0 +1,7 @@ +export interface Channel { +} + +export class ChannelModule implements Channel { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts new file mode 100644 index 00000000..d540d1dd --- /dev/null +++ b/app/sdk/src/contact.ts @@ -0,0 +1,7 @@ +export interface Contact { +} + +export class ContactModule implements Contact { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/group.ts b/app/sdk/src/group.ts new file mode 100644 index 00000000..698fa9cd --- /dev/null +++ b/app/sdk/src/group.ts @@ -0,0 +1,7 @@ +export interface Group { +} + +export class GroupModule implements Group { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index 596a8828..d4bfe723 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -1,5 +1,5 @@ -import { AccountSession } from './accountSession'; -import { AdminSession } from './adminSession'; +import { type User, UserModule } from './user'; +import { type Admin, AdminModule } from './admin'; export interface SqlStore { set(stmt: string, params: (string | number)[]): Promise; @@ -15,44 +15,43 @@ export interface WebStore { export class DatabagSDK { - private sqlStore: SqlStore | null = null; - private webStore: WebStore | null = null; + private store: SqlStore | WebStore | null = null; constructor() { console.log("databag sdk"); } - public async initOfflineStore(sql: SqlStore): Promise { - this.sqlStore = sql; + public async initOfflineStore(sql: SqlStore): Promise { + this.store = sql; // initialize - return new AccountSession(this.sqlStore, this.webStore); + return new UserModule(this.store, '', ''); } - public async initOnlineStore(web: WebStore): Promise { - this.webStore = web; + public async initOnlineStore(web: WebStore): Promise { + this.store = web; // initialize - return new AccountSession(this.sqlStore, this.webStore); + return new UserModule(this.store, '', ''); } - public async accountLogin(): Promise { - return new AccountSession(this.sqlStore, this.webStore); + public async userLogin(handle: string, password: string, url: string): Promise { + return new UserModule(this.store, '', ''); } - public async accountAccess(): Promise { - return new AccountSession(this.sqlStore, this.webStore); + public async userAccess(token: string, url: string): Promise { + return new UserModule(this.store, '', ''); } - public async accountCreate(): Promise { - return new AccountSession(this.sqlStore, this.webStore); + public async userCreate(handle: string, password: string, url: string, token: string): Promise { + return new UserModule(this.store, '', ''); } - public async accountLogout(session: AccountSession): Promise { + public async userLogout(session: User): Promise { } - public async adminLogin(): Promise { - return new AdminSession(); + public async adminLogin(token: string, url: string): Promise { + return new AdminModule('', ''); } - public async adminLogout(session: AdminSession): Promise { + public async adminLogout(session: Admin): Promise { } } diff --git a/app/sdk/src/profile.ts b/app/sdk/src/profile.ts new file mode 100644 index 00000000..bb8da87a --- /dev/null +++ b/app/sdk/src/profile.ts @@ -0,0 +1,7 @@ +export interface Profile { +} + +export class ProfileModule implements Profile { + constructor(token: string, url: string) {} +} + diff --git a/app/sdk/src/user.ts b/app/sdk/src/user.ts new file mode 100644 index 00000000..685072b4 --- /dev/null +++ b/app/sdk/src/user.ts @@ -0,0 +1,70 @@ +import { EventEmitter } from 'events'; + +import { SqlStore } from './index'; +import { WebStore } from './index'; + +import { type Account, AccountModule } from './account'; +import { type Profile, ProfileModule } from './profile'; +import { type Contact, ContactModule } from './contact'; +import { type Group, GroupModule } from './group'; +import { type Attribute, AttributeModule } from './attribute'; +import { type Channel, ChannelModule } from './channel'; + +export interface User { + getAccount(): Account; + getProfile(): Profile; + getContact(): Contact; + getGroup(): Group; + getAttribute(): Attribute; + getChannel(): Channel; +} + +export class UserModule implements User { + + private store: SqlStore | WebStore | null; + private token: string; + private url: string; + + private account: AccountModule; + private profile: ProfileModule; + private contact: ContactModule; + private group: GroupModule; + private attribute: AttributeModule; + private channel: ChannelModule; + + constructor(store: SqlStore | WebStore | null, token: string, url: string) { + this.store = store; + this.token = token; + this.url = url; + this.account = new AccountModule(token, url); + this.profile = new ProfileModule(token, url); + this.contact = new ContactModule(token, url); + this.group = new GroupModule(token, url); + this.attribute = new AttributeModule(token, url); + this.channel = new ChannelModule(token, url); + } + + public getAccount(): Account { + return this.account; + } + + public getProfile(): Profile { + return this.profile; + } + + public getContact(): Contact { + return this.contact; + } + + public getGroup(): Group { + return this.group; + } + + public getAttribute(): Attribute { + return this.attribute; + } + + public getChannel(): Channel { + return this.channel; + } +} diff --git a/app/sdk/tsup.config.ts b/app/sdk/tsup.config.ts index 03cbfb72..3863d1d0 100644 --- a/app/sdk/tsup.config.ts +++ b/app/sdk/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["src/index.ts", "src/AccountSession.ts", "src/AdminSession.ts"], + entry: ["src/index.ts", "src/user.ts", "src/admin.ts", "src/account", "src/profile", "src/contact", "src/group", "src/attribute", "src/channel"], format: ["cjs", "esm"], // Build for commonJS and ESmodules dts: true, // Generate declaration file (.d.ts) splitting: false,