Skip to content

Commit

Permalink
Merge branch 'v2' into psachs/v2-query-client
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs committed Nov 15, 2024
2 parents 554937c + 3131c79 commit 8bc29eb
Show file tree
Hide file tree
Showing 61 changed files with 1,732 additions and 797 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const config = {
},
},
{
files: ["**/eliza/*", "**/gen/**", "**/snapshots/**"], // generated code
files: ["**/eliza/*", "gen/**", "**/gen/**", "**/snapshots/**"], // generated code
rules: {
"eslint-comments/no-unused-enable": "off",
"eslint-comments/no-unused-disable": "off",
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"git.enableCommitSigning": true,
"git.alwaysSignOff": true,
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!-- markdownlint-disable-next-line MD041 MD033 -- 033: necessary for setting the width; 041: this is the style of bufbuild READMEs -->

> [!IMPORTANT]
> 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).
<img src="assets/[email protected]" width="15%" />

<!-- omit in toc -->
Expand Down
26 changes: 13 additions & 13 deletions examples/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
"format": "prettier --write . '!src/gen' && eslint . --fix && license-header"
},
"dependencies": {
"@bufbuild/buf": "1.43.0",
"@bufbuild/protobuf": "^2.2.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@connectrpc/connect": "^2.0.0-rc.1",
"@bufbuild/buf": "1.46.0",
"@bufbuild/protobuf": "^2.2.1",
"@bufbuild/protoc-gen-es": "^2.2.1",
"@connectrpc/connect": "^2.0.0-rc.2",
"@connectrpc/connect-query": "workspace:*",
"@connectrpc/connect-web": "^2.0.0-rc.1",
"@connectrpc/connect-web": "^2.0.0-rc.2",
"@connectrpc/protoc-gen-connect-query": "workspace:*",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-query-devtools": "^5.58.0",
"@testing-library/jest-dom": "^6.5.0",
"@tanstack/react-query": "^5.59.16",
"@tanstack/react-query-devtools": "^5.59.16",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.4",
"vite": "^5.4.8"
"typescript": "^5.6.3",
"vite": "^5.4.10"
}
}
2 changes: 1 addition & 1 deletion examples/react/basic/src/gen/eliza_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
},
"devDependencies": {
"@bufbuild/license-header": "^0.0.4",
"@types/node": "^22.5.1",
"@types/node": "^22.8.6",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"@typescript-eslint/utils": "7.15.0",
"@vitest/ui": "^2.1.2",
"cspell": "8.14.2",
"@vitest/ui": "^2.1.4",
"cspell": "8.15.5",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
Expand All @@ -37,9 +37,9 @@
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-vitest": "0.5.4",
"prettier": "3.3.3",
"turbo": "^2.1.1",
"typescript": "5.5.4",
"vitest": "^2.1.2"
"turbo": "^2.2.3",
"typescript": "5.6.3",
"vitest": "^2.1.4"
},
"engineStrict": true,
"engines": {
Expand Down
1 change: 0 additions & 1 deletion packages/connect-query-core/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dist
coverage
src/gen
2 changes: 1 addition & 1 deletion packages/connect-query-core/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @connectrpc/connect-query-core

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`).
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`).
26 changes: 15 additions & 11 deletions packages/connect-query-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@connectrpc/connect-query-core",
"version": "2.0.0-rc.2",
"description": "Core of connect-query, framework agnostic helpers for typescript safe queries.",
"description": "Core of Connect-Query, framework agnostic helpers for type-safe queries.",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand All @@ -13,7 +13,6 @@
"build": "npm run build:cjs && npm run build:esm",
"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\"}'",
"build:esm": "tsc --project tsconfig.build.json",
"generate": "buf generate",
"test": "vitest --run",
"test:watch": "vitest --watch",
"format": "prettier . --write --ignore-path ./.eslintignore && eslint . --fix && license-header",
Expand All @@ -29,18 +28,23 @@
}
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.2",
"@bufbuild/buf": "1.43.0",
"@arethetypeswrong/cli": "^0.16.4",
"@bufbuild/buf": "1.46.0",
"@bufbuild/jest-environment-jsdom": "^0.1.1",
"@bufbuild/protobuf": "^2.2.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@connectrpc/connect": "^2.0.0-rc.1",
"@connectrpc/connect-web": "^2.0.0-rc.1",
"typescript": "^5.5.4"
"@bufbuild/protobuf": "^2.2.1",
"@bufbuild/protoc-gen-es": "^2.2.1",
"@connectrpc/connect": "^2.0.0-rc.2",
"@connectrpc/connect-web": "^2.0.0-rc.2",
"test-utils": "workspace:*",
"typescript": "^5.6.3",
"@tanstack/query-core": "^5.59.16"
},
"peerDependencies": {
"@bufbuild/protobuf": "2.x",
"@connectrpc/connect": "^2.0.0-rc.1",
"@connectrpc/connect": "^2.0.0-rc.2",
"@tanstack/query-core": "5.x"
}
},
"files": [
"dist/**"
]
}
4 changes: 2 additions & 2 deletions packages/connect-query-core/src/connect-query-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

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

