Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_forEachObject_: d('c', function (cb) {
getOwnPropertyNames(this).forEach(function (name) {
var value;
if (!startsWith.call(name, '__')) return;
if (name === '__value') return;
value = this[name];
if (!value._id_) return;
if (!value.hasOwnProperty('_value')) return;
cb(value, value._id_, this);
}, this);
}),
rel: d('c', function (data) {
if (data == null) return this;
return new RelTransport(this, data);
}),
required: d.gs('c', function () {
return new RelTransport(this, { required: true });
}),
coerce: d('c', function (value) { return value; }),
_serialize_: d('c', serialize)
});
defineProperty(Plain, '$$proto', d('c', function (nu) {
var old = getPrototypeOf(this);
if (!nu) {
nu = Plain;
delete Base[this._id_];
}
if (old === nu) return;
if (!nu.prototype) {
// Should never happen, but we better take it easy
var value;
if (startsWith.call(name, '__')) {
if (name === '__value') return;
value = this[name];
if (!value._id_) return;
if (!value.hasOwnProperty('_value')) return;
} else if (isDigit(name[0]) && this.propertyIsEnumerable(name)) {
value = this[name];
if (!value || !value._id_ || !endsWith.call(value._id_, '"')) return;
} else {
return;
}
cb(value, value._id_, this);
}, this);
}),
_objectValue_: d.gs(function () {
var value = this.value, type;
if (value == null) return value;
type = typeof value;
if ((type === 'object') || (type === 'function')) return value;
value = Object(value);
value.__proto__ = this.ns.prototype;
return value;
}),
value: d.gs(function () {
var value = this.__value;
if ((typeof value === 'function') && !value._id_) {
if (value.length) return value;
value = value.call(this.obj);
if (this.multiple) return new RelSetReadOnly(this.ns, value);
return (value == null) ? null : this.ns.normalize(value);
}
ns = value.ns;
ext = value.ext;
value = value.value;
} else if (isNamespace(value)) {
ns = value;
value = null;
}
prop = new Property(obj, value, ns, name);
if (ext) extend(prop, ext);
propName = '_$' + name;
defineProperty(obj, propName, d('', prop));
defineProperty(obj, '_' + name, d.gs('', function () {
return this.hasOwnProperty(propName) ? this[propName] : undefined;
}));
defineProperty(obj, name, d.gs(attr, get = function () {
var prop = this[propName], value = prop.value, ns = prop.ns;
if ((value == null) || !ns || (ns._$async.value && !prop.resolved)) {
return value;
}
return ns._$normalize.value(value);
}, set = function (value) {
var ns, ext;
if (value && value.__propertyExtension) {
ns = value.ns;
ext = value.ext;
value = value.value;
} else if (isNamespace(value)) {
ns = value;
value = null;
}
if (this.hasOwnProperty(propName)) {
} else if (!this.hasOwnProperty('_value')) {
defineProperty(this, '_value', d('w', value));
return;
}
this._value = value;
}),
_remove: d(function (value) {
if (this.hasOwnProperty('count')) {
delete this[getKey(value)];
--this.count;
if (this._value === value) this._value = this._last;
return;
}
this._value = null;
}),
value: d.gs(function () {
if (!this._rel.unique) {
if (!this.hasOwnProperty('count')) this._initSet();
return this;
}
return this._value;
}),
forEach: d(function (cb/*, thisArg*/) {
var thisArg = arguments[1], index = -1;
this._assertSet();
callable(cb);
forEach(this, function (value) {
call.call(cb, thisArg, value, null, this, ++index);
}, this);
}),
values: d.gs(function () {
this._assertSet();
}, set = function (value) {
var ns, ext;
if (value && value.__propertyExtension) {
ns = value.ns;
ext = value.ext;
value = value.value;
} else if (isNamespace(value)) {
ns = value;
value = null;
}
if (this.hasOwnProperty(propName)) {
this[propName].set(value, ns);
} else {
defineProperty(this, propName,
d('', this[propName].create(this, value, ns)));
defineProperty(this, name, d.gs(attr, get, set));
}
if (ext) extend(this[propName], ext);
return this[propName].value;
}));
return prop.value;
return (this[name] = value);
}
return define(this, name, value, (attr == null) ? 'ce' : attr);
}),
rel: d('c', function (data) {
var value;
validValue(data);
if (data.default) {
data = copy(data);
value = data.default;
delete data.default;
}
return new PropertyExt(value, this, data);
}),
required: d.gs('c', function () {
return new PropertyExt(null, this, requiredOpts);
}),
transaction: d('c', function (fn) {
if (base.lock) return fn();
base.lock = now();
try {
return fn();
} finally {
base.lock = null;
}
}),
serialize: d('c', function (value) {
var type;
if (value === null) return null;
type = typeof value;
if (type === 'object') {
keys(current).forEach(function (id) {
var previous, his = history[id];
if (his[0] !== current) {
his.splice(his.indexOf(current), 1);
return;
}
his.shift();
previous = his[0] && his[0][id];
if (contains.call(id, ':')) objects[id].$$setValue(previous);
else objects[id].$$proto(previous);
delete current[id];
});
clear.call(current._order);
}),
history: d(history),
sourceId: d.gs(function () { return Signal.prototype._sourceId; },
function (value) { Signal.prototype._sourceId = String(value); })
});
objects = require('./objects');
getObject = objects._get;
} else {
if (!this.hasOwnProperty('_value') &&
!this.hasOwnProperty('_descriptor_')) {
defineProperty(this.obj, this.name, this._descriptor_);
getPrototypeOf(this).off('update', this._refresh_);
}
this._value = value;
}
this._refresh_();
}),
$setValue: d(function (value) {
value = this._normalize(value);
this.$$setValue(value);
signal(this, value);
}),
lastModified: d.gs(function () {
var data = history[this._id_];
return (data && data[0] && data[0]._stamp) || 0;
}),
validate: d(function (value) { return null; })
}));
module.exports = function (obj, name, value) {
var get, set, rel, relName, attr;
relName = '__' + name;
attr = ((typeof obj === 'function') || !obj._id_ || obj._descriptor_) ? '' :
'e';
rel = new RelBasic(obj, name, d.gs('c' + attr, get = function () {
return this[relName]._value;
}, set = function (value) {
if (!this.hasOwnProperty(relName)) fillChain(this, relName);
attr = ((typeof obj === 'function') || !obj._id_ || obj._descriptor_) ? '' :
'e';
rel = new RelBasic(obj, name, d.gs('c' + attr, get = function () {
return this[relName]._value;
}, set = function (value) {
if (!this.hasOwnProperty(relName)) fillChain(this, relName);
this[relName].value = value;
}));
rel._value = rel.__value = value;
defineProperty(obj, relName, d('', rel));
defineProperty(obj, '_' + name, d.gs('', function () {
if (!this.hasOwnProperty(relName)) fillChain(this, relName);
return this[relName];
}));
defineProperty(obj, name, d.gs(attr, get, set));
};
exports.set = function (rel, name) {
var proto = rel.ns.prototype
, revRel = proto['_' + name];
if (!revRel) {
define(proto, name);
revRel = proto['_' + name];
}
defineProperty(proto, name, d.gs('c', function () {
var id = this._id_, data = reverse[id], rev;
if (!data) data = reverse[id] = {};
rev = data[rel._id_];
if (!rev) rev = data[rel._id_] = new RelReverse(rel);
return rev.value;
}));
revRel._foreign_ = rel._id_;
};
exports.unset = function (rel, name) {