-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved from WebSocket to IPC for tRPC
- Loading branch information
Showing
49 changed files
with
456 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { IpcMainInvokeEvent } from 'electron' | ||
|
||
export const theRpcChannel = 'trpc:msg' | ||
|
||
export interface CreateContextOptions { | ||
event: IpcMainInvokeEvent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Base64 } from 'js-base64' | ||
import { SuperJSON } from 'superjson' | ||
import { Attachment } from '../attachments' | ||
import { raiseError } from '../error-handling' | ||
|
||
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' | ||
) | ||
|
||
// HACK: tRPC won't serialize functions; but doesn't filter | ||
// them out, so IPC throws an error if they are passed. | ||
// This can also ensure any types with functions | ||
// won't be returned as seen in the return | ||
// type information for the router. | ||
SuperJSON.registerCustom( | ||
{ | ||
isApplicable: (v): v is () => undefined => typeof v === 'function', | ||
serialize: (_: () => undefined) => raiseError(() => new TypeError('Functions may not be serialized')), | ||
deserialize: (_: never) => () => undefined | ||
}, | ||
'Function' | ||
) | ||
|
||
return SuperJSON | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.