import { createConnectQueryKey } from "./connect-query-key.js";
import { ElizaService, SayRequestSchema } from "./gen/eliza_pb.js";
import { ListRequestSchema, ListService } from "./gen/list_pb.js";
import { skipToken } from "./index.js";
import { createMessageKey } from "./message-key.js";
import { createTransportKey } from "./transport-key.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021-2023 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { mockEliza } from "test-utils";
import { ListService } from "test-utils/gen/list_pb.js";
import { describe, expect, expectTypeOf, it } from "vitest";

import { createInfiniteQueryOptions, skipToken } from "./index.js";

const listMethod = ListService.method.list;

const mockedElizaTransport = mockEliza();

describe("createInfiniteQueryOptions", () => {
it("honors skipToken", () => {
const opt = createInfiniteQueryOptions(listMethod, skipToken, {
transport: mockedElizaTransport,
getNextPageParam: (lastPage) => lastPage.page + 1n,
pageParamKey: "page",
});
expect(opt.queryFn).toBe(skipToken);
expectTypeOf(opt.queryFn).toEqualTypeOf(skipToken);
});
});
81 changes: 81 additions & 0 deletions packages/connect-query-core/src/create-infinite-query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,87 @@ function createUnaryInfiniteQueryFn<
/**
* Query the method provided. Maps to useInfiniteQuery on tanstack/react-query
*/
export function createInfiniteQueryOptions<
I extends DescMessage,
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: DescMethodUnary<I, O>,
input: MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>,
{
transport,
getNextPageParam,
pageParamKey,
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
): {
getNextPageParam: ConnectInfiniteQueryOptions<
I,
O,
ParamKey
>["getNextPageParam"];
queryKey: ConnectQueryKey;
queryFn: QueryFunction<
MessageShape<O>,
ConnectQueryKey,
MessageInitShape<I>[ParamKey]
>;
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
initialPageParam: MessageInitShape<I>[ParamKey];
};
export function createInfiniteQueryOptions<
I extends DescMessage,
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: DescMethodUnary<I, O>,
input: SkipToken,
{
transport,
getNextPageParam,
pageParamKey,
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
): {
getNextPageParam: ConnectInfiniteQueryOptions<
I,
O,
ParamKey
>["getNextPageParam"];
queryKey: ConnectQueryKey;
queryFn: SkipToken;
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
initialPageParam: MessageInitShape<I>[ParamKey];
};
export function createInfiniteQueryOptions<
I extends DescMessage,
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: DescMethodUnary<I, O>,
input:
| SkipToken
| (MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>),
{
transport,
getNextPageParam,
pageParamKey,
}: ConnectInfiniteQueryOptions<I, O, ParamKey> & { transport: Transport },
): {
getNextPageParam: ConnectInfiniteQueryOptions<
I,
O,
ParamKey
>["getNextPageParam"];
queryKey: ConnectQueryKey;
queryFn:
| QueryFunction<
MessageShape<O>,
ConnectQueryKey,
MessageInitShape<I>[ParamKey]
>
| SkipToken;
structuralSharing: (oldData: unknown, newData: unknown) => unknown;
initialPageParam: MessageInitShape<I>[ParamKey];
};
export function createInfiniteQueryOptions<
I extends DescMessage,
O extends DescMessage,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-query-core/src/create-query-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
// limitations under the License.

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

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

// TODO: maybe create a helper to take a service and method and generate this.
const sayMethodDescriptor = ElizaService.method.say;
Expand Down
34 changes: 23 additions & 11 deletions packages/connect-query-core/src/gen/bigint_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@
// @generated from file bigint.proto (syntax proto3)
/* eslint-disable */

import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv1";
import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv1";
import type {
GenFile,
GenMessage,
GenService,
} from "@bufbuild/protobuf/codegenv1";
import {
fileDesc,
messageDesc,
serviceDesc,
} from "@bufbuild/protobuf/codegenv1";
import type { EmptySchema } from "@bufbuild/protobuf/wkt";
import { file_google_protobuf_empty } from "@bufbuild/protobuf/wkt";
import type { Message } from "@bufbuild/protobuf";

/**
* Describes the file bigint.proto.
*/
export const file_bigint: GenFile = /*@__PURE__*/
fileDesc("CgxiaWdpbnQucHJvdG8iGwoMQ291bnRSZXF1ZXN0EgsKA2FkZBgBIAEoAyIeCg1Db3VudFJlc3BvbnNlEg0KBWNvdW50GAEgASgDMmsKDUJpZ0ludFNlcnZpY2USJgoFQ291bnQSDS5Db3VudFJlcXVlc3QaDi5Db3VudFJlc3BvbnNlEjIKCEdldENvdW50EhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5Gg4uQ291bnRSZXNwb25zZWIGcHJvdG8z", [file_google_protobuf_empty]);
export const file_bigint: GenFile =
/*@__PURE__*/
fileDesc(
"CgxiaWdpbnQucHJvdG8iGwoMQ291bnRSZXF1ZXN0EgsKA2FkZBgBIAEoAyIeCg1Db3VudFJlc3BvbnNlEg0KBWNvdW50GAEgASgDMmsKDUJpZ0ludFNlcnZpY2USJgoFQ291bnQSDS5Db3VudFJlcXVlc3QaDi5Db3VudFJlc3BvbnNlEjIKCEdldENvdW50EhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5Gg4uQ291bnRSZXNwb25zZWIGcHJvdG8z",
[file_google_protobuf_empty],
);

/**
* @generated from message CountRequest
Expand All @@ -42,7 +54,8 @@ export type CountRequest = Message<"CountRequest"> & {
* Describes the message CountRequest.
* Use `create(CountRequestSchema)` to create a new message.
*/
export const CountRequestSchema: GenMessage<CountRequest> = /*@__PURE__*/
export const CountRequestSchema: GenMessage<CountRequest> =
/*@__PURE__*/
messageDesc(file_bigint, 0);

/**
Expand All @@ -59,7 +72,8 @@ export type CountResponse = Message<"CountResponse"> & {
* Describes the message CountResponse.
* Use `create(CountResponseSchema)` to create a new message.
*/
export const CountResponseSchema: GenMessage<CountResponse> = /*@__PURE__*/
export const CountResponseSchema: GenMessage<CountResponse> =
/*@__PURE__*/
messageDesc(file_bigint, 1);

/**
Expand All @@ -73,15 +87,13 @@ export const BigIntService: GenService<{
methodKind: "unary";
input: typeof CountRequestSchema;
output: typeof CountResponseSchema;
},
};
/**
* @generated from rpc BigIntService.GetCount
*/
getCount: {
methodKind: "unary";
input: typeof EmptySchema;
output: typeof CountResponseSchema;
},
}> = /*@__PURE__*/
serviceDesc(file_bigint, 0);

};
}> = /*@__PURE__*/ serviceDesc(file_bigint, 0);
Loading

0 comments on commit 8bc29eb

Please sign in to comment.