Skip to content

Commit 5002df7

Browse files
authored
Merge pull request #340 from Permify/update-permify-client-types
feat(grpc): add explicit PermifyClient type for gRPC client factory
2 parents 576b9a4 + 1c50648 commit 5002df7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@permify/permify-node",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "Permify Node Client",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

src/grpc/clients.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ClientMiddleware, createChannel, createClientFactory, ChannelCredentials } from 'nice-grpc';
1+
import { ClientMiddleware, createChannel, createClientFactory, ChannelCredentials, RawClient } from 'nice-grpc';
2+
import type { FromTsProtoServiceDefinition, TsProtoServiceDefinition } from 'nice-grpc/lib/service-definitions/ts-proto';
23
import {
34
PermissionDefinition,
45
SchemaDefinition,
@@ -9,6 +10,22 @@ import {
910
} from './generated/base/v1/service';
1011
import { Config } from './config';
1112

13+
// Helper type to extract the client type from a service definition
14+
type ClientFromDefinition<T extends TsProtoServiceDefinition> = RawClient<FromTsProtoServiceDefinition<T>>;
15+
16+
/**
17+
* Return type for the Permify gRPC client.
18+
* This explicit type ensures proper type preservation through export layers.
19+
*/
20+
export type PermifyClient = {
21+
permission: ClientFromDefinition<typeof PermissionDefinition>;
22+
schema: ClientFromDefinition<typeof SchemaDefinition>;
23+
data: ClientFromDefinition<typeof DataDefinition>;
24+
bundle: ClientFromDefinition<typeof BundleDefinition>;
25+
tenancy: ClientFromDefinition<typeof TenancyDefinition>;
26+
watch: ClientFromDefinition<typeof WatchDefinition>;
27+
};
28+
1229
/**
1330
* Create a new gRPC service client for Permify.
1431
* The client can be configured with multiple client interceptors. For authentication interceptors,
@@ -19,7 +36,7 @@ import { Config } from './config';
1936
*
2037
* @returns A new gRPC service client for the Permission API of Permify.
2138
*/
22-
export function newClient(conf: Config, ...interceptors: ClientMiddleware[]) {
39+
export function newClient(conf: Config, ...interceptors: ClientMiddleware[]): PermifyClient {
2340
const channel = conf.insecure
2441
? createChannel(conf.endpoint, ChannelCredentials.createInsecure())
2542
: createChannel(conf.endpoint, ChannelCredentials.createSsl(conf.cert, conf.pk, conf.certChain));

0 commit comments

Comments
 (0)