Skip to content

Commit 8bc29eb

Browse files
committed
Merge branch 'v2' into psachs/v2-query-client
2 parents 554937c + 3131c79 commit 8bc29eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1732
-797
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const config = {
9999
},
100100
},
101101
{
102-
files: ["**/eliza/*", "**/gen/**", "**/snapshots/**"], // generated code
102+
files: ["**/eliza/*", "gen/**", "**/gen/**", "**/snapshots/**"], // generated code
103103
rules: {
104104
"eslint-comments/no-unused-enable": "off",
105105
"eslint-comments/no-unused-disable": "off",

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"git.enableCommitSigning": true,
3+
"git.alwaysSignOff": true,
4+
"typescript.tsdk": "node_modules/typescript/lib"
5+
}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<!-- markdownlint-disable-next-line MD041 MD033 -- 033: necessary for setting the width; 041: this is the style of bufbuild READMEs -->
2+
3+
> [!IMPORTANT]
4+
> You are looking at the release candidate for version 2. For the current stable version, see the branch [v1](https://github.com/connectrpc/connect-query-es/tree/v1).
5+
26
<img src="assets/[email protected]" width="15%" />
37

48
<!-- omit in toc -->

examples/react/basic/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
"format": "prettier --write . '!src/gen' && eslint . --fix && license-header"
1313
},
1414
"dependencies": {
15-
"@bufbuild/buf": "1.43.0",
16-
"@bufbuild/protobuf": "^2.2.0",
17-
"@bufbuild/protoc-gen-es": "^2.2.0",
18-
"@connectrpc/connect": "^2.0.0-rc.1",
15+
"@bufbuild/buf": "1.46.0",
16+
"@bufbuild/protobuf": "^2.2.1",
17+
"@bufbuild/protoc-gen-es": "^2.2.1",
18+
"@connectrpc/connect": "^2.0.0-rc.2",
1919
"@connectrpc/connect-query": "workspace:*",
20-
"@connectrpc/connect-web": "^2.0.0-rc.1",
20+
"@connectrpc/connect-web": "^2.0.0-rc.2",
2121
"@connectrpc/protoc-gen-connect-query": "workspace:*",
22-
"@tanstack/react-query": "^5.56.2",
23-
"@tanstack/react-query-devtools": "^5.58.0",
24-
"@testing-library/jest-dom": "^6.5.0",
22+
"@tanstack/react-query": "^5.59.16",
23+
"@tanstack/react-query-devtools": "^5.59.16",
24+
"@testing-library/jest-dom": "^6.6.3",
2525
"@testing-library/react": "^16.0.1",
26-
"@types/react": "^18.3.5",
27-
"@types/react-dom": "^18.3.0",
28-
"@vitejs/plugin-react": "^4.3.2",
26+
"@types/react": "^18.3.12",
27+
"@types/react-dom": "^18.3.1",
28+
"@vitejs/plugin-react": "^4.3.3",
2929
"react": "^18.3.1",
3030
"react-dom": "^18.3.1",
31-
"typescript": "^5.5.4",
32-
"vite": "^5.4.8"
31+
"typescript": "^5.6.3",
32+
"vite": "^5.4.10"
3333
}
3434
}

examples/react/basic/src/gen/eliza_pb.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
15+
// @generated by protoc-gen-es v2.2.1 with parameter "target=ts"
1616
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
1717
/* eslint-disable */
1818

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
},
2323
"devDependencies": {
2424
"@bufbuild/license-header": "^0.0.4",
25-
"@types/node": "^22.5.1",
25+
"@types/node": "^22.8.6",
2626
"@typescript-eslint/eslint-plugin": "7.15.0",
2727
"@typescript-eslint/parser": "7.15.0",
2828
"@typescript-eslint/utils": "7.15.0",
29-
"@vitest/ui": "^2.1.2",
30-
"cspell": "8.14.2",
29+
"@vitest/ui": "^2.1.4",
30+
"cspell": "8.15.5",
3131
"eslint": "8.57.0",
3232
"eslint-config-prettier": "9.1.0",
3333
"eslint-import-resolver-typescript": "^3.6.3",
@@ -37,9 +37,9 @@
3737
"eslint-plugin-simple-import-sort": "^12.1.1",
3838
"eslint-plugin-vitest": "0.5.4",
3939
"prettier": "3.3.3",
40-
"turbo": "^2.1.1",
41-
"typescript": "5.5.4",
42-
"vitest": "^2.1.2"
40+
"turbo": "^2.2.3",
41+
"typescript": "5.6.3",
42+
"vitest": "^2.1.4"
4343
},
4444
"engineStrict": true,
4545
"engines": {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
dist
22
coverage
3-
src/gen

packages/connect-query-core/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# @connectrpc/connect-query-core
22

3-
This package provides the core functionality for the Connect Query API. It exposes all the necessary functions to use with the different variants of the tanstack/query packages. Documentation for these APIs can be found in the main repo readme at https://github.com/connectrpc/connect-query-es and covers any non-hook functions (anything that doesn't start with `use`).
3+
This package provides the core functionality for the Connect-Query API. It exposes all the necessary functions to use with the different variants of the tanstack/query packages. Documentation for these APIs can be found in the main repo readme at https://github.com/connectrpc/connect-query-es and covers any non-hook functions (anything that doesn't start with `use`).

packages/connect-query-core/package.json

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@connectrpc/connect-query-core",
33
"version": "2.0.0-rc.2",
4-
"description": "Core of connect-query, framework agnostic helpers for typescript safe queries.",
4+
"description": "Core of Connect-Query, framework agnostic helpers for type-safe queries.",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",
@@ -13,7 +13,6 @@
1313
"build": "npm run build:cjs && npm run build:esm",
1414
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node10 --verbatimModuleSyntax false --outDir ./dist/cjs --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
1515
"build:esm": "tsc --project tsconfig.build.json",
16-
"generate": "buf generate",
1716
"test": "vitest --run",
1817
"test:watch": "vitest --watch",
1918
"format": "prettier . --write --ignore-path ./.eslintignore && eslint . --fix && license-header",
@@ -29,18 +28,23 @@
2928
}
3029
},
3130
"devDependencies": {
32-
"@arethetypeswrong/cli": "^0.15.2",
33-
"@bufbuild/buf": "1.43.0",
31+
"@arethetypeswrong/cli": "^0.16.4",
32+
"@bufbuild/buf": "1.46.0",
3433
"@bufbuild/jest-environment-jsdom": "^0.1.1",
35-
"@bufbuild/protobuf": "^2.2.0",
36-
"@bufbuild/protoc-gen-es": "^2.2.0",
37-
"@connectrpc/connect": "^2.0.0-rc.1",
38-
"@connectrpc/connect-web": "^2.0.0-rc.1",
39-
"typescript": "^5.5.4"
34+
"@bufbuild/protobuf": "^2.2.1",
35+
"@bufbuild/protoc-gen-es": "^2.2.1",
36+
"@connectrpc/connect": "^2.0.0-rc.2",
37+
"@connectrpc/connect-web": "^2.0.0-rc.2",
38+
"test-utils": "workspace:*",
39+
"typescript": "^5.6.3",
40+
"@tanstack/query-core": "^5.59.16"
4041
},
4142
"peerDependencies": {
4243
"@bufbuild/protobuf": "2.x",
43-
"@connectrpc/connect": "^2.0.0-rc.1",
44+
"@connectrpc/connect": "^2.0.0-rc.2",
4445
"@tanstack/query-core": "5.x"
45-
}
46+
},
47+
"files": [
48+
"dist/**"
49+
]
4650
}

packages/connect-query-core/src/connect-query-key.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import { create } from "@bufbuild/protobuf";
1616
import type { Transport } from "@connectrpc/connect";
17+
import { ElizaService, SayRequestSchema } from "test-utils/gen/eliza_pb.js";
18+
import { ListRequestSchema, ListService } from "test-utils/gen/list_pb.js";
1719
import { describe, expect, it } from "vitest";
1820

1921
import { createConnectQueryKey } from "./connect-query-key.js";
20-
import { ElizaService, SayRequestSchema } from "./gen/eliza_pb.js";
21-
import { ListRequestSchema, ListService } from "./gen/list_pb.js";
2222
import { skipToken } from "./index.js";
2323
import { createMessageKey } from "./message-key.js";
2424
import { createTransportKey } from "./transport-key.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2021-2023 The Connect Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { mockEliza } from "test-utils";
16+
import { ListService } from "test-utils/gen/list_pb.js";
17+
import { describe, expect, expectTypeOf, it } from "vitest";
18+
19+
import { createInfiniteQueryOptions, skipToken } from "./index.js";
20+
21+
const listMethod = ListService.method.list;
22+
23+
const mockedElizaTransport = mockEliza();
24+
25+
describe("createInfiniteQueryOptions", () => {
26+
it("honors skipToken", () => {
27+
const opt = createInfiniteQueryOptions(listMethod, skipToken, {
28+
transport: mockedElizaTransport,
29+
getNextPageParam: (lastPage) => lastPage.page + 1n,
30+
pageParamKey: "page",
31+
});
32+
expect(opt.queryFn).toBe(skipToken);
33+
expectTypeOf(opt.queryFn).toEqualTypeOf(skipToken);
34+
});
35+
});

packages/connect-query-core/src/create-infinite-query-options.ts

