• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oprajs / opra / 19958387866

05 Dec 2025 09:19AM UTC coverage: 80.99% (-0.2%) from 81.23%
19958387866

push

github

erayhanoglu
chore: Updated deps

3534 of 4540 branches covered (77.84%)

Branch coverage included in aggregate %.

31111 of 38237 relevant lines covered (81.36%)

218.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/angular/src/client.module.ts
1
/* eslint-disable import-x/extensions */
×
2
// @ts-ignore
×
3
import { HttpClient } from '@angular/common/http';
×
4
import {
×
5
  type ModuleWithProviders,
×
6
  NgModule,
×
7
  type Provider,
×
8
  Type,
×
9
} from '@angular/core';
×
10
import { kClient } from '@opra/client';
×
11
import { OpraAngularClient } from './angular-client';
×
12
import { OPRA_CLIENT_MODULE_OPTIONS } from './constants';
×
13
import type {
×
14
  OpraClientModuleAsyncOptions,
×
15
  OpraClientModuleOptions,
×
16
} from './interfaces/module-options.interface';
×
17

×
18
@NgModule({})
×
19
export class OpraClientModule {
×
20
  public static registerClient(
×
21
    options: OpraClientModuleOptions,
×
22
  ): ModuleWithProviders<OpraClientModule> {
×
23
    const CLIENT_TOKEN = options.token || OpraAngularClient;
×
24
    return {
×
25
      ngModule: OpraClientModule,
×
26
      providers: [
×
27
        {
×
28
          provide: CLIENT_TOKEN,
×
29
          deps: [HttpClient],
×
30
          useFactory: (httpClient: HttpClient) =>
×
31
            new OpraAngularClient(httpClient, options.serviceUrl, options),
×
32
        },
×
33
      ],
×
34
    };
×
35
  }
×
36

×
37
  public static registerService<T>(
×
38
    serviceClass: Type<T>,
×
39
    options: OpraClientModuleOptions,
×
40
  ): ModuleWithProviders<OpraClientModule> {
×
41
    const SERVICE_TOKEN = options.token || serviceClass;
×
42
    return {
×
43
      ngModule: OpraClientModule,
×
44
      providers: [
×
45
        {
×
46
          provide: SERVICE_TOKEN,
×
47
          deps: [HttpClient],
×
48
          useFactory: (httpClient: HttpClient) => {
×
49
            const opraAngularClient = new OpraAngularClient(
×
50
              httpClient,
×
51
              options.serviceUrl,
×
52
              options,
×
53
            );
×
54
            const service = new serviceClass(opraAngularClient);
×
55
            service[kClient] = opraAngularClient;
×
56
            return service;
×
57
          },
×
58
        },
×
59
      ],
×
60
    };
×
61
  }
×
62

×
63
  public static registerClientAsync(
×
64
    options: OpraClientModuleAsyncOptions,
×
65
  ): ModuleWithProviders<OpraClientModule> {
×
66
    const CLIENT_TOKEN = options.token || OpraAngularClient;
×
67
    const asyncProviders = this._createAsyncProviders(options);
×
68
    return {
×
69
      ngModule: OpraClientModule,
×
70
      providers: [
×
71
        ...asyncProviders,
×
72
        {
×
73
          provide: CLIENT_TOKEN,
×
74
          deps: [HttpClient, OPRA_CLIENT_MODULE_OPTIONS],
×
75
          useFactory: (httpClient: HttpClient, opts: OpraClientModuleOptions) =>
×
76
            new OpraAngularClient(httpClient, opts.serviceUrl, opts),
×
77
        },
×
78
      ],
×
79
    };
×
80
  }
×
81

×
82
  public static registerServiceAsync<T>(
×
83
    serviceClass: Type<T>,
×
84
    options: OpraClientModuleAsyncOptions,
×
85
  ): ModuleWithProviders<OpraClientModule> {
×
86
    const SERVICE_TOKEN = options.token || serviceClass;
×
87
    const asyncProviders = this._createAsyncProviders(options);
×
88
    return {
×
89
      ngModule: OpraClientModule,
×
90
      providers: [
×
91
        ...asyncProviders,
×
92
        {
×
93
          provide: SERVICE_TOKEN,
×
94
          deps: [HttpClient, OPRA_CLIENT_MODULE_OPTIONS],
×
95
          useFactory: (
×
96
            httpClient: HttpClient,
×
97
            opts: OpraClientModuleOptions,
×
98
          ) => {
×
99
            const opraAngularClient = new OpraAngularClient(
×
100
              httpClient,
×
101
              opts.serviceUrl,
×
102
              opts,
×
103
            );
×
104
            const service = new serviceClass(opraAngularClient);
×
105
            service[kClient] = opraAngularClient;
×
106
            return service;
×
107
          },
×
108
        },
×
109
      ],
×
110
    };
×
111
  }
×
112

×
113
  private static _createAsyncProviders(
×
114
    options: OpraClientModuleAsyncOptions,
×
115
  ): Provider[] {
×
116
    if (options.useExisting || options.useFactory)
×
117
      return [this._createAsyncOptionsProvider(options)];
×
118

×
119
    if (options.useClass) {
×
120
      return [
×
121
        this._createAsyncOptionsProvider(options),
×
122
        {
×
123
          provide: options.useClass,
×
124
          useClass: options.useClass,
×
125
        },
×
126
      ];
×
127
    }
×
128

×
129
    throw new Error(
×
130
      'Invalid configuration. Must provide useFactory, useClass or useExisting',
×
131
    );
×
132
  }
×
133

×
134
  private static _createAsyncOptionsProvider(
×
135
    options: OpraClientModuleAsyncOptions,
×
136
  ): Provider {
×
137
    if (options.useFactory) {
×
138
      return {
×
139
        provide: OPRA_CLIENT_MODULE_OPTIONS,
×
140
        useFactory: options.useFactory,
×
141
        deps: options.deps || [],
×
142
      };
×
143
    }
×
144
    const useClass = options.useClass || options.useExisting;
×
145
    if (useClass) {
×
146
      return {
×
147
        provide: OPRA_CLIENT_MODULE_OPTIONS,
×
148
        useFactory: o => o,
×
149
        deps: [useClass],
×
150
      };
×
151
    }
×
152
    throw new Error(
×
153
      'Invalid configuration. Must provide useFactory, useClass or useExisting',
×
154
    );
×
155
  }
×
156
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc