Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
make parse methods immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneJeon committed Apr 3, 2021
1 parent af90222 commit b248ee5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const HashId = require('hashids/cjs')
const memoize = require('lodash/memoize')
const get = require('lodash/get')
const set = require('lodash/set')
const deepCopy = require('lodash/cloneDeep')

const memoizeHashId = memoize(
(salt, minLength, alphabet, seps) =>
Expand Down Expand Up @@ -51,8 +52,8 @@ module.exports = Model => {
return []
}

$formatJson(obj) {
obj = super.$formatJson(obj)
$formatJson(originalObj) {
const obj = deepCopy(super.$formatJson(originalObj))

// inject the hashed PK into the resulting JSON - a reminder
// that hashId/hashid fields are virtual and do not get written to JSON.
Expand All @@ -69,8 +70,8 @@ module.exports = Model => {
return obj
}

$parseJson(json, opt) {
json = super.$parseJson(json, opt)
$parseJson(originalJSON, opt) {
const json = deepCopy(super.$parseJson(originalJSON, opt))

// decode any `hashedFields`, which are guaranteed to be single column
this.constructor.hashedFields.forEach(field => {
Expand Down

0 comments on commit b248ee5

Please sign in to comment.