Skip to content

Cannot use class-based custom encoder #77

@MeirionHughes

Description

@MeirionHughes

I'm not sure if this would be a bug as its a new code-base afterall; but its certainly a deviation from the leveldown way, where this worked.

class CustomEncoding {
  encode (arg) { return JSON.stringify(arg) }
  decode (arg) { return JSON.parse(arg) };
  constructor () {
    this.format = 'utf8'
    this.type = 'custom'
  }
}

const customEncoding = new CustomEncoding()

const db = testCommon.factory({
  keyEncoding: customEncoding,
  valueEncoding: customEncoding
})

TypeError: The 'encode' property must be a function
at new Encoding (D:\Code\abstract-level\node_modules\level-transcoder\lib\encoding.js:28:13)
at new UTF8Format (D:\Code\abstract-level\node_modules\level-transcoder\lib\formats.js:75:5)
at from (D:\Code\abstract-level\node_modules\level-transcoder\index.js:111:25)
at Transcoder.encoding (D:\Code\abstract-level\node_modules\level-transcoder\index.js:66:20)
at new AbstractLevel (D:\Code\abstract-level\abstract-level.js:4:432)
at new MinimalLevel (D:\Code\abstract-level\test\util.js:123:5)
at Object.factory (D:\Code\abstract-level\test\self.js:1078:12)
at run (D:\Code\abstract-level\test\encoding-custom-class-test.js:72:27)
at Test. (D:\Code\abstract-level\test\encoding-custom-class-test.js:7:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpull request welcomeA pull request is welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions