Skip to content

Commit

Permalink
fix(ui): convert all js files to typescript and fix all typescript er…
Browse files Browse the repository at this point in the history
…rors (~300)
  • Loading branch information
flawiddsouza committed Mar 15, 2024
1 parent e4c34de commit 71c2ce8
Show file tree
Hide file tree
Showing 20 changed files with 534 additions and 258 deletions.
3 changes: 2 additions & 1 deletion packages/ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
'vue/max-attributes-per-line': 'off',
'vue/attributes-order': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/order-in-components': 'off'
'vue/order-in-components': 'off',
'vue/require-explicit-emits': 'off',
}
}
2 changes: 1 addition & 1 deletion packages/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
63 changes: 63 additions & 0 deletions packages/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"vuex": "^4.0.2"
},
"devDependencies": {
"@types/lodash.get": "^4.4.9",
"@types/lodash.set": "^4.3.9",
"@types/shell-quote": "^1.7.5",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@vitejs/plugin-vue": "^4.4.0",
Expand Down
File renamed without changes.
62 changes: 34 additions & 28 deletions packages/ui/src/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import Dexie from 'dexie'
import 'dexie-export-import'
import {
CollectionItem,
Plugin,
RequestFinalResponse,
Workspace,
} from './global'

export class RestfoxDatabase extends Dexie {
workspaces!: Dexie.Table<any>
Expand Down Expand Up @@ -34,7 +40,7 @@ export async function exportDB() {
return blob
}

export async function importDB(file) {
export async function importDB(file: File) {
await db.delete()
await db.open()
await db.import(file)
Expand All @@ -47,25 +53,25 @@ export async function getAllWorkspaces() {
return db.workspaces.toCollection().reverse().sortBy('updatedAt')
}

export async function putWorkspace(workspace) {
export async function putWorkspace(workspace: Workspace) {
await db.workspaces.put(workspace)
}

export async function updateWorkspace(workspaceId, updatedFields) {
export async function updateWorkspace(workspaceId: string, updatedFields: Partial<Workspace>) {
await db.workspaces.update(workspaceId, updatedFields)
}

export async function deleteWorkspace(workspaceId) {
export async function deleteWorkspace(workspaceId: string) {
await db.workspaces.delete(workspaceId)
}

// Collections

export async function getAllCollectionIdsForGivenWorkspace(workspaceId) {
export async function getAllCollectionIdsForGivenWorkspace(workspaceId: string) {
return db.collections.where({ workspaceId }).primaryKeys()
}

export async function getCollectionForWorkspace(workspaceId, type = null) {
export async function getCollectionForWorkspace(workspaceId: string, type = null): Promise<{ error: string | null, collection: CollectionItem[] }> {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -88,7 +94,7 @@ export async function getCollectionForWorkspace(workspaceId, type = null) {
}
}

export async function getCollectionById(workspaceId, collectionId) {
export async function getCollectionById(workspaceId: string, collectionId: string): Promise<CollectionItem> {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -99,7 +105,7 @@ export async function getCollectionById(workspaceId, collectionId) {
return db.collections.where({ ':id': collectionId }).first()
}

export async function createCollection(workspaceId, collection) {
export async function createCollection(workspaceId: string, collection: CollectionItem) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -110,7 +116,7 @@ export async function createCollection(workspaceId, collection) {
await db.collections.put(collection)
}

export async function createCollections(workspaceId, collections) {
export async function createCollections(workspaceId: string, collections: CollectionItem[]) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -121,7 +127,7 @@ export async function createCollections(workspaceId, collections) {
await db.collections.bulkPut(collections)
}

export async function updateCollection(workspaceId, collectionId, updatedFields) {
export async function updateCollection(workspaceId: string, collectionId: string, updatedFields: Partial<CollectionItem>) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -132,11 +138,11 @@ export async function updateCollection(workspaceId, collectionId, updatedFields)
await db.collections.update(collectionId, updatedFields)
}

export async function modifyCollections(workspaceId) {
export async function modifyCollections(workspaceId: string) {
await db.collections.toCollection().modify({ workspaceId })
}

export async function deleteCollectionsByWorkspaceId(workspaceId) {
export async function deleteCollectionsByWorkspaceId(workspaceId: string) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -147,7 +153,7 @@ export async function deleteCollectionsByWorkspaceId(workspaceId) {
await db.collections.where({ workspaceId }).delete()
}

export async function deleteCollectionsByIds(workspaceId, collectionIds) {
export async function deleteCollectionsByIds(workspaceId: string, collectionIds: string[]) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -160,7 +166,7 @@ export async function deleteCollectionsByIds(workspaceId, collectionIds) {

// Responses

export async function getResponsesByCollectionId(workspaceId, collectionId) {
export async function getResponsesByCollectionId(workspaceId: string, collectionId: string) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -171,7 +177,7 @@ export async function getResponsesByCollectionId(workspaceId, collectionId) {
return db.responses.where({ collectionId }).reverse().sortBy('createdAt')
}

export async function createResponse(workspaceId, response) {
export async function createResponse(workspaceId: string, response: RequestFinalResponse) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -182,7 +188,7 @@ export async function createResponse(workspaceId, response) {
await db.responses.put(response)
}

export async function updateResponse(workspaceId, collectionId, responseId, updatedFields) {
export async function updateResponse(workspaceId: string, collectionId: string, responseId: string, updatedFields: Partial<RequestFinalResponse>) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -193,7 +199,7 @@ export async function updateResponse(workspaceId, collectionId, responseId, upda
await db.responses.update(responseId, updatedFields)
}

export async function deleteResponse(workspaceId, collectionId, responseId) {
export async function deleteResponse(workspaceId: string, collectionId: string, responseId: string) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -204,7 +210,7 @@ export async function deleteResponse(workspaceId, collectionId, responseId) {
await db.responses.where({ _id: responseId }).delete()
}

export async function deleteResponsesByIds(workspaceId, collectionId, responseIds) {
export async function deleteResponsesByIds(workspaceId: string, collectionId: string, responseIds: string[]) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -215,7 +221,7 @@ export async function deleteResponsesByIds(workspaceId, collectionId, responseId
await db.responses.where(':id').anyOf(responseIds).delete()
}

export async function deleteResponsesByCollectionIds(workspaceId, collectionIds) {
export async function deleteResponsesByCollectionIds(workspaceId: string, collectionIds: string[]) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand All @@ -226,7 +232,7 @@ export async function deleteResponsesByCollectionIds(workspaceId, collectionIds)
await db.responses.where('collectionId').anyOf(collectionIds).delete()
}

export async function deleteResponsesByCollectionId(workspaceId, collectionId) {
export async function deleteResponsesByCollectionId(workspaceId: string, collectionId: string) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if(workspace._type === 'file') {
Expand Down Expand Up @@ -264,7 +270,7 @@ export async function getWorkspacePlugins(workspaceId: string) {
]
}

export async function createPlugin(plugin, workspaceId = null) {
export async function createPlugin(plugin: Plugin, workspaceId: string | null = null) {
if(import.meta.env.MODE === 'desktop-electron' && workspaceId !== null) {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
Expand All @@ -275,7 +281,7 @@ export async function createPlugin(plugin, workspaceId = null) {
await db.plugins.put(plugin)
}

export async function updatePlugin(pluginId, updatedFields, workspaceId = null, collectionId = null) {
export async function updatePlugin(pluginId: string, updatedFields: Partial<Plugin>, workspaceId: string | null = null, collectionId: string | null = null) {
if(import.meta.env.MODE === 'desktop-electron' && workspaceId !== null) {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
Expand All @@ -286,7 +292,7 @@ export async function updatePlugin(pluginId, updatedFields, workspaceId = null,
await db.plugins.update(pluginId, updatedFields)
}

export async function deletePlugin(pluginId, workspaceId = null, collectionId = null) {
export async function deletePlugin(pluginId: string, workspaceId: string | null = null, collectionId: string | null = null) {
if(import.meta.env.MODE === 'desktop-electron' && workspaceId !== null) {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
Expand All @@ -297,7 +303,7 @@ export async function deletePlugin(pluginId, workspaceId = null, collectionId =
await db.plugins.where({ _id: pluginId }).delete()
}

export async function deletePluginsByWorkspace(workspaceId) {
export async function deletePluginsByWorkspace(workspaceId: string) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
Expand All @@ -308,7 +314,7 @@ export async function deletePluginsByWorkspace(workspaceId) {
await db.plugins.where({ workspaceId }).delete()
}

export async function deletePluginsByCollectionIds(workspaceId, collectionIds) {
export async function deletePluginsByCollectionIds(workspaceId: string, collectionIds: string[]) {
if(import.meta.env.MODE === 'desktop-electron') {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
Expand All @@ -320,13 +326,13 @@ export async function deletePluginsByCollectionIds(workspaceId, collectionIds) {
}

// used for import
export async function createPlugins(plugin, workspaceId = null) {
export async function createPlugins(plugins: Plugin[], workspaceId: string | null = null) {
if(import.meta.env.MODE === 'desktop-electron' && workspaceId !== null) {
const workspace = await db.workspaces.get(workspaceId)
if (workspace._type === 'file') {
return window.electronIPC.createPlugins(workspace, plugin)
return window.electronIPC.createPlugins(workspace, plugins)
}
}

await db.plugins.bulkPut(plugin)
await db.plugins.bulkPut(plugins)
}
File renamed without changes.
Loading

0 comments on commit 71c2ce8

Please sign in to comment.