0.0.20 • Published 3 years ago

@firecamp/indexed-db v0.0.20

Weekly downloads
121
License
MIT
Repository
github
Last release
3 years ago

@firecamp/indexed-db


Usage

import { constants, misc } from '@firecamp/utility'
import DB from '@firecamp/indexed-db'

const { APP } = constants.INFO

const init = async () => {
  try {
    const db = await DB.init('firecamp', 1)

    // Fetch App Version
    const appInfo = misc.isElectron()
      ? await window.r.send(APP.IPC_EVENTS.FETCH_APP_INFO)
      : chrome.runtime.getManifest().version

    await db.app.init(appInfo.version)

    return Promise.resolve(db)
  } catch (error) {
    console.error('Error: ', error)
    return Promise.reject(error)
  }
}

export default init

How to access any API

// API which prepare push payload
await db.collab.preparePushPayload()

// API to add request and request insert commit action into the local DB
await db.request.add(requestPayload, true)

API

app

    /**
     * Perform operation require on DB initialization
     *
     * @param appVersion 
     */
    init(appVersion: string): Promise<void>

    /**
     * Fetch workspace projects in sorted order
     *
     * @param workspaceUUID 
     */
    getWorkspaceProjects(workspaceUUID: string): Promise<any[]>

    /**
     * clear db specific stores on logut
     * Add my workspace with defaut environment
     * Update Firecamp store entries
     */
    clearDB(): Promise<void>

danger

    /**
     * Remove Organization and its children
     * 
     * @param orgUUID 
     */
    removeOrganization(orgUUID: string): Promise<void>

    /**
     * Remove Workspace and its children
     * 
     * @param workspaceUUID 
     */
    removeWorkspace(workspaceUUID: string): Promise<void>

    /**
     * Remove Project and its children
     * 
     * @param _meta 
     * @param commit 
     */
    removeProject(_meta: any, commitAction: false): Promise<void>

    /**
     * Remove Module and its children
     * 
     * @param _meta 
     * @param commit 
     */
    removeModule(_meta: any, commitAction: false): Promise<void>

collab

    /**
     * Return push payload based on the commit actions
     */
    preparePushPayload(): Promise<any[]>

    /**
     * Handle pull payload received in the '/pull' API
     * 
     * @param pullPayload 
     */
    handlePullPayload(pullPayload: []): Promise<void>

commitaction

  /**
   * Add commit action into the local DB
   * 
   * @param entry 
   */
  add(entry: any): Promise<string>

  /**
   * Fetch commit action from the local DB
   * 
   * @param uuid 
   */
  fetch(uuid: string): Promise<any>

  /**
   * Fetch commit actions by index '_meta.project_uuid'
   * 
   * @param projectUUID 
   */
  fetchAllByProjectUUID(projectUUID: string): Promise<any[]>
  
  /**
   * Fetch commit actions by index '_meta.uuid'
   * 
   * @param uuid 
   */
  fetchAllByUUID(uuid: string): Promise<any[]>
  
  /**
   * Update commit action
   * 
   * @param uuid 
   * @param entry 
   */
  update(uuid: string, entry: any): Promise<void>

  /**
   * Add/Update commit action
   * 
   * @param uuid 
   * @param entry 
   */
  put(uuid: string, entry: any): Promise<void>

  /**
   * Remove commit action by store_uuid
   * 
   * @param store_uuid
   */
  remove(store_uuid: string): Promise<void>

  /**
   * Remove commit actions by index: '_meta.project_uuid'
   * 
   * @param projectUUID 
   */
  removeByProjectUUID(projectUUID: string): Promise<void>
  
  /**
   * Remove commit actions by index: '_meta.uuid'
   * 
   * @param uuid 
   */
  removeByUUID(uuid: string): Promise<void>

cookie

    /**
     * Add cookie
     * @param payload
     */
    add(payload: any): Promise<void>

    /**
     * Add multiple cookies
     * @param payload
     * @param remote
     */
    addCookies(payload: any[]): Promise<void>

    /**
     * Fetch cookies group by domain
     */
    fetchAllByDomain(): Promise<any>

    /**
     * Update cookie
     *
     * @param cookieUUID
     * @param payload
     */
    update(cookieUUID: string, payload: any): Promise<void>

    /**
     * Remove cookie by it's UUID
     *
     * @param cookieUUID
     */
    remove(cookieUUID: string): Promise<void>

    /**
     * Remove cookies which domain name match
     *
     * @param domain
     */
    removeByDomain(domain: string): Promise<void>