+81
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,87 @@ function createUnaryInfiniteQueryFn<
8686
/**
8787
* Query the method provided. Maps to useInfiniteQuery on tanstack/react-query
8888
*/
89+
export function createInfiniteQueryOptions<
90+
I extends DescMessage,
91+
O extends DescMessage,
92+
ParamKey extends keyof MessageInitShape<I>,
93+
>(
94+
schema: DescMethodUnary<I, O>,
95+
input: MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>,
96+
{
97+
transport,
98+
getNextPageParam,
99+
pageParamKey,
100+
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
101+
): {
102+
getNextPageParam: ConnectInfiniteQueryOptions<
103+
I,
104+
O,
105+
ParamKey
106+
>["getNextPageParam"];
107+
queryKey: ConnectQueryKey;
108+
queryFn: QueryFunction<
109+
MessageShape<O>,
110+
ConnectQueryKey,
111+
MessageInitShape<I>[ParamKey]
112+
>;
113+
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
114+
initialPageParam: MessageInitShape<I>[ParamKey];
115+
};
116+
export function createInfiniteQueryOptions<
117+
I extends DescMessage,
118+
O extends DescMessage,
119+
ParamKey extends keyof MessageInitShape<I>,
120+
>(
121+
schema: DescMethodUnary<I, O>,
122+
input: SkipToken,
123+
{
124+
transport,
125+
getNextPageParam,
126+
pageParamKey,
127+
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
128+
): {
129+
getNextPageParam: ConnectInfiniteQueryOptions<
130+
I,
131+
O,
132+
ParamKey
133+
>["getNextPageParam"];
134+
queryKey: ConnectQueryKey;
135+
queryFn: SkipToken;
136+
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
137+
initialPageParam: MessageInitShape<I>[ParamKey];
138+
};
139+
export function createInfiniteQueryOptions<
140+
I extends DescMessage,
141+
O extends DescMessage,
142+
ParamKey extends keyof MessageInitShape<I>,
143+
>(
144+
schema: DescMethodUnary<I, O>,
145+
input:
146+
| SkipToken
147+
| (MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>),
148+
{
149+
transport,
150+
getNextPageParam,
151+
pageParamKey,
152+
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
153+
): {
154+
getNextPageParam: ConnectInfiniteQueryOptions<
155+
I,
156+
O,
157+
ParamKey
158+
>["getNextPageParam"];
159+
queryKey: ConnectQueryKey;
160+
queryFn:
161+
| QueryFunction<
162+
MessageShape<O>,
163+
ConnectQueryKey,
164+
MessageInitShape<I>[ParamKey]
165+
>
166+
| SkipToken;
167+
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
168+
initialPageParam: MessageInitShape<I>[ParamKey];
169+
};
89170
export function createInfiniteQueryOptions<
90171
I extends DescMessage,
91172
O extends DescMessage,

packages/connect-query-core/src/create-query-options.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// limitations under the License.
1414

1515
import { skipToken as tanstackSkipToken } from "@tanstack/query-core";
16+
import { mockEliza } from "test-utils";
17+
import { ElizaService } from "test-utils/gen/eliza_pb.js";
1618
import { describe, expect, expectTypeOf, it } from "vitest";
1719

1820
import { createConnectQueryKey } from "./connect-query-key.js";
1921
import { createQueryOptions } from "./create-query-options.js";
20-
import { ElizaService } from "./gen/eliza_pb.js";
2122
import { skipToken } from "./index.js";
22-
import { mockEliza } from "./test/test-utils.js";
2323

2424
// TODO: maybe create a helper to take a service and method and generate this.
2525
const sayMethodDescriptor = ElizaService.method.say;

packages/connect-query-core/src/gen/bigint_pb.ts

+23-11
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@
1616
// @generated from file bigint.proto (syntax proto3)
1717
/* eslint-disable */
1818

19-
import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv1";
20-
import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv1";
19+
import type {
20+
GenFile,
21+
GenMessage,
22+
GenService,
23+
} from "@bufbuild/protobuf/codegenv1";
24+
import {
25+
fileDesc,
26+
messageDesc,
27+
serviceDesc,
28+
} from "@bufbuild/protobuf/codegenv1";
2129
import type { EmptySchema } from "@bufbuild/protobuf/wkt";
2230
import { file_google_protobuf_empty } from "@bufbuild/protobuf/wkt";
2331
import type { Message } from "@bufbuild/protobuf";
2432

2533
/**
2634
* Describes the file bigint.proto.
2735
*/
28-
export const file_bigint: GenFile = /*@__PURE__*/
29-
fileDesc("CgxiaWdpbnQucHJvdG8iGwoMQ291bnRSZXF1ZXN0EgsKA2FkZBgBIAEoAyIeCg1Db3VudFJlc3BvbnNlEg0KBWNvdW50GAEgASgDMmsKDUJpZ0ludFNlcnZpY2USJgoFQ291bnQSDS5Db3VudFJlcXVlc3QaDi5Db3VudFJlc3BvbnNlEjIKCEdldENvdW50EhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5Gg4uQ291bnRSZXNwb25zZWIGcHJvdG8z", [file_google_protobuf_empty]);
36+
export const file_bigint: GenFile =
37+
/*@__PURE__*/
38+
fileDesc(
39+
"CgxiaWdpbnQucHJvdG8iGwoMQ291bnRSZXF1ZXN0EgsKA2FkZBgBIAEoAyIeCg1Db3VudFJlc3BvbnNlEg0KBWNvdW50GAEgASgDMmsKDUJpZ0ludFNlcnZpY2USJgoFQ291bnQSDS5Db3VudFJlcXVlc3QaDi5Db3VudFJlc3BvbnNlEjIKCEdldENvdW50EhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5Gg4uQ291bnRSZXNwb25zZWIGcHJvdG8z",
40+
[file_google_protobuf_empty],
41+
);
3042

3143
/**
3244
* @generated from message CountRequest
@@ -42,7 +54,8 @@ export type CountRequest = Message<"CountRequest"> & {
4254
* Describes the message CountRequest.
4355
* Use `create(CountRequestSchema)` to create a new message.
4456
*/
45-
export const CountRequestSchema: GenMessage<CountRequest> = /*@__PURE__*/
57+
export const CountRequestSchema: GenMessage<CountRequest> =
58+
/*@__PURE__*/
4659
messageDesc(file_bigint, 0);
4760

4861
/**
@@ -59,7 +72,8 @@ export type CountResponse = Message<"CountResponse"> & {
5972
* Describes the message CountResponse.
6073
* Use `create(CountResponseSchema)` to create a new message.
6174
*/
62-
export const CountResponseSchema: GenMessage<CountResponse> = /*@__PURE__*/
75+
export const CountResponseSchema: GenMessage<CountResponse> =
76+
/*@__PURE__*/
6377
messageDesc(file_bigint, 1);
6478

6579
/**
@@ -73,15 +87,13 @@ export const BigIntService: GenService<{
7387
methodKind: "unary";
7488
input: typeof CountRequestSchema;
7589
output: typeof CountResponseSchema;
76-
},
90+
};
7791
/**
7892
* @generated from rpc BigIntService.GetCount
7993
*/
8094
getCount: {
8195
methodKind: "unary";
8296
input: typeof EmptySchema;
8397
output: typeof CountResponseSchema;
84-
},
85-
}> = /*@__PURE__*/
86-
serviceDesc(file_bigint, 0);
87-
98+
};
99+
}> = /*@__PURE__*/ serviceDesc(file_bigint, 0);

0 commit comments

Comments
 (0)