@mgremy/core 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ import * as i0 from '@angular/core';
2
+ import { PipeTransform } from '@angular/core';
3
+
4
+ declare class ArrayFilterPipe<T> implements PipeTransform {
5
+ transform(value: T[], callback: (x: T) => boolean, mode: 'multiple'): T[];
6
+ transform(value: T[], callback: (x: T) => boolean, mode: 'single'): T | undefined;
7
+ static ɵfac: i0.ɵɵFactoryDeclaration<ArrayFilterPipe<any>, never>;
8
+ static ɵpipe: i0.ɵɵPipeDeclaration<ArrayFilterPipe<any>, "arrayFilter", true>;
9
+ }
10
+
11
+ declare class LocalizedDatePipe implements PipeTransform {
12
+ private readonly _translationService;
13
+ transform(value: any, format?: string, timezone?: string): string | null;
14
+ static ɵfac: i0.ɵɵFactoryDeclaration<LocalizedDatePipe, never>;
15
+ static ɵpipe: i0.ɵɵPipeDeclaration<LocalizedDatePipe, "localizedDate", true>;
16
+ }
17
+
18
+ declare class EnumKeyValuePairPipe implements PipeTransform {
19
+ transform(value: object): {
20
+ key: string;
21
+ value: number;
22
+ }[];
23
+ static ɵfac: i0.ɵɵFactoryDeclaration<EnumKeyValuePairPipe, never>;
24
+ static ɵpipe: i0.ɵɵPipeDeclaration<EnumKeyValuePairPipe, "enumKeyValuePair", true>;
25
+ }
26
+
27
+ declare class FirstLetterUpperPipe implements PipeTransform {
28
+ transform(value: string): string;
29
+ static ɵfac: i0.ɵɵFactoryDeclaration<FirstLetterUpperPipe, never>;
30
+ static ɵpipe: i0.ɵɵPipeDeclaration<FirstLetterUpperPipe, "firstLetterUpper", true>;
31
+ }
32
+
33
+ export { ArrayFilterPipe, EnumKeyValuePairPipe, FirstLetterUpperPipe, LocalizedDatePipe };
@@ -0,0 +1,11 @@
1
+ import { ResolveData } from '@angular/router';
2
+
3
+ /**
4
+ * Creates a route resolver that extracts a query parameter value with type safety.
5
+ * @param key - The query parameter key to extract
6
+ * @param defaultValue - The default value to use if the parameter is not present
7
+ * @returns A resolver function for use in Angular route configuration
8
+ */
9
+ declare const paramResolver: <T extends string | number | boolean>(key: string, defaultValue: T) => ResolveData;
10
+
11
+ export { paramResolver };
@@ -0,0 +1,14 @@
1
+ import { FormControl, FormArray, FormGroup } from '@angular/forms';
2
+
3
+ type FlagExcludeType<Base, Type> = {
4
+ [Key in keyof Base]: Base[Key] extends Type ? never : Key;
5
+ };
6
+ type AllowedNames<Base, Type> = FlagExcludeType<Base, Type>[keyof Base];
7
+ type OmitType<Base, Type> = Pick<Base, AllowedNames<Base, Type>>;
8
+ type ExcludeFuncType<T> = OmitType<T, Function>;
9
+ type FormItems<T> = [T] extends [boolean | number | string | null | undefined | Date] ? FormControl<T> : [T] extends [(infer U)[]] ? FormArray<FormItems<U>> : FormGroup<FormType<T>>;
10
+ type FormType<T> = {
11
+ [K in keyof ExcludeFuncType<T>]: FormItems<T[K]>;
12
+ };
13
+
14
+ export type { FormType };
@@ -0,0 +1,13 @@
1
+ import { PaginationRequest } from '@mgremy/core/models';
2
+ import * as rxjs from 'rxjs';
3
+ import * as z from 'zod';
4
+
5
+ declare function hasProperty<K extends PropertyKey>(value: unknown, key: K): value is Record<K, unknown>;
6
+
7
+ type ToURLSearchParamsHandler = (params: URLSearchParams) => void;
8
+ declare function toURLSearchParams(...handlers: ToURLSearchParamsHandler[]): URLSearchParams;
9
+ declare function withPagination<T>(request: PaginationRequest<T>): ToURLSearchParamsHandler;
10
+
11
+ declare function zParse<T extends z.ZodType>(zObj: T): rxjs.UnaryFunction<rxjs.Observable<unknown>, rxjs.Observable<z.core.output<T>>>;
12
+
13
+ export { hasProperty, toURLSearchParams, withPagination, zParse };
@@ -1,7 +1,12 @@
1
- import { InjectionToken, Signal } from '@angular/core';
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Type, Provider, EnvironmentProviders, Signal, Injector, ResourceRef } from '@angular/core';
3
+ import { AuthConfig } from 'angular-oauth2-oidc';
4
+ import { Observable } from 'rxjs';
5
+ import { FilterRequest, PaginationResponse, PaginationRequest } from '@mgremy/core/models';
6
+ import { RxResourceOptions } from '@angular/core/rxjs-interop';
2
7
 
3
- declare const APP_CONFIG_SERVICE: InjectionToken<IAppConfigService>;
4
- interface IAppConfigService {
8
+ declare const CONFIG_SERVICE: InjectionToken<IConfigService>;
9
+ interface IConfigService {
5
10
  get appUrl(): string;
6
11
  get appBaseHref(): string;
7
12
  get apiUrl(): string;
@@ -10,9 +15,96 @@ interface IAppConfigService {
10
15
  get authRealm(): string;
11
16
  get authClientId(): string;
12
17
  }
18
+ declare class ConfigService implements IConfigService {
19
+ private readonly _environment;
20
+ private readonly _windowKey;
21
+ private isValidValue;
22
+ private getValue;
23
+ get appUrl(): string;
24
+ get appBaseHref(): string;
25
+ get apiUrl(): string;
26
+ get defaultLanguage(): string;
27
+ get authUrl(): string;
28
+ get authRealm(): string;
29
+ get authClientId(): string;
30
+ static ɵfac: i0.ɵɵFactoryDeclaration<ConfigService, never>;
31
+ static ɵprov: i0.ɵɵInjectableDeclaration<ConfigService>;
32
+ }
33
+ declare function provideConfig(options?: {
34
+ service?: Type<IConfigService>;
35
+ }): (Provider | EnvironmentProviders)[];
13
36
 
14
- declare const APP_ENVIRONMENT_SERVICE: InjectionToken<Environment>;
15
- interface Environment {
37
+ declare const AUTH_SERVICE: InjectionToken<IAuthService>;
38
+ interface IdToken {
39
+ sub: string;
40
+ iss: string;
41
+ aud: string | string[];
42
+ exp: number;
43
+ iat: number;
44
+ name?: string;
45
+ given_name?: string;
46
+ family_name?: string;
47
+ email?: string;
48
+ email_verified?: boolean;
49
+ preferred_username?: string;
50
+ [key: string]: unknown;
51
+ }
52
+ interface AccessToken {
53
+ exp: number;
54
+ iat: number;
55
+ jti: string | undefined;
56
+ iss: string;
57
+ aud: string;
58
+ sub: string;
59
+ typ: string | undefined;
60
+ azp: string | undefined;
61
+ sid: string | undefined;
62
+ acr: string | undefined;
63
+ 'allowed-origins': string[] | undefined;
64
+ realm_access: Record<string, string[]> | undefined;
65
+ scope: string | undefined;
66
+ email_verified: boolean | undefined;
67
+ roles: string[] | undefined;
68
+ name: string | undefined;
69
+ preferred_username: string | undefined;
70
+ given_name: string | undefined;
71
+ family_name: string | undefined;
72
+ email: string | undefined;
73
+ }
74
+ interface IAuthService {
75
+ isAuthenticated: Signal<boolean>;
76
+ init(): Observable<void>;
77
+ getIdToken(): IdToken;
78
+ getAccessToken(): string;
79
+ getDecodedAccessToken(): AccessToken | undefined;
80
+ hasRoles(roles: string): boolean;
81
+ hasRoles(roles: string[], mode: 'any' | 'all'): boolean;
82
+ login(): void;
83
+ logout(): void;
84
+ }
85
+ declare class AuthService implements IAuthService {
86
+ private readonly _authService;
87
+ private readonly _isAuthenticated;
88
+ readonly isAuthenticated: Signal<boolean>;
89
+ constructor();
90
+ init(): Observable<void>;
91
+ getIdToken(): IdToken;
92
+ getAccessToken(): string;
93
+ getDecodedAccessToken(): AccessToken | undefined;
94
+ hasRoles(roles: string): boolean;
95
+ hasRoles(roles: string[], mode: 'any' | 'all'): boolean;
96
+ login(): void;
97
+ logout(): void;
98
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
99
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
100
+ }
101
+ declare function provideAuthConfig(options?: {
102
+ service?: Type<IAuthService>;
103
+ authConfig?: AuthConfig;
104
+ }): (Provider | EnvironmentProviders)[];
105
+
106
+ declare const ENVIRONMENT_VALUE: InjectionToken<IEnvironment>;
107
+ interface IEnvironment {
16
108
  production: boolean;
17
109
  appUrl: string;
18
110
  appBaseHref: string;
@@ -22,23 +114,51 @@ interface Environment {
22
114
  authRealm: string;
23
115
  authClientId: string;
24
116
  }
117
+ declare function provideEnvironmentConfig(options: {
118
+ value: IEnvironment;
119
+ }): (Provider | EnvironmentProviders)[];
25
120
 
26
- declare const APP_STORAGE_SERVICE: InjectionToken<IStorageService>;
121
+ declare const STORAGE_SERVICE: InjectionToken<IStorageService>;
27
122
  interface IStorageService {
28
123
  getItem(key: string): string | undefined;
29
124
  setItem(key: string, value: string): void;
30
125
  removeItem(key: string): void;
31
126
  clear(): void;
32
127
  }
128
+ declare class StorageService implements IStorageService {
129
+ getItem(key: string): string | undefined;
130
+ setItem(key: string, value: string): void;
131
+ removeItem(key: string): void;
132
+ clear(): void;
133
+ static ɵfac: i0.ɵɵFactoryDeclaration<StorageService, never>;
134
+ static ɵprov: i0.ɵɵInjectableDeclaration<StorageService>;
135
+ }
136
+ declare function provideStorageConfig(options?: {
137
+ service?: Type<IStorageService>;
138
+ }): (Provider | EnvironmentProviders)[];
33
139
 
34
- declare const APP_THEME_SERVICE: InjectionToken<IAppThemeService>;
35
- type AppTheme = 'light' | 'dark';
36
- interface IAppThemeService {
37
- getTheme(): AppTheme;
38
- setTheme(value: AppTheme): void;
140
+ declare const THEME_SERVICE: InjectionToken<IThemeService>;
141
+ type Theme = 'light' | 'dark';
142
+ interface IThemeService {
143
+ getTheme(): Theme;
144
+ setTheme(value: Theme): void;
145
+ }
146
+ declare class ThemeService implements IThemeService {
147
+ private readonly _storageService;
148
+ protected readonly _storageKeys: {
149
+ theme: string;
150
+ };
151
+ constructor();
152
+ getTheme(): Theme;
153
+ setTheme(key: Theme): void;
154
+ static ɵfac: i0.ɵɵFactoryDeclaration<ThemeService, never>;
155
+ static ɵprov: i0.ɵɵInjectableDeclaration<ThemeService>;
39
156
  }
157
+ declare function provideThemeConfig(options?: {
158
+ service?: Type<IThemeService>;
159
+ }): (Provider | EnvironmentProviders)[];
40
160
 
41
- declare const APP_TRANSLATION_SERVICE: InjectionToken<ITranslationService>;
161
+ declare const TRANSLATION_SERVICE: InjectionToken<ITranslationService>;
42
162
  interface ITranslationService {
43
163
  currentLanguage: Signal<string>;
44
164
  init(): void;
@@ -47,6 +167,62 @@ interface ITranslationService {
47
167
  instant(key: string[], params?: Record<string, string>): string[];
48
168
  instant(key: string | string[], params?: Record<string, string>): string | string[];
49
169
  }
170
+ declare class TranslationService implements ITranslationService {
171
+ private readonly _storageService;
172
+ private readonly _appConfigService;
173
+ private readonly _translationService;
174
+ protected readonly _storageKeys: {
175
+ lang: string;
176
+ };
177
+ protected readonly _currentLanguage: i0.WritableSignal<string>;
178
+ readonly currentLanguage: Signal<string>;
179
+ init(): void;
180
+ setLanguage(code: string): void;
181
+ instant(key: string, params?: Record<string, string>): string;
182
+ instant(key: string[], params?: Record<string, string>): string[];
183
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslationService, never>;
184
+ static ɵprov: i0.ɵɵInjectableDeclaration<TranslationService>;
185
+ }
186
+ declare function provideTranslationConfig(options?: {
187
+ service?: Type<ITranslationService>;
188
+ }): (Provider | EnvironmentProviders)[];
189
+
190
+ declare abstract class BaseComponent {
191
+ protected readonly _injector: Injector;
192
+ }
193
+
194
+ /**
195
+ * Wrapper around PaginationRequest/PaginationResponses and RxResources used side by side with API.
196
+ * It supports AutoRefreshing data.
197
+ */
198
+ declare class PaginationContainer<TResult> {
199
+ /**
200
+ * Value is computed each time pageNumber | pageSize | sortRequest (if not undefined) is updated.
201
+ */
202
+ private readonly _paginationRequest;
203
+ readonly pageNumber: i0.WritableSignal<number>;
204
+ readonly pageSize: i0.WritableSignal<number>;
205
+ readonly sortRequest: i0.WritableSignal<Record<keyof TResult, boolean | undefined>>;
206
+ readonly filterRequest: i0.WritableSignal<FilterRequest<TResult>[]>;
207
+ readonly resource: ResourceRef<PaginationResponse<TResult> | undefined>;
208
+ constructor(resourceOpts: Omit<RxResourceOptions<PaginationResponse<TResult>, PaginationRequest<TResult> | undefined>, 'params'>);
209
+ /**
210
+ * Update the sort status on property from TResult.
211
+ *
212
+ * It goes undefined -> false -> true.
213
+ * In terms of usage, it goes undefined -> ASC -> DESC.
214
+ * @param propertyName The name of the property from TResult on which we want to update the sort status
215
+ */
216
+ onSortChange(propertyName: keyof TResult): void;
217
+ }
218
+ declare function paginationContainer<TResult>(resourceOpts: Omit<RxResourceOptions<PaginationResponse<TResult>, PaginationRequest<TResult> | undefined>, 'params'>): PaginationContainer<TResult>;
219
+
220
+ /**
221
+ * Generate a unique id for an element
222
+ * @param prefix - The prefix to use for the id
223
+ * @returns The generated id
224
+ */
225
+ declare function uniqueId(prefix: string): string;
50
226
 
51
- export { APP_CONFIG_SERVICE, APP_ENVIRONMENT_SERVICE, APP_STORAGE_SERVICE, APP_THEME_SERVICE, APP_TRANSLATION_SERVICE };
52
- export type { AppTheme, Environment, IAppConfigService, IAppThemeService, IStorageService, ITranslationService };
227
+ export { AUTH_SERVICE, AuthService, BaseComponent, CONFIG_SERVICE, ConfigService, ENVIRONMENT_VALUE, PaginationContainer, STORAGE_SERVICE, StorageService, THEME_SERVICE, TRANSLATION_SERVICE, ThemeService, TranslationService, paginationContainer, provideAuthConfig, provideConfig, provideEnvironmentConfig, provideStorageConfig, provideThemeConfig, provideTranslationConfig, uniqueId };
228
+ export type { AccessToken, IAuthService, IConfigService, IEnvironment, IStorageService, IThemeService, ITranslationService, IdToken, Theme };
@@ -0,0 +1,3 @@
1
+ # @mgremy/core/src/lib/utils
2
+
3
+ Secondary entry point of `@mgremy/core`. It can be used by importing from `@mgremy/core/utils`.