directory

    /**
     * Add directory into the local DB
     *
     * @param directory - directory payload
     * @param commitAction - flag to manage should insert directory insert commit action into the local DB
     */
    add(directory: any, commitAction: false): Promise<void>

    /**
     * Add multiple directories into the local DB
     *
     * @param directories - Array of directories
     * @param commitAction - flag to manage should insert directory insert commit action into the local DB
     */
    addMultiple(directories: any[], commitAction: false): Promise<void>

    /**
     * Fetch directory by UUID from the local DB
     *
     * @remarks Only use for run test case
     *
     * @param directoryUUID - directory UUID to fetch directory
     */
    fetch(directoryUUID: string): Promise<any>

    /**
     * Prepare the list of children UUID. Use to retrieve the children UUID
     * of directory which should also remove on remove directory
     *
     * @param directoryUUID - directory uuid to fetch all children UUID
     */
    fetchAllChildrenUUIDs(directoryUUID: string): Promise<void>

    /**
     * Update the directory
     * 
     * @param updates - directory update payload
     * @param commitAction - flag to manage should update directory commit action add into the local DB
     */
    update(updates: any, commitAction: false): Promise<void>

    /**
     * Remove directory
     * @param _meta - directory _meta
     * @param commitAction - flag to manage should insert directory remove commit action into the local DB
     */
    remove(_meta: any, commitAction: false): Promise<void>

    /**
     * Remove multiple directories
     *
     * @param _metas - Array of the directory _meta
     * @param commitAction - flag to manage should insert directory remove commit action into the local DB
     */
    removeMultiple(_metas: any[], commitAction: false): Promise<void>

    /**
     * Insert commit action
     *
     * @param action
     * @param commitPayload
     */
    commit(action: string, commitAction: { updates?: any, _meta: any }): Promise<void>

dnd

  /**
   * Update orders by type
   * @param parentID - Parent ID which childs order upated
   * @param orders - Orders will be `r_orders`, `m_orders`, `p_orders`
   * @param type - Type will be `WRS`, `P`, `M`
   * @param cloudSync
   */
  updateOrderByType(parentID: string, orders: any, type: string, cloudSync: boolean): Promise<void>

  /**
   * Update orders on source of element change
   * @param from - Source Parent element
   * @param to - Destination Parent element
   * @param intent - Element which DND
   */
  updateOrderOnSourceChange(from: any, to: any, intent: any): Promise<void>

  updateKeysOfDNDResource(uuid: string, intent: any, to: any): Promise<void>

environment

    /**
     * Add environment into the local DB
     *
     * @param environment
     * @param commit
     */
    add(environment: any, commitAction: false): Promise<void>

    /**
     * Add mutiple environments
     *
     * @param environments
     * @param commit
     */
    addMultiple(environments: any[], commitAction: false): Promise<void>

    /**
     * Add project default environments into the local DB
     * k
     * @param projectUUID
     * @param commit
     */
    addProjectEnvironments(projectUUID: string, commitAction: false): Promise<string>

    /**
     * Return environment
     *
     * @param environmentUUID
     */
    fetch(environmentUUID: string): Promise<any>

    /**
     * Return project's all environments from the local DB
     *
     * @param projectUUID
     */
    fetchProjectEnvironments(projectUUID: string): Promise<any[]>

    /**
     * Update environment
     *
     * @param updates
     */
    update(updates: { name: string, variables: any, removed_variables: string[], _meta: any }): Promise<void>

    /**
     * Remove environment from the local DB
     *
     * @param _meta
     * @param commit
     */
    remove(_meta: any, commitAction: false): Promise<void>

    /**
     * Insert environment commit action into the local DB
     *
     * @param action
     * @param commitPayload
     */
    commit(action: string, commitAction: { action?: any, _meta: any }): Promise<void>

firecamp

  /**
   * Add key into the local DB
   *
   * @param key
   * @param value
   */
  add(key: string, value: any): Promise<void>

  /**
   * Add key: 'sync_id'
   *
   * @param value
   */
  addSyncID(value: string): Promise<void>

  /**
   * Add key: 'my_workspace' if not exist
   */
  addMyWorkspace(): Promise<void>

  /**
   * Add key: 'active_workspace' if not exist
   */
  addActiveWorkspace(): Promise<void>

  /**
   * Fetch key, if not exist then add key with value: undefined
   *
   * @param key
   * @param defaultValue
   */
  fetch(key: string, defaultValue?: string): Promise<any>

  /**
   * Fetch key: `client_id`, if not exist then add and return
   */
  fetchClientID(): Promise<string>

  /**
   * Fetch key: `sync_id`, return undefined if not exist
   */
  fetchSyncID(): Promise<any>

  /**
   * Fetch key: `initSync`, return undefined if not exist
   */
  fetchInitSync(): Promise<any>

  /**
   * Fetch key: `session-${workspaceUUID}
   * @param sessionID
   */
  fetchSession(sessionID: string): Promise<any>

  /**
   * Fetch app version, if not exist then add key with empty value into the local DB
   */
  fetchAppVersion(): Promise<any>

  /**
   * Update key value
   *
   * @param key
   * @param value
   */
  update(key: string, value: any): Promise<void>

  /**
   * Update key: 'active_workspace' into the local DB
   * @param workspacesUUID
   */
  updateActiveWorkspace(workspacesUUID: string): Promise<void>

  /**
   * Remove key
   * @param key
   */
  remove(key: string): Promise<void>

  /**
   * Add key: 'client_id' if not exist
   */
  checkClientID(): Promise<void>

  /**
   * Add key: 'theme' if not exist with default value: 'light'
   */
  checkTheme(): Promise<void>

  /**
   * Add key: 'version' if not exist
   *
   * @param appVersion
   */
  checkAppVersion(appVersion: string): Promise<void>

  /**
   * Add key: 'my_workspace' if not exist
   */
  checkMyWorkspace(): Promise<void>

  /**
   * Add key: 'active_workspace' if not exist
   */
  checkActiveWorkspace(): Promise<void>

  /**
   * Clear DB store
   *
   * @param storeName
   */
  clearStore(storeName: string): Promise<void>

  /**
   * Remove workspace session
   *
   * @param workspacesUUID
   */
  removeSession(workspacesUUID: string): Promise<void>

  /**
   * Remove all session
   */
  removeAllSession(): Promise<void>

  /**
   * Remove keys not required after logout
   */
  removeAccoutDetails(): Promise<void>

history

  /**
   * Add history into the local DB
   *
   * @param history
   * @param commit
   */
  add(history: any, commitAction: false): Promise<void>

  /**
   * Add multiple histories into the local DB
   *
   * @param histories
   * @param commit
   */
  addMultiple(histories: any[], commitAction: false): Promise<void>

  /**
   * Return history by UUID
   *
   * @param historyUUID
   */
  fetch(historyUUID: string): Promise<any>

  /**
   * Fetch workspace histories
   *
   * @param workspaceUUID
   */
  fetchWorkspaceHistories(workspaceUUID: string): Promise<any[]>

  /**
   * Remove history by it's UUID
   *
   * @param _meta
   * @param commit
   */
  remove(_meta: any, commit: false,): Promise<void>

  /**
   * Remove workspace histories
   *
   * @param workspaceUUID
   */
  removeWorkspaceHistories(workspaceUUID: string): Promise<void>

  /**
   * Add history commit action into the local DB
   *
   * @param actionType
   * @param commitPayload
   */
  commit(actionType: TActionType, commitAction: ICommitAction): Promise<void>

leaf

    /**
     * Add leaf and leaf insert commit action into the local DB
     *
     * @param leaf - leaf payload
     * @param commitAction - flag for whether insert or not commit action
     */
    add(leaf: any, commitAction: false): Promise<void>

    /**
     * Add multiple leaves into the local DB
     *
     * @param leaves
     * @param commit
     */
    addMultiple(leaves: any[], commitAction: false): Promise<void>

    /**
     * Update leaf and insert update leaf commit action into the local DB
     *
     * @param updates
     * @param commit
     */
    update(updates: any, commitAction: false): Promise<void>

    /**
     * Remove leaf
     *
     * @param _meta
     * @param commit
     */
    remove(_meta: any, commitAction: false): Promise<void>

    /**
     * Remove request's all leaves
     *
     * @param requestUUID
     */
    removeAll(requestUUID: string): Promise<void>

    /**
     * Remove multiple leaves
     *
     * @param uuids
     * @param commit
     */
    removeMultiple(uuids: string[], commitAction: false): Promise<void>

