Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smaye81 committed Dec 18, 2024
1 parent a8a8412 commit 6138ade
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
43 changes: 18 additions & 25 deletions angular/src/connect/connect.module.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { inject, InjectionToken, Provider } from "@angular/core";
import { Interceptor, Transport } from "@connectrpc/connect";
import { createConnectTransport, createGrpcWebTransport } from "@connectrpc/connect-web";
import {
createConnectTransport,
createGrpcWebTransport,
} from "@connectrpc/connect-web";
import { DescService } from "@bufbuild/protobuf";
import { createObservableClient, ObservableClient } from "./observable-client";

export const TRANSPORT = new InjectionToken<Transport>("connect.transport");
const TRANSPORT = new InjectionToken<Transport>("connect.transport");

export const INTERCEPTORS = new InjectionToken<Interceptor[]>(
"connect.interceptors",
{
factory: () => [],
},
);
const INTERCEPTORS = new InjectionToken<Interceptor[]>("connect.interceptors", {
factory: () => [],
});

export function createClientToken<T extends DescService>(service: T): InjectionToken<ObservableClient<T>> {
return new InjectionToken(
`client for ${service.typeName}`,
{
factory() {
return createObservableClient(service, inject(TRANSPORT));
}
}
);
export function createClientToken<T extends DescService>(
service: T,
): InjectionToken<ObservableClient<T>> {
return new InjectionToken(`client for ${service.typeName}`, {
factory() {
return createObservableClient(service, inject(TRANSPORT));
},
});
}

export function provideConnect(
options: Omit<
Parameters<typeof createConnectTransport>[0],
"interceptors"
>,
options: Omit<Parameters<typeof createConnectTransport>[0], "interceptors">,
): Provider[] {
return [
{
Expand All @@ -44,10 +40,7 @@ export function provideConnect(
}

export function provideGrpcWeb(
options: Omit<
Parameters<typeof createGrpcWebTransport>[0],
"interceptors"
>,
options: Omit<Parameters<typeof createGrpcWebTransport>[0], "interceptors">,
): Provider[] {
return [
{
Expand Down
3 changes: 3 additions & 0 deletions angular/src/connect/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ElizaService } from "src/gen/connectrpc/eliza/v1/eliza_pb";
import { createClientToken } from "./connect.module";

// Create an injection token for the Eliza service client
export const ELIZA = createClientToken(ElizaService);

// Additional client tokens representing Connect services could be added here

0 comments on commit 6138ade

Please sign in to comment.