ExploreConsulting / netsuite-fasttrack-toolkit-ss2

NFT for SuiteScript 2.X
75 stars 20 forks source link

Validation Application Block Suggestion #6

Open rhackeyexplore opened 6 years ago

rhackeyexplore commented 6 years ago

Suggestion to adding maximum field length handling. Maybe truncating the string automatically based on field type. Also, custom record name field = 30 characters.

ShawnTalbert commented 6 years ago

possibly apply something like io-ts or joi

ShawnTalbert commented 5 years ago

Since NFT surfaces both raw records and search results as plain JS objects, I think we should leverage a third party validation library that already works with plain JS

ShawnTalbert commented 2 years ago

ajv is another solid contender.

steveklett commented 2 years ago

I've had good success with ajv for JSON payload validation of RESTlet APIs. If used for NFT-DA validation, would the schema of the DA objects need to be modelled as JSON for adv to consume?

ShawnTalbert commented 2 years ago

We probably need to decide where validation comes up most often. Do we need it most at endpoint boundaries (e.g. validate JSON input/output for a RESTlet) or more useful on plain NSDAL objects?

Rachel's mention of custom record name - well that's not really something we can enforce in a meaningful way in NFT code because the custom record must already exist in NetSuite before we create an NSDAL class to represent it.

In my experience, exceeding things like max string length for a field usually comes up due to data integration - the source of that overflow text is an external system. What should happen in such an overflow case varies depending on the needs of the customer. Should it throw an error? Should it just truncate? Should it instead do some other mapping of input string to reduce the length so it fits in NS?

If we accept that the handling rules vary and it usually comes up in JSON data integration, then something like ajv makes sense in that it supports a schema definition external to the code. This decouples the rules for a given application from any underlying data types (e.g. DataAccess/XXX class).

The 'Validation Application Block' referred in the title was a .NET framework validation library that allowed you to apply static decorators on your classes to control validation. That's nice if the rules never change.