Skip to content

Commit

Permalink
idk
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Oct 24, 2023
1 parent 942d3ac commit cdeb4b9
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/create-rspc-app/templates/axum_base/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn router() -> axum::Router {
axum::Router::new()
.route("/", get(|| async { "Welcome to your new rspc app!" }))
.route("/health", get(|| async { "Ok!" }))
.next("/rspc", router.endpoint(|| Ctx {}).axum())
.nest("/rspc", router.endpoint(|| Ctx {}).axum())
}

#[tokio::main]
Expand Down
3 changes: 2 additions & 1 deletion crates/create-rspc-app/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ async fn _test(base_dir: &Path) -> Result<(), String> {
})
});

join_all(x).await.into_iter().collect::<Result<(), _>>()
// join_all(x).await.into_iter().collect::<Result<(), _>>()
Ok(())
}
118 changes: 118 additions & 0 deletions crates/tauri/packages/tauri/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.

export const commands = {

}

export const events = __makeEvents__<{
msg: Msg,
transportResp: Response[]
}>({
msg: "plugin:rspc:msg",
transportResp: "plugin:rspc:transport-resp"
})

/** user-defined types **/

export type Error = { code: ErrorCode; message: string }
/**
* TODO
*/
export type ErrorCode = "BadRequest" | "Unauthorized" | "Forbidden" | "NotFound" | "Timeout" | "Conflict" | "PreconditionFailed" | "PayloadTooLarge" | "MethodNotSupported" | "ClientClosedRequest" | "InternalServerError"
export type Msg = any
export type ProcedureError = { Exec: Error } | { Resolver: any }
/**
* The type of a response from rspc.
*
* @internal
*/
export type Response = (
/**
* The result of a successful operation.
*/
{ type: "value"; value: any } |
/**
* The result of a failed operation.
*/
{ type: "error"; value: ProcedureError } |
/**
* A message to indicate that the operation is complete.
*/
{ type: "complete" }) & { id: number }
/**
* A value that can be a successful result or an error.
*
* @internal
*/
export type ResponseInner =
/**
* The result of a successful operation.
*/
{ type: "value"; value: any } |
/**
* The result of a failed operation.
*/
{ type: "error"; value: ProcedureError } |
/**
* A message to indicate that the operation is complete.
*/
{ type: "complete" }

/** tauri-specta globals **/

import { invoke as TAURI_INVOKE } from "@tauri-apps/api";
import * as TAURI_API_EVENT from "@tauri-apps/api/event";
import { type WebviewWindowHandle as __WebviewWindowHandle__ } from "@tauri-apps/api/window";

type __EventObj__<T> = {
listen: (
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
once: (
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
emit: T extends null
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
};

type __Result__<T, E> =
| { status: "ok"; data: T }
| { status: "error"; error: E };

function __makeEvents__<T extends Record<string, any>>(
mappings: Record<keyof T, string>
) {
return new Proxy(
{} as unknown as {
[K in keyof T]: __EventObj__<T[K]> & {
(handle: __WebviewWindowHandle__): __EventObj__<T[K]>;
};
},
{
get: (_, event) => {
const name = mappings[event as keyof T];

return new Proxy((() => {}) as any, {
apply: (_, __, [window]: [__WebviewWindowHandle__]) => ({
listen: (arg: any) => window.listen(name, arg),
once: (arg: any) => window.once(name, arg),
emit: (arg: any) => window.emit(name, arg),
}),
get: (_, command: keyof __EventObj__<any>) => {
switch (command) {
case "listen":
return (arg: any) => TAURI_API_EVENT.listen(name, arg);
case "once":
return (arg: any) => TAURI_API_EVENT.once(name, arg);
case "emit":
return (arg: any) => TAURI_API_EVENT.emit(name, arg);
}
},
});
},
}
);
}


0 comments on commit cdeb4b9

Please sign in to comment.