@unisian/start 0.1.0 → 0.3.0
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/client.d.mts +8 -1
- package/dist/client.mjs +43 -8
- package/package.json +10 -10
package/dist/client.d.mts
CHANGED
|
@@ -5,11 +5,12 @@ import { AppRouterOptions, createAppRouter } from "./router.mjs";
|
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import * as Option from "effect/Option";
|
|
7
7
|
import { AnyContract, FailureOf, InputOf, OutputOf } from "@unisian/capability";
|
|
8
|
-
import { QueryClient, QueryKey, UseSuspenseQueryOptions } from "@tanstack/react-query";
|
|
8
|
+
import { InfiniteData, QueryClient, QueryKey, UseSuspenseQueryOptions } from "@tanstack/react-query";
|
|
9
9
|
//#region src/client.d.ts
|
|
10
10
|
export type ServerFn<ContractType extends AnyContract> = (options: {
|
|
11
11
|
readonly data: InputOf<ContractType>["Encoded"];
|
|
12
12
|
readonly headers?: Record<string, string>;
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
13
14
|
}) => Promise<Schema.Json>;
|
|
14
15
|
export interface PerCall {
|
|
15
16
|
readonly headers?: Record<string, string> | undefined;
|
|
@@ -18,6 +19,12 @@ export interface PerCall {
|
|
|
18
19
|
export declare const query: <ContractType extends AnyContract>(contract: ContractType, serverFn: ServerFn<ContractType>) => (input: InputOf<ContractType>["Type"], perCall?: PerCall) => import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<Schema.Json, CapabilityFailureError<FailureOf<ContractType>["Type"]>, OutputOf<ContractType>["Type"], readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]]>, "queryFn"> & {
|
|
19
20
|
queryFn?: import("@tanstack/react-query").QueryFunction<Schema.Json, readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]], never>;
|
|
20
21
|
} & import("@tanstack/react-query").QueryKeyWithDataTag<readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]], Schema.Json, CapabilityFailureError<FailureOf<ContractType>["Type"]>>;
|
|
22
|
+
export interface InfiniteQueryOptions<ContractType extends AnyContract> {
|
|
23
|
+
readonly getNextPageParam: (lastPage: OutputOf<ContractType>["Type"], lastInput: InputOf<ContractType>["Type"]) => InputOf<ContractType>["Type"] | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare const infiniteQuery: <ContractType extends AnyContract>(contract: ContractType, serverFn: ServerFn<ContractType>, { getNextPageParam }: InfiniteQueryOptions<ContractType>) => (input: InputOf<ContractType>["Type"], perCall?: PerCall) => import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseInfiniteQueryOptions<Schema.Json, CapabilityFailureError<FailureOf<ContractType>["Type"]>, InfiniteData<OutputOf<ContractType>["Type"], InputOf<ContractType>["Type"]>, readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]], InputOf<ContractType>["Encoded"]>, "queryFn"> & {
|
|
26
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<Schema.Json, readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]], InputOf<ContractType>["Encoded"]>;
|
|
27
|
+
} & import("@tanstack/react-query").QueryKeyWithDataTag<readonly [ContractType["name"], InputOf<ContractType>["Encoded"], ...Schema.Json[]], InfiniteData<Schema.Json, unknown>, CapabilityFailureError<FailureOf<ContractType>["Type"]>>;
|
|
21
28
|
export declare const cachedData: <Output>(client: QueryClient, options: {
|
|
22
29
|
readonly queryKey: QueryKey;
|
|
23
30
|
readonly select?: ((encoded: Schema.Json) => Output) | undefined;
|
package/dist/client.mjs
CHANGED
|
@@ -5,19 +5,28 @@ import { useCommandForm } from "./command-form.mjs";
|
|
|
5
5
|
import { createAppRouter } from "./router.mjs";
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
7
7
|
import * as Option from "effect/Option";
|
|
8
|
-
import { environmentManager, mutationOptions, queryOptions } from "@tanstack/react-query";
|
|
8
|
+
import { environmentManager, infiniteQueryOptions, mutationOptions, queryOptions } from "@tanstack/react-query";
|
|
9
9
|
//#region src/client.ts
|
|
10
10
|
const transportRetries = 2;
|
|
11
11
|
const keyFor = (head, { key }) => key === void 0 ? head : [...head, key];
|
|
12
|
+
const retry = (failureCount, error) => !(error instanceof CapabilityFailureError) && failureCount < (environmentManager.isServer() ? 0 : transportRetries);
|
|
12
13
|
const callerFor = (contract, serverFn) => {
|
|
13
14
|
const encodeInput = Schema.encodeSync(contract.input);
|
|
15
|
+
const decodeInput = Schema.decodeUnknownSync(contract.input);
|
|
14
16
|
const decodeOutput = Schema.decodeUnknownSync(Schema.toCodecJson(contract.output));
|
|
15
17
|
const { decode } = wireFor(contract.failure);
|
|
16
18
|
return {
|
|
17
|
-
call: (data, { headers }) =>
|
|
18
|
-
data
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
call: (data, { headers }, signal) => {
|
|
20
|
+
const options = headers === void 0 ? { data } : {
|
|
21
|
+
data,
|
|
22
|
+
headers
|
|
23
|
+
};
|
|
24
|
+
return serverFn(signal === void 0 ? options : {
|
|
25
|
+
...options,
|
|
26
|
+
signal
|
|
27
|
+
}).then(decode);
|
|
28
|
+
},
|
|
29
|
+
decodeInput,
|
|
21
30
|
decodeOutput,
|
|
22
31
|
encodeInput
|
|
23
32
|
};
|
|
@@ -27,13 +36,39 @@ const query = (contract, serverFn) => {
|
|
|
27
36
|
return (input, perCall = {}) => {
|
|
28
37
|
const data = encodeInput(input);
|
|
29
38
|
return queryOptions({
|
|
30
|
-
queryFn: () => call(data, perCall),
|
|
39
|
+
queryFn: ({ signal }) => call(data, perCall, signal),
|
|
31
40
|
queryKey: keyFor([contract.name, data], perCall),
|
|
32
|
-
retry
|
|
41
|
+
retry,
|
|
33
42
|
select: decodeOutput
|
|
34
43
|
});
|
|
35
44
|
};
|
|
36
45
|
};
|
|
46
|
+
const infiniteQuery = (contract, serverFn, { getNextPageParam }) => {
|
|
47
|
+
const { encodeInput, decodeInput, decodeOutput, call } = callerFor(contract, serverFn);
|
|
48
|
+
const nextInput = (lastPage, _allPages, lastInput) => {
|
|
49
|
+
const next = getNextPageParam(decodeOutput(lastPage), decodeInput(lastInput));
|
|
50
|
+
return next === void 0 ? void 0 : encodeInput(next);
|
|
51
|
+
};
|
|
52
|
+
const select = ({ pageParams, pages }) => ({
|
|
53
|
+
pageParams: pageParams.map((pageParam) => decodeInput(pageParam)),
|
|
54
|
+
pages: pages.map((page) => decodeOutput(page))
|
|
55
|
+
});
|
|
56
|
+
return (input, perCall = {}) => {
|
|
57
|
+
const data = encodeInput(input);
|
|
58
|
+
return infiniteQueryOptions({
|
|
59
|
+
getNextPageParam: nextInput,
|
|
60
|
+
initialPageParam: data,
|
|
61
|
+
queryFn: ({ pageParam, signal }) => call(pageParam, perCall, signal),
|
|
62
|
+
queryKey: keyFor([
|
|
63
|
+
contract.name,
|
|
64
|
+
data,
|
|
65
|
+
"pages"
|
|
66
|
+
], perCall),
|
|
67
|
+
retry,
|
|
68
|
+
select
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
};
|
|
37
72
|
const cachedData = (client, options) => {
|
|
38
73
|
const encoded = client.getQueryData(options.queryKey);
|
|
39
74
|
return encoded === void 0 ? void 0 : options.select?.(encoded);
|
|
@@ -60,4 +95,4 @@ const command = (contract, serverFn, options) => {
|
|
|
60
95
|
});
|
|
61
96
|
};
|
|
62
97
|
//#endregion
|
|
63
|
-
export { cachedData, cachedQuery, command, createAppRouter, query, reportBrowserErrors, useBrowserErrorReference, useCommandForm };
|
|
98
|
+
export { cachedData, cachedQuery, command, createAppRouter, infiniteQuery, query, reportBrowserErrors, useBrowserErrorReference, useCommandForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unisian/start",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"@tanstack/react-router": "1.170.41",
|
|
30
30
|
"@tanstack/react-router-ssr-query": "1.167.3",
|
|
31
31
|
"@tanstack/react-start": "1.168.60",
|
|
32
|
-
"effect": "4.0.
|
|
32
|
+
"effect": "4.0.6",
|
|
33
33
|
"react": "19.3.0",
|
|
34
34
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
|
|
35
|
-
"@unisian/capability": "0.
|
|
36
|
-
"@unisian/effect-observability": "0.
|
|
37
|
-
"@unisian/shopify-auth": "0.
|
|
38
|
-
"@unisian/shopify-sessions": "0.
|
|
35
|
+
"@unisian/capability": "0.3.0",
|
|
36
|
+
"@unisian/effect-observability": "0.3.0",
|
|
37
|
+
"@unisian/shopify-auth": "0.3.0",
|
|
38
|
+
"@unisian/shopify-sessions": "0.3.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@tanstack/react-query": "^5.104.1",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@tanstack/react-start": "^1.168.60",
|
|
45
45
|
"effect": "^4.0.2",
|
|
46
46
|
"react": "^19.3.0",
|
|
47
|
-
"@unisian/effect-observability": "0.
|
|
48
|
-
"@unisian/
|
|
49
|
-
"@unisian/shopify-
|
|
50
|
-
"@unisian/
|
|
47
|
+
"@unisian/effect-observability": "0.3.0",
|
|
48
|
+
"@unisian/shopify-auth": "0.3.0",
|
|
49
|
+
"@unisian/shopify-sessions": "0.3.0",
|
|
50
|
+
"@unisian/capability": "0.3.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {}
|
|
53
53
|
}
|