From 4e36c9e8a1bfd51c1c41ea671d798ddcd8a7206e Mon Sep 17 00:00:00 2001 From: AtHeartEngineer <1675654+AtHeartEngineer@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:49:54 -0700 Subject: [PATCH] type cleanup --- src/lib/stores/index.ts | 5 ++- src/lib/types/enums.ts | 18 ++++++++ src/lib/types/index.ts | 90 ++----------------------------------- src/lib/types/interfaces.ts | 42 +++++++++++++++++ src/lib/types/stores.ts | 41 +++++++++++++++++ src/routes/+layout.svelte | 42 +++-------------- vite.config.ts | 3 -- 7 files changed, 115 insertions(+), 126 deletions(-) create mode 100644 src/lib/types/enums.ts create mode 100644 src/lib/types/interfaces.ts create mode 100644 src/lib/types/stores.ts diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index 7a79a86..a4123ac 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -1,10 +1,11 @@ import { storable, sessionable } from './storeFactory'; -import { writable, derived } from 'svelte/store'; +import { derived } from 'svelte/store'; import { configDefaults } from '$lib/defaults'; import type { ConfigurationI, IdentityStoreI, messageStoreI, + pixelStoreI, rateLimitStoreI, roomStoreI, selectedRoomStoreI, @@ -52,6 +53,8 @@ export const currentSelectedRoom = derived( */ export const messageStore = sessionable({} as messageStoreI, 'messages'); +export const pixelStore = sessionable({} as pixelStoreI, 'pixelmaps'); + /* ------------------ Misc State ------------------*/ /** * @description Configuration and misc state diff --git a/src/lib/types/enums.ts b/src/lib/types/enums.ts new file mode 100644 index 0000000..14aa3c7 --- /dev/null +++ b/src/lib/types/enums.ts @@ -0,0 +1,18 @@ +export enum Experiences { + 'Chat', + 'Draw' +} + +export enum IdentityStoreE { + 'NO_IDENTITY', + 'localStorage', + 'cryptKeeper', + 'PCDPass' +} + +export enum ActionRepresentationE { + 'AP', + 'Hearts', + 'Shields', + 'Battery' +} diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index c3ba1ab..bd57c3d 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -1,87 +1,3 @@ -import type { MessageI, RoomI as RI, ServerI } from 'discreetly-interfaces'; - -export interface ButtonI { - link: string; - cls: string; - text: string; -} - -export interface IdentityStoreI { - _commitment: string; - _trapdoor: string; - _nullifier: string; - _secret: string; -} - -export interface JoinResponseI { - status: string; - roomIds: string[]; -} - -// Keyed by server URL -export interface serverStoreI { - [key: string]: ServerI; -} - -// Keyed by server URL -export interface selectedRoomStoreI { - [key: string]: string; -} - -// Keyed by roomId -export interface roomStoreI { - [key: string]: RoomI; -} - -// Keyed by roomId -export interface messageStoreI { - [key: string]: MessageI[]; -} - -// Keyed by roomId -export interface rateLimitStoreI { - [key: string]: { - lastEpoch: number; - messagesSent: number; - }; -} - -export enum IdentityStoreE { - 'NO_IDENTITY', - 'localStorage', - 'cryptKeeper', - 'PCDPass' -} - -export interface SignUpStatusI { - inviteAccepted: boolean; - identityBackedUp: boolean; - inviteCode?: string; -} - -export enum ActionRepresentationE { - 'AP', - 'Hearts', - 'Shields', - 'Battery' -} - -export interface ConfigurationI { - signUpStatus: SignUpStatusI; - identityStore: IdentityStoreE; - apiUsername?: string; - apiPassword?: string; - actionRepresentation?: ActionRepresentationE; -} - -export interface RoomI extends RI { - server?: string; -} - -export interface InviteCode { - claimcode: string; -} -export interface Invites { - message?: string; - codes: InviteCode[]; -} +export * from './stores'; +export * from './enums'; +export * from './interfaces'; diff --git a/src/lib/types/interfaces.ts b/src/lib/types/interfaces.ts new file mode 100644 index 0000000..ff3522e --- /dev/null +++ b/src/lib/types/interfaces.ts @@ -0,0 +1,42 @@ +import type { IdentityStoreE, ActionRepresentationE, Experiences } from '.'; +import type { RoomI as RI } from 'discreetly-interfaces'; + +export interface ConfigurationI { + signUpStatus: SignUpStatusI; + identityStore: IdentityStoreE; + apiUsername?: string; + apiPassword?: string; + actionRepresentation?: ActionRepresentationE; + experience?: Experiences; +} + +export interface RoomI extends RI { + server?: string; +} + +export interface InviteCode { + claimcode: string; +} +export interface Invites { + message?: string; + codes: InviteCode[]; +} + +export interface ButtonI { + link: string; + cls: string; + text: string; +} + +export interface JoinResponseI { + status: string; + roomIds: string[]; +} + +// Keyed by roomId + +export interface SignUpStatusI { + inviteAccepted: boolean; + identityBackedUp: boolean; + inviteCode?: string; +} diff --git a/src/lib/types/stores.ts b/src/lib/types/stores.ts new file mode 100644 index 0000000..521e103 --- /dev/null +++ b/src/lib/types/stores.ts @@ -0,0 +1,41 @@ +import type { ServerI, MessageI, HexColor } from 'discreetly-interfaces'; +import type { RoomI } from './interfaces'; + +// Keyed by server URL +export interface serverStoreI { + [key: string]: ServerI; +} + +// Keyed by server URL +export interface selectedRoomStoreI { + [key: string]: string; +} + +// Keyed by roomId +export interface roomStoreI { + [key: string]: RoomI; +} + +// Keyed by roomId +export interface messageStoreI { + [key: string]: MessageI[]; +} + +// Keyed by roomId +export interface pixelStoreI { + [key: string]: HexColor[][]; +} + +export interface IdentityStoreI { + _commitment: string; + _trapdoor: string; + _nullifier: string; + _secret: string; +} + +export interface rateLimitStoreI { + [key: string]: { + lastEpoch: number; + messagesSent: number; + }; +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8f37fec..2855b31 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,5 +1,5 @@