@ponder/react 0.11.28 → 0.11.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/hook.js +12 -4
- package/dist/esm/hook.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils.js +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/context.d.ts +8 -3
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/hook.d.ts +8 -2
- package/dist/types/hook.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils.d.ts +3 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/context.ts +5 -2
- package/src/hook.ts +22 -5
- package/src/index.ts +15 -1
- package/src/utils.ts +6 -4
package/dist/esm/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import { compileQuery } from "@ponder/client";
|
|
|
2
2
|
import { stringify } from "superjson";
|
|
3
3
|
export function getPonderQueryOptions(client, queryFn) {
|
|
4
4
|
const queryPromise = queryFn(client.db);
|
|
5
|
+
// @ts-expect-error
|
|
5
6
|
if ("getSQL" in queryPromise === false) {
|
|
6
7
|
throw new Error('"queryFn" must return SQL');
|
|
7
8
|
}
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAKtC,MAAM,UAAU,qBAAqB,CACnC,MAA8B,EAC9B,OAAgD;IAKhD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAExC,mBAAmB;IACnB,IAAI,QAAQ,IAAI,YAAY,KAAK,KAAK,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;KAC9C;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,YAAqC,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAExE,OAAO;QACL,QAAQ;QACR,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY;KAC5B,CAAC;AACJ,CAAC"}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Client } from "@ponder/client";
|
|
3
|
-
|
|
3
|
+
import type { ResolvedSchema } from "./index.js";
|
|
4
|
+
export declare const PonderContext: import("react").Context<Client<{
|
|
5
|
+
[name: string]: unknown;
|
|
6
|
+
}> | undefined>;
|
|
4
7
|
type PonderProviderProps = {
|
|
5
|
-
client: Client
|
|
8
|
+
client: Client<ResolvedSchema>;
|
|
6
9
|
};
|
|
7
|
-
export declare function PonderProvider(parameters: React.PropsWithChildren<PonderProviderProps>): import("react").FunctionComponentElement<import("react").ProviderProps<Client
|
|
10
|
+
export declare function PonderProvider(parameters: React.PropsWithChildren<PonderProviderProps>): import("react").FunctionComponentElement<import("react").ProviderProps<Client<{
|
|
11
|
+
[name: string]: unknown;
|
|
12
|
+
}> | undefined>>;
|
|
8
13
|
export {};
|
|
9
14
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,aAAa;;eAEzB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;CAChC,CAAC;AAEF,wBAAgB,cAAc,CAC5B,UAAU,EAAE,KAAK,CAAC,iBAAiB,CAAC,mBAAmB,CAAC;;iBAKzD"}
|
package/dist/types/hook.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Client, Status } from "@ponder/client";
|
|
2
|
-
import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import { type QueryKey, type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
|
|
3
|
+
import type { ResolvedSchema } from "./index.js";
|
|
3
4
|
export declare function usePonderQuery<result>(params: {
|
|
4
|
-
queryFn: (db: Client["db"]) => Promise<result>;
|
|
5
|
+
queryFn: (db: Client<ResolvedSchema>["db"]) => Promise<result>;
|
|
5
6
|
} & Omit<UseQueryOptions<result>, "queryFn" | "queryKey">): UseQueryResult<result>;
|
|
7
|
+
export declare function usePonderClient(): Client<ResolvedSchema>;
|
|
8
|
+
export declare function usePonderQueryOptions<T>(queryFn: (db: Client<ResolvedSchema>["db"]) => T): {
|
|
9
|
+
queryKey: QueryKey;
|
|
10
|
+
queryFn: () => T;
|
|
11
|
+
};
|
|
6
12
|
export declare function usePonderStatus(params: Omit<UseQueryOptions<Status>, "queryFn" | "queryKey">): UseQueryResult<Status>;
|
|
7
13
|
//# sourceMappingURL=hook.d.ts.map
|
package/dist/types/hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/hook.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EAGpB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/hook.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EAGpB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,wBAAgB,cAAc,CAAC,MAAM,EACnC,MAAM,EAAE;IACN,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAChE,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,GACxD,cAAc,CAAC,MAAM,CAAC,CAyBxB;AAED,wBAAgB,eAAe,IAAI,MAAM,CAAC,cAAc,CAAC,CAMxD;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAC/C;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,CAAC;CAClB,CAGA;AAID,wBAAgB,eAAe,CAC7B,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,GAC5D,cAAc,CAAC,MAAM,CAAC,CAsBxB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { PonderProvider, PonderContext } from "./context.js";
|
|
2
|
-
export { usePonderQuery, usePonderStatus } from "./hook.js";
|
|
2
|
+
export { usePonderQuery, usePonderStatus, usePonderClient, usePonderQueryOptions, } from "./hook.js";
|
|
3
3
|
export { getPonderQueryOptions } from "./utils.js";
|
|
4
|
+
export interface Register {
|
|
5
|
+
}
|
|
6
|
+
export type ResolvedSchema = Register extends {
|
|
7
|
+
schema: infer schema;
|
|
8
|
+
} ? schema : {
|
|
9
|
+
[name: string]: unknown;
|
|
10
|
+
};
|
|
4
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,WAAW,QAAQ;CAAG;AAE5B,MAAM,MAAM,cAAc,GAAG,QAAQ,SAAS;IAAE,MAAM,EAAE,MAAM,MAAM,CAAA;CAAE,GAClE,MAAM,GACN;IACE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB,CAAC"}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Client, compileQuery } from "@ponder/client";
|
|
2
2
|
import type { QueryKey } from "@tanstack/react-query";
|
|
3
|
+
import type { ResolvedSchema } from "./index.js";
|
|
3
4
|
export type SQLWrapper = Exclude<Parameters<typeof compileQuery>[0], string>;
|
|
4
|
-
export declare function getPonderQueryOptions<
|
|
5
|
+
export declare function getPonderQueryOptions<T>(client: Client<ResolvedSchema>, queryFn: (db: Client<ResolvedSchema>["db"]) => T): {
|
|
5
6
|
queryKey: QueryKey;
|
|
6
|
-
queryFn: () =>
|
|
7
|
+
queryFn: () => T;
|
|
7
8
|
};
|
|
8
9
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,EAC9B,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAC/C;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,CAAC;CAClB,CAeA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ponder/react",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.30",
|
|
4
4
|
"description": "React hooks for Ponder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"superjson": "^2.2.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@ponder/client": ">=0.11.
|
|
34
|
+
"@ponder/client": ">=0.11.30",
|
|
35
35
|
"@tanstack/react-query": ">=5.0.0",
|
|
36
36
|
"react": ">=18",
|
|
37
37
|
"typescript": ">=5.0.4"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"rimraf": "^5.0.5",
|
|
53
53
|
"tsx": "^4.19.2",
|
|
54
|
-
"@ponder/client": "0.11.
|
|
54
|
+
"@ponder/client": "0.11.30"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsx build.ts",
|
package/src/context.ts
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Client } from "@ponder/client";
|
|
4
4
|
import { createContext, createElement } from "react";
|
|
5
|
+
import type { ResolvedSchema } from "./index.js";
|
|
5
6
|
|
|
6
|
-
export const PonderContext = createContext<Client | undefined>(
|
|
7
|
+
export const PonderContext = createContext<Client<ResolvedSchema> | undefined>(
|
|
8
|
+
undefined,
|
|
9
|
+
);
|
|
7
10
|
|
|
8
11
|
type PonderProviderProps = {
|
|
9
|
-
client: Client
|
|
12
|
+
client: Client<ResolvedSchema>;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
export function PonderProvider(
|
package/src/hook.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Client, Status } from "@ponder/client";
|
|
4
4
|
import {
|
|
5
|
+
type QueryKey,
|
|
5
6
|
type UseQueryOptions,
|
|
6
7
|
type UseQueryResult,
|
|
7
8
|
useQuery,
|
|
@@ -9,19 +10,17 @@ import {
|
|
|
9
10
|
} from "@tanstack/react-query";
|
|
10
11
|
import { useContext, useEffect, useMemo } from "react";
|
|
11
12
|
import { PonderContext } from "./context.js";
|
|
13
|
+
import type { ResolvedSchema } from "./index.js";
|
|
12
14
|
import { getPonderQueryOptions } from "./utils.js";
|
|
13
15
|
|
|
14
16
|
export function usePonderQuery<result>(
|
|
15
17
|
params: {
|
|
16
|
-
queryFn: (db: Client["db"]) => Promise<result>;
|
|
18
|
+
queryFn: (db: Client<ResolvedSchema>["db"]) => Promise<result>;
|
|
17
19
|
} & Omit<UseQueryOptions<result>, "queryFn" | "queryKey">,
|
|
18
20
|
): UseQueryResult<result> {
|
|
19
21
|
const queryClient = useQueryClient();
|
|
20
22
|
|
|
21
|
-
const client =
|
|
22
|
-
if (client === undefined) {
|
|
23
|
-
throw new Error("PonderProvider not found");
|
|
24
|
-
}
|
|
23
|
+
const client = usePonderClient();
|
|
25
24
|
|
|
26
25
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
27
26
|
const queryOptions = useMemo(
|
|
@@ -45,6 +44,24 @@ export function usePonderQuery<result>(
|
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
export function usePonderClient(): Client<ResolvedSchema> {
|
|
48
|
+
const client = useContext(PonderContext);
|
|
49
|
+
if (client === undefined) {
|
|
50
|
+
throw new Error("PonderProvider not found");
|
|
51
|
+
}
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function usePonderQueryOptions<T>(
|
|
56
|
+
queryFn: (db: Client<ResolvedSchema>["db"]) => T,
|
|
57
|
+
): {
|
|
58
|
+
queryKey: QueryKey;
|
|
59
|
+
queryFn: () => T;
|
|
60
|
+
} {
|
|
61
|
+
const client = usePonderClient();
|
|
62
|
+
return getPonderQueryOptions(client, queryFn);
|
|
63
|
+
}
|
|
64
|
+
|
|
48
65
|
const statusQueryKey = ["status"];
|
|
49
66
|
|
|
50
67
|
export function usePonderStatus(
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
export { PonderProvider, PonderContext } from "./context.js";
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
usePonderQuery,
|
|
4
|
+
usePonderStatus,
|
|
5
|
+
usePonderClient,
|
|
6
|
+
usePonderQueryOptions,
|
|
7
|
+
} from "./hook.js";
|
|
3
8
|
export { getPonderQueryOptions } from "./utils.js";
|
|
9
|
+
|
|
10
|
+
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
|
|
11
|
+
export interface Register {}
|
|
12
|
+
|
|
13
|
+
export type ResolvedSchema = Register extends { schema: infer schema }
|
|
14
|
+
? schema
|
|
15
|
+
: {
|
|
16
|
+
[name: string]: unknown;
|
|
17
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { type Client, compileQuery } from "@ponder/client";
|
|
2
2
|
import type { QueryKey } from "@tanstack/react-query";
|
|
3
3
|
import { stringify } from "superjson";
|
|
4
|
+
import type { ResolvedSchema } from "./index.js";
|
|
4
5
|
|
|
5
6
|
export type SQLWrapper = Exclude<Parameters<typeof compileQuery>[0], string>;
|
|
6
7
|
|
|
7
|
-
export function getPonderQueryOptions<
|
|
8
|
-
client: Client
|
|
9
|
-
queryFn: (db: Client["db"]) =>
|
|
8
|
+
export function getPonderQueryOptions<T>(
|
|
9
|
+
client: Client<ResolvedSchema>,
|
|
10
|
+
queryFn: (db: Client<ResolvedSchema>["db"]) => T,
|
|
10
11
|
): {
|
|
11
12
|
queryKey: QueryKey;
|
|
12
|
-
queryFn: () =>
|
|
13
|
+
queryFn: () => T;
|
|
13
14
|
} {
|
|
14
15
|
const queryPromise = queryFn(client.db);
|
|
15
16
|
|
|
17
|
+
// @ts-expect-error
|
|
16
18
|
if ("getSQL" in queryPromise === false) {
|
|
17
19
|
throw new Error('"queryFn" must return SQL');
|
|
18
20
|
}
|