Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tRPC and moved many IPC system to tRPC #81

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test and coverage checks

on:
push:
branches: [$default-branch, $protected-branches]
pull_request: {}

jobs:
eslint:
name: Run coverage scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: 'Install Node'
uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true
- name: Setup yarn
run: |
corepack enable yarn
corepack install
- name: Install dependencies
run: |
yarn --frozen-lockfile
- name: Check test coverage
run: |
mkdir logs
yarn coverage
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Style and form checks

on:
push:
branches: [$default-branch, $protected-branches]
pull_request: {}

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: 'Install Node'
uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true
- name: Setup yarn
run: |
corepack enable yarn
corepack install
- name: Install dependencies
run: |
yarn --frozen-lockfile --ignore-scripts
- name: Check code style
run: |
yarn check:prettier
yarn check:lint
36 changes: 36 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: TypeScript checks

on:
push:
branches: [$default-branch, $protected-branches]
pull_request: {}

jobs:
eslint:
name: Run type scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: 'Install Node'
uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true
- name: Setup yarn
run: |
corepack enable yarn
corepack install
- name: Install dependencies
run: |
yarn --frozen-lockfile --ignore-scripts
- name: Check types
run: |
yarn typecheck:config
yarn typecheck:node
yarn typecheck:web
yarn typecheck:test
5 changes: 3 additions & 2 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
- Milestones
- v2.1
- Switch the majority of the IPC using tRPC.
- Level uses a streaming IPC, so leave it be for now.
- Anything passing a file may still require some custom hanlding.
- Updater will require websocket for subscriptions.
- System will require moving the open and save file support to DOM APIs.
- Drivers will require an overhaul to no longer need handles.
- More drivers.
- Move more modules to core.
- Drivers
Expand Down
61 changes: 31 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,44 @@
},
"homepage": "https://github.com/6XGate/bridgecmdr#readme",
"devDependencies": {
"@intlify/core-base": "^9.14.1",
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@intlify/core-base": "^10.0.4",
"@intlify/unplugin-vue-i18n": "^5.2.0",
"@mdi/js": "^7.4.47",
"@mdi/svg": "^7.4.47",
"@sindresorhus/is": "^7.0.1",
"@sixxgate/lint": "^3.2.1",
"@trpc/client": "^10.45.2",
"@trpc/server": "^10.45.2",
"@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.5",
"@types/abstract-leveldown": "^7.2.5",
"@types/duplexify": "^3.6.4",
"@types/eslint": "^8.56.12",
"@types/ini": "^4.1.1",
"@types/level": "^6.0.3",
"@types/leveldown": "^4.0.6",
"@types/levelup": "^5.1.5",
"@types/node": "^20.16.15",
"@types/node": "^20.17.5",
"@types/pouchdb-core": "^7.0.15",
"@types/pouchdb-find": "^7.3.3",
"@types/setimmediate": "^1.0.4",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vitest/coverage-v8": "^2.1.3",
"@vitest/coverage-v8": "^2.1.4",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/tsconfig": "^0.5.1",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^11.1.0",
"@vueuse/shared": "^11.1.0",
"@zip.js/zip.js": "^2.7.52",
"abstract-leveldown": "^7.2.0",
"@vueuse/core": "^11.2.0",
"@vueuse/shared": "^11.2.0",
"@zip.js/zip.js": "^2.7.53",
"assert": "^2.1.0",
"auto-bind": "^5.0.1",
"buffer": "^6.0.3",
"duplexify": "^4.1.3",
"electron": "^31.6.0",
"electron": "^31.7.3",
"electron-builder": "^24.13.3",
"electron-unhandled": "^5.0.0",
"electron-updater": "^6.3.9",
Expand All @@ -106,53 +106,54 @@
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.12.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-vue": "^9.28.0",
"eslint-plugin-vue": "^9.30.0",
"events": "^3.3.0",
"execa": "^9.4.1",
"execa": "^9.5.1",
"husky": "^9.1.6",
"ini": "^4.1.3",
"ini": "^5.0.0",
"js-base64": "^3.7.7",
"levelup": "^5.1.1",
"mime": "^4.0.4",
"multileveldown": "^5.0.1",
"npm-check-updates": "^17.1.6",
"npm-run-all2": "^6.2.6",
"pinia": "^2.2.4",
"npm-check-updates": "^17.1.9",
"npm-run-all2": "^7.0.1",
"pinia": "^2.2.5",
"pouchdb-adapter-leveldb-core": "^9.0.0",
"pouchdb-core": "^9.0.0",
"pouchdb-find": "^9.0.0",
"prettier": "^3.3.3",
"radash": "^12.1.0",
"sass": "^1.79.6",
"sass": "^1.80.5",
"setimmediate": "^1.0.5",
"stream-browserify": "^3.0.0",
"tslib": "^2.7.0",
"superjson": "^2.2.1",
"tslib": "^2.8.1",
"type-fest": "^4.26.1",
"typescript": "^5.6.3",
"typescript-eslint-parser-for-extra-files": "^0.7.0",
"util": "^0.12.5",
"uuid": "^10.0.0",
"uuid": "^11.0.2",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.4.6",
"vite-plugin-vue-devtools": "^7.6.2",
"vite-plugin-vuetify": "^2.0.4",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.1.3",
"vitest": "^2.1.4",
"vue": "^3.5.12",
"vue-eslint-parser": "^9.4.3",
"vue-i18n": "^9.14.1",
"vue-i18n": "^10.0.4",
"vue-router": "^4.4.5",
"vue-tsc": "^2.1.8",
"vue-tsc": "^2.1.10",
"vuetify": "^3.7.3",
"xdg-basedir": "^5.1.0",
"zod": "^3.23.8"
},
"dependencies": {
"@electron-toolkit/utils": "^3.0.0",
"electron-log": "^5.2.0",
"level": "^7.0.1",
"leveldown": "^6.1.1",
"serialport": "^12.0.0"
}
}
27 changes: 27 additions & 0 deletions src/core/attachments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export class Attachment extends Uint8Array {
readonly name
readonly type

static async fromFile(file: File) {
return new Attachment(file.name, file.type, await file.arrayBuffer())
}

static async fromPouchAttachment(name: string, attachment: PouchDB.Core.FullAttachment) {
if (Buffer.isBuffer(attachment.data)) {
return new Attachment(name, attachment.content_type, attachment.data.buffer)
}

if (attachment.data instanceof Blob) {
return new Attachment(name, attachment.content_type, await attachment.data.arrayBuffer())
}

const textEncoder = new TextEncoder()
return new Attachment(name, attachment.content_type, textEncoder.encode(attachment.data))
}

constructor(name: string, type: string, data: ArrayBufferLike) {
super(data)
this.name = name
this.type = type
}
}
2 changes: 1 addition & 1 deletion src/core/error-handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getMessage(cause: unknown) {
if (cause instanceof Error) return cause.message
if (cause == null) return `BadError: ${cause}`
if (typeof cause === 'string') return cause
if (typeof cause !== 'object') return String(cause)
if (typeof cause !== 'object') return String(cause as never)
if (!('message' in cause)) return `BadError: ${Object.prototype.toString.call(cause)}`
if (typeof cause.message !== 'string') return String(cause.message)
return cause.message
Expand Down
21 changes: 21 additions & 0 deletions src/core/rpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Base64 } from 'js-base64'
import { SuperJSON } from 'superjson'
import { Attachment } from './attachments'

export default function useSuperJson() {
SuperJSON.registerCustom(
{
isApplicable: (v) => v instanceof Attachment,
serialize: (attachment) => ({
name: attachment.name,
type: attachment.type,
data: Base64.fromUint8Array(attachment)
}),
deserialize: (attachment) =>
new Attachment(attachment.name, attachment.type, Base64.toUint8Array(attachment.data))
},
'Attachment'
)

return SuperJSON
}
36 changes: 36 additions & 0 deletions src/main/dao/sources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineDatabase, getInsertable, getUpdateable } from '../services/database'
import useTiesDatabase from './ties'
import type { getDocument, DocumentId } from '../services/database'

export type Source = getDocument<typeof Source>
export const Source = z.object({
title: z.string().min(1),
image: z.string().min(1).nullable()
})

export const useSourcesDatabase = defineDatabase({
name: 'sources',
schema: Source,
setup: (base) => {
const ties = useTiesDatabase()

return {
remove: async (id: DocumentId) => {
await base.remove(id)

const related = await ties.forSource(id)
await Promise.all(
related.map(async ({ _id }) => {
await ties.remove(_id)
})
)
}
}
}
})

export type NewSource = getInsertable<typeof Source>
export const NewSource = getInsertable(Source)
export type SourceUpdate = getUpdateable<typeof Source>
export const SourceUpdate = getUpdateable(Source)
44 changes: 44 additions & 0 deletions src/main/dao/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { memo } from 'radash'
import { useLevelDb } from '../services/level'

export type UserStore = ReturnType<typeof useUserStore>
const useUserStore = memo(function useUserStore() {
const { levelup } = useLevelDb()

const booted = levelup('_userStorage')

function defineOperation<Args extends unknown[], Result>(
op: (db: Awaited<typeof booted>, ...args: Args) => Promise<Result>
) {
return async (...args: Args) => await op(await booted, ...args)
}

const getItem = defineOperation(async function getItem(db, key: string) {
try {
return (await db.get(key, { asBuffer: false })) as string
} catch {
return null
}
})

const setItem = defineOperation(async function setItem(db, key: string, value: string) {
await db.put(key, value)
})

const removeItem = defineOperation(async function removeItem(db, key: string) {
await db.del(key)
})

const clear = defineOperation(async function clear(db) {
await db.clear()
})

return {
getItem,
setItem,
removeItem,
clear
}
})

export default useUserStore
Loading