Skip to content

Commit

Permalink
V2: Replace MethodUnaryDescriptor with DescMethodUnary from `@buf…
Browse files Browse the repository at this point in the history
…build/protobuf` (#448)
  • Loading branch information
srikrsna-buf authored Oct 9, 2024
1 parent bf9728f commit 8a87c00
Show file tree
Hide file tree
Showing 26 changed files with 789 additions and 833 deletions.
8 changes: 4 additions & 4 deletions examples/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"dependencies": {
"@bufbuild/buf": "1.43.0",
"@bufbuild/protobuf": "^2.1.0",
"@bufbuild/protoc-gen-es": "^2.1.0",
"@bufbuild/protobuf": "^2.2.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@connectrpc/connect": "^2.0.0-beta.1",
"@connectrpc/connect-query": "workspace:*",
"@connectrpc/connect-web": "^2.0.0-beta.1",
Expand All @@ -26,10 +26,10 @@
"@testing-library/react": "^16.0.1",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"@vitejs/plugin-react": "^4.3.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.4",
"vite": "^5.4.7"
"vite": "^5.4.8"
}
}
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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"@typescript-eslint/utils": "7.15.0",
"@vitest/ui": "^2.1.1",
"@vitest/ui": "^2.1.2",
"cspell": "8.14.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
Expand All @@ -39,7 +39,7 @@
"prettier": "3.3.3",
"turbo": "^2.1.1",
"typescript": "5.5.4",
"vitest": "^2.1.1"
"vitest": "^2.1.2"
},
"engineStrict": true,
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@arethetypeswrong/cli": "^0.15.4",
"@bufbuild/buf": "1.43.0",
"@bufbuild/jest-environment-jsdom": "^0.1.1",
"@bufbuild/protobuf": "^2.1.0",
"@bufbuild/protoc-gen-es": "^2.1.0",
"@bufbuild/protobuf": "^2.2.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@connectrpc/connect": "^2.0.0-beta.1",
"@connectrpc/connect-web": "^2.0.0-beta.1",
"@tanstack/react-query": "^5.53.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/connect-query/src/call-unary-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
import { create } from "@bufbuild/protobuf";
import type { Transport } from "@connectrpc/connect";

import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";

