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

oprajs / opra / 14419802659

12 Apr 2025 12:55PM UTC coverage: 82.088% (+4.2%) from 77.908%
14419802659

push

github

web-flow
Merge pull request #27 from oprajs/dev

Dev

3458 of 4432 branches covered (78.02%)

Branch coverage included in aggregate %.

16 of 16 new or added lines in 10 files covered. (100.0%)

1793 existing lines in 129 files now uncovered.

29424 of 35625 relevant lines covered (82.59%)

183.2 hits per line

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

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

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

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

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

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

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

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

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

×
UNCOV
133
  private static _createAsyncOptionsProvider(
×
UNCOV
134
    options: OpraClientModuleAsyncOptions,
×
UNCOV
135
  ): Provider {
×
UNCOV
136
    if (options.useFactory) {
×
UNCOV
137
      return {
×
UNCOV
138
        provide: OPRA_CLIENT_MODULE_OPTIONS,
×
UNCOV
139
        useFactory: options.useFactory,
×
UNCOV
140
        deps: options.deps || [],
×
UNCOV
141
      };
×
UNCOV
142
    }
×
UNCOV
143
    const useClass = options.useClass || options.useExisting;
×
UNCOV
144
    if (useClass) {
×
UNCOV
145
      return {
×
UNCOV
146
        provide: OPRA_CLIENT_MODULE_OPTIONS,
×
UNCOV
147
        useFactory: o => o,
×
UNCOV
148
        deps: [useClass],
×
UNCOV
149
      };
×
UNCOV
150
    }
×
151
    throw new Error(
×
UNCOV
152
      'Invalid configuration. Must provide useFactory, useClass or useExisting',
×
UNCOV
153
    );
×
UNCOV
154
  }
×
UNCOV
155
}
×
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