Skip to content

Commit

Permalink
Migrate to Dexie (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmyersdev authored Sep 6, 2024
2 parents 2fe0412 + b86f2e8 commit 19d9d68
Show file tree
Hide file tree
Showing 63 changed files with 2,277 additions and 3,082 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CYPRESS_BASE_URL=http://127.0.0.1:8888
FIREBASE_PROJECT_ID=demo-octo
FIREBASE_TOKEN=fake
NUXT_PUBLIC_CDN_URL=
Expand Down
24 changes: 0 additions & 24 deletions .eslintrc-todo.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,6 @@
"unused-imports/no-unused-vars": "warn"
}
},
{
"files": [
"src/store/modules/contexts.js"
],
"rules": {
"@typescript-eslint/space-before-function-paren": "warn"
}
},
{
"files": [
"src/store/modules/documents.js"
Expand Down Expand Up @@ -604,14 +596,6 @@
"@typescript-eslint/comma-dangle": "warn"
}
},
{
"files": [
"src/store/plugins/caching/contexts.js"
],
"rules": {
"no-case-declarations": "warn"
}
},
{
"files": [
"src/store/plugins/caching/documents.js"
Expand Down Expand Up @@ -809,14 +793,6 @@
"@typescript-eslint/comma-dangle": "warn"
}
},
{
"files": [
"test/cypress/support/e2e.ts"
],
"rules": {
"no-proto": "warn"
}
},
{
"files": [
"types/types.ts"
Expand Down
55 changes: 0 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
Expand Down Expand Up @@ -93,62 +92,11 @@ jobs:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
- name: Run linter
run: pnpm lint
test-e2e-cypress:
env:
NUXT_PUBLIC_FIREBASE_EMULATOR_AUTH: http://127.0.0.1:32775
needs:
- install-dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
- uses: cypress-io/github-action@v6.5.0
with:
build: pnpm build
config: baseUrl=http://127.0.0.1:8889
install: false
start: |
pnpm firebase:start
pnpm preview
wait-on: 'http://127.0.0.1:8889,http://127.0.0.1:32777'
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: test/cypress/screenshots
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-videos
path: test/cypress/videos
test-e2e-playwright:
needs:
- install-dependencies
Expand All @@ -174,7 +122,6 @@ jobs:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
Expand Down Expand Up @@ -211,7 +158,6 @@ jobs:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
Expand Down Expand Up @@ -242,7 +188,6 @@ jobs:
key: v1-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: |
${{ env.STORE_PATH }}
~/.cache/Cypress
restore-keys: v1-${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --shamefully-hoist
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ firebase/data
node_modules
public/manifest.webmanifest
supabase
test/cypress/downloads
test/cypress/screenshots
test/cypress/videos

# We are not using Zero-Installs.
# https://yarnpkg.com/getting-started/qa/#which-files-should-be-gitignored
Expand Down
16 changes: 13 additions & 3 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script lang="ts">
import { loadSettings } from '#root/src/store/plugins/caching/settings'
import { appEventTypes, logEvent } from '/helpers/app'
import { loadKeybindings } from '/src/store/modules/keybindings'
import { loadDocs } from '/src/store/plugins/caching/documents'
import { loadSettings } from '/src/store/plugins/caching/settings'
import { syncDocs } from '/src/store/plugins/sync'
import 'overlayscrollbars/overlayscrollbars.css'
Expand All @@ -11,13 +15,19 @@ export default defineComponent({
const isMounted = ref(false)
onMounted(() => {
onMounted(async () => {
isMounted.value = true
await loadSettings(store)
await loadDocs(store)
await loadKeybindings(store)
syncDocs(store)
// This is used by tests to determine when the app is ready.
document.body.dataset.isMounted = 'true'
loadSettings(store)
logEvent(appEventTypes.appMounted)
})
const sizes = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion components/AssistantHistoryChat.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type Chat } from '#helpers/database'
import { type Chat } from '/src/db'
export default defineComponent({
props: {
Expand Down
2 changes: 1 addition & 1 deletion components/AssistantHistoryChatMessage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type ChatMessage } from '#helpers/database'
import { type ChatMessage } from '/src/db'
const trimMessage = (message = '') => {
return message.length > 200 ? `${message.slice(0, 200)}...` : message
Expand Down
1 change: 1 addition & 0 deletions components/CoreInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ onMounted(() => {
:value="modelProxy"
class="unset-all cursor-text block min-h-0 overflow-hidden resize-none placeholder-muted"
:class="{ 'whitespace-nowrap': !multiline }"
data-core-input
@input="modelProxy = $event.target.value"
@keypress.enter="handleEnter"
/>
Expand Down
2 changes: 1 addition & 1 deletion components/DocEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineComponent({
watch(coreEditor, () => {
focus()
// Expose the Ink instance for Cypress.
// Expose the Ink instance for tests.
window.inkMde = coreEditor.value?.instance
})
Expand Down
2 changes: 1 addition & 1 deletion components/DocList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default defineComponent({
@keypress.enter.prevent="selectDoc(doc.id)"
@click="selectDoc(doc.id)"
>
<LazyDoc v-bind="doc" :allow-discard="isEditing" class="h-96" />
<Doc v-bind="doc" :allow-discard="isEditing" class="h-96" />
<div v-if="doc.selected" class="flex items-center justify-center rounded absolute inset-0 bg-layer bg-opacity-50">
<Icon name="CheckCircle" size="3rem" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion composables/useChatMessages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ChatMessage } from '#helpers/database'
import { type ChatMessage } from '/src/db'

export const useChatMessage = (id?: Ref<string>) => {
const { db } = useDatabase()
Expand Down
2 changes: 1 addition & 1 deletion composables/useChats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Chat } from '#helpers/database'
import { type Chat } from '/src/db'

export const useChat = (id?: Ref<string>) => {
const { db } = useDatabase()
Expand Down
2 changes: 1 addition & 1 deletion composables/useDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { tryOnScopeDispose } from '@vueuse/core'
import { type Subscription } from 'rxjs'
import { liveQuery } from 'dexie'
import { type Ref, ref } from 'vue'
import { db } from '#helpers/database'
import { db } from '/src/db'
import { isClient } from '#helpers/environment'

export type QueryReturnType<T, I = undefined> = { result: Ref<T | I> }
Expand Down
6 changes: 2 additions & 4 deletions composables/useRoot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getAuth } from 'firebase/auth'
import { useStore } from 'vuex'
import { appEventTypes, logEvent } from '#helpers/app'
import { isClient } from '#helpers/environment'
import { init } from '#root/src/firebase'
Expand All @@ -14,15 +13,14 @@ const updateAppHeight = () => {

export const useRoot = () => {
const { user } = useUser()
const store = useStore()
const { store } = useVuex()
const { public: { firebaseDisabled } } = useRuntimeConfig()

useAppearance()
useSettings()
useToasts()

onMounted(() => {
logEvent(appEventTypes.appMounted)

if (localStorage.getItem('octo/welcome/v1') === null) {
store.dispatch('SET_SHOW_WELCOME', true)
}
Expand Down
10 changes: 10 additions & 0 deletions composables/useSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const buildSettings = () => {
const { store } = useVuex()
const legacySettings = computed(() => store.state.settings)

return {
legacySettings,
}
}

export const useSettings = () => injectOrProvide('settings', buildSettings)
2 changes: 1 addition & 1 deletion composables/useSystemInstructions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type SystemInstruction } from '#helpers/database'
import { type SystemInstruction } from '/src/db'

export type { SystemInstruction }

Expand Down
21 changes: 21 additions & 0 deletions composables/useWorkspaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { cloneDeep } from 'lodash-es'
import type { Workspace } from '/src/db'

export const useWorkspaces = () => {
const { db } = useDatabase()
const { result: workspaces } = useQuery(() => db.workspaces.orderBy('name').toArray(), [])

const createWorkspace = async (workspace: Workspace) => {
return db.workspaces.add(cloneDeep(workspace))
}

const destroyWorkspace = async (id: string) => {
return db.workspaces.delete(id)
}

return {
createWorkspace,
destroyWorkspace,
workspaces,
}
}
22 changes: 0 additions & 22 deletions cypress.config.ts

This file was deleted.

2 changes: 0 additions & 2 deletions helpers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const appReadyWatcher = (appEvent: AppEvent) => {
if (!isLogged(appEventTypes.appReady)) {
const readyEventTypes: AppEventType[] = [
appEventTypes.appMounted,
appEventTypes.appSettingsLoaded,
]

if (readyEventTypes.includes(appEvent.type)) {
Expand All @@ -30,7 +29,6 @@ const appReadyWatcher = (appEvent: AppEvent) => {
export const appEventTypes = {
appMounted: 'app_mounted',
appReady: 'app_ready',
appSettingsLoaded: 'app_settings_loaded',
networkDocLoaded: 'network_doc_loaded',
networkDocsSynced: 'network_docs_synced',
userSignedIn: 'user_signed_in',
Expand Down
Loading

0 comments on commit 19d9d68

Please sign in to comment.