@o3r/apis-manager 15.3.0-prerelease.16 → 15.3.0-prerelease.18

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.
@@ -1,196 +1,112 @@
1
- import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, Injectable, makeEnvironmentProviders } from '@angular/core';
3
-
4
- /**
5
- * Token used by the core library to provide an Api manager to services. It can be provided in the app.
6
- */
7
- const API_TOKEN = new InjectionToken('Custom API manager token');
8
-
9
- /**
10
- * Initial APIs instantiations
11
- */
12
- const INITIAL_APIS_TOKEN = new InjectionToken('Initial APIs token');
13
- class ApiFactoryService {
14
- constructor() {
15
- this.apiManager = inject(API_TOKEN);
16
- /** Map of loaded APIs */
17
- this.loadedApis = {};
18
- const apis = inject(INITIAL_APIS_TOKEN, { optional: true });
19
- if (apis) {
20
- this.updateApiMapping(apis);
21
- }
22
- }
23
- /**
24
- * Determine if the given parameter is a API class
25
- * @param apiClass object to check
26
- */
27
- isApiClass(apiClass) {
28
- return !!apiClass.apiName && typeof apiClass === 'function';
29
- }
30
- /**
31
- * Retrieve a specific API with loaded configuration
32
- * @param apiClass class of the API to retrieve
33
- * @param refreshCache Ignore cached API instance and refresh it
34
- * @param customApiName override the `apiName` set in the `apiClass`
35
- * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
36
- * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
37
- */
38
- getApi(apiClass, refreshCache = false, customApiName) {
39
- const apiName = customApiName ?? apiClass.apiName;
40
- const cache = this.loadedApis[apiName];
41
- if (!refreshCache && cache) {
42
- return cache;
43
- }
44
- const instance = this.createApi(apiClass, customApiName);
45
- this.loadedApis[apiName] = instance;
46
- return instance;
47
- }
48
- /**
49
- * Instantiate a new instance of a specific API with loaded configuration, without using cache mechanism.
50
- * Warning: This function should be used only in specific cases when the cache should not be used. Otherwise, {@link getApi} is highly recommended.
51
- * @param apiClass class of the API to retrieve
52
- * @param customApiName override the `apiName` set in the `apiClass`
53
- * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
54
- * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
55
- */
56
- createApi(apiClass, customApiName) {
57
- return new apiClass(this.getConfigFor(customApiName ?? apiClass));
58
- }
59
- /**
60
- * Update the Map of loaded APIs.
61
- * Note: Can be used to override the a specific API
62
- * @param map Map of loaded APIs to update
63
- */
64
- updateApiMapping(map) {
65
- const newItems = Array.isArray(map)
66
- ? map
67
- .reduce((acc, curr) => {
68
- acc[curr.apiName] = curr;
69
- return acc;
70
- }, {})
71
- : map;
72
- this.loadedApis = {
73
- ...this.loadedApis,
74
- ...Object.entries(newItems)
75
- .reduce((acc, [apiName, api]) => {
76
- acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;
77
- return acc;
78
- }, {})
79
- };
80
- }
81
- /**
82
- * Clear the cache of loaded APIs
83
- * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache
84
- */
85
- clearCache(apis) {
86
- if (apis) {
87
- apis.forEach((api) => delete this.loadedApis[typeof api === 'string' ? api : api.apiName]);
88
- }
89
- else {
90
- this.loadedApis = {};
91
- }
92
- }
93
- /**
94
- * Retrieve the configuration for a specific API
95
- * @param api API for which retrieving the configuration
96
- */
97
- getConfigFor(api) {
98
- return this.apiManager.getConfiguration(api);
99
- }
100
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ApiFactoryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
101
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ApiFactoryService, providedIn: 'root' }); }
102
- }
103
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ApiFactoryService, decorators: [{
104
- type: Injectable,
105
- args: [{
106
- providedIn: 'root'
107
- }]
108
- }], ctorParameters: () => [] });
109
-
110
- /**
111
- * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API
112
- * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of
113
- * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration
114
- * and the requested one.
115
- */
116
- class ApiManager {
117
- /**
118
- * Map of registered Api Client associated to specific API
119
- * Warning: This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead
120
- */
121
- get registeredApiConfigurations() {
122
- return { ...this.apiConfigurations };
123
- }
124
- /**
125
- * Create an API manager using a custom ApiClient
126
- * @param defaultConfiguration
127
- */
128
- constructor(defaultConfiguration, apiConfigurations = {}) {
129
- this.defaultConfiguration = defaultConfiguration;
130
- this.apiConfigurations = apiConfigurations;
131
- }
132
- /**
133
- * Retrieve a configuration for a specific API
134
- * @param api API to get the configuration for
135
- * @note When passing a string the configuration is expecting to exist else an error is thrown
136
- * @note when passing an Api instance that does not match a registered configuration, the default one will be returned
137
- */
138
- getConfiguration(api) {
139
- if (typeof api === 'string') {
140
- if (this.apiConfigurations[api]) {
141
- return this.apiConfigurations[api];
142
- }
143
- else {
144
- throw new Error(`Unknown API configuration: ${api}\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(', ')}`);
145
- }
146
- }
147
- return (api && this.apiConfigurations[api.apiName]) || this.defaultConfiguration;
148
- }
149
- /**
150
- * Set or override API configuration
151
- * @param apiClient API configuration to override to the given api
152
- * @param api API name to override, the default configuration will be used if not specified
153
- */
154
- setConfiguration(apiClient, api) {
155
- if (api) {
156
- this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient;
157
- }
158
- else {
159
- this.defaultConfiguration = apiClient;
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Add a preconnect `<link>` element to the DOM
166
- * @param baseUrl the origin href
167
- * @param supportCrossOrigin add crossorigin attribute to the link element
168
- */
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable, InjectionToken, inject, makeEnvironmentProviders } from "@angular/core";
3
+ const API_TOKEN = new InjectionToken("Custom API manager token");
4
+ const INITIAL_APIS_TOKEN = new InjectionToken("Initial APIs token");
5
+ var ApiFactoryService = class ApiFactoryService {
6
+ constructor() {
7
+ this.apiManager = inject(API_TOKEN);
8
+ this.loadedApis = {};
9
+ const apis = inject(INITIAL_APIS_TOKEN, { optional: true });
10
+ if (apis) this.updateApiMapping(apis);
11
+ }
12
+ isApiClass(apiClass) {
13
+ return !!apiClass.apiName && typeof apiClass === "function";
14
+ }
15
+ getApi(apiClass, refreshCache = false, customApiName) {
16
+ const apiName = customApiName ?? apiClass.apiName;
17
+ const cache = this.loadedApis[apiName];
18
+ if (!refreshCache && cache) return cache;
19
+ const instance = this.createApi(apiClass, customApiName);
20
+ this.loadedApis[apiName] = instance;
21
+ return instance;
22
+ }
23
+ createApi(apiClass, customApiName) {
24
+ return new apiClass(this.getConfigFor(customApiName ?? apiClass));
25
+ }
26
+ updateApiMapping(map) {
27
+ const newItems = Array.isArray(map) ? map.reduce((acc, curr) => {
28
+ acc[curr.apiName] = curr;
29
+ return acc;
30
+ }, {}) : map;
31
+ this.loadedApis = {
32
+ ...this.loadedApis,
33
+ ...Object.entries(newItems).reduce((acc, [apiName, api]) => {
34
+ acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;
35
+ return acc;
36
+ }, {})
37
+ };
38
+ }
39
+ clearCache(apis) {
40
+ if (apis) apis.forEach((api) => delete this.loadedApis[typeof api === "string" ? api : api.apiName]);
41
+ else this.loadedApis = {};
42
+ }
43
+ getConfigFor(api) {
44
+ return this.apiManager.getConfiguration(api);
45
+ }
46
+ static {
47
+ this.ɵfac = i0.ɵɵngDeclareFactory({
48
+ minVersion: "12.0.0",
49
+ version: "22.2.3",
50
+ ngImport: i0,
51
+ type: ApiFactoryService,
52
+ deps: [],
53
+ target: i0.ɵɵFactoryTarget.Injectable
54
+ });
55
+ }
56
+ static {
57
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
58
+ minVersion: "12.0.0",
59
+ version: "22.2.3",
60
+ ngImport: i0,
61
+ type: ApiFactoryService,
62
+ providedIn: "root"
63
+ });
64
+ }
65
+ };
66
+ i0.ɵɵngDeclareClassMetadata({
67
+ minVersion: "12.0.0",
68
+ version: "22.2.3",
69
+ ngImport: i0,
70
+ type: ApiFactoryService,
71
+ decorators: [{
72
+ type: Injectable,
73
+ args: [{ providedIn: "root" }]
74
+ }],
75
+ ctorParameters: () => []
76
+ });
77
+ var ApiManager = class {
78
+ get registeredApiConfigurations() {
79
+ return { ...this.apiConfigurations };
80
+ }
81
+ constructor(defaultConfiguration, apiConfigurations = {}) {
82
+ this.defaultConfiguration = defaultConfiguration;
83
+ this.apiConfigurations = apiConfigurations;
84
+ }
85
+ getConfiguration(api) {
86
+ if (typeof api === "string") {
87
+ if (this.apiConfigurations[api]) return this.apiConfigurations[api];
88
+ else throw new Error(`Unknown API configuration: ${api}\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(", ")}`);
89
+ }
90
+ return api && this.apiConfigurations[api.apiName] || this.defaultConfiguration;
91
+ }
92
+ setConfiguration(apiClient, api) {
93
+ if (api) this.apiConfigurations[typeof api === "string" ? api : api.apiName] = apiClient;
94
+ else this.defaultConfiguration = apiClient;
95
+ }
96
+ };
169
97
  function appendPreconnect(baseUrl, supportCrossOrigin = true) {
170
- const preConnectLink = document.createElement('link');
171
- preConnectLink.setAttribute('rel', 'preconnect');
172
- preConnectLink.setAttribute('href', baseUrl);
173
- if (supportCrossOrigin) {
174
- preConnectLink.setAttribute('crossorigin', '');
175
- }
176
- document.head.append(preConnectLink);
98
+ const preConnectLink = document.createElement("link");
99
+ preConnectLink.setAttribute("rel", "preconnect");
100
+ preConnectLink.setAttribute("href", baseUrl);
101
+ if (supportCrossOrigin) preConnectLink.setAttribute("crossorigin", "");
102
+ document.head.append(preConnectLink);
177
103
  }
178
-
179
- /**
180
- * Provide a custom {@link ApiManager}
181
- * A factory can be provided via injection to the token {@link API_TOKEN}
182
- * @param apiManager
183
- */
184
104
  function provideApiManager(apiManager) {
185
- return makeEnvironmentProviders([
186
- ApiFactoryService,
187
- { provide: API_TOKEN, useValue: apiManager }
188
- ]);
105
+ return makeEnvironmentProviders([ApiFactoryService, {
106
+ provide: API_TOKEN,
107
+ useValue: apiManager
108
+ }]);
189
109
  }
190
-
191
- /**
192
- * Generated bundle index. Do not edit.
193
- */
194
-
195
110
  export { API_TOKEN, ApiFactoryService, ApiManager, INITIAL_APIS_TOKEN, appendPreconnect, provideApiManager };
196
- //# sourceMappingURL=o3r-apis-manager.mjs.map
111
+
112
+ //# sourceMappingURL=o3r-apis-manager.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"o3r-apis-manager.mjs","sources":["../../src/apis-manager/api-manager-token.ts","../../src/apis-manager/api-factory-service.ts","../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager-helpers.ts","../../src/apis-manager/api-manager-module.ts","../../src/o3r-apis-manager.ts"],"sourcesContent":["import {\n InjectionToken,\n} from '@angular/core';\nimport type {\n ApiManager,\n} from './api-manager';\n\n/**\n * Token used by the core library to provide an Api manager to services. It can be provided in the app.\n */\nexport const API_TOKEN = new InjectionToken<ApiManager>('Custom API manager token');\n","import type {\n Api,\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\nimport {\n inject,\n Injectable,\n InjectionToken,\n} from '@angular/core';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} from './api-manager-token';\n\n/** Type of the Class of an SDK Api */\nexport type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;\n\n/**\n * Initial APIs instantiations\n */\nexport const INITIAL_APIS_TOKEN = new InjectionToken<(Api | ApiClassType)[]>('Initial APIs token');\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ApiFactoryService {\n private readonly apiManager = inject<ApiManager>(API_TOKEN);\n\n /** Map of loaded APIs */\n private loadedApis: Record<string, Api> = {};\n\n constructor() {\n const apis = inject(INITIAL_APIS_TOKEN, { optional: true });\n\n if (apis) {\n this.updateApiMapping(apis);\n }\n }\n\n /**\n * Determine if the given parameter is a API class\n * @param apiClass object to check\n */\n private isApiClass<T extends Api = Api>(apiClass: any): apiClass is ApiClassType<T> {\n return !!apiClass.apiName && typeof apiClass === 'function';\n }\n\n /**\n * Retrieve a specific API with loaded configuration\n * @param apiClass class of the API to retrieve\n * @param refreshCache Ignore cached API instance and refresh it\n * @param customApiName override the `apiName` set in the `apiClass`\n * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown\n * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned\n */\n public getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache = false, customApiName?: string): T {\n const apiName = customApiName ?? apiClass.apiName;\n const cache = this.loadedApis[apiName];\n if (!refreshCache && cache) {\n return cache as T;\n }\n\n const instance = this.createApi(apiClass, customApiName);\n this.loadedApis[apiName] = instance;\n return instance;\n }\n\n /**\n * Instantiate a new instance of a specific API with loaded configuration, without using cache mechanism.\n * Warning: This function should be used only in specific cases when the cache should not be used. Otherwise, {@link getApi} is highly recommended.\n * @param apiClass class of the API to retrieve\n * @param customApiName override the `apiName` set in the `apiClass`\n * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown\n * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned\n */\n public createApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, customApiName?: string): T {\n return new apiClass(this.getConfigFor(customApiName ?? apiClass));\n }\n\n /**\n * Update the Map of loaded APIs.\n * Note: Can be used to override the a specific API\n * @param map Map of loaded APIs to update\n */\n public updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>) {\n const newItems: Record<string, (Api | ApiClassType)> = Array.isArray(map)\n ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {})\n : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\n acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;\n return acc;\n }, {})\n };\n }\n\n /**\n * Clear the cache of loaded APIs\n * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache\n */\n public clearCache(apis?: (ApiName | string)[]) {\n if (apis) {\n apis.forEach((api) => delete this.loadedApis[typeof api === 'string' ? api : api.apiName]);\n } else {\n this.loadedApis = {};\n }\n }\n\n /**\n * Retrieve the configuration for a specific API\n * @param api API for which retrieving the configuration\n */\n public getConfigFor(api: string | ApiName): ApiClient {\n return this.apiManager.getConfiguration(api);\n }\n}\n","import type {\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\n\n/**\n * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API\n * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of\n * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration\n * and the requested one.\n */\nexport class ApiManager {\n private defaultConfiguration: ApiClient;\n private apiConfigurations: { [key: string]: ApiClient };\n\n /**\n * Map of registered Api Client associated to specific API\n * Warning: This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead\n */\n public get registeredApiConfigurations() {\n return { ...this.apiConfigurations } as const;\n }\n\n /**\n * Create an API manager using a custom ApiClient\n * @param defaultConfiguration\n */\n constructor(defaultConfiguration: ApiClient, apiConfigurations: { [key: string]: ApiClient } = {}) {\n this.defaultConfiguration = defaultConfiguration;\n this.apiConfigurations = apiConfigurations;\n }\n\n /**\n * Retrieve a configuration for a specific API\n * @param api API to get the configuration for\n * @note When passing a string the configuration is expecting to exist else an error is thrown\n * @note when passing an Api instance that does not match a registered configuration, the default one will be returned\n */\n public getConfiguration(api?: string | ApiName): ApiClient {\n if (typeof api === 'string') {\n if (this.apiConfigurations[api]) {\n return this.apiConfigurations[api];\n } else {\n throw new Error(`Unknown API configuration: ${api}\\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(', ')}`);\n }\n }\n return (api && this.apiConfigurations[api.apiName]) || this.defaultConfiguration;\n }\n\n /**\n * Set or override API configuration\n * @param apiClient API configuration to override to the given api\n * @param api API name to override, the default configuration will be used if not specified\n */\n public setConfiguration(apiClient: ApiClient, api?: string | ApiName): void {\n if (api) {\n this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","/**\n * Add a preconnect `<link>` element to the DOM\n * @param baseUrl the origin href\n * @param supportCrossOrigin add crossorigin attribute to the link element\n */\nexport function appendPreconnect(baseUrl: string, supportCrossOrigin = true): void {\n const preConnectLink = document.createElement('link');\n preConnectLink.setAttribute('rel', 'preconnect');\n preConnectLink.setAttribute('href', baseUrl);\n if (supportCrossOrigin) {\n preConnectLink.setAttribute('crossorigin', '');\n }\n document.head.append(preConnectLink);\n}\n","import {\n makeEnvironmentProviders,\n} from '@angular/core';\nimport {\n ApiFactoryService,\n} from './api-factory-service';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} from './api-manager-token';\n\n/**\n * Provide a custom {@link ApiManager}\n * A factory can be provided via injection to the token {@link API_TOKEN}\n * @param apiManager\n */\nexport function provideApiManager(apiManager: ApiManager) {\n return makeEnvironmentProviders([\n ApiFactoryService,\n { provide: API_TOKEN, useValue: apiManager }\n ]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAOA;;AAEG;MACU,SAAS,GAAG,IAAI,cAAc,CAAa,0BAA0B;;ACUlF;;AAEG;MACU,kBAAkB,GAAG,IAAI,cAAc,CAAyB,oBAAoB;MAKpF,iBAAiB,CAAA;AAM5B,IAAA,WAAA,GAAA;AALiB,QAAA,IAAA,CAAA,UAAU,GAAG,MAAM,CAAa,SAAS,CAAC;;QAGnD,IAAA,CAAA,UAAU,GAAwB,EAAE;AAG1C,QAAA,MAAM,IAAI,GAAG,MAAM,CAAC,kBAAkB,EAAE,EAAE,QAAQ,EA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AA,cAAc,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC;AAChD,IAAA,cAAc,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,IAAI,kBAAkB,EAAE;AACtB,QAAA,cAAc,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC;IAChD;AACA,IAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;AACtC;;ACAA;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,UAAsB,EAAA;AACtD,IAAA,OAAO,wBAAwB,CAAC;QAC9B,iBAAiB;AACjB,QAAA,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU;AAC3C,KAAA,CAAC;AACJ;;ACvBA;;AAEG;;"}
1
+ {"version":3,"file":"o3r-apis-manager.mjs","names":[],"sources":["../../src/apis-manager/api-manager-token.ts","../../src/apis-manager/api-factory-service.ts","../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager-helpers.ts","../../src/apis-manager/api-manager-module.ts"],"sourcesContent":["import {\n InjectionToken,\n} from '@angular/core';\nimport type {\n ApiManager,\n} from './api-manager';\n\n/**\n * Token used by the core library to provide an Api manager to services. It can be provided in the app.\n */\nexport const API_TOKEN = new InjectionToken<ApiManager>('Custom API manager token');\n","import type {\n Api,\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\nimport {\n inject,\n Injectable,\n InjectionToken,\n} from '@angular/core';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} from './api-manager-token';\n\n/** Type of the Class of an SDK Api */\nexport type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;\n\n/**\n * Initial APIs instantiations\n */\nexport const INITIAL_APIS_TOKEN = new InjectionToken<(Api | ApiClassType)[]>('Initial APIs token');\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ApiFactoryService {\n private readonly apiManager = inject<ApiManager>(API_TOKEN);\n\n /** Map of loaded APIs */\n private loadedApis: Record<string, Api> = {};\n\n constructor() {\n const apis = inject(INITIAL_APIS_TOKEN, { optional: true });\n\n if (apis) {\n this.updateApiMapping(apis);\n }\n }\n\n /**\n * Determine if the given parameter is a API class\n * @param apiClass object to check\n */\n private isApiClass<T extends Api = Api>(apiClass: any): apiClass is ApiClassType<T> {\n return !!apiClass.apiName && typeof apiClass === 'function';\n }\n\n /**\n * Retrieve a specific API with loaded configuration\n * @param apiClass class of the API to retrieve\n * @param refreshCache Ignore cached API instance and refresh it\n * @param customApiName override the `apiName` set in the `apiClass`\n * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown\n * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned\n */\n public getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache = false, customApiName?: string): T {\n const apiName = customApiName ?? apiClass.apiName;\n const cache = this.loadedApis[apiName];\n if (!refreshCache && cache) {\n return cache as T;\n }\n\n const instance = this.createApi(apiClass, customApiName);\n this.loadedApis[apiName] = instance;\n return instance;\n }\n\n /**\n * Instantiate a new instance of a specific API with loaded configuration, without using cache mechanism.\n * Warning: This function should be used only in specific cases when the cache should not be used. Otherwise, {@link getApi} is highly recommended.\n * @param apiClass class of the API to retrieve\n * @param customApiName override the `apiName` set in the `apiClass`\n * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown\n * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned\n */\n public createApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, customApiName?: string): T {\n return new apiClass(this.getConfigFor(customApiName ?? apiClass));\n }\n\n /**\n * Update the Map of loaded APIs.\n * Note: Can be used to override the a specific API\n * @param map Map of loaded APIs to update\n */\n public updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>) {\n const newItems: Record<string, (Api | ApiClassType)> = Array.isArray(map)\n ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {})\n : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\n acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;\n return acc;\n }, {})\n };\n }\n\n /**\n * Clear the cache of loaded APIs\n * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache\n */\n public clearCache(apis?: (ApiName | string)[]) {\n if (apis) {\n apis.forEach((api) => delete this.loadedApis[typeof api === 'string' ? api : api.apiName]);\n } else {\n this.loadedApis = {};\n }\n }\n\n /**\n * Retrieve the configuration for a specific API\n * @param api API for which retrieving the configuration\n */\n public getConfigFor(api: string | ApiName): ApiClient {\n return this.apiManager.getConfiguration(api);\n }\n}\n","import type {\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\n\n/**\n * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API\n * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of\n * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration\n * and the requested one.\n */\nexport class ApiManager {\n private defaultConfiguration: ApiClient;\n private apiConfigurations: { [key: string]: ApiClient };\n\n /**\n * Map of registered Api Client associated to specific API\n * Warning: This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead\n */\n public get registeredApiConfigurations() {\n return { ...this.apiConfigurations } as const;\n }\n\n /**\n * Create an API manager using a custom ApiClient\n * @param defaultConfiguration\n */\n constructor(defaultConfiguration: ApiClient, apiConfigurations: { [key: string]: ApiClient } = {}) {\n this.defaultConfiguration = defaultConfiguration;\n this.apiConfigurations = apiConfigurations;\n }\n\n /**\n * Retrieve a configuration for a specific API\n * @param api API to get the configuration for\n * @note When passing a string the configuration is expecting to exist else an error is thrown\n * @note when passing an Api instance that does not match a registered configuration, the default one will be returned\n */\n public getConfiguration(api?: string | ApiName): ApiClient {\n if (typeof api === 'string') {\n if (this.apiConfigurations[api]) {\n return this.apiConfigurations[api];\n } else {\n throw new Error(`Unknown API configuration: ${api}\\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(', ')}`);\n }\n }\n return (api && this.apiConfigurations[api.apiName]) || this.defaultConfiguration;\n }\n\n /**\n * Set or override API configuration\n * @param apiClient API configuration to override to the given api\n * @param api API name to override, the default configuration will be used if not specified\n */\n public setConfiguration(apiClient: ApiClient, api?: string | ApiName): void {\n if (api) {\n this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","/**\n * Add a preconnect `<link>` element to the DOM\n * @param baseUrl the origin href\n * @param supportCrossOrigin add crossorigin attribute to the link element\n */\nexport function appendPreconnect(baseUrl: string, supportCrossOrigin = true): void {\n const preConnectLink = document.createElement('link');\n preConnectLink.setAttribute('rel', 'preconnect');\n preConnectLink.setAttribute('href', baseUrl);\n if (supportCrossOrigin) {\n preConnectLink.setAttribute('crossorigin', '');\n }\n document.head.append(preConnectLink);\n}\n","import {\n makeEnvironmentProviders,\n} from '@angular/core';\nimport {\n ApiFactoryService,\n} from './api-factory-service';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} from './api-manager-token';\n\n/**\n * Provide a custom {@link ApiManager}\n * A factory can be provided via injection to the token {@link API_TOKEN}\n * @param apiManager\n */\nexport function provideApiManager(apiManager: ApiManager) {\n return makeEnvironmentProviders([\n ApiFactoryService,\n { provide: API_TOKEN, useValue: apiManager }\n ]);\n}\n"],"mappings":";;AAUA,MAAa,YAAY,IAAI,eAA2B,0BAA0B;ACalF,MAAa,qBAAqB,IAAI,eAAuC,oBAAoB;AAKjG,IAAa,oBAAb,MAAa,kBAAiB;CAM5B,cAAA;EALiB,KAAA,aAAa,OAAmB,SAAS;EAGlD,KAAA,aAAkC,CAAA;EAGxC,MAAM,OAAO,OAAO,oBAAoB,EAAE,UAAU,KAAI,CAAE;EAE1D,IAAI,MACF,KAAK,iBAAiB,IAAI;CAE9B;CAMQ,WAAgC,UAAa;EACnD,OAAO,CAAC,CAA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AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAiB,YAAA,CAAA;EAH7B,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA;;;;AChBD,IAAa,aAAb,MAAuB;CAQrB,IAAW,8BAA2B;EACpC,OAAO,EAAE,GAAG,KAAK,kBAAiB;CACpC;CAMA,YAAY,sBAAiC,oBAAkD,CAAA,GAAE;EAC/F,KAAK,uBAAuB;EAC5B,KAAK,oBAAoB;CAC3B;CAQO,iBAAiB,KAAsB;EAC5C,IAAI,OAAO,QAAQ,UAAU;GAC3B,IAAI,KAAK,kBAAkB,MACzB,OAAO,KAAK,kBAAkB;QAE9B,MAAM,IAAI,MAAM,8BAA8B,IAAG,8BAA+B,OAAO,KAAK,KAAK,iBAAiB,CAAC,CAAC,KAAK,IAAI,GAAG;EAEpI;EACA,OAAQ,OAAO,KAAK,kBAAkB,IAAI,YAAa,KAAK;CAC9D;CAOO,iBAAiB,WAAsB,KAAsB;EAClE,IAAI,KACF,KAAK,kBAAkB,OAAO,QAAQ,WAAW,MAAM,IAAI,WAAW;OAEtE,KAAK,uBAAuB;CAEhC;AACD;ACxDD,SAAgB,iBAAiB,SAAiB,qBAAqB,MAAI;CACzE,MAAM,iBAAiB,SAAS,cAAc,MAAM;CACpD,eAAe,aAAa,OAAO,YAAY;CAC/C,eAAe,aAAa,QAAQ,OAAO;CAC3C,IAAI,oBACF,eAAe,aAAa,eAAe,EAAE;CAE/C,SAAS,KAAK,OAAO,cAAc;AACrC;ACKA,SAAgB,kBAAkB,YAAsB;CACtD,OAAO,yBAAyB,CAC9B,mBACA;EAAE,SAAS;EAAW,UAAU;CAAU,CAC3C,CAAA;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/apis-manager",
3
- "version": "15.3.0-prerelease.16",
3
+ "version": "15.3.0-prerelease.18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -11,12 +11,12 @@
11
11
  "otter-module"
12
12
  ],
13
13
  "peerDependencies": {
14
- "@ama-sdk/client-fetch": "~15.3.0-prerelease.16",
15
- "@ama-sdk/core": "~15.3.0-prerelease.16",
14
+ "@ama-sdk/client-fetch": "~15.3.0-prerelease.18",
15
+ "@ama-sdk/core": "~15.3.0-prerelease.18",
16
16
  "@angular-devkit/schematics": "^22.0.0",
17
17
  "@angular/common": "^22.0.0",
18
18
  "@angular/core": "^22.0.0",
19
- "@o3r/schematics": "~15.3.0-prerelease.16",
19
+ "@o3r/schematics": "~15.3.0-prerelease.18",
20
20
  "@schematics/angular": "^22.0.0",
21
21
  "rxjs": "^7.8.1",
22
22
  "type-fest": "^5.3.1",
@@ -40,7 +40,7 @@
40
40
  }
41
41
  },
42
42
  "dependencies": {
43
- "@o3r/schematics": "~15.3.0-prerelease.16",
43
+ "@o3r/schematics": "~15.3.0-prerelease.18",
44
44
  "tslib": "^2.6.2"
45
45
  },
46
46
  "schematics": "./collection.json",
@@ -1,118 +1,110 @@
1
- import { Api, ApiClient, ApiName } from '@ama-sdk/core';
2
- import * as i0 from '@angular/core';
3
- import { InjectionToken } from '@angular/core';
4
-
1
+ import { Api, ApiClient, ApiName } from "@ama-sdk/core";
2
+ import * as i0 from "@angular/core";
3
+ import { InjectionToken } from "@angular/core";
5
4
  /** Type of the Class of an SDK Api */
6
- type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;
5
+ export type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;
7
6
  /**
8
7
  * Initial APIs instantiations
9
8
  */
10
- declare const INITIAL_APIS_TOKEN: InjectionToken<(Api | ApiClassType<Api>)[]>;
11
- declare class ApiFactoryService {
12
- private readonly apiManager;
13
- /** Map of loaded APIs */
14
- private loadedApis;
15
- constructor();
16
- /**
17
- * Determine if the given parameter is a API class
18
- * @param apiClass object to check
19
- */
20
- private isApiClass;
21
- /**
22
- * Retrieve a specific API with loaded configuration
23
- * @param apiClass class of the API to retrieve
24
- * @param refreshCache Ignore cached API instance and refresh it
25
- * @param customApiName override the `apiName` set in the `apiClass`
26
- * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
27
- * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
28
- */
29
- getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache?: boolean, customApiName?: string): T;
30
- /**
31
- * Instantiate a new instance of a specific API with loaded configuration, without using cache mechanism.
32
- * Warning: This function should be used only in specific cases when the cache should not be used. Otherwise, {@link getApi} is highly recommended.
33
- * @param apiClass class of the API to retrieve
34
- * @param customApiName override the `apiName` set in the `apiClass`
35
- * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
36
- * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
37
- */
38
- createApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, customApiName?: string): T;
39
- /**
40
- * Update the Map of loaded APIs.
41
- * Note: Can be used to override the a specific API
42
- * @param map Map of loaded APIs to update
43
- */
44
- updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>): void;
45
- /**
46
- * Clear the cache of loaded APIs
47
- * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache
48
- */
49
- clearCache(apis?: (ApiName | string)[]): void;
50
- /**
51
- * Retrieve the configuration for a specific API
52
- * @param api API for which retrieving the configuration
53
- */
54
- getConfigFor(api: string | ApiName): ApiClient;
55
- static ɵfac: i0.ɵɵFactoryDeclaration<ApiFactoryService, never>;
56
- static ɵprov: i0.ɵɵInjectableDeclaration<any>;
9
+ export declare const INITIAL_APIS_TOKEN: InjectionToken<(Api | ApiClassType<Api>)[]>;
10
+ export declare class ApiFactoryService {
11
+ private readonly apiManager;
12
+ /** Map of loaded APIs */
13
+ private loadedApis;
14
+ constructor();
15
+ /**
16
+ * Determine if the given parameter is a API class
17
+ * @param apiClass object to check
18
+ */
19
+ private isApiClass;
20
+ /**
21
+ * Retrieve a specific API with loaded configuration
22
+ * @param apiClass class of the API to retrieve
23
+ * @param refreshCache Ignore cached API instance and refresh it
24
+ * @param customApiName override the `apiName` set in the `apiClass`
25
+ * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
26
+ * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
27
+ */
28
+ getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache?: boolean, customApiName?: string): T;
29
+ /**
30
+ * Instantiate a new instance of a specific API with loaded configuration, without using cache mechanism.
31
+ * Warning: This function should be used only in specific cases when the cache should not be used. Otherwise, {@link getApi} is highly recommended.
32
+ * @param apiClass class of the API to retrieve
33
+ * @param customApiName override the `apiName` set in the `apiClass`
34
+ * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
35
+ * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
36
+ */
37
+ createApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, customApiName?: string): T;
38
+ /**
39
+ * Update the Map of loaded APIs.
40
+ * Note: Can be used to override the a specific API
41
+ * @param map Map of loaded APIs to update
42
+ */
43
+ updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>): void;
44
+ /**
45
+ * Clear the cache of loaded APIs
46
+ * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache
47
+ */
48
+ clearCache(apis?: (ApiName | string)[]): void;
49
+ /**
50
+ * Retrieve the configuration for a specific API
51
+ * @param api API for which retrieving the configuration
52
+ */
53
+ getConfigFor(api: string | ApiName): ApiClient;
54
+ static ɵfac: i0.ɵɵFactoryDeclaration<ApiFactoryService, never>;
55
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
57
56
  }
58
-
59
57
  /**
60
58
  * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API
61
59
  * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of
62
60
  * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration
63
61
  * and the requested one.
64
62
  */
65
- declare class ApiManager {
66
- private defaultConfiguration;
67
- private apiConfigurations;
68
- /**
69
- * Map of registered Api Client associated to specific API
70
- * Warning: This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead
71
- */
72
- get registeredApiConfigurations(): {
73
- readonly [key: string]: ApiClient;
74
- };
75
- /**
76
- * Create an API manager using a custom ApiClient
77
- * @param defaultConfiguration
78
- */
79
- constructor(defaultConfiguration: ApiClient, apiConfigurations?: {
80
- [key: string]: ApiClient;
81
- });
82
- /**
83
- * Retrieve a configuration for a specific API
84
- * @param api API to get the configuration for
85
- * @note When passing a string the configuration is expecting to exist else an error is thrown
86
- * @note when passing an Api instance that does not match a registered configuration, the default one will be returned
87
- */
88
- getConfiguration(api?: string | ApiName): ApiClient;
89
- /**
90
- * Set or override API configuration
91
- * @param apiClient API configuration to override to the given api
92
- * @param api API name to override, the default configuration will be used if not specified
93
- */
94
- setConfiguration(apiClient: ApiClient, api?: string | ApiName): void;
63
+ export declare class ApiManager {
64
+ private defaultConfiguration;
65
+ private apiConfigurations;
66
+ /**
67
+ * Map of registered Api Client associated to specific API
68
+ * Warning: This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead
69
+ */
70
+ get registeredApiConfigurations(): {
71
+ readonly [key: string]: ApiClient;
72
+ };
73
+ /**
74
+ * Create an API manager using a custom ApiClient
75
+ * @param defaultConfiguration
76
+ */
77
+ constructor(defaultConfiguration: ApiClient, apiConfigurations?: {
78
+ [key: string]: ApiClient;
79
+ });
80
+ /**
81
+ * Retrieve a configuration for a specific API
82
+ * @param api API to get the configuration for
83
+ * @note When passing a string the configuration is expecting to exist else an error is thrown
84
+ * @note when passing an Api instance that does not match a registered configuration, the default one will be returned
85
+ */
86
+ getConfiguration(api?: string | ApiName): ApiClient;
87
+ /**
88
+ * Set or override API configuration
89
+ * @param apiClient API configuration to override to the given api
90
+ * @param api API name to override, the default configuration will be used if not specified
91
+ */
92
+ setConfiguration(apiClient: ApiClient, api?: string | ApiName): void;
95
93
  }
96
-
97
94
  /**
98
95
  * Add a preconnect `<link>` element to the DOM
99
96
  * @param baseUrl the origin href
100
97
  * @param supportCrossOrigin add crossorigin attribute to the link element
101
98
  */
102
- declare function appendPreconnect(baseUrl: string, supportCrossOrigin?: boolean): void;
103
-
99
+ export declare function appendPreconnect(baseUrl: string, supportCrossOrigin?: boolean): void;
104
100
  /**
105
101
  * Provide a custom {@link ApiManager}
106
102
  * A factory can be provided via injection to the token {@link API_TOKEN}
107
103
  * @param apiManager
108
104
  */
109
- declare function provideApiManager(apiManager: ApiManager): i0.EnvironmentProviders;
110
-
105
+ export declare function provideApiManager(apiManager: ApiManager): import("@angular/core").EnvironmentProviders;
111
106
  /**
112
107
  * Token used by the core library to provide an Api manager to services. It can be provided in the app.
113
108
  */
114
- declare const API_TOKEN: InjectionToken<ApiManager>;
115
-
116
- export { API_TOKEN, ApiFactoryService, ApiManager, INITIAL_APIS_TOKEN, appendPreconnect, provideApiManager };
117
- export type { ApiClassType };
118
- //# sourceMappingURL=o3r-apis-manager.d.ts.map
109
+ export declare const API_TOKEN: InjectionToken<ApiManager>;
110
+ //# sourceMappingURL=o3r-apis-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o3r-apis-manager.d.ts","sources":["../../src/apis-manager/api-factory-service.ts","../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager-helpers.ts","../../src/apis-manager/api-manager-module.ts","../../src/apis-manager/api-manager-token.ts"],"mappings":";;;;AAiBA;KACY,YAAY,WAAW,GAAG,GAAG,GAAG,kBAAkB,SAAS,UAAU,OAAO;AAExF;;AAEG;AACH,cAAa,kBAAkB,EAAA,cAAA,EAAA,GAAA,GAAA,YAAA,CAAA,GAAA;AAE/B,cAGa,iBAAiB;AAC5B;;;;AAaA;;;AAGG;AACH;AAIA;;;;;;;AAOG;qBACqB,GAAG,0BAA0B,SAAS,UAAU,OAAO;AAY/E;;;;;;;AAOG;wBACwB,GAAG,0BAA0B,SAAS,UAAU,OAAO;AAIlF;;;;AAIG;AACI,2BAAuB,GAAG,GAAG,YAAY,MAAM,MAAM,UAAU,GAAG,GAAG,YAAY;AAmBxF;;;AAGG;uBACuB,OAAO;AAQjC;;;AAGG;AACI,+BAA2B,OAAO,GAAG,SAAS;yCA9F1C,iBAAiB;;AAiG7B;;ACxHD;;;;;AAKG;AACH,cAAa,UAAU;;;AAIrB;;;AAGG;AACH;;AAEC;AAED;;;AAGG;AACS,sCAAsB,SAAS;AAAuB,uBAAe,SAAS;AAAO;AAKjG;;;;;AAKG;oCACoC,OAAO,GAAG,SAAS;AAW1D;;;;AAIG;AACI,gCAA4B,SAAS,iBAAiB,OAAO;AAOrE;;AC7DD;;;;AAIG;AACH,iBAAgB,gBAAgB;;ACQhC;;;;AAIG;AACH,iBAAgB,iBAAiB,aAAa,UAAU,GAAAA,EAAA,CAAA,oBAAA;;ACXxD;;AAEG;AACH,cAAa,SAAS,EAAA,cAAA,CAAA,UAAA;;","names":["_angular_core"]}
1
+ {"version":3,"file":"o3r-apis-manager.d.ts","names":[],"sources":["../../src/apis-manager/api-factory-service.ts","../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager-helpers.ts","../../src/apis-manager/api-manager-module.ts","../../src/apis-manager/api-manager-token.ts"],"mappings":";;;;YAkBY,aAAa,UAAU,MAAM,aAAa,QAAQ,cAAc,KAAK;;;;qBAKpE,oBAAkB,gBAAA,MAAA,aAAA;qBAKlB;mBACM;;UAGT;;;;;;UAcA;;;;;;;;;EAYD,OAAO,UAAU,KAAK,gBAAgB,QAAQ,cAAc,KAAK,SAAS,wBAAsB,yBAAyB;;;;;;;;;EAoBzH,UAAU,UAAU,KAAK,gBAAgB,QAAQ,cAAc,KAAK,SAAS,yBAAyB;;;;;;EAStG,iBAAiB,MAAM,MAAM,kBAAkB,gBAAgB,MAAM;;;;;EAuBrE,WAAW,QAAQ;;;;;EAYnB,aAAa,cAAc,UAAU;SA9FjC,MAAA,GAAA,qBAAA;;;;;;;;;qBCjBA;UACH;UACA;;;;;MAMG;;;;;;;EAQC,YAAA,sBAAsB,WAAW;KAAsB,cAAc;;;;;;;;EAW1E,iBAAiB,eAAe,UAAU;;;;;;EAgB1C,iBAAiB,WAAW,WAAW,eAAe;;;;;;;wBCjD/C,iBAAiB,iBAAiB;;;;;;wBCalC,kBAAkB,YAAY,qCAAU;;;;qBCR3C,WAAS,eAAA"}