This library is fully documented and so you will find detailed migration guides.
- Angular 19 is required.
- RxJS >= 7.6 is required. RxJS 6 is not supported.
- Angular 18 is required.
- RxJS >= 7.6 is required. RxJS 6 is not supported.
- Made internal properties and methods of
StorageMap
natively private (#property
) instead of protected. ExtendingStorageMap
was undocumented so it is not considered a breaking change.
- Angular 17 is required.
- RxJS >= 7.4 is required. RxJS 6 is not supported.
- All things deprecated in v16 are removed in v17:
LocalStorage
service- specific
JSONSchemaXXX
interfaces JSONValidator
LocalDatabase
See the migration guide.
-
Specific
JSONSchemaXXX
interfaces are deprecated and will be removed in version 17. They were introduced in very old versions of this library as a workaround to some TypeScript issues which are gone for a long time now. Since version 8, you should have used the genericJSONSchema
interface. Note that if you are usingJSONSchemaArray
for a tuple schema, you need to switch toJSONSchema
now because of the fix in version 16.2.0. -
JSONValidator
is deprecated and will no longer be available in version 17. It is an internal utility class which is limited, could change at any time and is out of scope of this library. If you need a JSON validator, there are far better and dedicated libraries available like ajv. -
LocalDatabase
is deprecated and will no longer be available in version 17. It is an internal utility class, and overriding it is an undocumented behavior. If you are doing so, you are basically rewriting your own storage library, so using this one makes no sense, you can your service directly.
Little adapatation of the JSONSchema
type for compatibility with @sinclair/typebox
. You will find a new way to validate with this library in the validation guide.
LocalStorage
service is deprecated and will be removed in v17. The StorageMap
replacement exists since v8 now, so it is time to move forward. As usual, see the migration guide.
- Angular 16 is required.
- RxJS >= 7.4 is required. RxJS 6 is not supported.
- TypeScript 5.0 is recommended (TypeScript 4.9 should work but is not tested).
- Angular 15 is required.
- RxJS >= 7.4 is required. RxJS 6 is not supported.
Advanced configuration via StorageModule.forRoot()
is deprecated.
Use the new provideXXX()
methods as shown in the interoperability or collision guides, depending on your case.
This aligns with the new standalone APIs in Angular 15.
Version published by error, use v13 for Angular 13 and 14 and use v15 for Angular 15.
peerDependencies
restricted to Angular 13 and 14. Version 15 has been released for Angular 15.
Fix schematic for "ng add" for Angular 13.
Just a documentation update.
Supports and requires Angular 13.
For some reasons, Angular 13 supports both RxJS >= 6.5.3 or >= 7.4. It can be difficult for library authors to support multiple versions at the same time.
So while for now the library still allows RxJS 6 in its peerDependencies
as CI tests seem to be fine, be aware we do not guarantee RxJS 6 support. v13 of the library is built with RxJS 7, and you should upgrade your app to RxJS >= 7.4 too.
Angular 13 dropped Internet Explorer support, and so this library too.
Allow RxJS 7 in peerDependencies, to align with Angular 12.2.
Note that Angular and this library are still built with RxJS 6, so while the tests with RxJS 7 seem to pass, be cautious if you want to upgrade RxJS right now without waiting for Angular 13.
While it may still work, Angular 9 LTS has ended, so it is not officially supported anymore.
ng update @ngx-pwa/local-storage
A full migration guide to version 12 is available.
If you did not update to version 9 yet, be sure to follow the migration guide, as otherwise you could lose all previously stored data.
Supports and requires Angular 12.
Incorrect typings that were deprecated in v11 for .get()
and .watch()
are now removed:
this.storage.get<User>('user')
(add a JSON schema or remove the cast)this.storage.get('user', { type: 'object' })
(cast is required in addition to the JSON schema for non-primitive types)this.storage.get<number>('name', { type: 'string' })
(and all other primitive mismatches)
See the migration guide for v11 for detailed instructions.
Angular 2-8 internal engine was named ViewEngine. It was replaced automatically by a new engine called Ivy in Angular 9.
While Angular 9-11 still allowed to manually switch back to ViewEngine, Angular 12 has removed ViewEngine support. So now libraries are compiled directly for Ivy.
Angular 12 deprecates IE 11 support. Meaning it is still supported, but it will be removed in version 13.
No library change, just rebuilt with Angular 11.1 (still compatible with Angular 11.0).
No library change, just a fix in schematics to avoid ng add
breaking with Angular 11.1.
No change, just a release to update link to new main
branch.
A full migration guide to version 11 is available.
If you did not update to version 9 yet, be sure to follow it, as otherwise you could lose all previously stored data.
Supports and requires Angular 11.
TypeScript typings for .get()
and .watch()
has been modified to better match the library behavior.
For now, wrong usages are just marked as deprecated, so there is no breaking change and it will just be reported by linters. But they may be removed in future releases.
Be sure to read the validation guide for all the why and how of validation.
- Cast without a JSON schema
this.storage.get<User>('user');
was allowed but the result was still unknown
.
This is a very common misconception of client-side storage: you can store and get anything in storage, so many people think that casting as above is enough to get the right result type. It is not.
Why? Because you are getting data from client-side storage: so it may have been modified (just go to your browser developer tools and hack what you want).
A cast is just an information for compilation:
it basically says to TypeScript: "believe me, it will be a User
".
But that's not true: you are not sure you will get a User
.
This is why this library provides a runtime validation system, via a JSON schema as the second parameter:
this.storage.get<User>('user', {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
});
- Non-primitive JSON schema without a cast
this.storage.get('user', {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
});
was allowed but the result was still unknown
.
This is because, for now, the library is able to infer the return type based on the JSON schema
for primitives (string
, number
, integer
, boolean
and array
of these),
but not for more complex structures like objects.
So in this case, both the JSON schema and the cast are required:
this.storage.get<User>('user', {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
});
Be aware you are responsible the casted type (User
) describes the same structure as the JSON schema.
For the same reason, the library cannot check that.
Auto-inferring the type from all JSON schemas is in progress in #463.
- Mismatch between cast and primitive JSON schema
this.storage.get<number>('name', { type: 'string' });
was allowed but is of course an error. Now the match between the cast and simple JSON schemas (string
, number
, integer
, boolean
and array
of these) is checked.
Note that in this scenario, the cast is not needed at all, it will be automatically inferred by the lib, so just do:
this.storage.get('name', { type: 'string' });
- JSON schema with
as const
assertion
Given how JSON schema works, sometimes it is better to set them as const
:
this.storage.get('name', { type: 'string' } as const);
But before v11, it was not possible when using some JSON schema properties
(enum
, items
, required
). This is now fixed.
No code change, just rebuilt with Angular 10.1.
Correctly propagate the browser error when trying to store a value exceeding the browser size limit.
Supports and requires Angular 10.
No library change.
A full migration guide to version 10 is available.
If you did not update to version 9 yet, be sure to follow it, as otherwise you could lose all previously stored data.
No code change, just rebuilt with very last Angular 9.0.6 to prevent any ngcc
issues.
If you were already using version >= v9.0.0-beta.4 or v9.0.0-rc.x of this lib,
as a one time exception, please update with a classic npm install @ngx-pwa/local-storage@9
,
to avoid migration happening twice.
For future v9+ updates and if you are coming from v8.0.0 or version v9.0.0-beta.1-3,
please stick to ng update @ngx-pwa/local-storage
.
Following these instructions is very important, otherwise it would result in wrong config and loss of previously stored data.
A full migration guide to version 9 is available.
Be sure to follow it, as otherwise you could lose all previously stored data.
v9 requires Angular 9.
Doing ng update
should have managed backward compatibility.
But it is not easy to be sure schematics work in all cases,
so be sure to check the migration was done correctly by following the
migration guide to v9, otherwise you would lost previously stored data.
- New
.watch()
method onStorageMap
service (see documentation)
The following APIs were already deprecated in v8 and are now removed in v9. Please follow the migration guide to v8 for more details about how to update to new APIs.
- Removed providers for prefix management
- If you are concerned, be very careful with this migration, otherwise you could lost previously stored data
{ provide: LOCAL_STORAGE_PREFIX, useValue: 'myapp' }
andlocalStorageProviders()
(useStorageModule.forRoot({ LSPrefix: 'myapp_', IDBDBName: 'myapp_ngStorage' })
module import instead)LocalStorageProvidersConfig
interface (useless)
- Removed APIs in validation
JSONSchemaNumeric
interface (useJSONSchema
instead)LSGetItemOptions
interface (useless)
- Removed methods in
LocalStorage
service.size
(use.length
orStorageMap.size
instead).has()
(useStorageMap.has()
instead).keys()
(use iterativeStorageMap.keys()
instead).setItemSubscribe()
(use.setItem().subscribe()
instead).removeItemSubscribe()
(use.removeItem().subscribe()
instead).clearSubscribe()
(use.clear().subscribe()
instead)
No code change, just a release built with last Angular 8. Probably the last before Angular 9.
Also, documentation about sponsorship.
.size
in now working in Firefox private mode
The repo has moved from CircleCI to GitHub Actions. So it is free and a lot easier to test on several configurations, and now the library is tested for each pull request on:
- Chrome (Ubuntu & Windows)
- Firefox (Ubuntu & Windows)
- Safari (macOS)
- IE (Windows)
- in private mode of Chrome, Firefox and IE
Previously, the library was only automatically tested in Chrome and Firefox on Ubuntu, in normal mode (other configs were tested manually).
- Fix a regression introduced in 8.2.0, causing the library to fail instead of falling back to other storages in Firefox private mode
- Support for
ng add @ngx-pwa/local-storage
(for versions >= 8) - Support for
ng update @ngx-pwa/local-storage
(it does not mean you do not have work to do when updating, be sure to follow the migrations guides)
Before v8.2.0, this library was listening to indexedDb
request success
event.
Now it is listening to transaction complete
event.
Except for the special .keys()
method, all other methods in this library are doing just one request by transaction.
So request success
or transaction complete
are supposed to be equivalent. But there are rare cases like
#162
where the transaction could fail even if the request succeeded (meaning the data will not be written on disk).
So now it should catch more rare edgy cases, but for nearly everyone it should not change anything. But it is still a sensitive change as it concerns asynchrony (the order of operations are not exactly the same).
- Simpler and quicker way to store a value with
indexedDb
- Same fix as previous release, but makes it work for all browsers (fixes #118)
- When storage is fully disabled in browser (via the "Block all cookies" option),
just trying to check
indexedDB
orlocalStorage
variables causes a security exception, and all Angular code will fail. So the library is now catching the error, and fallbacks to in-memory storage in this case.
A full migration guide to version 8 is available.
v8 requires Angular 8.
See the general documentation.
- The schema used for validation can (and should) be passed directly as the second argument of
getItem()
- The returned type of
getItem()
is now inferred for basic types (string
,number
,boolean
) and arrays of basic types (string[]
,number[]
,boolean[]
) - Just use the new
JSONSchema
interface, IntelliSense will adjust itself based on thetype
option
See the new validation guide.
This library started as a little project and is now the first Angular library used for client-side storage. It was time to do a full review and refactoring, which results in:
- Better error management (see README)
- Better documentation
- Better overall code (= easier to contribute)
indexedDB
database and object store names default values are exported and can be changed (see the interoperability guide)- When trying to store
null
orundefined
,removeItem()
instead of just bypassing (meaning the old value was kept)
type
now required for array, object, const and enum validation schemasJSONSchemaNull
removed (useless,null
does not require any validation)JSONSchema
no longer accepts extra propertiesgetUnsafeItem()
is removed (was already deprecated in v7)
.has()
,.keys()
and.size
are deprecated inLocalStorage
. They will be removed in v9. They moved to the newStorageMap
service.JSONSchemaNumeric
deprecated (will be removed in v9)LSGetItemsOptions
deprecated (not necessary anymore, will be removed in v9)LOCAL_STORAGE_PREFIX
,LocalStorageProvidersConfig
andlocalStorageProviders()
deprecated (will be removed in v9). Moved toStorageModule.forRoot()
setItemSubscribe()
,removeItemSubscribe()
andclearSubscribe()
deprecated (will be removed in v9)
Should not concern you as it was internal stuff.
IndexedDBDatabase
andLocalStorageDatabase
not exported anymoreMockLocalDatabase
renamed and not exported anymore
- No code change, only changes in documentation to prepare changes in v8 by recommending to:
- explicit
type
in every JSON schema, especiallytype: 'array'
andtype: 'object'
which were optional but will be required in v8 - prefer the generic
JSONSchema
interface (v7 only) - avoid constants and enums validation (v7 only)
- avoid
null
in JSON schemas - avoid adding unsupported extra properties in JSON schemas
- use
localStorageProviders()
for configuration instead ofLOCAL_STORAGE_PREFIX
- explicit
has()
andkeys()
now work in IE too (fixes #69)
Do not use: it is deprecated in v8.
getItem()
andsetItem()
will now work with values stored from elsewhere (ie. via the native APIs or via another library likelocalForage
), given some limitations and adaptations (see the interoperability documentation) (fixes #65)
- Avoid throwing when storing
undefined
inlocalStorage
fallback
- Correct validation for required vs optional properties (fixes #63)
- Added a partial
Map
-like API:.keys()
method.has(key)
method.size
property
In v7.2, has()
and keys()
were not supported in Internet Explorer. Update to v7.4.
Do not use: it is deprecated in v8.
See documentation.
One of the features released in 7.1 caused an unforeseen critical regression. As it concerned only a minor feature introduced in 7.1, released only 4 days ago (so probably no one is using it yet), decision has been made to do an exceptional breaking change of this just released minor feature, before it was too late.
keys()
is now returningObservable<string[]>
(returning directly an array with all keys) instead ofObservable<string>
(it was iterating over the keys).
Documentation has been updated accordingly.
These releases have been deprecated due to a critical regression.
- Support of Angular 7
- New interfaces for better validation of your JSON schemas:
JSONSchemaConst
JSONSchemaEnum
JSONSchemaString
JSONSchemaNumeric
(deprecated in v8)JSONSchemaBoolean
JSONSchemaArray
JSONSchemaObject
See the full validation guide for more info.
A migration guide to version 7 is available.
Be sure to read it before upgrading, as v7 introduces an important major change.
Validation of data is now required when using getItem()
:
-
getItem<string>('test', { schema: { type: 'string' } })
: no change -
getItem<string>('test')
: now returns the new TypeScript 3unknown
type instead ofany
, requiring from you to check the data manually
Migration is not urgent: while you manage this breaking change, you can just upgrade to v6.2.0, which is compatible with Angular 7.
- Allow Angular 7 in
peerDependencies
- Fixed
IndexedDB setter issue : Key already exists in the object store
when there are concurrentsetItem
calls (note this situation should not happen, see #47 for details)
-
New JSON Schema validation options supported (see #18 for the full list).
-
localStorageProviders({ prefix: 'myapp' })
to avoid collision in multiple apps on same subdomain
A migration guide is available to ease the update. It is just a couple of refactorings. (If you want to contribute, it could be automated.)
- Angular 6
- TypeScript 2.7, 2.8 & 2.9
AsyncLocalStorage
removed, renamed toLocalStorage
.AsyncLocalDatabase
removed, renamed toLocalDatabase
.ALSGetItemOptions
removed, renamed toLSGetItemOptions
.
LocalStorageModule
no longer needed and so removed. You must delete the import in your AppModule
.
- To be consistent with the strict validation, and to prepare future enhancement of JSON Schema typings,
it is no longer possible to specify an array for
type
. JSONSchemaType
has been removed. It should very unlikely concern you, it was an internal type.
- Distribution files and directories have been changed to match official Angular Package Format v6. It affects your code only if you were manually loading UMD bundles, otherwise building tools like Angular CLI / webpack know where to find the files.
- Tree-shakable providers.
- Full support of official Angular Package Format v6
- Distribution files and directories have been changed to match official Angular Package Format v6. It affects your code only if you were manually loading UMD bundles, otherwise building tools like Angular CLI / webpack know where to find the files.
localStorageProviders({ prefix: 'myapp' })
feature was adding the prefix twice.
- If you were using previous v6 RC (v5 is not concerned) and relying on the
prefix
option above, your app will restart from empty data. If you want to keep your previous data, double the prefix, for example:localStorageProviders({ prefix: 'myapp_myapp' })
localStorageProviders({ prefix: 'myapp' })
to avoid collision in multiple apps on same subdomain
- Correct too wide type inference for
getItem()
AsyncLocalStorageModule
deprecated (but still working). Renamed toLocalStorageModule
AsyncLocalStorage
deprecated (but still working). Renamed toLocalStorage
AsyncLocalDatabase
deprecated (but still working). Renamed toLocalDatabase
ALSGetItemOptions
deprecated (but still working). Renamed toLSGetItemOptions
See the migration guides.
This library has been renamed from angular-async-local-storage
to @ngx-pwa/local-storage
. See the migration guide.
This library major version is now aligned to the major version of Angular. Meaning this v5 is for Angular 5. Same as v3.1.4.
This library has been renamed from angular-async-local-storage
to @ngx-pwa/local-storage
. See the migration guide.
This library major version is now aligned to the major version of Angular. Meaning this v4 is for Angular 4. Same as v2.
We follow Angular LTS support, meaning we support Angular 4 until October 2018. So we backported some bug fixes:
- Detect if storages are null or undefined (partially fixes (partially fixes #26)
- Correctly complete observables (fixes #25 & #5)
- Some IndexedDB connection errors were not caught
Previous versions were only released under angular-async-local-storage
.
- Detect if storages are null (partially fixes #26)
- Detect if storages are undefined (partially fixes #26)
- Some IndexedDB connection errors were not caught
- Browser info has been added for IndexedDB errors
- JSON Schema validation
- Extensibility : add your own storage
See README for instructions.
- Angular 5 is now supported and required
- RxJS >= 5.5.2 is now supported and required : lettable operators
- RxJS operators can now be used again on returned observables (fixes #10)
- Implements Angular Package Format
- Compatible with Universal builds from Angular CLI >= 1.3 (fixes #9)
- Compatible with ES2015+ target builds (= smaller builds)
- Better type checking with generics :
this.storage.getItem<string>('color')
- Angular 4 is now required
- TypeScript >= 2.3 is now required
- Use Angular 4 platform tests to detect storages support instead of try/catch
- Unit tests
- Up to date with Angular 4.0
- Rename package to angular-async-local-storage
Previous versions were only released under angular2-async-local-storage
.
- Up to date with Angular 2.4 and RxJS final
- Recompiled with Angular 2.3.1, following Angular changelog advice
- Up to date with Angular 2.3
- Update peerDependencies :
- reflect-metadata 0.1.8
- rxjs 5.0.0-rc.4
- zone.js 0.7.2
- allow falsy values in mock database
- null instead of undefined for unexisting item in mock database
- Initial release : asynchronous client-side storage module for Angular
- Up to date with Angular 2.1
- Compatible with AoT pre-compiling
- Compatible with Universal server-side rendering
- IE9 support via native localStorage (public API still asynchronous but synchronous internally)