diff --git a/frontend/app/package.json b/frontend/app/package.json index 49c6f445..0b7f01dc 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -56,7 +56,6 @@ "@angular/core": "13.3.11", "@angular/forms": "13.3.11", "@angular/platform-browser": "13.3.11", - "@angular/platform-browser-dynamic": "13.3.11", "@angular/router": "13.3.11", "@asymmetrik/ngx-leaflet": "13.0.2", "@asymmetrik/ngx-leaflet-markercluster": "13.0.1", @@ -80,7 +79,7 @@ "@hugotomazi/capacitor-navigation-bar": "2.0.0", "@ionic-native/core": "5.36.0", "@ionic/angular": "6.3.9", - "@ionic/storage-angular": "3.0.6", + "@ionic/storage": "4.0.0", "@ngx-translate/core": "14.0.0", "@ngx-translate/http-loader": "7.0.0", "@openid/appauth": "1.3.1", diff --git a/frontend/app/src/app/modules/storage/storage.module.ts b/frontend/app/src/app/modules/storage/storage.module.ts index f2be12c0..6ba7b322 100644 --- a/frontend/app/src/app/modules/storage/storage.module.ts +++ b/frontend/app/src/app/modules/storage/storage.module.ts @@ -13,7 +13,7 @@ * this program. If not, see . */ import {NgModule} from '@angular/core'; -import {IonicStorageModule} from '@ionic/storage-angular'; +import {IonicStorageModule} from '../../util/ionic-storage.module'; import {StorageProvider} from './storage.provider'; /** diff --git a/frontend/app/src/app/modules/storage/storage.provider.spec.ts b/frontend/app/src/app/modules/storage/storage.provider.spec.ts index 6e916203..f7d97abe 100644 --- a/frontend/app/src/app/modules/storage/storage.provider.spec.ts +++ b/frontend/app/src/app/modules/storage/storage.provider.spec.ts @@ -14,7 +14,7 @@ */ /* eslint-disable @typescript-eslint/no-explicit-any */ import {TestBed} from '@angular/core/testing'; -import {Storage} from '@ionic/storage-angular'; +import {Storage} from '@ionic/storage'; import {StorageModule} from './storage.module'; import {StorageProvider} from './storage.provider'; diff --git a/frontend/app/src/app/modules/storage/storage.provider.ts b/frontend/app/src/app/modules/storage/storage.provider.ts index 7b1bfe4a..0a1b6a97 100644 --- a/frontend/app/src/app/modules/storage/storage.provider.ts +++ b/frontend/app/src/app/modules/storage/storage.provider.ts @@ -13,7 +13,7 @@ * this program. If not, see . */ import {Injectable} from '@angular/core'; -import {Storage} from '@ionic/storage-angular'; +import {Storage} from '@ionic/storage'; /** * Provides interaction with the (ionic) storage on the device (in the browser) diff --git a/frontend/app/src/app/util/ionic-storage.module.ts b/frontend/app/src/app/util/ionic-storage.module.ts new file mode 100644 index 00000000..96a83f7e --- /dev/null +++ b/frontend/app/src/app/util/ionic-storage.module.ts @@ -0,0 +1,105 @@ +/* eslint-disable @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars,unicorn/no-null,jsdoc/require-jsdoc,@typescript-eslint/no-explicit-any,@typescript-eslint/ban-types */ +/** + * The MIT License (MIT) + * + * Copyright (c) 2021 Drifty, co. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +// This is based on the Ionic Storage 4.0.0 implementation until we can +// upgrade to Angular 14+ and use the new update. +// https://github.com/ionic-team/ionic-storage/blob/main/angular/src/index.ts +import {isPlatformServer} from '@angular/common'; +import type {ModuleWithProviders} from '@angular/core'; +import {InjectionToken, NgModule, PLATFORM_ID} from '@angular/core'; +import {Storage, StorageConfig} from '@ionic/storage'; + +const StorageConfigToken = new InjectionToken('STORAGE_CONFIG_TOKEN'); + +export {StorageConfigToken}; + +class NoopStorage extends Storage { + constructor() { + super(); + } + + async create() { + return this; + } + + async defineDriver() {} + + get driver(): string | null { + return 'noop'; + } + + // @ts-expect-error unused + async get(key: string) { + return null; + } + + // @ts-expect-error unused + async set(key: string, value: any) {} + + // @ts-expect-error unused + async remove(key: string): Promise {} + + async clear(): Promise {} + + async length(): Promise { + return 0; + } + + async keys() { + return []; + } + + // @ts-expect-error unused + async forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise {} + + // @ts-expect-error unused + setEncryptionKey(key: string) {} +} + +export function provideStorage(platformId: any, storageConfig: StorageConfig): Storage { + if (isPlatformServer(platformId)) { + // When running in a server context return the NoopStorage + return new NoopStorage(); + } + + return new Storage(storageConfig); +} + +@NgModule() +export class IonicStorageModule { + // @ts-expect-error unused + static forRoot(storageConfig: StorageConfig = null): ModuleWithProviders { + return { + ngModule: IonicStorageModule, + providers: [ + {provide: StorageConfigToken, useValue: storageConfig}, + { + provide: Storage, + useFactory: provideStorage, + deps: [PLATFORM_ID, StorageConfigToken], + }, + ], + }; + } +} diff --git a/frontend/app/src/main.ts b/frontend/app/src/main.ts index bac43391..c7b912ea 100644 --- a/frontend/app/src/main.ts +++ b/frontend/app/src/main.ts @@ -13,7 +13,7 @@ * this program. If not, see . */ import {enableProdMode} from '@angular/core'; -import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; +import {platformBrowser} from '@angular/platform-browser'; import {AppModule} from './app/app.module'; import {environment} from './environments/environment'; @@ -21,7 +21,7 @@ if (environment.production) { enableProdMode(); } -platformBrowserDynamic() +platformBrowser() .bootstrapModule(AppModule) // eslint-disable-next-line unicorn/prefer-top-level-await .catch(async error => console.error(error)); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0f2a0e47..74af63d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -735,9 +735,6 @@ importers: '@angular/platform-browser': specifier: 13.3.11 version: 13.3.11(@angular/animations@13.3.11)(@angular/common@13.3.11)(@angular/core@13.3.11) - '@angular/platform-browser-dynamic': - specifier: 13.3.11 - version: 13.3.11(@angular/common@13.3.11)(@angular/compiler@13.3.11)(@angular/core@13.3.11)(@angular/platform-browser@13.3.11) '@angular/router': specifier: 13.3.11 version: 13.3.11(@angular/common@13.3.11)(@angular/core@13.3.11)(@angular/platform-browser@13.3.11)(rxjs@7.8.0) @@ -807,9 +804,9 @@ importers: '@ionic/angular': specifier: 6.3.9 version: 6.3.9(@angular/core@13.3.11)(@angular/forms@13.3.11)(@angular/router@13.3.11)(rxjs@7.8.0)(zone.js@0.12.0) - '@ionic/storage-angular': - specifier: 3.0.6 - version: 3.0.6(@angular/core@13.3.11)(rxjs@7.8.0) + '@ionic/storage': + specifier: 4.0.0 + version: 4.0.0 '@ngx-translate/core': specifier: 14.0.0 version: 14.0.0(@angular/core@13.3.11)(rxjs@7.8.0) @@ -2481,6 +2478,7 @@ packages: engines: {node: ^12.20.0 || ^14.15.0 || >=16.10.0} dependencies: tslib: 2.4.1 + dev: true /@angular/core@13.3.11(rxjs@7.8.0)(zone.js@0.12.0): resolution: {integrity: sha512-9BmE2CxyV0g+AkBeuc8IwjSOiJ8Y+kptXnqD/J8EAFT3B0/fLGVnjFdZC6Sev9L0SNZb6qdzebpfIOLqbUjReQ==} @@ -2514,22 +2512,6 @@ packages: engines: {node: ^12.20.0 || ^14.15.0 || >=16.10.0} dev: true - /@angular/platform-browser-dynamic@13.3.11(@angular/common@13.3.11)(@angular/compiler@13.3.11)(@angular/core@13.3.11)(@angular/platform-browser@13.3.11): - resolution: {integrity: sha512-xM0VRC1Nw//SHO3gkghUHyjCaaQbk1UYMq4vIu3iKVq9KLqOSZgccv0NcOKHzXXN3S5RgX2auuyOUOCD6ny1Pg==} - engines: {node: ^12.20.0 || ^14.15.0 || >=16.10.0} - peerDependencies: - '@angular/common': 13.3.11 - '@angular/compiler': 13.3.11 - '@angular/core': 13.3.11 - '@angular/platform-browser': 13.3.11 - dependencies: - '@angular/common': 13.3.11(@angular/core@13.3.11)(rxjs@7.8.0) - '@angular/compiler': 13.3.11 - '@angular/core': 13.3.11(rxjs@7.8.0)(zone.js@0.12.0) - '@angular/platform-browser': 13.3.11(@angular/animations@13.3.11)(@angular/common@13.3.11)(@angular/core@13.3.11) - tslib: 2.4.1 - dev: false - /@angular/platform-browser@13.3.11(@angular/animations@13.3.11)(@angular/common@13.3.11)(@angular/core@13.3.11): resolution: {integrity: sha512-PG3chCErARb6wNzkOed2NsZmgvTmbumRx/6sMXqGkDKXYQm0JULnl4X42Rn+JCgJ9DLJi5/jrd1dbcBCrKk9Vg==} engines: {node: ^12.20.0 || ^14.15.0 || >=16.10.0} @@ -5826,24 +5808,19 @@ packages: tslib: 2.4.1 dev: false - /@ionic/storage-angular@3.0.6(@angular/core@13.3.11)(rxjs@7.8.0): - resolution: {integrity: sha512-ZXlIFWGU27aCxVFgZb0KFJFtWwnn6+HK6v0rMGzjN8f7oV2ewXaQ2dl1gTw/A8YoozTVPOFxwfFHCjhWLFR1Fw==} - peerDependencies: - '@angular/core': '*' - rxjs: '*' - dependencies: - '@angular/core': 13.3.11(rxjs@7.8.0)(zone.js@0.12.0) - '@ionic/storage': 3.0.6 - rxjs: 7.8.0 - tslib: 1.14.1 - dev: false - /@ionic/storage@3.0.6: resolution: {integrity: sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==} requiresBuild: true dependencies: localforage: 1.10.0 dev: false + optional: true + + /@ionic/storage@4.0.0: + resolution: {integrity: sha512-3N21P19Xk6cICLnSXZ3ilRqbSXAGSFeIF3HNqz+1kARcm0UFT/vwmZreaXtFyq437vvEWOfJ2enlj3JHLKS0FA==} + dependencies: + localforage: 1.10.0 + dev: false /@ionic/utils-array@2.1.5: resolution: {integrity: sha512-HD72a71IQVBmQckDwmA8RxNVMTbxnaLbgFOl+dO5tbvW9CkkSFCv41h6fUuNsSEVgngfkn0i98HDuZC8mk+lTA==}