Skip to content

Conversation

@cyrilletuzi
Copy link
Owner

@cyrilletuzi cyrilletuzi commented Jan 17, 2019

  • Added predefined constants for basic JSON schemas to simplify validation:
    • SCHEMA_BOOLEAN (shortcut for: { type: 'boolean' })
    • SCHEMA_INTEGER (shortcut for: { type: 'integer' })
    • SCHEMA_NUMBER (shortcut for: { type: 'number' })
    • SCHEMA_STRING (shortcut for: { type: 'string' })
    • SCHEMA_ARRAY_OF_BOOLEANS (shortcut for: { items: { type: 'boolean' } })
    • SCHEMA_ARRAY_OF_INTEGER (shortcut for: { items: { type: 'integer' } })
    • SCHEMA_ARRAY_OF_NUMBER (shortcut for: { items: { type: 'number' } })
    • SCHEMA_ARRAY_OF_STRINGS (shortcut for: { items: { type: 'string' } })

This is especially useful for advanced types (arrays, objects, nested types),
to avoid TypeScript limitations.

  • For the same types as above, the result type is now automatically infered,
    meaning you don't need to cast anymore!

Before v7.5:

this.localStorage.getItem('test', { schema: { type: 'string' } })
.subscribe((result) => {
  result; // type: any :(
});

this.localStorage.getItem<string>('test', { schema: { type: 'string' } })
.subscribe((result) => {
  result; // type: string :)
});

From v7.5:

import { SCHEMA_STRING } from '@ngx-pwa/local-storage';

this.localStorage.getItem('test', { schema: SCHEMA_STRING })
.subscribe((result) => {
  result; // type: string :D
});
  • Added better interfaces for some JSON schemas:
    • JSONSchemaArrayOf<T>
    • JSONSchemaConstOf<T>
    • JSONSchemaEnumOf<T>

Why?

See documentation included in the PR.

@cyrilletuzi cyrilletuzi added this to the v7.5 milestone Jan 18, 2019
@cyrilletuzi cyrilletuzi changed the title feat: predefined constants for basic JSON schemas feat: simpler validation Jan 20, 2019
@cyrilletuzi
Copy link
Owner Author

Will wait a little for #72 to anticipate as much as possible and minimize possible breaking changes in v8.

@cyrilletuzi
Copy link
Owner Author

Closing in favor of #74

@cyrilletuzi cyrilletuzi deleted the validationconstants branch February 4, 2019 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants