-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on #2246. --------- Signed-off-by: Timo Stamm <[email protected]> Signed-off-by: Steve Ayers <[email protected]> Co-authored-by: Steve Ayers <[email protected]>
- Loading branch information
Showing
9 changed files
with
88 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { provideConnect } from "../connect/connect.module"; | ||
import { provideProtractorTestingSupport } from "@angular/platform-browser"; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideConnect({ | ||
baseUrl: "https://demo.connectrpc.com", | ||
}), | ||
provideProtractorTestingSupport(), | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,59 @@ | ||
import { ModuleWithProviders, NgModule } from "@angular/core"; | ||
import { Interceptor } from "@connectrpc/connect"; | ||
import { createConnectTransport } from "@connectrpc/connect-web"; | ||
import { INTERCEPTORS, TRANSPORT } from "./tokens"; | ||
import { inject, InjectionToken, Provider } from "@angular/core"; | ||
import { Interceptor, Transport } from "@connectrpc/connect"; | ||
import { | ||
createConnectTransport, | ||
createGrpcWebTransport, | ||
} from "@connectrpc/connect-web"; | ||
import { DescService } from "@bufbuild/protobuf"; | ||
import { createObservableClient, ObservableClient } from "./observable-client"; | ||
|
||
@NgModule() | ||
export class ConnectModule { | ||
public static forRoot( | ||
connectOptions: Omit< | ||
Parameters<typeof createConnectTransport>[0], | ||
"interceptors" | ||
>, | ||
): ModuleWithProviders<ConnectModule> { | ||
return { | ||
ngModule: ConnectModule, | ||
providers: [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createConnectTransport({ | ||
...connectOptions, | ||
interceptors: interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
], | ||
}; | ||
} | ||
const TRANSPORT = new InjectionToken<Transport>("connect.transport"); | ||
|
||
export 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 provideConnect( | ||
options: Omit<Parameters<typeof createConnectTransport>[0], "interceptors">, | ||
): Provider[] { | ||
return [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createConnectTransport({ | ||
...options, | ||
interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
]; | ||
} | ||
|
||
export function provideGrpcWeb( | ||
options: Omit<Parameters<typeof createGrpcWebTransport>[0], "interceptors">, | ||
): Provider[] { | ||
return [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createGrpcWebTransport({ | ||
...options, | ||
interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
import { InjectionToken } from "@angular/core"; | ||
import type { Interceptor, Transport } from "@connectrpc/connect"; | ||
import { ElizaService } from "src/gen/connectrpc/eliza/v1/eliza_pb"; | ||
import { ObservableClient } from "./observable-client"; | ||
import { createClientToken } from "./connect.module"; | ||
|
||
export const TRANSPORT = new InjectionToken<Transport>("connect.transport"); | ||
// Create an injection token for the Eliza service client | ||
export const ELIZA = createClientToken(ElizaService); | ||
|
||
export const INTERCEPTORS = new InjectionToken<Interceptor[]>( | ||
"connect.interceptors", | ||
{ | ||
factory: () => [], | ||
}, | ||
); | ||
|
||
export const ELIZA = new InjectionToken<ObservableClient<typeof ElizaService>>( | ||
ElizaService.name, | ||
); | ||
// Additional client tokens representing Connect services could be added here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { enableProdMode } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { AppComponent } from './app/app.component'; | ||
import { appConfig } from "./app/app.config"; | ||
|
||
import { AppModule } from './app/app.module'; | ||
import { environment } from './environments/environment'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule) | ||
.catch(err => console.error(err)); | ||
bootstrapApplication(AppComponent, appConfig).catch((err) => | ||
console.error(err), | ||
); |