diff --git a/CHANGELOG.md b/CHANGELOG.md index 8426257..bceb863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix empty payload serialization. +### Deprecated + +* Deprecate `Config::$version`, will be removed in `0.5.0`. + ## [0.3.0] 2025-10-23 ### Added diff --git a/composer.json b/composer.json index cbd1894..f310bf9 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "amphp/socket": "^2.3.1", "cuyz/valinor": "^1.15 || ^2.3", "revolt/event-loop": "^1.0.7", + "thesis/package-version": "^0.1.2", "thesis/time-span": "^0.2.3" }, "require-dev": { diff --git a/src/Config.php b/src/Config.php index e8f50c1..fada1f2 100644 --- a/src/Config.php +++ b/src/Config.php @@ -17,7 +17,10 @@ private const int DEFAULT_MAX_PINGS = 5; private const string DEFAULT_CLIENT_NAME = 'thesis/nats'; - /** @var non-empty-string */ + /** + * @var non-empty-string + * @deprecated will be removed in 0.5.0 + */ public string $version; /** @@ -52,7 +55,7 @@ public function __construct( public ?string $jetStreamDomain = null, public string $clientName = self::DEFAULT_CLIENT_NAME, ) { - $this->version = '0.1.x'; // TODO: replace with actual version. + $this->version = '0.1.x'; } public static function default(): self diff --git a/src/Internal/Connection/SocketConnection.php b/src/Internal/Connection/SocketConnection.php index 4cb7363..16d9b14 100644 --- a/src/Internal/Connection/SocketConnection.php +++ b/src/Internal/Connection/SocketConnection.php @@ -12,12 +12,15 @@ use Thesis\Nats\Internal\Hooks; use Thesis\Nats\Internal\Nkey\Signer; use Thesis\Nats\Internal\Protocol; +use function Thesis\Package\version; /** * @internal */ final class SocketConnection implements Connection { + private const string PACKAGE_NAME = 'thesis/nats'; + private readonly Framer $framer; /** @var \SplQueue> */ @@ -71,7 +74,7 @@ public function startup(): void pedantic: $this->config->pedantic, tlsRequired: false, name: $this->config->clientName, - version: $this->config->version, + version: version(self::PACKAGE_NAME), user: $this->config->user, pass: $this->config->password, sig: $this->generateSignature($frame->nonce, $this->config->nkey), diff --git a/tests/Internal/Connection/SocketConnectionJwtTest.php b/tests/Internal/Connection/SocketConnectionJwtTest.php index 00e8d24..a65bdda 100644 --- a/tests/Internal/Connection/SocketConnectionJwtTest.php +++ b/tests/Internal/Connection/SocketConnectionJwtTest.php @@ -10,6 +10,7 @@ use Thesis\Nats\Config; use Thesis\Nats\Internal\Nkey\Signer; use Thesis\Nats\Internal\Protocol\Connect; +use function Thesis\Package\version; #[CoversClass(Connect::class)] #[CoversClass(Signer::class)] @@ -26,7 +27,7 @@ public function testConnectProtocolCreationWithJwtOnly(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), user: $config->user, pass: $config->password, sig: null, @@ -59,7 +60,7 @@ public function testConnectProtocolCreationWithNkeyOnly(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), user: $config->user, pass: $config->password, sig: $signature, @@ -94,7 +95,7 @@ public function testConnectProtocolCreationWithBothJwtAndNkey(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), user: $config->user, pass: $config->password, sig: $signature, @@ -122,7 +123,7 @@ public function testConnectProtocolCreationWithoutJwtAndNkey(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), user: $config->user, pass: $config->password, sig: null, @@ -168,7 +169,7 @@ public function testConfigBackwardCompatibility(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), authToken: null, user: $config->user, pass: $config->password, @@ -202,7 +203,7 @@ public function testJwtAndNkeyPrecedenceOverUserPassword(): void pedantic: $config->pedantic, tlsRequired: false, name: 'thesis/nats', - version: $config->version, + version: version('thesis/nats'), user: $config->user, pass: $config->password, sig: $signature,