/**
* Call a unary method given its signature and input.
*/
Expand All @@ -31,7 +30,7 @@ export async function callUnaryMethod<
O extends DescMessage,
>(
transport: Transport,
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input: MessageInitShape<I> | undefined,
options?: {
signal?: AbortSignal;
Expand Down
7 changes: 4 additions & 3 deletions packages/connect-query/src/connect-query-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ type KeyParams<Desc extends DescMethod | DescService> = Desc extends DescMethod
*
* @see ConnectQueryKey for information on the components of Connect-Query's keys.
*/
export function createConnectQueryKey<Desc extends DescMethod | DescService>(
params: KeyParams<Desc>,
): ConnectQueryKey {
export function createConnectQueryKey<
Desc extends DescMethod | DescService,
Params extends KeyParams<Desc>,
>(params: Params): ConnectQueryKey {
const props: ConnectQueryKey[1] =
params.schema.kind == "rpc"
? {
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-query/src/create-infinite-query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
Expand All @@ -32,7 +33,6 @@ import {
type ConnectQueryKey,
createConnectQueryKey,
} from "./connect-query-key.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { createStructuralSharing } from "./structural-sharing.js";
import { assert } from "./utils.js";

Expand Down Expand Up @@ -60,7 +60,7 @@ function createUnaryInfiniteQueryFn<
ParamKey extends keyof MessageInitShape<I>,
>(
transport: Transport,
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input: MessageInitShape<I>,
{
pageParamKey,
Expand Down Expand Up @@ -93,7 +93,7 @@ export function createInfiniteQueryOptions<
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input:
| SkipToken
| (MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>),
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-query/src/create-query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
Expand All @@ -30,12 +31,11 @@ import { skipToken } from "@tanstack/react-query";
import { callUnaryMethod } from "./call-unary-method.js";
import type { ConnectQueryKey } from "./connect-query-key.js";
import { createConnectQueryKey } from "./connect-query-key.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { createStructuralSharing } from "./structural-sharing.js";

function createUnaryQueryFn<I extends DescMessage, O extends DescMessage>(
transport: Transport,
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input: MessageInitShape<I> | undefined,
): QueryFunction<MessageShape<O>, ConnectQueryKey> {
return async (context) => {
Expand All @@ -52,7 +52,7 @@ export function createQueryOptions<
I extends DescMessage,
O extends DescMessage,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input: SkipToken | MessageInitShape<I> | undefined,
{
transport,
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/src/gen/bigint_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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file bigint.proto (syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/src/gen/list_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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file list.proto (syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/src/gen/proto2_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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file proto2.proto (package test, syntax proto2)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/src/gen/proto3_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.1.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated from file proto3.proto (package test, syntax proto3)
/* eslint-disable */

Expand Down
1 change: 0 additions & 1 deletion packages/connect-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type { UseMutationOptions } from "./use-mutation.js";
export { useMutation } from "./use-mutation.js";
export type { ConnectUpdater } from "./utils.js";
export { callUnaryMethod } from "./call-unary-method.js";
export type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
export { createInfiniteQueryOptions } from "./create-infinite-query-options.js";
export { createQueryOptions } from "./create-query-options.js";
export type { UseInfiniteQueryOptions } from "./use-infinite-query.js";
Expand Down
21 changes: 0 additions & 21 deletions packages/connect-query/src/method-unary-descriptor.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/connect-query/src/use-infinite-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
Expand All @@ -34,7 +35,6 @@ import {
import type { ConnectQueryKey } from "./connect-query-key.js";
import type { ConnectInfiniteQueryOptions } from "./create-infinite-query-options.js";
import { createInfiniteQueryOptions } from "./create-infinite-query-options.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { useTransport } from "./use-transport.js";

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ export function useInfiniteQuery<
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input:
| SkipToken
| (MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>),
Expand Down Expand Up @@ -122,7 +122,7 @@ export function useSuspenseInfiniteQuery<
O extends DescMessage,
ParamKey extends keyof MessageInitShape<I>,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input: MessageInitShape<I> & Required<Pick<MessageInitShape<I>, ParamKey>>,
{
transport,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-query/src/use-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
Expand All @@ -26,7 +27,6 @@ import { useMutation as tsUseMutation } from "@tanstack/react-query";
import { useCallback } from "react";

import { callUnaryMethod } from "./call-unary-method.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { useTransport } from "./use-transport.js";

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ export function useMutation<
O extends DescMessage,
Ctx = unknown,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
{ transport, ...queryOptions }: UseMutationOptions<I, O, Ctx> = {},
): UseMutationResult<MessageShape<O>, ConnectError, MessageInitShape<I>, Ctx> {
const transportFromCtx = useTransport();
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-query/src/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
Expand All @@ -32,7 +33,6 @@ import {

import type { ConnectQueryKey } from "./connect-query-key.js";
import { createQueryOptions } from "./create-query-options.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { useTransport } from "./use-transport.js";

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ export function useQuery<
O extends DescMessage,
SelectOutData = MessageShape<O>,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input?: SkipToken | MessageInitShape<I>,
{ transport, ...queryOptions }: UseQueryOptions<O, SelectOutData> = {},
): UseQueryResult<SelectOutData, ConnectError> {
Expand Down Expand Up @@ -103,7 +103,7 @@ export function useSuspenseQuery<
O extends DescMessage,
SelectOutData = MessageShape<O>,
>(
schema: MethodUnaryDescriptor<I, O>,
schema: DescMethodUnary<I, O>,
input?: MessageInitShape<I>,
{
transport,
Expand Down
5 changes: 2 additions & 3 deletions packages/connect-query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

import type {
DescMessage,
DescMethodUnary,
MessageInitShape,
MessageShape,
} from "@bufbuild/protobuf";
import { create, isMessage } from "@bufbuild/protobuf";

import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";

/**
* Throws an error with the provided message when the condition is `false`
*/
Expand Down Expand Up @@ -64,7 +63,7 @@ export type ConnectUpdater<O extends DescMessage> =
*/
export const createProtobufSafeUpdater =
<O extends DescMessage>(
schema: Pick<MethodUnaryDescriptor<never, O>, "output">,
schema: Pick<DescMethodUnary<never, O>, "output">,
updater: ConnectUpdater<O>,
) =>
(prev?: MessageShape<O>): MessageShape<O> | undefined => {
Expand Down
6 changes: 3 additions & 3 deletions packages/protoc-gen-connect-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"preferUnplugged": true,
"devDependencies": {
"@bufbuild/buf": "1.43.0",
"@bufbuild/protoc-gen-es": "^2.1.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@connectrpc/connect": "^2.0.0-beta.1",
"@connectrpc/connect-query": "workspace:*",
"@tanstack/react-query": "^5.56.2",
"typescript": "^5.5.4"
},
"dependencies": {
"@bufbuild/protobuf": "^2.1.0",
"@bufbuild/protoplugin": "^2.1.0"
"@bufbuild/protobuf": "^2.2.0",
"@bufbuild/protoplugin": "^2.2.0"
},
"peerDependencies": {
"@bufbuild/protoc-gen-es": "1.x"
Expand Down
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.1.0 with parameter "js_import_style=legacy_commonjs,import_extension=js"
// @generated by protoc-gen-es v2.2.0 with parameter "js_import_style=legacy_commonjs,import_extension=js"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */

Expand Down
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.1.0 with parameter "js_import_style=legacy_commonjs,import_extension=js"
// @generated by protoc-gen-es v2.2.0 with parameter "js_import_style=legacy_commonjs,import_extension=js"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */

Expand Down
Loading

0 comments on commit 8a87c00

Please sign in to comment.