UNPKG

@jsonjoy.com/json-type

Version:

High-performance JSON Pointer implementation

63 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjValue = void 0; const ModuleType_1 = require("../type/classes/ModuleType"); const Value_1 = require("./Value"); const FnValue_1 = require("./FnValue"); class ObjValue extends Value_1.Value { get system() { return this.type.getSystem(); } get t() { return this.system.t; } keys() { const type = this.type; return type.keys.map((field) => field.key); } get(key) { const field = this.type.getField(key); if (!field) throw new Error('NO_FIELD'); const data = this.data[key]; return new Value_1.Value(data, field.val); } fn(key) { const val = this.get(key); return new FnValue_1.FnValue(val.data, val.type); } field(field, data) { field = typeof field === 'function' ? field(this.type.getSystem().t) : field; this.data[field.key] = data; const type = this.type; const system = type.system; if (!system) throw new Error('NO_SYSTEM'); type.keys.push(field); return this; } add(key, type, data) { const system = this.type.getSystem(); const t = system.t; type = typeof type === 'function' ? type(t) : type; return this.field(t.Key(key, type), data); } set(key, value) { return this.add(key, value.type, value.data); } merge(obj) { Object.assign(this.data, obj.data); const type = this.type; const system = type.system; if (!system) throw new Error('NO_SYSTEM'); type.keys.push(...type.keys); return this; } name() { return 'ObjValue'; } } exports.ObjValue = ObjValue; ObjValue.new = (system = new ModuleType_1.ModuleType()) => new ObjValue({}, system.t.obj); //# sourceMappingURL=ObjValue.js.map