UNPKG

@aurbi/ts-binding

Version:

bidirectionally bind serialized & simplified objects to full-featured runtime objects. kinda like a subset of zod, but it goes both ways.

36 lines (35 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransformationError = void 0; exports.stack = stack; exports.stackwrap = stackwrap; class TransformationError { constructor(message, customStack = stack(), offender) { this.message = message; this.offender = offender; this.location = customStack.stack.map(e => e.toString()).join(' -> ') + "(!!)"; } toString() { return "hi"; } } exports.TransformationError = TransformationError; function stack(existing = []) { return { with: (message) => stack(existing.concat(message)), stack: existing }; } /** convenience wrapper to push a stack message on simple alias types */ function stackwrap(upstream, thisMessage) { return { transform: (object, s = stack()) => { s = s.with(thisMessage); return upstream.transform(object, s); }, restore: (json, s = stack()) => { s = s.with(thisMessage); return upstream.restore(json, s); } }; }