localclient

  /**
   * Add local client certificate/schema info into the local DB
   *
   * @param payload
   * @param commit
   */
  add(payload: any, commitAction: false): Promise<void>

  /**
   * Return all local client certificate/schema from the local DB
   */
  fetchAll(): Promise<any[]>

  /**
   * Update local client certificate/schema info into the local DB
   *
   * @param updates
   * @param commit
   */
  update(updates: any, commitAction: false): Promise<void>

  /**
   * Remove local client certificate/schema info from the local DB
   *
   * @param _meta
   * @param commit
   */
  remove(_meta: any, commitAction: false): Promise<void>

module

    /**
     * Add module into the local DB
     * 
     * @param module 
     * @param commit 
     */
    add(module: any, commitAction: false): Promise<void>

    /**
     * Add multiple module into the local DB
     * 
     * @param modules 
     * @param commit 
     */
    addMultiple(modules: any[], commitAction: false): Promise<void>

    /**
     * Return module from the local DB
     * 
     * @param moduleUUID 
     */
    fetch(moduleUUID: string): Promise<any>

    /**
     * Return the list of module's children module UUID
     * 
     * @param moduleUUID 
     */
    _fetchChildModulesUUID(moduleUUID: string): Promise<string[]>

    /**
     * Update module into the local DB
     * 
     * @param updates 
     * @param commit 
     */
    update(updates: any, commitAction: false): Promise<void>

    /**
     * Add/Update module into the local DB
     * 
     * @param module 
     */
    put(module: any): Promise<void>

    /**
     * Remove module from the local DB
     * 
     * @param _meta 
     * @param commit 
     */
    remove(_meta: any, commitAction: false): Promise<void>

organization

    /**
     * Add organization into the local DB
     *  
     * @param organization
     */
    add(organization: any): Promise<void>

    /**
     * Fetch organization from the local DB
     * 
     * @param organizationUUID - Organizaion UUID
     */
    fetch(organizationUUID: string): Promise<any>

    /**
     * Fetch all organization
     */
    fetchAll(): Promise<any>

    /**
     * Return the org's workspaces UUID list
     * 
     * @param orgUUID 
     */
    fetchAllWorkspacesUUID(orgUUID: string): Promise<string[]>

    /**
     * Remove single organization
     * 
     * @param orgUUID 
     */
    remove(orgUUID: string): Promise<void>

project

    /**
     * Add the project into the local DB
     * 
     * @param projectPayload 
     * @param commit 
     */
    add(projectPayload: any, commitAction: false): Promise<void>

    /**
     * Return the project from the local DB
     * 
     * @param projectUUID 
     */
    fetch(projectUUID: string): Promise<any>

    /**
     * Return the project's all environments
     * 
     * @param projectUUID 
     */
    fetchEnvironments(projectUUID: string): Promise<any>

    /**
     * Return the project's workspace UUID list
     * 
     * @param projectUUIDs 
     */
    fetchProjectsWorkspaceUUID(projectUUIDs: string[]): Promise<any>

    /**
     * Return the populate project
     * 
     * @param projectUUID 
     */
    populate(projectUUID: string): Promise<any>

    /**
     * Update the project and add it's commit action into the local DB
     * 
     * @param updates 
     * @param commit 
     */
    update(updates: any, commit: false,): Promise<void>

    /**
     * Remove the project from and add it's commit action into the local DB
     * 
     * @param _meta 
     * @param commit 
     */
    remove(_meta: any, commitAction: false): Promise<void>

