Skip to content

Angular 19 support #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20'
node-version: '22'
- name: Install dependencies
# run: npm ci
run: npm install --force
Expand All @@ -37,7 +37,7 @@ jobs:

test-minimum:

name: Test with Angular@18.0.0 and minimum dependencies requirements
name: Test with Angular@19.0.0 and minimum dependencies requirements
runs-on: ubuntu-latest
timeout-minutes: 10

Expand All @@ -55,7 +55,7 @@ jobs:
- name: Build the lib (with the current version, as it is what is published on npm)
run: npm run build
- name: Downgrade dependencies to minimal required version
run: npm install typescript@5.4.2 [email protected] [email protected] zone.js@0.14.0 @angular/common@18.0.0 @angular/compiler@18.0.0 @angular/core@18.0.0 @angular/platform-browser@18.0.0 @angular/router@18.0.0 @angular/cli@18.0.0 @angular/compiler-cli@18.0.0 @angular-devkit/build-angular@18.0.0 --legacy-peer-deps
run: npm install typescript@5.6.3 [email protected] [email protected] zone.js@0.15.0 @angular/common@next @angular/compiler@next @angular/core@next @angular/platform-browser@next @angular/router@next @angular/cli@next @angular/compiler-cli@next @angular-devkit/build-angular@next --legacy-peer-deps
env:
CI: true
- name: Run unit tests
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ testem.log
# System Files
.DS_Store
Thumbs.db

# Playwright
test-results
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This library is fully documented and so you will find detailed [migration guides](https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/MIGRATION.md).

## 19.0.0 (2024-11-19)

### Breaking changes

- Angular 19 is required.
- RxJS >= 7.6 is required. RxJS 6 is not supported.

## 18.0.0 (2024-05-22)

### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Migration to version 16](./docs/MIGRATION_TO_V16.md)
- [Migration to version 17](./docs/MIGRATION_TO_V17.md)
- [Migration to version 18](./docs/MIGRATION_TO_V18.md)
- [Migration to version 19](./docs/MIGRATION_TO_V19.md)

[Full changelog available here.](./CHANGELOG.md)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This library has a simple API similar to native `localStorage`, but internally s
Install the package:

```bash
# For Angular LTS (Angular >= 16):
# For Angular LTS (Angular >= 17):
ng add @ngx-pwa/local-storage
```

Expand Down
8 changes: 4 additions & 4 deletions docs/MANUAL_INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ If it causes an error, please file an issue. In the meantime, you can proceed to
Install the right version according to your Angular one via [`npm`](http://npmjs.com):

```bash
# For Angular 19:
npm install @ngx-pwa/local-storage@^19.0.0

# For Angular 18:
npm install @ngx-pwa/local-storage@^18.0.0

# For Angular 17:
npm install @ngx-pwa/local-storage@^17.0.0

# For Angular 16:
npm install @ngx-pwa/local-storage@^16.0.0
```

> [!NOTE]
> Angular versions <= 15 are [officially outdated](https://angular.dev/reference/versions).
> Angular versions <= 16 are [officially outdated](https://angular.dev/reference/versions).

[Back to general documentation](../README.md)
3 changes: 2 additions & 1 deletion docs/MIGRATION_TO_NEW_PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ But **do not worry: the previous package is still here** and will be as long as
- v15 for Angular 15,
- v16 for Angular 16,
- v17 for Angular 17,
- v18 for Angular 18.
- v18 for Angular 18,
- v19 for Angular 19.

[Angular <= 15 are officially outdated](https://angular.dev/reference/versions#actively-supported-versions).

Expand Down
2 changes: 1 addition & 1 deletion docs/MIGRATION_TO_V18.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ ng update @ngx-pwa/local-storage

## More documentation

- [Full changelog for v17](../CHANGELOG.md)
- [Full changelog for v18](../CHANGELOG.md)
- [Other migration guides](../MIGRATION.md)
- [Main documentation](../README.md)
24 changes: 24 additions & 0 deletions docs/MIGRATION_TO_V19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Migration guide to version 19

## How to update

```bash
ng update @ngx-pwa/local-storage
```

> [!IMPORTANT]
> If your project is actually in a version < 18, please do the [other migrations](../MIGRATION.md) first in an incremental way. **The version 9 migration is especially important**, as a wrongly done migration could lead to the loss of all previously stored data.

## Breaking changes

- Angular 19 is required.
- RxJS >= 7.6 is required.

> [!IMPORTANT]
> RxJS 6 is *not* supported.

## More documentation

- [Full changelog for v19](../CHANGELOG.md)
- [Other migration guides](../MIGRATION.md)
- [Main documentation](../README.md)
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ module.exports = tseslint.config(
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/no-useless-empty-export": "error",
"@typescript-eslint/no-unsafe-type-assertion": "error",
// Stricter Angular ESLint rules
"@angular-eslint/prefer-standalone": "error",
"@angular-eslint/prefer-standalone": "off",
"@angular-eslint/consistent-component-styles": "error",
"@angular-eslint/sort-lifecycle-methods": "error",
"@angular-eslint/contextual-decorator": "error",
Expand Down
6 changes: 3 additions & 3 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"@angular/common": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/common": "^19.0.0",
"@angular/core": "^19.0.0",
"rxjs": "^7.6.0"
},
"schematics": "./schematics/collection.json",
"ng-update": {
"migrations": "./schematics/migration.json"
},
"sideEffects": false
}
}
6 changes: 3 additions & 3 deletions lib/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export default function (): Rule {
context.logger.warn(`Not able to detect @angular/core version. Be aware that Angular versions <= 14 are no longer supported.`);
}

if (angularMajorVersion !== undefined && (angularMajorVersion <= 15)) {
throw new SchematicsException("Angular versions <= 15 are no longer supported.");
if (angularMajorVersion !== undefined && (angularMajorVersion <= 16)) {
throw new SchematicsException("Angular versions <= 16 are no longer supported.");
}

const rxjsMajorVersion = getDependencyMajorVersion("rxjs", host);

if (rxjsMajorVersion === undefined) {
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is recommended for Angular 14 and required for Angular >= 15.`);
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is required, rxjs 6 is not supported.`);
}

if (rxjsMajorVersion !== undefined && (rxjsMajorVersion < 7)) {
Expand Down
1 change: 1 addition & 0 deletions lib/schematics/utility/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function getAllMainPaths(host: Tree): Promise<string[]> {
if (buildTarget.options?.["main"] === undefined) {
throw new SchematicsException(`angular.json config is broken, can't find 'architect.build.options.main' in one or more projects`);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
mainPaths.push(buildTarget.options["main"] as string);

} else if (!e2eTarget) {
Expand Down
1 change: 1 addition & 0 deletions lib/schematics/utility/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function updateAppModule(host: Tree, appModulePath: string, appModuleFile: strin
/* Third param is to disable transpilation, 4rd note sure I just followed other official schematics */
const appModuleSource = createSourceFile(appModulePath, appModuleFile, ScriptTarget.Latest, true);

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const appModuleChanges = addImportToModule(appModuleSource, appModulePath, storageModuleName, packageName) as InsertChange[];

/* The changes must be applied, otherwise the previous line does nothing */
Expand Down
2 changes: 2 additions & 0 deletions lib/src/lib/databases/indexeddb-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export class IndexedDBDatabase implements LocalDatabase {
} catch (error) {

/* The store could have been deleted from outside */
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return throwError(() => error as DOMException);

}
Expand Down Expand Up @@ -424,6 +425,7 @@ export class IndexedDBDatabase implements LocalDatabase {
/* Throw on error to be able to catch errors in RxJS way.
* Here `event.target` must be used, as `transactionOrRequest.error` will be `null`
* if we are on the request and the error is only triggered later by the transaction */
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
mergeMap((event) => throwError(() => (event.target as IDBTransaction | IDBRequest | null)?.error)),
);

Expand Down
3 changes: 3 additions & 0 deletions lib/src/lib/databases/localstorage-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class LocalStorageDatabase implements LocalDatabase {
return of(parsedData);

} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return throwError(() => error as SyntaxError);
}

Expand Down Expand Up @@ -84,13 +85,15 @@ export class LocalStorageDatabase implements LocalDatabase {
try {
serializedData = JSON.stringify(data);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return throwError(() => error as TypeError);
}

/* Can fail if storage quota is exceeded */
try {
localStorage.setItem(this.prefixKey(key), serializedData);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return throwError(() => error as DOMException);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/lib/storage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export class StorageModule {
return {
ngModule: StorageModule,
providers: [
// eslint-disable-next-line @typescript-eslint/no-deprecated
config.LSPrefix !== undefined ? { provide: LS_PREFIX, useValue: config.LSPrefix } : [],
// eslint-disable-next-line @typescript-eslint/no-deprecated
config.IDBDBName !== undefined ? { provide: IDB_DB_NAME, useValue: config.IDBDBName } : [],
// eslint-disable-next-line @typescript-eslint/no-deprecated
config.IDBStoreName !== undefined ? { provide: IDB_STORE_NAME, useValue: config.IDBStoreName } : [],
// eslint-disable-next-line @typescript-eslint/no-deprecated
config.IDBDBVersion !== undefined ? { provide: IDB_DB_VERSION, useValue: config.IDBDBVersion } : [],
(config.IDBNoWrap === false) ? { provide: IDB_NO_WRAP, useValue: config.IDBNoWrap } : [],
],
Expand Down
2 changes: 2 additions & 0 deletions lib/src/lib/storages/storage-map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class StorageMap {
}

/* Data have been checked, so it's OK to cast */
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return of(data as T | undefined);

}
Expand Down Expand Up @@ -422,6 +423,7 @@ export class StorageMap {

/* Only the public API of the Observable should be returned */
return (schema ?
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
notifier.asObservable() as Observable<T | undefined> :
notifier.asObservable()
);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/lib/testing/cleaning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function clearStorage(done: DoneFn, storageService: StorageMap): void {

} else if (storageService.backingEngine === "memory") {

// eslint-disable-next-line @typescript-eslint/dot-notation
// eslint-disable-next-line @typescript-eslint/dot-notation, @typescript-eslint/no-unsafe-type-assertion
(storageService["ɵinternalGetDatabase"]() as MemoryDatabase)["memoryStorage"].clear();

done();
Expand All @@ -95,6 +95,7 @@ export function closeAndDeleteDatabase(done: DoneFn, storageService: StorageMap)
/* Only `indexedDB` is concerned */
if (storageService.backingEngine === "indexedDB") {

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const indexedDBService = storageService["ɵinternalGetDatabase"]() as IndexedDBDatabase;

// eslint-disable-next-line @typescript-eslint/dot-notation
Expand Down
4 changes: 2 additions & 2 deletions lib/src/lib/validation/json-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(`JSONValidator`, () => {
additionalProperties: true,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-type-assertion
jsonValidator.validate({ test: "test" }, schema as any);

}).not.toThrow();
Expand Down Expand Up @@ -102,7 +102,7 @@ describe(`JSONValidator`, () => {

it("special case: readonly", () => {

const schema = { type: "string", enum: ["", "hello"] } satisfies JSONSchema;
const schema = { type: "string", enum: ["", "hello"] } satisfies JSONSchema;

const test = jsonValidator.validate("", schema);

Expand Down
4 changes: 3 additions & 1 deletion lib/src/lib/validation/json-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class JSONValidator {

// TODO: remove when TypeScript 4.1 is available
// (currently the narrowed type from `Array.isArray()` is lost on readonly arrays)
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
if (!this.validate(value, schema.items as JSONSchema)) {
return false;
}
Expand Down Expand Up @@ -285,7 +286,7 @@ export class JSONValidator {
/* Filter to keep only real properties (no internal JS stuff) and check if the data has the property too */
if (Object.hasOwn(schema.properties, property) && Object.hasOwn(data, property)) {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Ensured by the logic
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unsafe-type-assertion -- Ensured by the logic
if (!this.validate((data as Record<string, unknown>)[property], schema.properties[property]!)) {
return false;
}
Expand Down Expand Up @@ -327,6 +328,7 @@ export class JSONValidator {
}

/* Cast as the data can be of multiple types, and so TypeScript is lost */
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return ((schema.enum as unknown[]).includes(data));

}
Expand Down
2 changes: 1 addition & 1 deletion lib/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"sourceMap": true,
"target": "es6",
"target": "es2018",
"strict": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
Expand Down
Loading
Loading