Skip to content

Commit 293def9

Browse files
committed
Reshuffle some stuff...
1 parent b997358 commit 293def9

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ esbuild.build({
1010
minify: false,
1111
platform: "neutral",
1212
sourcemap: true,
13-
external: ["react-query"],
13+
external: ["react-query", "fast-safe-stringify"],
1414
...argv,
1515
});

example-app/server-sdk.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createBifrost, QueryClient } from "bifrost";
2+
import axios from "axios";
3+
import type { ApiType } from "./server-api";
4+
5+
export function createServerSDK(queryClient: QueryClient) {
6+
const ServerSDK = createBifrost<ApiType>({
7+
queryClient,
8+
doFetch: async ({ argument, path }) => {
9+
return axios
10+
.post(`http://localhost:8000/${path.join("/")}`, { argument })
11+
.then((resp) => resp.data);
12+
},
13+
});
14+
15+
return { ServerSDK };
16+
}

example-app/src/App.tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect } from "react";
22
import { render } from "react-dom";
3-
import type { ApiType } from "../server-api";
4-
import axios from "axios";
5-
import { createBifrost } from "bifrost";
6-
import {
7-
QueryClient,
8-
QueryClientProvider,
9-
useMutation,
10-
useQueryClient,
11-
} from "react-query";
3+
import { createServerSDK } from "../server-sdk";
4+
import { QueryClient, QueryClientProvider, useQueryClient } from "react-query";
125

136
const queryClient = new QueryClient();
147

15-
const Bifrost = createBifrost<ApiType>({
16-
queryClient,
17-
doFetch: async ({ argument, path }) => {
18-
return axios
19-
.post(`http://localhost:8000/${path.join("/")}`, { argument })
20-
.then((resp) => resp.data);
21-
},
22-
});
8+
const { ServerSDK } = createServerSDK(queryClient);
239

2410
function App() {
2511
return (
@@ -31,16 +17,16 @@ function App() {
3117

3218
function AppInner() {
3319
useEffect(() => {
34-
Bifrost.sdk.accounts.someCoolAccountsFn({ foo: "asdf" }).then((data) => {
20+
ServerSDK.sdk.accounts.someCoolAccountsFn({ foo: "asdf" }).then((data) => {
3521
console.log("Fetched data!", data.someValue);
3622
});
3723
}, []);
3824

39-
const r2 = Bifrost.useSDKMutation().accounts.someCoolAccountsFn();
25+
const r2 = ServerSDK.useSDKMutation().accounts.someCoolAccountsFn();
4026

4127
const qc = useQueryClient();
4228

43-
const r = Bifrost.useSDK().accounts.anotherCoolAccountsFn(
29+
const r = ServerSDK.useSDK().accounts.anotherCoolAccountsFn(
4430
{ bar: 123, blah: "asdf" },
4531
{
4632
select: (a) => a.waddup,
@@ -50,7 +36,7 @@ function AppInner() {
5036
return (
5137
<div
5238
onClick={() => {
53-
const asdf = Bifrost.getSDKQueryKey.accounts.anotherCoolAccountsFn({
39+
const asdf = ServerSDK.getSDKQueryKey.accounts.anotherCoolAccountsFn({
5440
blah: "asdf",
5541
bar: 123,
5642
});

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
} from "react-query";
1919
import { createBifrostSDK } from "./server";
2020

21+
//For convenience, export the react-query QueryClient type
22+
export type { QueryClient } from "react-query";
23+
2124
export function createBifrost<Endpoints extends DeepAsyncFnRecord<Endpoints>>(
2225
opts: Opts
2326
): {

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"noEmitHelpers": true,
1717
"noImplicitAny": true,
1818
"noImplicitReturns": true,
19+
"emitDeclarationOnly": true,
1920
"noImplicitThis": true,
2021
"preserveWatchOutput": true,
2122
"noPropertyAccessFromIndexSignature": true,

0 commit comments

Comments
 (0)