proxy

    /**
     * Add the proxy into the local DB
     * 
     * @param proxy 
     * @param commit 
     */
    add(proxy: any, commitAction: false): Promise<void>

    /**
     * Return the proxy from the local DB
     * 
     * @param proxyUUID 
     */
    fetch(proxyUUID: string): Promise<any>

    /**
     * Return all proxies
     */
    fetchAll(): Promise<any[]>

    /**
     * Update the proxy into the local DB
     * 
     * @param updates 
     * @param commit 
     */
    update(updates: any, commitAction: false): Promise<void>

    /**
     * Remove the proxy from the local DB
     * 
     * @param _meta 
     * @param commit 
     */
    remove(_meta: any, commitAction: false): Promise<void>

    /**
     * Add proxy commit action into the local DB
     * 
     * @param actionType 
     * @param commitPayload 
     */
    commit(actionType: TActionType, commitAction: ICommitAction): Promise<void>

    /**
     * Prepare proxy insert push payload
     * 
     * @param commit 
     */
    prepareInsertPushPayload(commitAction: any): Promise<any>

    /**
     * Prepare proxy update push payload
     * 
     * @param commit 
     */    
    prepareUpdatePushPayload(commitAction: any): Promise<any>

    /**
     * Prepare proxy delete push payload
     * 
     * @param commit 
     */
    prepareDeletePushPayload(commitAction: any): Promise<any>

    /**
     * Handle proxy insert pull payload
     * 
     * @param commit 
     */    
    handleInsertPullPayload(pullPayload: any): Promise<any>

    /**
     * Handle proxy update pull payload
     * 
     * @param commit 
     */    
    handleUpdatePullPayload(pullPayload: any): Promise<any>

    /**
     * Handle proxy delete pull payload
     * 
     * @param commit 
     */    
    handleDeletePullPayload(pullPayload: any): Promise<any>

request

    /**
     * Add request into the local DB with it's commit action
     * 
     * @param requestPayload 
     * @param commit 
     */
    add(requestPayload: any, commitAction: false): Promise<void>

    /**
     * Fetch request from the local DB
     * 
     * @param requestUUID 
     */
    fetch(requestUUID: string): Promise<any>

    /**
     * Update request in the DB and add it's commit action
     * 
     * @param updates 
     * @param requestType
     */
    update(updates: string, requestType: string): Promise<void>

    /**
     * Remove request from the local DB and add it's commit action
     * 
     * @param _meta 
     * @param commit 
     */
    remove(_meta: any, commitAction: false): Promise<void>

    /**
     * Return the populate request
     * 
     * @param requestUUID
     * @param requestType
     */
    populate(requestUUID: string, requestType: string): Promise<void>

    /**
     * Add the request's commit action into the local DB
     * 
     * @param action 
     * @param _meta 
     */
    commit(action: string, _meta: any): Promise<void>

workspace

    /**
     * Add workspace into the local DB
     * 
     * @param workspace 
     */
    add(workspace: any): Promise<void>

    /**
     * Add default workspace into the local DB
     */
    addDefaultWorkspace(): Promise<void>

    /**
     * Add remote default workspace into the local DB
     * Also update workspace_uuid into children
     * 
     * @param remoteWorkspace 
     */
    addRemoteDefaultWorkspace(remoteWorkspace: any): Promise<void>

    /**
     * Add personal workspace into the local DB
     * 
     * @param workspace 
     */
    addPersonal(workspace: any): Promise<void>

    /**
     * Add organizational workspace
     * 
     * @param workspace 
     */
    addOrganizational(workspace: any): Promise<string>

    /**
     * Return workspace
     * 
     * @param workspaceUUID 
     */
    fetch(workspaceUUID: string): Promise<any>

    /**
     * Return all workspaces
     */
    fetchAll(): Promise<any[]>

    /**
     * Return all personal workspaces
     */
    fetchAllPersonal(): Promise<any[]>

    /**
     * Return all organizational workspaces
     */
    fetchAllOrganizational(): Promise<any[]>

    /**
     * Return workspace all projects
     * 
     * @param workspaceUUID 
     */
    fetchProjects(workspaceUUID: string): Promise<any>
    
    /**
     * Return workspace all environments
     * 
     * @param workspaceUUID 
     */
    fetchEnvironments(workspaceUUID: string): Promise<any[]>
    
    /**
     * Return workspace all histories
     * 
     * @param workspaceUUID 
     */
    fetchHistories(workspaceUUID: string): Promise<any[]>

    /**
     * Return workspace projects with environments
     * 
     * @param workspaceUUID 
     */
    fetchProjectsWithEnvironment(workspaceUUID: string): Promise<any[]>

    /**
     * Return workspace active environment
     * 
     * @param workspaceUUID 
     */
    fetchActiveEnvironment(workspaceUUID: string): Promise<string>

    /**
     * Update workspace into the local DB
     * 
     * @param updates 
     */
    update(updates: any): Promise<void>

    /**
     * Add/Update workspace into the local DB
     * 
     * @param workspace 
     */
    put(workspace: any): Promise<void>

    /**
     * Remove worksapce environment
     * 
     * @param workspaceUUID 
     */
    remove(workspaceUUID: string): Promise<void>
0.0.20

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago