Skip to content
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

Refactor API Surface #1

Closed
blakeembrey opened this issue May 22, 2016 · 2 comments
Closed

Refactor API Surface #1

blakeembrey opened this issue May 22, 2016 · 2 comments

Comments

@blakeembrey
Copy link
Member

Three types of methods:

  • formatter (for serialising data)
  • parser (for deserialising data)
  • validate (for validating native representations)

Serialising and deserialising can be completely synchronous, they would be based on structural type checking (none of the validation logic needs to occur). The tricky part here is picking which branch to use during serialisation/deserialisation (E.g. for union types). Maybe the structural checks can throw errors and pick the first branch that doesn't error? Also, sort union types by assignability (E.g. "a is a subset of b, but b is not a subset of a").

It'd be nice to remove the classes, but I think they'll just get more prominent as I add complexity (E.g. sort union types, proper intersection types). Could make it so the classes don't hold anything and move logic outside. E.g.

import { types, compile } from 'jaywalk'

const schema = {
  type: 'string',
  properties: {
    username: {
      type: 'string'
    }
  }
}

const validate = compile(types, schema)

Vs

import { Types, compile } from 'jaywalk'

const schema = new Types.Object({
  properties: {
    username: new Types.String()
  }
})

const validate = compile(schema)
@blakeembrey blakeembrey changed the title Factor API Surface Refactor API Surface May 22, 2016
@blakeembrey
Copy link
Member Author

blakeembrey commented May 24, 2016

Classes need to extend and implement:

_isType (value: any): boolean // Synchronous type checking.
_compile (): Function // Compile an asynchronous function from the current type.
_intersect (type: Any): Any // Intersect one type with another, returning the intersected type.
_visit (fn: Function): void // Walk a type according to the schema.

@blakeembrey
Copy link
Member Author

Closing in favour of granular issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant