Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ngx-pwa/local-storage

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngx-pwa/local-storage - npm Package Versions

1
13

12.0.0-0

Diff

cyrilletuzi
published 11.1.0 •

Changelog

Source

11.1.0 (2021-01-21)

No library change, just rebuilt with Angular 11.1 (still compatible with Angular 11.0).

cyrilletuzi
published 11.0.2 •

Changelog

Source

11.0.2 (2020-12-23)

No library change, just a fix in schematics to avoid ng add breaking with Angular 11.1.

cyrilletuzi
published 11.0.1 •

Changelog

Source

11.0.1 (2020-11-13)

No change, just a release to update link to new main branch.

cyrilletuzi
published 11.0.0 •

Changelog

Source

11.0.0 (2020-11-12)

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.

Feature

Supports and requires Angular 11.

Typings

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.

  1. 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'],
});
  1. 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.

  1. 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' });
  1. 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.

cyrilletuzi
published 11.0.0-3 •

cyrilletuzi
published 11.0.0-2 •

cyrilletuzi
published 11.0.0-1 •

cyrilletuzi
published 11.0.0-0 •

cyrilletuzi
published 10.1.0 •

Changelog

Source

10.1.0 (2020-09-03)

No code change, just rebuilt with Angular 10.1.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc