Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"options": {
"symlink": true,
"versions": {
"thesis/grpc-client": "0.1.x-dev",
"thesis/grpc-protocol": "0.1.x-dev",
"thesis/grpc-server": "0.1.x-dev"
"thesis/grpc-client": "0.2.x-dev",
"thesis/grpc-protocol": "0.2.x-dev",
"thesis/grpc-server": "0.2.x-dev"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"amphp/http-client": "^5.3",
"amphp/socket": "^2.3",
"league/uri": "^7.8",
"thesis/grpc-protocol": "^0.1.5"
"thesis/grpc-protocol": "^0.2"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function create(
return new ConcurrentClientStream(
responseFuture: $response,
send: $send,
decode: fn(Response $response) => $this->codec->decode($response->getBody(), $invoke->type, $cancellation),
decode: fn(Response $response) => $this->codec->decode($response->getBody(), $invoke->output, $cancellation),
errors: $this->errors,
complete: $deferred->getFuture(),
);
Expand Down
7 changes: 5 additions & 2 deletions packages/client/src/Client/Invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Thesis\Grpc\Client;

use Thesis\Grpc\RpcType;

/**
* @api
* @template-covariant In of object = object
Expand All @@ -13,10 +15,11 @@
{
/**
* @param non-empty-string $method
* @param class-string<Out> $type
* @param class-string<Out> $output
*/
public function __construct(
public string $method,
public string $type,
public string $output,
public RpcType $type,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Thesis\Grpc\Server;
namespace Thesis\Grpc;

/**
* @api
Expand Down
2 changes: 1 addition & 1 deletion packages/server/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"amphp/socket": "^2.3",
"amphp/sync": "^2.3",
"psr/log": "^3.0",
"thesis/grpc-protocol": "^0.1.5"
"thesis/grpc-protocol": "^0.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/Server/Rpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Thesis\Grpc\Server;

use Thesis\Grpc\RpcType;

/**
* @api
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/Server/StreamInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Thesis\Grpc\Server;

use Thesis\Grpc\RpcType;

/**
* @api
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/Internal/Http2/UriFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Thesis\Grpc\Client\Internal\Http2\UriFactory;
use Thesis\Grpc\Client\Internal\HttpScheme;
use Thesis\Grpc\Client\Invoke;
use Thesis\Grpc\RpcType;

#[CoversClass(UriFactory::class)]
final class UriFactoryTest extends TestCase
Expand Down Expand Up @@ -51,7 +52,7 @@ public function testCreate(
string $uri,
): void {
$factory = new UriFactory(HttpScheme::from($scheme));
$invoke = new Invoke($method, \stdClass::class);
$invoke = new Invoke($method, \stdClass::class, RpcType::Unary);

self::assertSame($uri, $factory->create(new Address($address), $invoke));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/NotImplementedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public function testEmptyMethod(): void
$client = new Client\Builder()->build();

$this->expectExceptionMessage('A grpc error with status code "UNIMPLEMENTED" and message "Malformed method name: /" occurred');
$client->invoke(new EchoRequest(), new Invoke('/', EchoResponse::class));
$client->invoke(new EchoRequest(), new Invoke('/', EchoResponse::class, RpcType::Unary));
}

public function testServiceNotImplemented(): void
{
$client = new Client\Builder()->build();

$this->expectExceptionMessage('A grpc error with status code "UNIMPLEMENTED" and message "Unknown service echos.api.v2.EchoService" occurred');
$client->invoke(new EchoRequest(), new Invoke('/echos.api.v2.EchoService/Echo', EchoResponse::class));
$client->invoke(new EchoRequest(), new Invoke('/echos.api.v2.EchoService/Echo', EchoResponse::class, RpcType::Unary));
}

public function testMethodNotImplemented(): void
{
$client = new Client\Builder()->build();

$this->expectExceptionMessage('A grpc error with status code "UNIMPLEMENTED" and message "Unknown method Ping for service echos.api.v1.EchoService" occurred');
$client->invoke(new EchoRequest(), new Invoke('/echos.api.v1.EchoService/Ping', EchoResponse::class));
$client->invoke(new EchoRequest(), new Invoke('/echos.api.v1.EchoService/Ping', EchoResponse::class, RpcType::Unary));
}
}
2 changes: 1 addition & 1 deletion tests/genproto/Chat/Api/V1/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/chat_v1.proto
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/genproto/Chat/Api/V1/MessengerServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/chat_v1.proto
*/
Expand All @@ -14,6 +14,7 @@

use Amp\Cancellation;
use Amp\NullCancellation;
use Thesis\Grpc;
use Thesis\Grpc\Client;
use Thesis\Grpc\Metadata;

Expand All @@ -36,7 +37,8 @@ public function chat(
/** @var Client\Invoke<\Chat\Api\V1\Message, \Chat\Api\V1\Message> $invoke */
$invoke = new Client\Invoke(
method: '/chat.api.v1.MessengerService/Chat',
type: \Chat\Api\V1\Message::class,
output: \Chat\Api\V1\Message::class,
type: Grpc\RpcType::BidirectionalStream,
);

$stream = $this->client->createStream(
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Chat/Api/V1/MessengerServiceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/chat_v1.proto
*/
Expand Down
9 changes: 5 additions & 4 deletions tests/genproto/Chat/Api/V1/MessengerServiceServerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/chat_v1.proto
*/
Expand All @@ -13,6 +13,7 @@
namespace Chat\Api\V1;

use Override;
use Thesis\Grpc;
use Thesis\Grpc\Server;

/**
Expand All @@ -29,9 +30,9 @@ public function services(): iterable
{
yield new Server\Service('chat.api.v1.MessengerService', [
new Server\Rpc(
new Server\Handle('Chat', \Chat\Api\V1\Message::class),
new Server\BidirectionalStreamHandler($this->server->chat(...)),
Server\RpcType::BidirectionalStream,
handle: new Server\Handle('Chat', \Chat\Api\V1\Message::class),
handler: new Server\BidirectionalStreamHandler($this->server->chat(...)),
type: Grpc\RpcType::BidirectionalStream,
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/chat_v1.proto
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Chat/Api/V1/autoload.metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Echos/Api/V1/EchoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Echos/Api/V1/EchoResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/genproto/Echos/Api/V1/EchoServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand All @@ -14,6 +14,7 @@

use Amp\Cancellation;
use Amp\NullCancellation;
use Thesis\Grpc;
use Thesis\Grpc\Client;
use Thesis\Grpc\Exception\ClientStreamIsClosed;
use Thesis\Grpc\InvokeError;
Expand All @@ -40,7 +41,8 @@ public function echo(
/** @var Client\Invoke<\Echos\Api\V1\EchoRequest, \Echos\Api\V1\EchoResponse> $invoke */
$invoke = new Client\Invoke(
method: '/echos.api.v1.EchoService/Echo',
type: \Echos\Api\V1\EchoResponse::class,
output: \Echos\Api\V1\EchoResponse::class,
type: Grpc\RpcType::Unary,
);

return $this->client->invoke(
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Echos/Api/V1/EchoServiceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand Down
9 changes: 5 additions & 4 deletions tests/genproto/Echos/Api/V1/EchoServiceServerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand All @@ -13,6 +13,7 @@
namespace Echos\Api\V1;

use Override;
use Thesis\Grpc;
use Thesis\Grpc\Server;

/**
Expand All @@ -29,9 +30,9 @@ public function services(): iterable
{
yield new Server\Service('echos.api.v1.EchoService', [
new Server\Rpc(
new Server\Handle('Echo', \Echos\Api\V1\EchoRequest::class),
new Server\UnaryHandler($this->server->echo(...)),
Server\RpcType::Unary,
handle: new Server\Handle('Echo', \Echos\Api\V1\EchoRequest::class),
handler: new Server\UnaryHandler($this->server->echo(...)),
type: Grpc\RpcType::Unary,
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/echo_v1.proto
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/Echos/Api/V1/autoload.metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/File/Api/V1/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/file_v1.proto
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/File/Api/V1/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/file_v1.proto
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/genproto/File/Api/V1/FileServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/file_v1.proto
*/
Expand All @@ -14,6 +14,7 @@

use Amp\Cancellation;
use Amp\NullCancellation;
use Thesis\Grpc;
use Thesis\Grpc\Client;
use Thesis\Grpc\Metadata;

Expand All @@ -36,7 +37,8 @@ public function upload(
/** @var Client\Invoke<\File\Api\V1\Chunk, \File\Api\V1\FileInfo> $invoke */
$invoke = new Client\Invoke(
method: '/file.api.v1.FileService/Upload',
type: \File\Api\V1\FileInfo::class,
output: \File\Api\V1\FileInfo::class,
type: Grpc\RpcType::ClientStream,
);

$stream = $this->client->createStream(
Expand Down
2 changes: 1 addition & 1 deletion tests/genproto/File/Api/V1/FileServiceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.24
* thesis/protoc-plugin — v0.2.0
* protoc — v6.33.5
* Source: tests/protos/file_v1.proto
*/
Expand Down
Loading