partitioning sdk api

This commit is contained in:
Roland Osborne 2024-06-21 22:52:15 -07:00
parent 1ffa7043cf
commit 8f91be0b49
12 changed files with 146 additions and 40 deletions

7
app/sdk/src/account.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Account {
}
export class AccountModule implements Account {
constructor(token: string, url: string) {}
}

View File

@ -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;
}
}

14
app/sdk/src/admin.ts Normal file
View File

@ -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;
}
}

View File

@ -1,5 +0,0 @@
export class AdminSession {
constructor() { }
}

7
app/sdk/src/attribute.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Attribute {
}
export class AttributeModule implements Attribute {
constructor(token: string, url: string) {}
}

7
app/sdk/src/channel.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Channel {
}
export class ChannelModule implements Channel {
constructor(token: string, url: string) {}
}

7
app/sdk/src/contact.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Contact {
}
export class ContactModule implements Contact {
constructor(token: string, url: string) {}
}

7
app/sdk/src/group.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Group {
}
export class GroupModule implements Group {
constructor(token: string, url: string) {}
}

View File

@ -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<void>;
@ -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<AccountSession | null> {
this.sqlStore = sql;
public async initOfflineStore(sql: SqlStore): Promise<User | null> {
this.store = sql;
// initialize
return new AccountSession(this.sqlStore, this.webStore);
return new UserModule(this.store, '', '');
}
public async initOnlineStore(web: WebStore): Promise<AccountSession | null> {
this.webStore = web;
public async initOnlineStore(web: WebStore): Promise<User | null> {
this.store = web;
// initialize
return new AccountSession(this.sqlStore, this.webStore);
return new UserModule(this.store, '', '');
}
public async accountLogin(): Promise<AccountSession> {
return new AccountSession(this.sqlStore, this.webStore);
public async userLogin(handle: string, password: string, url: string): Promise<User> {
return new UserModule(this.store, '', '');
}
public async accountAccess(): Promise<AccountSession> {
return new AccountSession(this.sqlStore, this.webStore);
public async userAccess(token: string, url: string): Promise<User> {
return new UserModule(this.store, '', '');
}
public async accountCreate(): Promise<AccountSession> {
return new AccountSession(this.sqlStore, this.webStore);
public async userCreate(handle: string, password: string, url: string, token: string): Promise<User> {
return new UserModule(this.store, '', '');
}
public async accountLogout(session: AccountSession): Promise<void> {
public async userLogout(session: User): Promise<void> {
}
public async adminLogin(): Promise<AdminSession> {
return new AdminSession();
public async adminLogin(token: string, url: string): Promise<Admin> {
return new AdminModule('', '');
}
public async adminLogout(session: AdminSession): Promise<void> {
public async adminLogout(session: Admin): Promise<void> {
}
}

7
app/sdk/src/profile.ts Normal file
View File

@ -0,0 +1,7 @@
export interface Profile {
}
export class ProfileModule implements Profile {
constructor(token: string, url: string) {}
}

70
app/sdk/src/user.ts Normal file
View File

@ -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;
}
}

View File

@ -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,