gomtm 0.0.1 → 0.0.3

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.
Files changed (55) hide show
  1. package/dist/esm/clientlib.d.ts +6 -0
  2. package/dist/esm/clientlib.js +44 -0
  3. package/dist/esm/connectquery/call-unary-method.d.ts +8 -0
  4. package/dist/esm/connectquery/call-unary-method.js +47 -0
  5. package/dist/esm/connectquery/connect-query-key.d.ts +16 -0
  6. package/dist/esm/connectquery/connect-query-key.js +15 -0
  7. package/dist/esm/connectquery/create-use-infinite-query-options.d.ts +21 -0
  8. package/dist/esm/connectquery/create-use-infinite-query-options.js +92 -0
  9. package/dist/esm/connectquery/create-use-query-options.d.ts +19 -0
  10. package/dist/esm/connectquery/create-use-query-options.js +74 -0
  11. package/dist/esm/connectquery/default-options.d.ts +6 -0
  12. package/dist/esm/connectquery/default-options.js +9 -0
  13. package/dist/esm/connectquery/index.d.ts +16 -0
  14. package/dist/esm/connectquery/index.js +33 -0
  15. package/dist/esm/connectquery/method-unary-descriptor.d.ts +4 -0
  16. package/dist/esm/connectquery/method-unary-descriptor.js +0 -0
  17. package/dist/esm/connectquery/use-infinite-query.d.ts +12 -0
  18. package/dist/esm/connectquery/use-infinite-query.js +87 -0
  19. package/dist/esm/connectquery/use-mutation.d.ts +10 -0
  20. package/dist/esm/connectquery/use-mutation.js +79 -0
  21. package/dist/esm/connectquery/use-query.d.ts +12 -0
  22. package/dist/esm/connectquery/use-query.js +75 -0
  23. package/dist/esm/connectquery/use-transport.d.ts +7 -0
  24. package/dist/esm/connectquery/use-transport.js +23 -0
  25. package/dist/esm/connectquery/utils.d.ts +12 -0
  26. package/dist/esm/connectquery/utils.js +24 -0
  27. package/dist/esm/consts.d.ts +28 -0
  28. package/dist/esm/consts.js +58 -0
  29. package/dist/esm/http/cors.d.ts +15 -0
  30. package/dist/esm/http/cors.js +129 -0
  31. package/dist/esm/http/fetchMiddleWithCache.d.ts +2 -0
  32. package/dist/esm/http/fetchMiddleWithCache.js +87 -0
  33. package/dist/esm/http/fetchMiddleWithUrlProxy.d.ts +2 -0
  34. package/dist/esm/http/fetchMiddleWithUrlProxy.js +28 -0
  35. package/dist/esm/http/mthttp.d.ts +5 -0
  36. package/dist/esm/http/mthttp.js +61 -0
  37. package/dist/esm/http/response-cache.test.js +72 -0
  38. package/dist/esm/messageTypeRegistry.d.ts +4 -0
  39. package/dist/esm/messageTypeRegistry.js +36 -0
  40. package/dist/esm/mtmFetcher.d.ts +13 -0
  41. package/dist/esm/mtmFetcher.js +145 -0
  42. package/dist/esm/mtmcore.d.ts +5 -0
  43. package/dist/esm/mtmcore.js +19 -0
  44. package/dist/esm/providers/GomtmProvider.d.ts +68 -0
  45. package/dist/esm/providers/GomtmProvider.js +100 -0
  46. package/dist/esm/providers/MtConnectProvider.d.ts +2 -0
  47. package/dist/esm/providers/MtConnectProvider.js +18 -0
  48. package/dist/esm/providers/ReactQueryProvider.d.ts +4 -0
  49. package/dist/esm/providers/ReactQueryProvider.js +63 -0
  50. package/dist/esm/providers/userContext.d.ts +14 -0
  51. package/dist/esm/providers/userContext.js +99 -0
  52. package/dist/esm/utils.d.ts +1 -0
  53. package/dist/esm/utils.js +32 -0
  54. package/dist/tsconfig.type.tsbuildinfo +1 -1
  55. package/package.json +10 -3
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T>;
3
+ export declare function getCookie(name: string): string | undefined;
4
+ export declare function deleteCookie(name: string): void;
5
+ export declare function deleteAllCookies(): void;
6
+ export declare function setCookie(name: string, value: any): void;
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ function mergeRefs(refs) {
3
+ return (value) => {
4
+ refs.forEach((ref) => {
5
+ if (typeof ref === "function") {
6
+ ref(value);
7
+ } else if (ref != null) {
8
+ ;
9
+ ref.current = value;
10
+ }
11
+ });
12
+ };
13
+ }
14
+ function getCookie(name) {
15
+ const cookieArr = document.cookie.split(";");
16
+ for (let i = 0; i < cookieArr.length; i++) {
17
+ const cookiePair = cookieArr[i].split("=");
18
+ if (name == cookiePair[0].trim()) {
19
+ return decodeURIComponent(cookiePair[1]);
20
+ }
21
+ }
22
+ }
23
+ function deleteCookie(name) {
24
+ document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
25
+ }
26
+ function deleteAllCookies() {
27
+ const cookies = document.cookie.split(";");
28
+ for (let i = 0; i < cookies.length; i++) {
29
+ const cookie = cookies[i];
30
+ const eqPos = cookie.indexOf("=");
31
+ const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
32
+ document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
33
+ }
34
+ }
35
+ function setCookie(name, value) {
36
+ document.cookie = `${name}=${value}`;
37
+ }
38
+ export {
39
+ deleteAllCookies,
40
+ deleteCookie,
41
+ getCookie,
42
+ mergeRefs,
43
+ setCookie
44
+ };
@@ -0,0 +1,8 @@
1
+ import { PlainMessage, type Message, type PartialMessage } from "@bufbuild/protobuf";
2
+ import type { CallOptions, Transport } from "@connectrpc/connect";
3
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
4
+ import { MtUnaryCallError } from "./utils";
5
+ export declare function callUnaryMethod<I extends Message<I>, O extends Message<O>>(methodType: MethodUnaryDescriptor<I, O>, input: PartialMessage<I> | undefined, { callOptions, transport, }: {
6
+ transport: Transport;
7
+ callOptions?: CallOptions | undefined;
8
+ }): Promise<PlainMessage<O> & MtUnaryCallError>;
@@ -0,0 +1,47 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { toPlainMessage } from "@bufbuild/protobuf";
22
+ function callUnaryMethod(_0, _1, _2) {
23
+ return __async(this, arguments, function* (methodType, input, {
24
+ callOptions,
25
+ transport
26
+ }) {
27
+ try {
28
+ const result = yield transport.unary(
29
+ { typeName: methodType.service.typeName, methods: {} },
30
+ methodType,
31
+ callOptions == null ? void 0 : callOptions.signal,
32
+ callOptions == null ? void 0 : callOptions.timeoutMs,
33
+ callOptions == null ? void 0 : callOptions.headers,
34
+ input != null ? input : {}
35
+ );
36
+ return toPlainMessage(result.message);
37
+ } catch (e) {
38
+ return {
39
+ error_message: e == null ? void 0 : e.toString(),
40
+ error_code: "unary_call_error"
41
+ };
42
+ }
43
+ });
44
+ }
45
+ export {
46
+ callUnaryMethod
47
+ };
@@ -0,0 +1,16 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
3
+ import type { DisableQuery } from "./utils";
4
+ export type ConnectQueryKey<I extends Message<I>> = [
5
+ serviceTypeName: string,
6
+ methodName: string,
7
+ input: PartialMessage<I>
8
+ ];
9
+ export declare function createConnectQueryKey<I extends Message<I>, O extends Message<O>>(methodDescriptor: Pick<MethodUnaryDescriptor<I, O>, "I" | "name" | "service">, input?: DisableQuery | PartialMessage<I> | undefined): ConnectQueryKey<I>;
10
+ export type ConnectInfiniteQueryKey<I extends Message<I>> = [
11
+ serviceTypeName: string,
12
+ methodName: string,
13
+ input: PartialMessage<I>,
14
+ "infinite"
15
+ ];
16
+ export declare function createConnectInfiniteQueryKey<I extends Message<I>, O extends Message<O>>(methodDescriptor: Pick<MethodUnaryDescriptor<I, O>, "I" | "name" | "service">, input?: DisableQuery | PartialMessage<I> | undefined): ConnectInfiniteQueryKey<I>;
@@ -0,0 +1,15 @@
1
+ import { disableQuery } from "./utils";
2
+ function createConnectQueryKey(methodDescriptor, input) {
3
+ return [
4
+ methodDescriptor.service.typeName,
5
+ methodDescriptor.name,
6
+ input === disableQuery || !input ? {} : input
7
+ ];
8
+ }
9
+ function createConnectInfiniteQueryKey(methodDescriptor, input) {
10
+ return [...createConnectQueryKey(methodDescriptor, input), "infinite"];
11
+ }
12
+ export {
13
+ createConnectInfiniteQueryKey,
14
+ createConnectQueryKey
15
+ };
@@ -0,0 +1,21 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { CallOptions, ConnectError, Transport } from "@connectrpc/connect";
3
+ import type { GetNextPageParamFunction, InfiniteData, QueryFunction, UseInfiniteQueryOptions, UseSuspenseInfiniteQueryOptions } from "@tanstack/react-query";
4
+ import { type ConnectInfiniteQueryKey } from "./connect-query-key";
5
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
6
+ import { MtUnaryCallError, type DisableQuery } from "./utils";
7
+ export interface ConnectInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> {
8
+ pageParamKey: ParamKey;
9
+ transport: Transport;
10
+ callOptions?: Omit<CallOptions, "signal"> | undefined;
11
+ getNextPageParam: GetNextPageParamFunction<PartialMessage<I>[ParamKey], O | MtUnaryCallError>;
12
+ }
13
+ export type CreateInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> = ConnectInfiniteQueryOptions<I, O, ParamKey> & Omit<UseInfiniteQueryOptions<O, ConnectError, InfiniteData<O>, O, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>, "getNextPageParam" | "initialPageParam" | "queryFn" | "queryKey">;
14
+ export type CreateSuspenseInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> = ConnectInfiniteQueryOptions<I, O, ParamKey> & Omit<UseSuspenseInfiniteQueryOptions<O, ConnectError, InfiniteData<O>, O, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>, "getNextPageParam" | "initialPageParam" | "queryFn" | "queryKey">;
15
+ export declare function createUseInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>>(methodSig: MethodUnaryDescriptor<I, O>, input: DisableQuery | (PartialMessage<I> & Required<Pick<PartialMessage<I>, ParamKey>>), { transport, getNextPageParam, pageParamKey, callOptions, }: ConnectInfiniteQueryOptions<I, O, ParamKey>): {
16
+ getNextPageParam: ConnectInfiniteQueryOptions<I, O, ParamKey>["getNextPageParam"];
17
+ queryKey: ConnectInfiniteQueryKey<I>;
18
+ queryFn: QueryFunction<O | MtUnaryCallError, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>;
19
+ initialPageParam: PartialMessage<I>[ParamKey];
20
+ enabled: boolean;
21
+ };
@@ -0,0 +1,92 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { callUnaryMethod } from "./call-unary-method";
41
+ import {
42
+ createConnectInfiniteQueryKey
43
+ } from "./connect-query-key";
44
+ import { assert, disableQuery } from "./utils";
45
+ function createUnaryInfiniteQueryFn(methodType, input, {
46
+ callOptions,
47
+ transport,
48
+ pageParamKey
49
+ }) {
50
+ return (context) => __async(this, null, function* () {
51
+ var _a;
52
+ assert(input !== disableQuery, "Disabled query cannot be fetched");
53
+ assert("pageParam" in context, "pageParam must be part of context");
54
+ const inputCombinedWithPageParam = __spreadProps(__spreadValues({}, input), {
55
+ [pageParamKey]: context.pageParam
56
+ });
57
+ console.log("callUnaryMothod", inputCombinedWithPageParam);
58
+ return callUnaryMethod(methodType, inputCombinedWithPageParam, {
59
+ callOptions: __spreadProps(__spreadValues({}, callOptions), {
60
+ signal: (_a = callOptions == null ? void 0 : callOptions.signal) != null ? _a : context.signal
61
+ }),
62
+ transport
63
+ });
64
+ });
65
+ }
66
+ function createUseInfiniteQueryOptions(methodSig, input, {
67
+ transport,
68
+ getNextPageParam,
69
+ pageParamKey,
70
+ callOptions
71
+ }) {
72
+ const queryKey = createConnectInfiniteQueryKey(
73
+ methodSig,
74
+ input === disableQuery ? void 0 : __spreadProps(__spreadValues({}, input), {
75
+ [pageParamKey]: void 0
76
+ })
77
+ );
78
+ return {
79
+ getNextPageParam,
80
+ initialPageParam: input === disableQuery ? void 0 : input[pageParamKey],
81
+ queryKey,
82
+ queryFn: createUnaryInfiniteQueryFn(methodSig, input, {
83
+ transport,
84
+ callOptions,
85
+ pageParamKey
86
+ }),
87
+ enabled: input !== disableQuery
88
+ };
89
+ }
90
+ export {
91
+ createUseInfiniteQueryOptions
92
+ };
@@ -0,0 +1,19 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { CallOptions, ConnectError, Transport } from "@connectrpc/connect";
3
+ import type { QueryFunction, UseQueryOptions, UseSuspenseQueryOptions } from "@tanstack/react-query";
4
+ import type { ConnectQueryKey } from "./connect-query-key";
5
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
6
+ import { MtUnaryCallError, type DisableQuery } from "./utils";
7
+ export interface ConnectQueryOptions {
8
+ transport: Transport;
9
+ callOptions?: Omit<CallOptions, "signal"> | undefined;
10
+ }
11
+ export type CreateQueryOptions<I extends Message<I>, O extends Message<O>, SelectOutData = 0 | MtUnaryCallError> = ConnectQueryOptions & Omit<UseQueryOptions<O | MtUnaryCallError, ConnectError, SelectOutData, ConnectQueryKey<I>>, "queryFn" | "queryKey">;
12
+ export type CreateSuspenseQueryOptions<I extends Message<I>, O extends Message<O>, SelectOutData = 0> = ConnectQueryOptions & Omit<UseSuspenseQueryOptions<O | MtUnaryCallError, ConnectError, SelectOutData, ConnectQueryKey<I>>, "queryFn" | "queryKey">;
13
+ export declare function createUseQueryOptions<I extends Message<I>, O extends Message<O>>(methodSig: MethodUnaryDescriptor<I, O>, input: DisableQuery | PartialMessage<I> | undefined, { transport, callOptions, }: ConnectQueryOptions & {
14
+ transport: Transport;
15
+ }): {
16
+ queryKey: ConnectQueryKey<I>;
17
+ queryFn: QueryFunction<O | MtUnaryCallError, ConnectQueryKey<I>>;
18
+ enabled: boolean;
19
+ };
@@ -0,0 +1,74 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { callUnaryMethod } from "./call-unary-method";
41
+ import { createConnectQueryKey } from "./connect-query-key";
42
+ import { assert, disableQuery } from "./utils";
43
+ function createUnaryQueryFn(methodType, input, {
44
+ callOptions,
45
+ transport
46
+ }) {
47
+ return (context) => __async(this, null, function* () {
48
+ var _a;
49
+ assert(input !== disableQuery, "Disabled query cannot be fetched");
50
+ return callUnaryMethod(methodType, input, {
51
+ callOptions: __spreadProps(__spreadValues({}, callOptions), {
52
+ signal: (_a = callOptions == null ? void 0 : callOptions.signal) != null ? _a : context.signal
53
+ }),
54
+ transport
55
+ });
56
+ });
57
+ }
58
+ function createUseQueryOptions(methodSig, input, {
59
+ transport,
60
+ callOptions
61
+ }) {
62
+ const queryKey = createConnectQueryKey(methodSig, input);
63
+ return {
64
+ queryKey,
65
+ queryFn: createUnaryQueryFn(methodSig, input, {
66
+ transport,
67
+ callOptions
68
+ }),
69
+ enabled: input !== disableQuery
70
+ };
71
+ }
72
+ export {
73
+ createUseQueryOptions
74
+ };
@@ -0,0 +1,6 @@
1
+ import stableHash from "stable-hash";
2
+ export declare const defaultOptions: {
3
+ queries: {
4
+ queryKeyHashFn: typeof stableHash;
5
+ };
6
+ };
@@ -0,0 +1,9 @@
1
+ import stableHash from "stable-hash";
2
+ const defaultOptions = {
3
+ queries: {
4
+ queryKeyHashFn: stableHash
5
+ }
6
+ };
7
+ export {
8
+ defaultOptions
9
+ };
@@ -0,0 +1,16 @@
1
+ export { callUnaryMethod } from "./call-unary-method";
2
+ export { createConnectInfiniteQueryKey, createConnectQueryKey } from "./connect-query-key";
3
+ export type { ConnectInfiniteQueryKey, ConnectQueryKey } from "./connect-query-key";
4
+ export { createUseInfiniteQueryOptions as createInfiniteQueryOptions } from "./create-use-infinite-query-options";
5
+ export type { CreateInfiniteQueryOptions as UseInfiniteQueryOptions } from "./create-use-infinite-query-options";
6
+ export { createUseQueryOptions as createQueryOptions } from "./create-use-query-options";
7
+ export type { CreateQueryOptions as UseQueryOptions } from "./create-use-query-options";
8
+ export { defaultOptions } from "./default-options";
9
+ export type { MethodUnaryDescriptor } from "./method-unary-descriptor";
10
+ export { useInfiniteQuery, useSuspenseInfiniteQuery } from "./use-infinite-query";
11
+ export { useMutation } from "./use-mutation";
12
+ export type { UseMutationOptions } from "./use-mutation";
13
+ export { useQuery, useSuspenseQuery } from "./use-query";
14
+ export { TransportProvider, useTransport } from "./use-transport";
15
+ export { createProtobufSafeUpdater, disableQuery } from "./utils";
16
+ export type { ConnectUpdater, DisableQuery } from "./utils";
@@ -0,0 +1,33 @@
1
+ import { callUnaryMethod } from "./call-unary-method";
2
+ import {
3
+ createConnectInfiniteQueryKey,
4
+ createConnectQueryKey
5
+ } from "./connect-query-key";
6
+ import { createUseInfiniteQueryOptions } from "./create-use-infinite-query-options";
7
+ import { createUseQueryOptions } from "./create-use-query-options";
8
+ import { defaultOptions } from "./default-options";
9
+ import {
10
+ useInfiniteQuery,
11
+ useSuspenseInfiniteQuery
12
+ } from "./use-infinite-query";
13
+ import { useMutation } from "./use-mutation";
14
+ import { useQuery, useSuspenseQuery } from "./use-query";
15
+ import { TransportProvider, useTransport } from "./use-transport";
16
+ import { createProtobufSafeUpdater, disableQuery } from "./utils";
17
+ export {
18
+ TransportProvider,
19
+ callUnaryMethod,
20
+ createConnectInfiniteQueryKey,
21
+ createConnectQueryKey,
22
+ createUseInfiniteQueryOptions as createInfiniteQueryOptions,
23
+ createProtobufSafeUpdater,
24
+ createUseQueryOptions as createQueryOptions,
25
+ defaultOptions,
26
+ disableQuery,
27
+ useInfiniteQuery,
28
+ useMutation,
29
+ useQuery,
30
+ useSuspenseInfiniteQuery,
31
+ useSuspenseQuery,
32
+ useTransport
33
+ };
@@ -0,0 +1,4 @@
1
+ import type { Message, MethodInfoUnary, ServiceType } from "@bufbuild/protobuf";
2
+ export type MethodUnaryDescriptor<I extends Message<I>, O extends Message<O>> = MethodInfoUnary<I, O> & {
3
+ readonly service: Omit<ServiceType, "methods">;
4
+ };
@@ -0,0 +1,12 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { ConnectError, Transport } from "@connectrpc/connect";
3
+ import type { InfiniteData, UseInfiniteQueryResult, UseSuspenseInfiniteQueryResult } from "@tanstack/react-query";
4
+ import type { CreateInfiniteQueryOptions, CreateSuspenseInfiniteQueryOptions } from "./create-use-infinite-query-options";
5
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
6
+ import type { DisableQuery, MtUnaryCallError } from "./utils";
7
+ export declare function useInfiniteQuery<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>>(methodSig: MethodUnaryDescriptor<I, O>, input: DisableQuery | (PartialMessage<I> & Required<Pick<PartialMessage<I>, ParamKey>>), { transport, callOptions, pageParamKey, getNextPageParam, ...options }: Omit<CreateInfiniteQueryOptions<I, O, ParamKey>, "transport"> & {
8
+ transport?: Transport;
9
+ }): UseInfiniteQueryResult<InfiniteData<O | MtUnaryCallError>, ConnectError>;
10
+ export declare function useSuspenseInfiniteQuery<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>>(methodSig: MethodUnaryDescriptor<I, O>, input: PartialMessage<I> & Required<Pick<PartialMessage<I>, ParamKey>>, { transport, callOptions, pageParamKey, getNextPageParam, ...options }: Omit<CreateSuspenseInfiniteQueryOptions<I, O, ParamKey>, "transport" | "refetchInterval"> & {
11
+ transport?: Transport;
12
+ }): UseSuspenseInfiniteQueryResult<InfiniteData<O & MtUnaryCallError>, ConnectError>;
@@ -0,0 +1,87 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import {
33
+ useInfiniteQuery as tsUseInfiniteQuery,
34
+ useSuspenseInfiniteQuery as tsUseSuspenseInfiniteQuery
35
+ } from "@tanstack/react-query";
36
+ import { createUseInfiniteQueryOptions } from "./create-use-infinite-query-options";
37
+ import { useTransport } from "./use-transport";
38
+ function useInfiniteQuery(methodSig, input, _a) {
39
+ var _b = _a, {
40
+ transport,
41
+ callOptions,
42
+ pageParamKey,
43
+ getNextPageParam
44
+ } = _b, options = __objRest(_b, [
45
+ "transport",
46
+ "callOptions",
47
+ "pageParamKey",
48
+ "getNextPageParam"
49
+ ]);
50
+ var _a2;
51
+ const transportFromCtx = useTransport();
52
+ const baseOptions = createUseInfiniteQueryOptions(methodSig, input, {
53
+ transport: transport != null ? transport : transportFromCtx,
54
+ getNextPageParam,
55
+ pageParamKey,
56
+ callOptions
57
+ });
58
+ const enabled = baseOptions.enabled && ((_a2 = options.enabled) != null ? _a2 : true);
59
+ return tsUseInfiniteQuery(__spreadProps(__spreadValues(__spreadValues({}, options), baseOptions), {
60
+ enabled
61
+ }));
62
+ }
63
+ function useSuspenseInfiniteQuery(methodSig, input, _c) {
64
+ var _d = _c, {
65
+ transport,
66
+ callOptions,
67
+ pageParamKey,
68
+ getNextPageParam
69
+ } = _d, options = __objRest(_d, [
70
+ "transport",
71
+ "callOptions",
72
+ "pageParamKey",
73
+ "getNextPageParam"
74
+ ]);
75
+ const transportFromCtx = useTransport();
76
+ const baseOptions = createUseInfiniteQueryOptions(methodSig, input, {
77
+ transport: transport != null ? transport : transportFromCtx,
78
+ getNextPageParam,
79
+ pageParamKey,
80
+ callOptions
81
+ });
82
+ return tsUseSuspenseInfiniteQuery(__spreadValues(__spreadValues({}, options), baseOptions));
83
+ }
84
+ export {
85
+ useInfiniteQuery,
86
+ useSuspenseInfiniteQuery
87
+ };
@@ -0,0 +1,10 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { CallOptions, ConnectError, Transport } from "@connectrpc/connect";
3
+ import type { UseMutationOptions as TSUseMutationOptions, UseMutationResult } from "@tanstack/react-query";
4
+ import type { ConnectQueryKey } from "./connect-query-key";
5
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
6
+ export type UseMutationOptions<I extends Message<I>, O extends Message<O>> = Omit<TSUseMutationOptions<O, ConnectError, PartialMessage<I>, ConnectQueryKey<I>>, "mutationFn"> & {
7
+ transport?: Transport;
8
+ callOptions?: CallOptions;
9
+ };
10
+ export declare function useMutation<I extends Message<I>, O extends Message<O>>(methodSig: MethodUnaryDescriptor<I, O>, { transport, callOptions, ...queryOptions }?: UseMutationOptions<I, O>): UseMutationResult<O, ConnectError, PartialMessage<I>>;
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+ import { useMutation as tsUseMutation } from "@tanstack/react-query";
53
+ import { useCallback } from "react";
54
+ import { useTransport } from "./use-transport";
55
+ function useMutation(methodSig, _a = {}) {
56
+ var _b = _a, { transport, callOptions } = _b, queryOptions = __objRest(_b, ["transport", "callOptions"]);
57
+ const transportFromCtx = useTransport();
58
+ const transportToUse = transport != null ? transport : transportFromCtx;
59
+ const mutationFn = useCallback(
60
+ (input) => __async(this, null, function* () {
61
+ const result = yield transportToUse.unary(
62
+ { typeName: methodSig.service.typeName, methods: {} },
63
+ methodSig,
64
+ callOptions == null ? void 0 : callOptions.signal,
65
+ callOptions == null ? void 0 : callOptions.timeoutMs,
66
+ callOptions == null ? void 0 : callOptions.headers,
67
+ input
68
+ );
69
+ return result.message;
70
+ }),
71
+ [transportToUse, callOptions, methodSig]
72
+ );
73
+ return tsUseMutation(__spreadProps(__spreadValues({}, queryOptions), {
74
+ mutationFn
75
+ }));
76
+ }
77
+ export {
78
+ useMutation
79
+ };
@@ -0,0 +1,12 @@
1
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
+ import type { ConnectError, Transport } from "@connectrpc/connect";
3
+ import type { UseQueryResult, UseSuspenseQueryResult } from "@tanstack/react-query";
4
+ import type { CreateQueryOptions, CreateSuspenseQueryOptions } from "./create-use-query-options";
5
+ import type { MethodUnaryDescriptor } from "./method-unary-descriptor";
6
+ import type { DisableQuery, MtUnaryCallError } from "./utils";
7
+ export declare function useQuery<I extends Message<I>, O extends Message<O>, SelectOutData = O>(methodSig: MethodUnaryDescriptor<I, O>, input?: DisableQuery | PartialMessage<I>, { transport, callOptions, ...queryOptions }?: Omit<CreateQueryOptions<I, O, SelectOutData>, "transport"> & {
8
+ transport?: Transport;
9
+ }): UseQueryResult<SelectOutData | MtUnaryCallError, ConnectError>;
10
+ export declare function useSuspenseQuery<I extends Message<I>, O extends Message<O>, SelectOutData = O & MtUnaryCallError>(methodSig: MethodUnaryDescriptor<I, O>, input?: PartialMessage<I>, { transport, callOptions, ...queryOptions }?: Omit<CreateSuspenseQueryOptions<I, O, SelectOutData>, "transport"> & {
11
+ transport?: Transport;
12
+ }): UseSuspenseQueryResult<SelectOutData, ConnectError>;