mirror of
https://github.com/balzack/databag.git
synced 2025-05-04 23:45:21 +00:00
partitioning sdk api
This commit is contained in:
parent
1ffa7043cf
commit
8f91be0b49
7
app/sdk/src/account.ts
Normal file
7
app/sdk/src/account.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface Account {
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AccountModule implements Account {
|
||||||
|
constructor(token: string, url: string) {}
|
||||||
|
}
|
||||||
|
|
@ -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
14
app/sdk/src/admin.ts
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
export class AdminSession {
|
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
}
|
|
7
app/sdk/src/attribute.ts
Normal file
7
app/sdk/src/attribute.ts
Normal 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
7
app/sdk/src/channel.ts
Normal 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
7
app/sdk/src/contact.ts
Normal 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
7
app/sdk/src/group.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface Group {
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GroupModule implements Group {
|
||||||
|
constructor(token: string, url: string) {}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
import { AccountSession } from './accountSession';
|
import { type User, UserModule } from './user';
|
||||||
import { AdminSession } from './adminSession';
|
import { type Admin, AdminModule } from './admin';
|
||||||
|
|
||||||
export interface SqlStore {
|
export interface SqlStore {
|
||||||
set(stmt: string, params: (string | number)[]): Promise<void>;
|
set(stmt: string, params: (string | number)[]): Promise<void>;
|
||||||
@ -15,44 +15,43 @@ export interface WebStore {
|
|||||||
|
|
||||||
export class DatabagSDK {
|
export class DatabagSDK {
|
||||||
|
|
||||||
private sqlStore: SqlStore | null = null;
|
private store: SqlStore | WebStore | null = null;
|
||||||
private webStore: WebStore | null = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log("databag sdk");
|
console.log("databag sdk");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initOfflineStore(sql: SqlStore): Promise<AccountSession | null> {
|
public async initOfflineStore(sql: SqlStore): Promise<User | null> {
|
||||||
this.sqlStore = sql;
|
this.store = sql;
|
||||||
// initialize
|
// initialize
|
||||||
return new AccountSession(this.sqlStore, this.webStore);
|
return new UserModule(this.store, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initOnlineStore(web: WebStore): Promise<AccountSession | null> {
|
public async initOnlineStore(web: WebStore): Promise<User | null> {
|
||||||
this.webStore = web;
|
this.store = web;
|
||||||
// initialize
|
// initialize
|
||||||
return new AccountSession(this.sqlStore, this.webStore);
|
return new UserModule(this.store, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async accountLogin(): Promise<AccountSession> {
|
public async userLogin(handle: string, password: string, url: string): Promise<User> {
|
||||||
return new AccountSession(this.sqlStore, this.webStore);
|
return new UserModule(this.store, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async accountAccess(): Promise<AccountSession> {
|
public async userAccess(token: string, url: string): Promise<User> {
|
||||||
return new AccountSession(this.sqlStore, this.webStore);
|
return new UserModule(this.store, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async accountCreate(): Promise<AccountSession> {
|
public async userCreate(handle: string, password: string, url: string, token: string): Promise<User> {
|
||||||
return new AccountSession(this.sqlStore, this.webStore);
|
return new UserModule(this.store, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async accountLogout(session: AccountSession): Promise<void> {
|
public async userLogout(session: User): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async adminLogin(): Promise<AdminSession> {
|
public async adminLogin(token: string, url: string): Promise<Admin> {
|
||||||
return new AdminSession();
|
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
7
app/sdk/src/profile.ts
Normal 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
70
app/sdk/src/user.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { defineConfig } from "tsup";
|
import { defineConfig } from "tsup";
|
||||||
|
|
||||||
export default defineConfig({
|
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
|
format: ["cjs", "esm"], // Build for commonJS and ESmodules
|
||||||
dts: true, // Generate declaration file (.d.ts)
|
dts: true, // Generate declaration file (.d.ts)
|
||||||
splitting: false,
|
splitting: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user