Skip to content

Commit

Permalink
feat(connectrpc): init
Browse files Browse the repository at this point in the history
  • Loading branch information
TorinAsakura committed Jan 22, 2025
1 parent 073061f commit 6dd5922
Show file tree
Hide file tree
Showing 23 changed files with 2,735 additions and 858 deletions.
604 changes: 602 additions & 2 deletions .pnp.cjs

Large diffs are not rendered by default.

1,892 changes: 1,048 additions & 844 deletions .yarn/releases/yarn-remote.mjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/nestjs-connectrpc-errors/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1

plugins:
- name: es
opt: target=ts+dts
out: integration/gen
- name: connect-es
opt: target=ts+dts
out: integration/gen
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @generated by protoc-gen-connect-es v0.8.6 with parameter "target=ts+dts"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { MethodKind } from '@bufbuild/protobuf'

import { ExecTestRequest } from './test_pb.js'
import { ExecTestResponse } from './test_pb.js'

/**
* @generated from service test.TestService
*/
export declare const TestService: {
readonly typeName: 'test.TestService'
readonly methods: {
/**
* @generated from rpc test.TestService.TestValidation
*/
readonly testValidation: {
readonly name: 'TestValidation'
readonly I: typeof ExecTestRequest
readonly O: typeof ExecTestResponse
readonly kind: MethodKind.Unary
}
}
}
27 changes: 27 additions & 0 deletions packages/nestjs-connectrpc-errors/integration/gen/test_connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @generated by protoc-gen-connect-es v0.8.6 with parameter "target=ts+dts"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { MethodKind } from '@bufbuild/protobuf'

import { ExecTestRequest } from './test_pb.js'
import { ExecTestResponse } from './test_pb.js'

/**
* @generated from service test.TestService
*/
export const TestService = {
typeName: 'test.TestService',
methods: {
/**
* @generated from rpc test.TestService.TestValidation
*/
testValidation: {
name: 'TestValidation',
I: ExecTestRequest,
O: ExecTestResponse,
kind: MethodKind.Unary,
},
},
} as const
100 changes: 100 additions & 0 deletions packages/nestjs-connectrpc-errors/integration/gen/test_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// @generated by protoc-gen-es v1.2.0 with parameter "target=ts+dts"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions } from '@bufbuild/protobuf'
import type { FieldList } from '@bufbuild/protobuf'
import type { JsonReadOptions } from '@bufbuild/protobuf'
import type { JsonValue } from '@bufbuild/protobuf'
import type { PartialMessage } from '@bufbuild/protobuf'
import type { PlainMessage } from '@bufbuild/protobuf'

import { Message } from '@bufbuild/protobuf'
import { proto3 } from '@bufbuild/protobuf'

/**
* @generated from message test.TestChild
*/
export declare class TestChild extends Message<TestChild> {
/**
* @generated from field: string id = 1;
*/
id: string

constructor(data?: PartialMessage<TestChild>)

static readonly runtime: typeof proto3
static readonly typeName = 'test.TestChild'
static readonly fields: FieldList

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): TestChild

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): TestChild

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): TestChild

static equals(
a: TestChild | PlainMessage<TestChild> | undefined,
b: TestChild | PlainMessage<TestChild> | undefined
): boolean
}

/**
* @generated from message test.ExecTestRequest
*/
export declare class ExecTestRequest extends Message<ExecTestRequest> {
/**
* @generated from field: string id = 1;
*/
id: string

/**
* @generated from field: test.TestChild child = 2;
*/
child?: TestChild

constructor(data?: PartialMessage<ExecTestRequest>)

static readonly runtime: typeof proto3
static readonly typeName = 'test.ExecTestRequest'
static readonly fields: FieldList

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ExecTestRequest

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ExecTestRequest

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ExecTestRequest

static equals(
a: ExecTestRequest | PlainMessage<ExecTestRequest> | undefined,
b: ExecTestRequest | PlainMessage<ExecTestRequest> | undefined
): boolean
}

/**
* @generated from message test.ExecTestResponse
*/
export declare class ExecTestResponse extends Message<ExecTestResponse> {
/**
* @generated from field: string id = 1;
*/
id: string

constructor(data?: PartialMessage<ExecTestResponse>)

static readonly runtime: typeof proto3
static readonly typeName = 'test.ExecTestResponse'
static readonly fields: FieldList

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ExecTestResponse

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ExecTestResponse

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ExecTestResponse

static equals(
a: ExecTestResponse | PlainMessage<ExecTestResponse> | undefined,
b: ExecTestResponse | PlainMessage<ExecTestResponse> | undefined
): boolean
}
140 changes: 140 additions & 0 deletions packages/nestjs-connectrpc-errors/integration/gen/test_pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// @generated by protoc-gen-es v1.2.0 with parameter "target=ts+dts"
// @generated from file test.proto (package test, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions } from '@bufbuild/protobuf'
import type { FieldList } from '@bufbuild/protobuf'
import type { JsonReadOptions } from '@bufbuild/protobuf'
import type { JsonValue } from '@bufbuild/protobuf'
import type { PartialMessage } from '@bufbuild/protobuf'
import type { PlainMessage } from '@bufbuild/protobuf'

import { Message } from '@bufbuild/protobuf'
import { proto3 } from '@bufbuild/protobuf'

/**
* @generated from message test.TestChild
*/
export class TestChild extends Message<TestChild> {
/**
* @generated from field: string id = 1;
*/
id = ''

constructor(data?: PartialMessage<TestChild>) {
super()
proto3.util.initPartial(data, this)
}

static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'test.TestChild'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
])

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): TestChild {
return new TestChild().fromBinary(bytes, options)
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): TestChild {
return new TestChild().fromJson(jsonValue, options)
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): TestChild {
return new TestChild().fromJsonString(jsonString, options)
}

static equals(
a: TestChild | PlainMessage<TestChild> | undefined,
b: TestChild | PlainMessage<TestChild> | undefined
): boolean {
return proto3.util.equals(TestChild, a, b)
}
}

/**
* @generated from message test.ExecTestRequest
*/
export class ExecTestRequest extends Message<ExecTestRequest> {
/**
* @generated from field: string id = 1;
*/
id = ''

/**
* @generated from field: test.TestChild child = 2;
*/
child?: TestChild

constructor(data?: PartialMessage<ExecTestRequest>) {
super()
proto3.util.initPartial(data, this)
}

static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'test.ExecTestRequest'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
{ no: 2, name: 'child', kind: 'message', T: TestChild },
])

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ExecTestRequest {
return new ExecTestRequest().fromBinary(bytes, options)
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ExecTestRequest {
return new ExecTestRequest().fromJson(jsonValue, options)
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ExecTestRequest {
return new ExecTestRequest().fromJsonString(jsonString, options)
}

static equals(
a: ExecTestRequest | PlainMessage<ExecTestRequest> | undefined,
b: ExecTestRequest | PlainMessage<ExecTestRequest> | undefined
): boolean {
return proto3.util.equals(ExecTestRequest, a, b)
}
}

/**
* @generated from message test.ExecTestResponse
*/
export class ExecTestResponse extends Message<ExecTestResponse> {
/**
* @generated from field: string id = 1;
*/
id = ''

constructor(data?: PartialMessage<ExecTestResponse>) {
super()
proto3.util.initPartial(data, this)
}

static readonly runtime: typeof proto3 = proto3
static readonly typeName = 'test.ExecTestResponse'
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
])

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ExecTestResponse {
return new ExecTestResponse().fromBinary(bytes, options)
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ExecTestResponse {
return new ExecTestResponse().fromJson(jsonValue, options)
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ExecTestResponse {
return new ExecTestResponse().fromJsonString(jsonString, options)
}

static equals(
a: ExecTestResponse | PlainMessage<ExecTestResponse> | undefined,
b: ExecTestResponse | PlainMessage<ExecTestResponse> | undefined
): boolean {
return proto3.util.equals(ExecTestResponse, a, b)
}
}
20 changes: 20 additions & 0 deletions packages/nestjs-connectrpc-errors/integration/proto/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package test;

service TestService {
rpc TestValidation (ExecTestRequest) returns (ExecTestResponse) {}
}

message TestChild {
string id = 1;
}

message ExecTestRequest {
string id = 1;
TestChild child = 2;
}

message ExecTestResponse {
string id = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'

import { ValidationModule } from '@atls/nestjs-validation'

import { TestController } from './test.controller.js'

@Module({
controllers: [TestController],
imports: [ValidationModule.register()],
})
export class ConnectRpcErrorsIntegrationModule {}
1 change: 1 addition & 0 deletions packages/nestjs-connectrpc-errors/integration/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './connectrpc-errors-integration.module.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UseFilters } from '@nestjs/common'

import { ConnectRpcMethod } from '@atls/nestjs-connectrpc'
import { ConnectRpcService } from '@atls/nestjs-connectrpc'
import { Validator } from '@atls/nestjs-validation'

import { ConnectRpcExceptionsFilter } from '../../src/index.js'
import { TestService } from '../gen/test_connect.js'
import { TestPayload } from './test.payload.js'

@ConnectRpcService(TestService)
@UseFilters(ConnectRpcExceptionsFilter)
export class TestController {
constructor(private readonly validator: Validator) {}

@ConnectRpcMethod()
async testValidation(request: { id: string }): Promise<{ id: string }> {
const payload: TestPayload = await this.validator.validate(request, TestPayload)

return {
id: payload.id,
}
}
}
19 changes: 19 additions & 0 deletions packages/nestjs-connectrpc-errors/integration/src/test.payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable max-classes-per-file */

import { Type } from 'class-transformer'
import { ValidateNested } from 'class-validator'
import { IsEmail } from 'class-validator'

export class TestNestedPayload {
@IsEmail()
id!: string
}

export class TestPayload {
@IsEmail()
id!: string

@ValidateNested()
@Type(() => TestNestedPayload)
child!: TestNestedPayload
}
Loading

0 comments on commit 6dd5922

Please sign in to comment.