diff --git a/README.md b/README.md index 70fdb973..3ddd9f33 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ msg.transaction( () => { // Prepare to make the sequence of changes on msg }); // Got single 'change!!!' message in the console. ``` -## [Documentation](https://volicon.github.io/Type-R/) +## [Documentation](https://volijs.github.io/Type-R/) ## Installation and requirements diff --git a/dist/index.js b/dist/index.js index 422c116b..adf9cd62 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Nested={})}(this,function(s){"use strict";function a(t,e){for(var n in e)e.hasOwnProperty(n)&&!t.hasOwnProperty(n)&&(t[n]=e[n]);if(2( dest : T, ...sources : Object[] ) : T\nexport function defaults< T >( dest : T, source : Object ) : T {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) && !dest.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n if( arguments.length > 2 ){\n for( let i = 2; i < arguments.length; i++ ){\n const other = arguments[ i ];\n other && defaults( dest, other );\n }\n }\n\n return dest;\n}\n\n/** Check if value is raw JSON */\nexport function isValidJSON( value : any ) : boolean {\n if( value === null ){\n return true;\n }\n\n switch( typeof value ){\n case 'number' :\n case 'string' :\n case 'boolean' :\n return true;\n\n case 'object':\n var proto = Object.getPrototypeOf( value );\n\n if( proto === Object.prototype || proto === Array.prototype ){\n return every( value, isValidJSON );\n }\n }\n\n return false;\n}\n\n/** Get the base class constructor function.\n * @param Class Subclass constructor function.\n * @returns Base class constructor function.\n */\nexport function getBaseClass( Class : Function ) {\n return Object.getPrototypeOf( Class.prototype ).constructor\n}\n\nexport function assignToClassProto( Class, definition : T, ...names : K[] ) : void {\n for( let name of names ){\n const value = definition[ name ];\n value === void 0 || ( Class.prototype[ name ] = value );\n }\n}\n\n/** Checks whenever given object is an empty hash `{}` */\nexport function isEmpty( obj : {} ) : boolean {\n if( obj ){\n for( let key in obj ){\n if( obj.hasOwnProperty( key ) ){\n return false;\n }\n }\n }\n\n return true;\n}\n\nexport type Iteratee = ( value : any, key? : string | number ) => any;\n\n/** @hidden */\nfunction someArray( arr : any[], fun : Iteratee ) : any {\n let result;\n\n for( let i = 0; i < arr.length; i++ ){\n if( result = fun( arr[ i ], i ) ){\n return result;\n }\n }\n}\n\n/** @hidden */\nfunction someObject( obj : {}, fun : Iteratee ) : any {\n let result;\n\n for( let key in obj ){\n if( obj.hasOwnProperty( key ) ){\n if( result = fun( obj[ key ], key ) ){\n return result;\n }\n }\n }\n}\n\n/** Similar to underscore `_.some` */\nexport function some( obj, fun : Iteratee ) : any {\n if( Object.getPrototypeOf( obj ) === ArrayProto ){\n return someArray( obj, fun );\n }\n else{\n return someObject( obj, fun );\n }\n}\n\n/** Similar to underscore `_.every` */\nexport function every( obj : { }, predicate : Iteratee ) : boolean {\n return !some( obj, x => !predicate( x ) );\n}\n\n/** Similar to `getOwnPropertyDescriptor`, but traverse the whole prototype chain. */\nexport function getPropertyDescriptor( obj : {}, prop : string ) : PropertyDescriptor {\n let desc : PropertyDescriptor;\n\n for( let proto = obj; !desc && proto; proto = Object.getPrototypeOf( proto ) ) {\n desc = Object.getOwnPropertyDescriptor( proto, prop );\n }\n\n return desc;\n}\n\n/** Similar to underscore `_.omit` */\nexport function omit( source : {}, ...rest : string[] ) : {}\nexport function omit( source ) : {} {\n const dest = {}, discard = {};\n\n for( let i = 1; i < arguments.length; i ++ ){\n discard[ arguments[ i ] ] = true;\n }\n\n for( var name in source ) {\n if( !discard.hasOwnProperty( name ) && source.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n return dest;\n}\n\n/** map `source` object properties with a given function, and assign the result to the `dest` object.\n * When `fun` returns `undefined`, skip this value. \n */\nexport function transform< A, B >( dest : { [ key : string ] : A }, source : { [ key : string ] : B }, fun : ( value : B, key : string ) => A | void ) : { [ key : string ] : A } {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) ) {\n var value = fun( source[ name ], name );\n value === void 0 || ( dest[ name ] = < A >value );\n }\n }\n\n return dest;\n}\n\n/** @hidden */\nexport function fastAssign< A >( dest : A, source : {} ) : A {\n for( var name in source ) {\n dest[ name ] = source[ name ];\n }\n\n return dest;\n}\n\n/** @hidden */\nexport function fastDefaults< A >( dest : A, source : {} ) : A {\n for( var name in source ) {\n if( dest[ name ] === void 0 ){\n dest[ name ] = source[ name ];\n }\n }\n\n return dest;\n}\n\n/** Similar to underscore `_.extend` and `Object.assign` */\nexport function assign< T >( dest : T, ...sources : Object[] ) : T\nexport function assign< T >( dest : T, source : Object ) : T {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n if( arguments.length > 2 ){\n for( let i = 2; i < arguments.length; i++ ){\n const other = arguments[ i ];\n other && assign( dest, other );\n }\n }\n\n return dest;\n}\n\n/** Similar to underscore `_.keys` */\nexport function keys( o : any ) : string[]{\n return o ? Object.keys( o ) : [];\n}\n\n/** Similar to underscore `_.once` */\nexport function once( func : Function ) : Function {\n var memo, first = true;\n return function() {\n if ( first ) {\n first = false;\n memo = func.apply(this, arguments);\n func = null;\n }\n return memo;\n };\n}\n\n/** @hidden */\nconst ArrayProto = Array.prototype,\n DateProto = Date.prototype,\n ObjectProto = Object.prototype;\n\n/**\n * Determine whenever two values are not equal, deeply traversing \n * arrays and plain JS objects (hashes). Dates are compared by enclosed timestamps, all other\n * values are compared with strict comparison.\n */\nexport function notEqual( a : any, b : any) : boolean {\n if( a === b ) return false;\n\n if( a && b && typeof a == 'object' && typeof b == 'object' ) {\n const protoA = Object.getPrototypeOf( a );\n\n if( protoA !== Object.getPrototypeOf( b ) ) return true;\n\n switch( protoA ){\n case DateProto : return +a !== +b;\n case ArrayProto : return arraysNotEqual( a, b );\n case ObjectProto :\n case null:\n return objectsNotEqual( a, b );\n }\n }\n\n return true;\n}\n\n/** @hidden */\nfunction objectsNotEqual( a, b ) {\n const keysA = Object.keys( a );\n\n if( keysA.length !== Object.keys( b ).length ) return true;\n\n for( let i = 0; i < keysA.length; i++ ) {\n const key = keysA[ i ];\n\n if( !b.hasOwnProperty( key ) || notEqual( a[ key ], b[ key ] ) ) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @hidden */\nfunction arraysNotEqual( a, b ) {\n if( a.length !== b.length ) return true;\n\n for( let i = 0; i < a.length; i++ ) {\n if( notEqual( a[ i ], b[ i ] ) ) return true;\n }\n\n return false;\n}\n\n/**\n * Create an object without Object prototype members except hasOwnProperty.\n * @param obj - optional parameter to populate the hash map from.\n */\nconst HashProto = Object.create( null );\nHashProto.hasOwnProperty = ObjectProto.hasOwnProperty;\n\nexport function hashMap( obj? ){\n const hash = Object.create( HashProto );\n return obj ? assign( hash, obj ) : hash;\n}","import { once as _once } from './tools'\n\n/*******************\n * Prebuilt events map, used for optimized bulk event subscriptions.\n *\n * const events = new EventMap({\n * 'change' : true, // Resend this event from self as it is.\n * 'change:attr' : 'localTargetFunction',\n * 'executedInTargetContext' : function(){ ... }\n * 'executedInNativeContext' : '^props.handler'\n * })\n */\n/** @hidden */\nexport interface EventsDefinition {\n [ events : string ] : Function | string | boolean\n}\n\n/** @hidden */\nexport class EventMap {\n handlers : EventDescriptor[] = [];\n\n constructor( map? : EventsDefinition | EventMap ){\n if( map ){\n if( map instanceof EventMap ){\n this.handlers = map.handlers.slice();\n }\n else{\n map && this.addEventsMap( map );\n }\n }\n }\n\n merge( map : EventMap ){\n this.handlers = this.handlers.concat( map.handlers );\n }\n\n addEventsMap( map : EventsDefinition ){\n for( let names in map ){\n this.addEvent( names, map[ names ] )\n }\n }\n\n bubbleEvents( names : string ){\n for( let name of names.split( eventSplitter ) ){\n this.addEvent( name, getBubblingHandler( name ) );\n }\n }\n\n addEvent( names : string, callback : Function | string | boolean ){\n const { handlers } = this;\n\n for( let name of names.split( eventSplitter ) ){\n handlers.push( new EventDescriptor( name, callback ) );\n }\n }\n\n subscribe( target : {}, source : EventSource ){\n for( let event of this.handlers ){\n on( source, event.name, event.callback, target );\n }\n }\n\n unsubscribe( target : {}, source : EventSource ){\n for( let event of this.handlers ){\n off( source, event.name, event.callback, target );\n }\n }\n}\n\n/** @hidden */\nexport class EventDescriptor {\n callback : Function\n\n constructor(\n public name : string,\n callback : Function | string | boolean\n ){\n if( callback === true ){\n this.callback = getBubblingHandler( name );\n }\n else if( typeof callback === 'string' ){\n this.callback =\n function localCallback(){\n const handler = this[ callback ];\n handler && handler.apply( this, arguments );\n };\n }\n else{\n this.callback = callback;\n }\n }\n}\n\n/** @hidden */\nconst _bubblingHandlers = {};\n\n/** @hidden */\nfunction getBubblingHandler( event : string ){\n return _bubblingHandlers[ event ] || (\n _bubblingHandlers[ event ] = function( a?, b?, c?, d?, e? ){\n if( d !== void 0 || e !== void 0 ) trigger5( this, event, a, b, c, d, e );\n if( c !== void 0 ) trigger3( this, event, a, b, c );\n else trigger2( this, event, a, b );\n }\n );\n}\n\n/** @hidden */\nexport interface HandlersByEvent {\n [ name : string ] : EventHandler\n}\n\n/** @hidden */\nexport class EventHandler {\n constructor( public callback : Callback, public context : any, public next = null ){}\n}\n\n/** @hidden */\nfunction listOff( _events : HandlersByEvent, name : string, callback : Callback, context : any ){\n const head = _events[ name ];\n\n let filteredHead, prev;\n\n for( let ev = head; ev; ev = ev.next ){\n // Element must be kept\n if( ( callback && callback !== ev.callback && callback !== ev.callback._callback ) ||\n ( context && context !== ev.context ) ){\n \n prev = ev;\n filteredHead || ( filteredHead = ev );\n }\n // Element must be skipped\n else{\n if( prev ) prev.next = ev.next;\n }\n }\n\n if( head !== filteredHead ) _events[ name ] = filteredHead;\n}\n\n/** @hidden */\nfunction listSend2( head : EventHandler, a, b ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b );\n}\n\n/** @hidden */\nfunction listSend3( head : EventHandler, a, b, c ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c );\n}\n\n/** @hidden */\nfunction listSend4( head : EventHandler, a, b, c, d ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d );\n}\n\n/** @hidden */\nfunction listSend5( head : EventHandler, a, b, c, d, e ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d, e );\n}\n\n/** @hidden */\nfunction listSend6( head : EventHandler, a, b, c, d, e, f ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d, e, f );\n}\n\n/** @hidden */\nexport interface Callback extends Function {\n _callback? : Function\n}\n\n/** @hidden */\nexport function on( source : EventSource, name : string, callback : Callback, context? : any ) : void {\n if( callback ){\n const _events = source._events || ( source._events = Object.create( null ) );\n _events[ name ] = new EventHandler( callback, context, _events[ name ] );\n }\n}\n\n/** @hidden */\nexport function once( source : EventSource, name : string, callback : Callback, context? : any ) : void {\n if( callback ){\n const once : Callback = _once( function(){\n off( source, name, once );\n callback.apply(this, arguments);\n });\n\n once._callback = callback;\n on( source, name, once, context );\n }\n}\n\n/** @hidden */\nexport function off( source : EventSource, name? : string, callback? : Callback, context? : any ) : void {\n const { _events } = source;\n if( _events ){\n if( callback || context ) {\n if( name ){\n listOff( _events, name, callback, context );\n }\n else{\n for( let name in _events ){\n listOff( _events, name, callback, context );\n }\n }\n }\n else if( name ){\n _events[ name ] = void 0;\n }\n else{\n source._events = void 0;\n }\n }\n}\n\n/** @hidden */\nexport interface EventSource {\n _events : HandlersByEvent\n}\n\n/** @hidden */\nconst eventSplitter = /\\s+/;\n\n/** @hidden */\nexport function strings( api : ApiEntry, source : EventSource, events : string, callback : Callback, context ){\n if( eventSplitter.test( events ) ){\n const names = events.split( eventSplitter );\n for( let name of names ) api( source, name, callback, context );\n }\n else api( source, events, callback, context );\n}\n\n/** @hidden */\nexport type ApiEntry = ( source : EventSource, event : string, callback : Callback, context? : any ) => void\n\n/*********************************\n * Event-triggering API\n */\n\n/** @hidden */\nexport function trigger2( self : EventSource, name : string, a, b ) : void {\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend2( queue, a, b );\n listSend3( all, name, a, b );\n }\n};\n\n/** @hidden */\nexport function trigger3( self : EventSource, name : string, a, b, c ) : void{\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend3( queue, a, b, c );\n listSend4( all, name, a, b, c );\n }\n};\n\n/** @hidden */\nexport function trigger5( self : EventSource, name : string, a, b, c, d, e ) : void{\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend5( queue, a, b, c, d, e );\n listSend6( all, name, a, b, c, d, e );\n }\n};","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","/*****************************************************************\n * Mixins engine and @define metaprogramming class extensions\n *\n * Vlad Balin & Volicon, (c) 2016-2017\n */\nimport { __extends } from 'tslib';\nimport { assign, defaults, getBaseClass, hashMap, transform } from './tools';\n\nexport interface Subclass< T > extends MixableConstructor {\n new ( ...args ) : T\n prototype : T\n}\n\nexport interface MixableConstructor extends Function{\n __super__? : object;\n mixins? : MixinsState;\n onExtend? : ( BaseClass : Function ) => void;\n onDefine? : ( definition : object, BaseClass : Function ) => void;\n define? : ( definition? : object, statics? : object ) => MixableConstructor;\n extend? : ( definition? : T, statics? : object ) => Subclass;\n}\n\nexport interface MixableDefinition {\n mixins? : Mixin[]\n}\n\n/**\n * Base class, holding metaprogramming class extensions.\n * Supports mixins and Class.define metaprogramming method.\n */\nexport class Mixable {\n static onExtend : ( BaseClass : Function ) => void;\n static onDefine : ( definition : object, BaseClass : Function ) => object; \n static __super__ : object\n static mixins : MixinsState;\n\n /** \n * Must be called after inheritance and before 'define'.\n */\n static define( protoProps : MixableDefinition = {}, staticProps? : object ) : MixableConstructor {\n const BaseClass : MixableConstructor = getBaseClass( this );\n\n // Assign statics.\n staticProps && assign( this, staticProps );\n\n // Extract and apply mixins from the definition.\n const { mixins, ...defineMixin } = protoProps;\n mixins && this.mixins.merge( mixins );\n\n // Unshift definition to the the prototype.\n this.mixins.mergeObject( this.prototype, defineMixin, true );\n\n // Unshift definition from statics to the prototype.\n this.mixins.mergeObject( this.prototype, this.mixins.getStaticDefinitions( BaseClass ), true );\n\n // Call onDefine hook, if it's present.\n this.onDefine && this.onDefine( this.mixins.definitions, BaseClass );\n \n // Apply merge rules to inherited members. No mixins can be added after this point.\n this.mixins.mergeInheritedMembers( BaseClass );\n\n return this;\n }\n\n /** Backbone-compatible extend method to be used in ES5 and for backward compatibility */\n static extend< T extends object>(spec? : T, statics? : {} ) : Subclass< T > {\n let TheSubclass : Subclass< T >;\n\n // 1. Create the subclass (ES5 compatibility shim).\n // If constructor function is given...\n if( spec && spec.hasOwnProperty( 'constructor' ) ){\n // ...we need to manually call internal TypeScript __extend function. Hack! Hack!\n TheSubclass = spec.constructor as any;\n __extends( TheSubclass, this );\n }\n // Otherwise, create the subclall in usual way.\n else{\n TheSubclass = class Subclass extends this {} as any;\n }\n\n predefine( TheSubclass );\n spec && TheSubclass.define( spec, statics );\n\n return TheSubclass;\n }\n}\n\n/** @decorator `@predefine` for forward definitions. Can be used with [[Mixable]] classes only.\n * Forwards the call to the [[Mixable.predefine]];\n */\nexport function predefine( Constructor : MixableConstructor ) : void {\n const BaseClass : MixableConstructor = getBaseClass( Constructor );\n\n // Legacy systems support\n Constructor.__super__ = BaseClass.prototype;\n \n // Initialize mixins structures...\n Constructor.define || MixinsState.get( Mixable ).populate( Constructor );\n\n // Make sure Ctor.mixins are ready before the callback...\n MixinsState.get( Constructor );\n\n // Call extend hook.\n Constructor.onExtend && Constructor.onExtend( BaseClass );\n}\n\n/** @decorator `@define` for metaprogramming magic. Can be used with [[Mixable]] classes only.\n * Forwards the call to [[Mixable.define]].\n */\nexport function define( ClassOrDefinition : Function ) : void;\nexport function define( ClassOrDefinition : object ) : ClassDecorator;\nexport function define( ClassOrDefinition : object | MixableConstructor ){\n // @define class\n if( typeof ClassOrDefinition === 'function' ){\n predefine( ClassOrDefinition );\n ( ClassOrDefinition as MixableConstructor ).define();\n }\n // @define({ prop : val, ... }) class\n else{\n return function( Ctor : MixableConstructor ){\n predefine( Ctor );\n Ctor.define( ClassOrDefinition );\n } as any;\n }\n}\n\nexport function definitions( rules : MixinMergeRules ) : ClassDecorator {\n return ( Class : Function ) => {\n const mixins = MixinsState.get( Class );\n mixins.definitionRules = defaults( hashMap(), rules, mixins.definitionRules );\n }\n}\n\n// Create simple property list decorator\nexport function propertyListDecorator( listName: string ) : PropertyDecorator {\n return function propList(proto, name : string) {\n const list = proto.hasOwnProperty( listName ) ?\n proto[ listName ] : (proto[ listName ] = (proto[ listName ] || []).slice()); \n\n list.push(name);\n }\n}\n\nexport function definitionDecorator( definitionKey, value ){\n return ( proto : object, name : string ) => {\n MixinsState\n .get( proto.constructor )\n .mergeObject( proto, {\n [ definitionKey ] : {\n [ name ] : value\n }\n });\n }\n}\n\nexport class MixinsState {\n mergeRules : MixinMergeRules;\n definitionRules : MixinMergeRules;\n definitions : object = {};\n appliedMixins : Mixin[];\n\n // Return mixins state for the class. Initialize if it's not exist.\n static get( Class ) : MixinsState {\n const { mixins } = Class;\n \n return mixins && Class === mixins.Class ? mixins :\n Class.mixins = new MixinsState( Class );\n }\n\n constructor( public Class : MixableConstructor ){\n const { mixins } = getBaseClass( Class );\n\n this.mergeRules = ( mixins && mixins.mergeRules ) || hashMap();\n this.definitionRules = ( mixins && mixins.definitionRules ) || hashMap();\n this.appliedMixins = ( mixins && mixins.appliedMixins ) || [];\n }\n\n getStaticDefinitions( BaseClass : Function ){\n const definitions = hashMap(),\n { Class } = this;\n\n return transform( definitions, this.definitionRules, ( rule, name ) =>{\n if( BaseClass[ name ] !== Class[ name ]){\n return Class[ name ];\n }\n });\n }\n\n merge( mixins : Mixin[] ){\n const proto = this.Class.prototype,\n { mergeRules } = this;\n\n // Copy applied mixins array as it's going to be updated.\n const appliedMixins = this.appliedMixins = this.appliedMixins.slice();\n\n // Apply mixins in sequence...\n for( let mixin of mixins ) {\n // Mixins array should be flattened.\n if( Array.isArray( mixin ) ) {\n this.merge( mixin );\n }\n // Don't apply mixins twice.\n else if( appliedMixins.indexOf( mixin ) < 0 ){\n appliedMixins.push( mixin );\n\n // For constructors, merge _both_ static and prototype members.\n if( typeof mixin === 'function' ){\n // Merge static members\n this.mergeObject( this.Class, mixin );\n\n // merge definitionRules and mergeRules\n const sourceMixins = ( mixin as any ).mixins;\n if( sourceMixins ){\n this.mergeRules = defaults( hashMap(), this.mergeRules, sourceMixins.mergeRules );\n this.definitionRules = defaults( hashMap(), this.definitionRules, sourceMixins.definitionRules );\n this.appliedMixins = this.appliedMixins.concat( sourceMixins.appliedMixins );\n }\n\n // Prototypes are merged according with rules.\n this.mergeObject( proto, mixin.prototype );\n }\n // Handle plain object mixins.\n else {\n this.mergeObject( proto, mixin );\n }\n }\n }\n }\n\n populate( ...ctors : Function[] ){\n for( let Ctor of ctors ) {\n MixinsState.get( Ctor ).merge([ this.Class ]);\n }\n }\n\n mergeObject( dest : object, source : object, unshift? : boolean ) {\n forEachOwnProp( source, name => {\n const sourceProp = Object.getOwnPropertyDescriptor( source, name );\n let rule : MixinMergeRule;\n\n if( rule = this.definitionRules[ name ] ){\n assignProperty( this.definitions, name, sourceProp, rule, unshift );\n }\n\n if( !rule || rule === mixinRules.protoValue ){\n assignProperty( dest, name, sourceProp, this.mergeRules[ name ], unshift );\n }\n });\n }\n\n mergeInheritedMembers( BaseClass : Function ){\n const { mergeRules, Class } = this;\n\n if( mergeRules ){\n const proto = Class.prototype,\n baseProto = BaseClass.prototype;\n\n for( let name in mergeRules ) {\n const rule = mergeRules[ name ];\n\n if( proto.hasOwnProperty( name ) && name in baseProto ){\n proto[ name ] = resolveRule( proto[ name ], baseProto[ name ], rule );\n }\n }\n }\n }\n}\n\nconst dontMix = {\n function : hashMap({\n length : true,\n prototype : true,\n caller : true,\n arguments : true,\n name : true,\n __super__ : true\n }),\n \n object : hashMap({\n constructor : true\n }) \n}\n\nfunction forEachOwnProp( object : object, fun : ( name : string ) => void ){\n const ignore = dontMix[ typeof object ];\n\n for( let name of Object.getOwnPropertyNames( object ) ) {\n ignore[ name ] || fun( name );\n }\n}\n\nexport interface MixinMergeRules {\n [ name : string ] : MixinMergeRule\n}\n\nexport type MixinMergeRule = ( a : any, b : any ) => any\nexport type Mixin = { [ key : string ] : any } | Function\n\n// @mixins( A, B, ... ) decorator.\nexport interface MixinRulesDecorator {\n ( rules : MixinMergeRules ) : ClassDecorator\n value( a : object, b : object) : object;\n protoValue( a : object, b : object) : object;\n merge( a : object, b : object ) : object;\n pipe( a: Function, b : Function ) : Function;\n defaults( a: Function, b : Function ) : Function;\n classFirst( a: Function, b : Function ) : Function;\n classLast( a: Function, b : Function ) : Function;\n every( a: Function, b : Function ) : Function;\n some( a: Function, b : Function ) : Function;\n}\n\nexport const mixins = ( ...list : Mixin[] ) => (\n ( Class : Function ) => MixinsState.get( Class ).merge( list )\n);\n\n// @mixinRules({ name : rule, ... }) decorator.\nexport const mixinRules = ( ( rules : MixinMergeRules ) => (\n ( Class : Function ) => {\n const mixins = MixinsState.get( Class );\n mixins.mergeRules = defaults( rules, mixins.mergeRules );\n }\n) ) as MixinRulesDecorator;\n\n// Pre-defined mixin merge rules\n\nmixinRules.value = ( a, b ) => a;\n\nmixinRules.protoValue = ( a, b ) => a;\n\n// Recursively merge members\nmixinRules.merge = ( a, b ) => defaults( {}, a, b );\n\n // Execute methods in pipe, with the class method executed last.\nmixinRules.pipe = ( a, b ) => (\n function( x : any ) : any {\n return a.call( this, b.call( this, x ) );\n }\n);\n\n // Assume methods return an object, and merge results with defaults (class method executed first)\nmixinRules.defaults = ( a : Function, b : Function ) => (\n function() : object {\n return defaults( a.apply( this, arguments ), b.apply( this, arguments ) );\n }\n);\n\n// Execute methods in sequence staring with the class method.\nmixinRules.classFirst = ( a : Function, b : Function ) => (\n function() : void {\n a.apply( this, arguments );\n b.apply( this, arguments );\n }\n);\n\n // Execute methods in sequence ending with the class method.\nmixinRules.classLast = ( a : Function, b : Function ) => (\n function() : void {\n b.apply( this, arguments );\n a.apply( this, arguments );\n }\n)\n\n // Execute methods in sequence returning the first falsy result.\nmixinRules.every = ( a : Function, b : Function ) =>(\n function() : any {\n return a.apply( this, arguments ) && b.apply( this, arguments );\n }\n);\n // Execute methods in sequence returning the first truthy result.\nmixinRules.some = ( a : Function, b : Function ) =>(\n function() : any {\n return a.apply( this, arguments ) || b.apply( this, arguments );\n }\n);\n\n/**\n * Helpers\n */\n\nfunction assignProperty( dest : object, name : string, sourceProp : PropertyDescriptor, rule : MixinMergeRule, unshift? : boolean ){\n// Destination prop is defined, thus the merge rules must be applied.\n if( dest.hasOwnProperty( name ) ){\n const destProp = Object.getOwnPropertyDescriptor( dest, name );\n\n if( destProp.configurable && 'value' in destProp ){\n dest[ name ] = unshift ?\n resolveRule( sourceProp.value, destProp.value, rule ) :\n resolveRule( destProp.value, sourceProp.value, rule ) ;\n }\n }\n // If destination is empty, just copy the prop over.\n else{\n Object.defineProperty( dest, name, sourceProp );\n }\n}\n\nfunction resolveRule( dest, source, rule : MixinMergeRule ){\n // When destination is empty, take the source.\n if( dest === void 0 ) return source;\n\n // In these cases we take non-empty destination:\n if( !rule || source === void 0 ) return dest;\n\n // In other cases we must merge values.\n return rule( dest, source );\n}","import * as _eventsApi from './eventsource';\nimport { EventMap, EventsDefinition, EventSource, HandlersByEvent } from './eventsource';\nimport { define, definitions, Mixable, MixableConstructor, mixinRules, MixinsState } from './mixins';\nimport { omit, transform } from './tools';\n\nconst { strings, on, off, once, trigger5, trigger2, trigger3 } = _eventsApi;\n\n/** @hidden */\nlet _idCount = 0;\n\n/** @hidden */\nfunction uniqueId() : string {\n return 'l' + _idCount++;\n}\n\nexport { EventMap, EventsDefinition };\n\nexport interface MessengerDefinition {\n _localEvents? : EventMap\n localEvents? : EventsDefinition\n properties? : PropertyMap\n [ name : string ] : any\n}\n\nexport interface PropertyMap {\n [ name : string ] : Property\n}\n\nexport type Property = PropertyDescriptor | ( () => any )\n\n/** @hidden */\nexport interface MessengersByCid {\n [ cid : string ] : Messenger\n}\n\n/** @hidden */\nexport type CallbacksByEvents = { [ events : string ] : Function }\n\n/*************************\n * Messenger is mixable class with capabilities of sending and receiving synchronous events.\n * This class itself can serve as both mixin and base class.\n */\n\n@define\n@definitions({\n properties : mixinRules.merge,\n localEvents : mixinRules.merge\n})\nexport class Messenger implements Mixable, EventSource {\n // Define extendable mixin static properties.\n static __super__ : object;\n static mixins : MixinsState;\n static onExtend : ( BaseClass : Function ) => void;\n static define : ( definition? : MessengerDefinition, statics? : object ) => MixableConstructor;\n static extend : ( definition? : MessengerDefinition, statics? : object ) => MixableConstructor;\n static onDefine({ localEvents, _localEvents, properties } : MessengerDefinition, BaseClass? : typeof Mixable ){\n // Handle localEvents definition\n if( localEvents || _localEvents ){\n const eventsMap = new EventMap( this.prototype._localEvents );\n\n localEvents && eventsMap.addEventsMap( localEvents );\n _localEvents && eventsMap.merge( _localEvents );\n \n this.prototype._localEvents = eventsMap;\n }\n\n // Handle properties definitions...\n if( properties ){\n Object.defineProperties( this.prototype, transform( {}, properties, toPropertyDescriptor ) );\n }\n }\n\n /** @hidden */ \n _events : HandlersByEvent = void 0;\n\n /** @hidden */ \n _listeningTo : MessengersByCid = void 0\n\n /** Unique client-only id. */\n cid : string\n\n /** @hidden Prototype-only property to manage automatic local events subscription */ \n _localEvents : EventMap\n\n /** @hidden */ \n constructor(){\n this.cid = uniqueId();\n this.initialize.apply( this, arguments );\n\n // TODO: local events subscribe?\n }\n\n /** Method is called at the end of the constructor */\n initialize() : void {}\n \n on( events : string | CallbacksByEvents, callback, context? ) : this {\n if( typeof events === 'string' ) strings( on, this, events, callback, context );\n else for( let name in events ) strings( on, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n once( events : string | CallbacksByEvents, callback, context? ) : this {\n if( typeof events === 'string' ) strings( once, this, events, callback, context );\n else for( let name in events ) strings( once, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n off( events? : string | CallbacksByEvents, callback?, context? ) : this {\n if( !events ) off( this, void 0, callback, context );\n else if( typeof events === 'string' ) strings( off, this, events, callback, context );\n else for( let name in events ) strings( off, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n // Trigger one or many events, firing all bound callbacks. Callbacks are\n // passed the same arguments as `trigger` is, apart from the event name\n // (unless you're listening on `\"all\"`, which will cause your callback to\n // receive the true name of the event as the first argument).\n trigger(name : string, a?, b?, c?, d?, e? ) : this {\n if( d !== void 0 || e !== void 0 ) trigger5( this, name, a, b, c, d, e );\n else if( c !== void 0 ) trigger3( this, name, a, b, c );\n else trigger2( this, name, a, b );\n return this;\n }\n\n listenTo( source : Messenger, a : string | CallbacksByEvents, b? : Function ) : this {\n if( source ){\n addReference( this, source );\n source.on( a, !b && typeof a === 'object' ? this : b, this );\n }\n\n return this;\n }\n\n listenToOnce( source : Messenger, a : string | CallbacksByEvents, b? : Function ) : this {\n if( source ){\n addReference( this, source );\n source.once( a, !b && typeof a === 'object' ? this : b, this );\n }\n\n return this;\n }\n\n stopListening( a_source? : Messenger, a? : string | CallbacksByEvents, b? : Function ) : this {\n const { _listeningTo } = this;\n if( _listeningTo ){\n const removeAll = !( a || b ),\n second = !b && typeof a === 'object' ? this : b;\n\n if( a_source ){\n const source = _listeningTo[ a_source.cid ];\n if( source ){\n if( removeAll ) delete _listeningTo[ a_source.cid ];\n source.off( a, second, this );\n }\n }\n else if( a_source == null ){\n for( let cid in _listeningTo ) _listeningTo[ cid ].off( a, second, this );\n\n if( removeAll ) ( this._listeningTo = void 0 );\n }\n }\n\n return this;\n }\n\n /**\n * Destructor. Stops messenger from listening to all objects,\n * and stop others from listening to the messenger. \n */\n _disposed : boolean\n\n dispose() : void {\n if( this._disposed ) return;\n\n this.stopListening();\n this.off();\n\n this._disposed = true;\n }\n}\n\n/**\n * Backbone 1.2 API conformant Events mixin.\n */\nexport const Events : Messenger = omit( Messenger.prototype, 'constructor', 'initialize' );\n\n/**\n * Messenger Private Helpers \n */\n\nfunction toPropertyDescriptor( x : Property ) : PropertyDescriptor {\n if( x ){\n return typeof x === 'function' ? { get : < () => any >x, configurable : true } : x;\n }\n}\n\n/** @hidden */\nfunction addReference( listener : Messenger, source : Messenger ){\n const listeningTo = listener._listeningTo || (listener._listeningTo = Object.create( null ) ),\n cid = source.cid || ( source.cid = uniqueId() );\n\n listeningTo[ cid ] = source;\n}","import { Messenger } from './events'\nimport { define } from './mixins';\n\nexport type LogLevel = 'error' | 'warn' | 'debug' | 'info' | 'log';\nexport type LoggerEventHandler = ( topic : string, msg : string, props : object ) => void;\n\nexport const isProduction = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production',\n logEvents : LogLevel[] = isProduction ?\n [ 'error', 'info' ] :\n [ 'error', 'warn', 'debug', 'info', 'log' ];\n\n@define\nexport class Logger extends Messenger {\n counter : { [ level in LogLevel ]? : number } = {}\n\n // Log events of the given log level to the console, optionally filtered by topic\n logToConsole( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n const args = [ `[${topic}] ${msg}` ];\n \n for( let name in props ){\n args.push( `\\n\\t${name}:`, toString( props[ name ] ) );\n }\n \n console[ level ].apply( console, args );\n }\n });\n }\n\n // Fire exception on the events of the given log level, optionally filtered by topic\n throwOn( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n throw new Error( `[${topic}] ${msg}` );\n }\n });\n }\n\n // Count log events of the given level, optionally filtered by topic\n count( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n this.counter[ level ] = ( this.counter[ level ] || 0 ) + 1;\n }\n });\n }\n\n trigger : ( level : LogLevel, topic : string, message : string, props? : object ) => this;\n \n off : ( event? : LogLevel ) => this;\n\n\n on( handlers : { [ name in LogLevel ] : LoggerEventHandler } ) : this;\n on( handlers : LogLevel, handler : LoggerEventHandler ) : this;\n on( handlers : 'all', handler : ( level : LogLevel, topic : string, msg : string, props : object ) => void ) : this;\n on( a : any, b? : any ){\n return super.on( a, b );\n }\n}\n\n/**\n * Convert objects to the plain text friendly format.\n * primitives as in JSON.\n */\nlet toString = typeof window === 'undefined' ? \n something => {\n if( something && typeof something === 'object' ){\n const { __inner_state__ } = something,\n value = __inner_state__ || something,\n isArray = Array.isArray( value );\n\n const body = isArray ? `[ length = ${ value.length } ]` : `{ ${ Object.keys( value ).join( ', ' )} }`;\n\n return something.constructor.name + ' ' + body;\n }\n\n return JSON.stringify( something );\n }\n : x => x;\n\nexport const logger = new Logger();\n\nif( typeof console !== 'undefined' ) {\n for( let event of logEvents ){\n logger.logToConsole( event );\n }\n}\n\nexport const throwingLogger = new Logger();\nthrowingLogger.throwOn( 'error' ).throwOn( 'warn' );\n\nexport const log : typeof logger.trigger = logger.trigger.bind( logger );","export interface IONode {\n _endpoint : IOEndpoint\n _ioPromise : IOPromise< this >\n}\n\nexport interface IOPromise extends Promise {\n abort? : () => void\n}\n\nexport interface IOEndpoint {\n list( options : IOOptions, collection? ) : IOPromise\n create( json : any, options : IOOptions, record? ) : IOPromise\n update( id : string | number, json :any, options : IOOptions, record? ) : IOPromise\n read( id : string | number, options : IOOptions, record? ) : IOPromise\n destroy( id : string | number, options : IOOptions, record? ) : IOPromise\n subscribe( events : IOEvents, collection? ) : IOPromise\n unsubscribe( events : IOEvents, collection? ) : void\n}\n\nexport interface IOOptions {\n ioUpdate? : boolean\n}\n\nexport interface IOEvents {\n updated? : ( json : any ) => void\n removed? : ( json : any ) => void\n}\n\nexport function getOwnerEndpoint( self ) : IOEndpoint {\n // Check if we are the member of the collection...\n const { collection } = self;\n if( collection ){\n return getOwnerEndpoint( collection );\n }\n\n // Now, if we're the member of the model...\n if( self._owner ){\n const { _endpoints } = self._owner;\n return _endpoints && _endpoints[ self._ownerKey ];\n }\n}\n\n/**\n * Create abortable promise.\n * Adds `promise.abort()` function which rejects the promise by default\n * initialize() function takes third optional argument `abort : ( resolve, reject ) => void`,\n * which can be used to add custom abort handling.\n */\ndeclare var Promise: PromiseConstructorLike;\n\nexport function createIOPromise( initialize : InitIOPromise ) : IOPromise{\n let resolve, reject, onAbort;\n\n function abort( fn ){\n onAbort = fn;\n }\n\n const promise : IOPromise = new Promise( ( a_resolve, a_reject ) =>{\n reject = a_reject;\n resolve = a_resolve;\n initialize( resolve, reject, abort );\n }) as IOPromise;\n\n promise.abort = () => {\n onAbort ? onAbort( resolve, reject ) : reject( new Error( \"I/O Aborted\" ) );\n }\n\n return promise;\n}\n\nexport type InitIOPromise = ( resolve : ( x? : any ) => void, reject : ( x? : any ) => void, abort? : ( fn : Function ) => void ) => void;\n\nexport function startIO( self : IONode, promise : IOPromise, options : IOOptions, thenDo : ( json : any ) => any ) : IOPromise {\n // Stop pending I/O first...\n abortIO( self );\n\n // Mark future update transaction as IO transaction.\n options.ioUpdate = true;\n\n self._ioPromise = promise\n .then( resp => {\n self._ioPromise = null;\n \n const result = thenDo ? thenDo( resp ) : resp;\n \n triggerAndBubble( self, 'sync', self, resp, options );\n \n return result;\n } ) \n .catch( err => {\n self._ioPromise = null;\n \n // Overlaps with a new `error` event.\n triggerAndBubble( self, 'error', self, err, options );\n \n throw err;\n } ) as IOPromise;\n\n self._ioPromise.abort = promise.abort;\n\n return self._ioPromise;\n}\n\nexport function abortIO( self : IONode ){\n if( self._ioPromise && self._ioPromise.abort ){\n self._ioPromise.abort();\n self._ioPromise = null;\n }\n}\n\nexport function triggerAndBubble( eventSource, ...args ){\n eventSource.trigger.apply( eventSource, args );\n const { collection } = eventSource;\n collection && collection.trigger.apply( collection, args ); \n}","/**\n * Traversable objects and symbolic references\n */\nexport interface Traversable {\n getStore() : Traversable\n getOwner() : Traversable\n get( key : string ) : any \n}\n\nconst referenceMask = /\\^|(store\\.[^.]+)|([^.]+)/g;\n\n// Compile reference to function\nexport type ResolveReference = ( root : Traversable ) => any; \n\nexport class CompiledReference {\n resolve : ResolveReference\n tail : string\n local : boolean\n\n constructor( reference : string, splitTail : boolean = false ){\n const path = reference\n .match( referenceMask )\n .map( key => {\n if( key === '^' || key === 'owner' ) return 'getOwner()';\n\n if( key[ 0 ] === '~' ) return `getStore().get(\"${ key.substr( 1 ) }\")`;\n\n if( key.indexOf( 'store.' ) === 0 ) return `getStore().get(\"${ key.substr( 6 ) }\")`;\n \n return key;\n } );\n \n this.tail = splitTail && path.pop();\n this.local = !path.length;\n \n this.resolve = new Function( 'self', `\n var v = self.${ path.shift() };\n \n ${ path.map( x => `\n v = v && v.${ x };\n `).join('')}\n\n return v;\n ` );\n }\n}\n\nexport function resolveReference( root : Traversable, reference : string, action : ( object, key : string ) => any ) : any {\n const path = reference.match( referenceMask ),\n skip = path.length - 1;\n \n let self = root;\n\n for( var i = 0; i < skip; i++ ){\n const key = path[ i ];\n switch( key ){\n case '~' : self = self.getStore(); break;\n case '^' : self = self.getOwner(); break;\n default : self = self.get( key );\n }\n\n // Do nothing if object on the path doesn't exist.\n if( !self ) return;\n }\n\n return action( self, path[ skip ] );\n}","export interface ChildrenErrors {\n [ key : string ] : ValidationError | any\n} \n\nexport interface Validatable {\n _validateNested( errors : ChildrenErrors ) : number;\n validate( self : any ) : any\n get( key : string ) : any\n}\n\n// Validation error object.\nexport class ValidationError {\n // Invalid nested object keys \n nested : ChildrenErrors \n length : number\n\n // Local error\n error : any\n\n constructor( obj : Validatable ){\n this.length = obj._validateNested( this.nested = {} );\n\n if( this.error = obj.validate( obj ) ){\n this.length++;\n }\n }\n\n each( iteratee : ( value : any, key : string ) => void ) : void {\n const { error, nested } = this;\n\n if( error ) iteratee( error, null );\n\n for( const key in nested ){\n iteratee( nested[ key ], key );\n }\n }\n\n eachError( iteratee : ( error : any, key : string, object : Validatable ) => void, object : Validatable ) : void {\n this.each( ( value : any, key : string ) => {\n if( value instanceof ValidationError ){\n (value).eachError( iteratee, object.get( key ) );\n }\n else{\n iteratee( value, key, object );\n }\n });\n }\n}","import { abortIO, IOEndpoint, IONode, IOPromise } from './io-tools';\nimport { CallbacksByEvents, define, definitions, eventsApi, Logger, LogLevel, Messenger, MessengerDefinition, MessengersByCid, mixinRules, mixins, MixinsState, throwingLogger } from './object-plus';\nimport { resolveReference, Traversable } from './traversable';\nimport { ChildrenErrors, Validatable, ValidationError } from './validation';\n\nconst { trigger3, on, off } = eventsApi;\n/***\n * Abstract class implementing ownership tree, tho-phase transactions, and validation. \n * 1. createTransaction() - apply changes to an object tree, and if there are some events to send, transaction object is created.\n * 2. transaction.commit() - send and process all change events, and close transaction.\n */\n\n/** @private */\nexport interface TransactionalDefinition extends MessengerDefinition {\n endpoint? : IOEndpoint\n}\n\nexport enum ItemsBehavior {\n share = 0b0001,\n listen = 0b0010,\n persistent = 0b0100\n}\n\n// Transactional object interface\n@define\n@definitions({\n endpoint : mixinRules.value\n})\n@mixins( Messenger )\nexport abstract class Transactional implements Messenger, IONode, Validatable, Traversable {\n // Mixins are hard in TypeScript. We need to copy type signatures over...\n // Here goes 'Mixable' mixin.\n static endpoint : IOEndpoint;\n static __super__ : object;\n static mixins : MixinsState;\n static define : ( definition? : TransactionalDefinition, statics? : object ) => typeof Transactional;\n static extend : ( definition? : T, statics? : object ) => any;\n\n static onDefine( definitions : TransactionalDefinition, BaseClass : typeof Transactional ){\n if( definitions.endpoint ) this.prototype._endpoint = definitions.endpoint;\n Messenger.onDefine.call( this, definitions, BaseClass );\n };\n\n static onExtend( BaseClass : typeof Transactional ) : void {\n // Make sure we don't inherit class factories.\n if( BaseClass.create === this.create ) {\n this.create = Transactional.create;\n }\n }\n\n // Define extendable mixin static properties.\n static create( a : any, b? : any ) : Transactional {\n return new (this as any)( a, b );\n }\n\n /** Generic class factory. May be overridden for abstract classes. Not inherited. */\n on : ( events : string | CallbacksByEvents, callback, context? ) => this\n once : ( events : string | CallbacksByEvents, callback, context? ) => this\n off : ( events? : string | CallbacksByEvents, callback?, context? ) => this\n trigger : (name : string, a?, b?, c?, d?, e? ) => this\n\n stopListening : ( source? : Messenger, a? : string | CallbacksByEvents, b? : Function ) => this\n listenTo : ( source : Messenger, a : string | CallbacksByEvents, b? : Function ) => this\n listenToOnce : ( source : Messenger, a : string | CallbacksByEvents, b? : Function ) => this\n \n _disposed : boolean;\n\n // State accessor. \n readonly __inner_state__ : any;\n\n // Shared modifier (used by collections of shared models)\n _shared? : number; \n \n dispose() : void {\n if( this._disposed ) return;\n \n abortIO( this );\n this._owner = void 0;\n this._ownerKey = void 0;\n this.off();\n this.stopListening();\n this._disposed = true;\n }\n\n // Must be called at the end of the constructor in the subclass.\n initialize() : void {}\n\n /** @private */\n _events : eventsApi.HandlersByEvent = void 0;\n\n /** @private */\n _listeningTo : MessengersByCid\n\n /** @private */\n _localEvents : eventsApi.EventMap\n\n cid : string\n cidPrefix : string\n\n // Unique version token replaced on change\n /** @private */\n _changeToken : {} = {}\n\n // true while inside of the transaction\n /** @private */\n _transaction : boolean = false;\n\n // Holds current transaction's options, when in the middle of transaction and there're changes but is an unsent change event\n /** @private */\n _isDirty : TransactionOptions = null;\n\n // Backreference set by owner (Record, Collection, or other object)\n /** @private */\n _owner : Owner = void 0;\n\n // Key supplied by owner. Used by record to identify attribute key.\n // Only collections doesn't set the key, which is used to distinguish collections.\n /** @private */ \n _ownerKey : string = void 0;\n\n // Name of the change event\n /** @private */\n _changeEventName : string\n\n /**\n * Subsribe for the changes.\n */\n onChanges( handler : Function, target? : Messenger ){\n on( this, this._changeEventName, handler, target );\n }\n\n /**\n * Unsubscribe from changes.\n */\n offChanges( handler? : Function, target? : Messenger ){\n off( this, this._changeEventName, handler, target );\n }\n\n /**\n * Listen to changes event. \n */\n listenToChanges( target : Transactional, handler ){\n this.listenTo( target, target._changeEventName, handler );\n }\n\n constructor( cid : string | number ){\n this.cid = this.cidPrefix + cid;\n }\n\n // Deeply clone ownership subtree\n abstract clone( options? : CloneOptions ) : this\n \n // Execute given function in the scope of ad-hoc transaction.\n transaction( fun : ( self : this ) => void, options : TransactionOptions = {} ) : void{\n const isRoot = transactionApi.begin( this );\n const update = fun.call( this, this );\n update && this.set( update );\n isRoot && transactionApi.commit( this );\n }\n\n // Assign transactional object \"by value\", copying aggregated items.\n assignFrom( source : Transactional | Object ) : this {\n // Need to delay change events until change token willl by synced.\n this.transaction( () =>{\n this.set( ( source ).__inner_state__ || source, { merge : true } );\n\n // Synchronize change tokens\n const { _changeToken } = source as any;\n \n if( _changeToken ){\n this._changeToken = _changeToken;\n } \n });\n\n return this;\n }\n\n // Create object from JSON. Throw if validation fail.\n static from Transactional >( this : T, json : any, { strict, ...options } : { strict? : boolean } & TransactionOptions = {} ) : InstanceType{\n const obj : Transactional = ( this as any ).create( json, { ...options, logger : strict ? throwingLogger : void 0 } );\n\n if( strict && obj.validationError ){\n obj.eachValidationError( ( error, key, obj ) => {\n throw new Error( `${ obj.getClassName() }.${ key }: ${ error }` );\n });\n }\n\n return obj as any;\n }\n\n // Apply bulk object update without any notifications, and return open transaction.\n // Used internally to implement two-phase commit.\n // Returns null if there are no any changes.\n /** @private */ \n abstract _createTransaction( values : any, options? : TransactionOptions ) : Transaction | void\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n abstract set( values : any, options? : TransactionOptions ) : this;\n\n \n // Parse function applied when 'parse' option is set for transaction.\n parse( data : any, options? : TransactionOptions ) : any { return data }\n\n // Convert object to the serializable JSON structure\n abstract toJSON( options? : object ) : {}\n\n /*******************\n * Traversals and member access\n */\n \n // Get object member by its key.\n abstract get( key : string ) : any\n\n // Get object member by symbolic reference.\n deepGet( reference : string ) : any {\n return resolveReference( this, reference, ( object, key ) => object.get ? object.get( key ) : object[ key ] );\n }\n\n //_isCollection : boolean\n\n // Return owner skipping collections.\n getOwner() : Owner {\n return this._owner;\n }\n\n // Store used when owner chain store lookup failed. Static value in the prototype. \n /** @private */\n _defaultStore : Transactional\n\n // Locate the closest store. Store object stops traversal by overriding this method. \n getStore() : Transactional {\n const { _owner } = this;\n return _owner ? _owner.getStore() : this._defaultStore;\n }\n\n\n /***************************************************\n * Iteration API\n */\n\n // Loop through the members. Must be efficiently implemented in container class.\n\n _endpoint : IOEndpoint\n _ioPromise : IOPromise\n\n hasPendingIO() : IOPromise { return this._ioPromise; }\n\n fetch( options? : object ) : IOPromise { throw new Error( \"Not implemented\" ); }\n\n getEndpoint() : IOEndpoint {\n return getOwnerEndpoint( this ) || this._endpoint;\n }\n \n /*********************************\n * Validation API\n */\n\n // Lazily evaluated validation error\n /** @private */\n _validationError : ValidationError = void 0\n\n // Validate ownership tree and return valudation error \n get validationError() : ValidationError {\n const error = this._validationError || ( this._validationError = new ValidationError( this ) );\n return error.length ? error : null; \n }\n\n // Validate nested members. Returns errors count.\n /** @private */\n abstract _validateNested( errors : ChildrenErrors ) : number\n\n // Object-level validator. Returns validation error.\n validate( obj? : Transactional ) : any {}\n\n // Return validation error (or undefined) for nested object with the given key. \n getValidationError( key? : string ) : any {\n var error = this.validationError;\n return ( key ? error && error.nested[ key ] : error ) || null;\n }\n\n // Get validation error for the given symbolic reference.\n deepValidationError( reference : string ) : any {\n return resolveReference( this, reference, ( object, key ) => object.getValidationError( key ) );\n }\n\n // Iterate through all validation errors across the ownership tree.\n eachValidationError( iteratee : ( error : any, key : string, object : Transactional ) => void ) : void {\n const { validationError } = this;\n validationError && validationError.eachError( iteratee, this );\n }\n\n // Check whenever member with a given key is valid. \n isValid( key? : string ) : boolean {\n return !this.getValidationError( key );\n }\n\n valueOf() : Object { return this.cid; }\n toString(){ return this.cid; }\n\n // Get class name for an object instance. Works fine with ES6 classes definitions (not in IE).\n getClassName() : string {\n const { name } = this.constructor;\n if( name !== 'Subclass' ) return name;\n }\n\n // Logging interface for run time errors and warnings.\n abstract _log( level : LogLevel, topic : string, text : string, value : any, logger? : Logger ) : void\n}\n\nexport interface CloneOptions {\n // 'Pin store' shall assign this._defaultStore = this.getStore();\n pinStore? : boolean\n}\n\n// Owner must accept children update events. It's an only way children communicates with an owner.\n/** @private */\nexport interface Owner extends Traversable, Messenger {\n _onChildrenChange( child : Transactional, options : TransactionOptions ) : void;\n getOwner() : Owner\n getStore() : Transactional\n}\n\n// Transaction object used for two-phase commit protocol.\n// Must be implemented by subclasses.\n// Transaction must be created if there are actual changes and when markIsDirty returns true.\n/** @private */ \nexport interface Transaction {\n // Object transaction is being made on.\n object : Transactional\n\n // Send out change events, process update triggers, and close transaction.\n // Nested transactions must be marked with isNested flag (it suppress owner notification).\n commit( initiator? : Transactional )\n}\n\n// Options for distributed transaction \nexport interface TransactionOptions {\n // Invoke parsing \n parse? : boolean\n\n // Optional logger\n logger? : Logger\n\n // Suppress change notifications and update triggers\n silent? : boolean\n\n // Update existing transactional members in place, or skip the update (ignored by models)\n merge? : boolean // =true\n\n // Should collections remove elements in set (ignored by models) \n remove? : boolean // =true\n\n // Always replace enclosed objects with new instances\n reset? : boolean // = false\n\n // Do not dispose aggregated members\n unset? : boolean\n\n validate? : boolean\n\n // `true` if the transaction is initiated as a result of IO operation\n ioUpdate? : boolean\n\n // The hint for IOEndpoint\n // If `true`, `record.save()` will behave as \"upsert\" operation for the records having id.\n upsert? : boolean\n}\n\n/**\n * Low-level transactions API. Must be used like this:\n * const isRoot = begin( record );\n * ...\n * isRoot && commit( record, options );\n * \n * When committing nested transaction, the flag must be set to true. \n * commit( object, options, isNested ) \n */\n\nexport const transactionApi = {\n // Start transaction. Return true if it's the root one.\n /** @private */\n begin( object : Transactional ) : boolean {\n return object._transaction ? false : ( object._transaction = true ); \n },\n\n // Mark object having changes inside of the current transaction.\n // Returns true whenever there notifications are required.\n /** @private */\n markAsDirty( object : Transactional, options : TransactionOptions ) : boolean {\n // If silent option is in effect, don't set isDirty flag.\n const dirty = !options.silent;\n if( dirty ) object._isDirty = options;\n \n // Reset version token.\n object._changeToken = {};\n\n // Object is changed, so validation must happen again. Clear the cache.\n object._validationError = void 0;\n\n return dirty;\n },\n\n // Commit transaction. Send out change event and notify owner. Returns true if there were changes.\n // Must be executed for the root transaction only.\n /** @private */\n commit( object : Transactional, initiator? : Transactional ){\n let originalOptions = object._isDirty;\n\n if( originalOptions ){\n // Send the sequence of change events, handling chained handlers.\n while( object._isDirty ){\n const options = object._isDirty;\n object._isDirty = null; \n trigger3( object, object._changeEventName, object, options, initiator );\n }\n \n // Mark transaction as closed.\n object._transaction = false;\n\n // Notify owner on changes out of transaction scope. \n const { _owner } = object; \n if( _owner && _owner !== initiator ){ // If it's the nested transaction, owner is already aware there are some changes.\n _owner._onChildrenChange( object, originalOptions );\n }\n }\n else{\n // No changes. Silently close transaction.\n object._isDirty = null;\n object._transaction = false;\n }\n },\n\n /************************************\n * Ownership management\n */\n\n // Add reference to the record.\n /** @private */\n aquire( owner : Owner, child : Transactional, key? : string ) : void {\n if( child._owner ) throw new ReferenceError( 'Trying to aquire ownership for an object already having an owner' );\n\n child._owner = owner;\n child._ownerKey = key;\n },\n\n // Remove reference to the record.\n /** @private */\n free( owner : Owner, child : Transactional ) : void {\n if( owner === child._owner ){\n child._owner = void 0;\n child._ownerKey = void 0;\n }\n }\n}\n\nfunction getOwnerEndpoint( self : Transactional ) : IOEndpoint {\n // Check if we are the member of the collection...\n const { collection } = self as any;\n if( collection ){\n return getOwnerEndpoint( collection );\n }\n\n // Now, if we're the member of the model...\n if( self._owner ){\n const { _endpoints } = self._owner as any;\n return _endpoints && _endpoints[ self._ownerKey ];\n }\n}\n","import { eventsApi } from '../object-plus';\nimport { Owner, Transaction, Transactional, transactionApi, TransactionOptions } from \"../transactions\";\nconst { begin : _begin, markAsDirty : _markAsDirty, commit } = transactionApi;\n\nconst { trigger3 } = eventsApi;\n\nexport interface ConstructorsMixin {\n Attributes : AttributesConstructor\n AttributesCopy : AttributesCopyConstructor\n}\n\nexport interface ConstructorOptions extends TransactionOptions{\n clone? : boolean\n}\n\nexport type AttributesConstructor = new ( record : AttributesContainer, values : object, options : TransactionOptions ) => AttributesValues;\nexport type AttributesCopyConstructor = new ( values : object ) => AttributesValues;\n\nexport interface AttributesContainer extends Transactional, Owner, ConstructorsMixin {\n // Attribute descriptors.\n _attributes : AttributesDescriptors\n\n // Attribute values.\n attributes : AttributesValues\n\n // Previous attribute values.\n _previousAttributes : AttributesValues\n\n // Changed attributes cache. \n _changedAttributes : AttributesValues\n}\n\nexport interface AttributesValues {\n [ name : string ] : any\n}\n\nexport interface AttributesDescriptors {\n [ name : string ] : AttributeUpdatePipeline\n}\n\nexport interface AttributeUpdatePipeline{\n doUpdate( value, record : AttributesContainer, options : TransactionOptions, nested? : Transaction[] ) : boolean\n}\n\n // Optimized single attribute transactional update. To be called from attributes setters\n // options.silent === false, parse === false. \nexport function setAttribute( record : AttributesContainer, name : string, value : any ) : void {\n // Open the transaction.\n const isRoot = begin( record ),\n options = {};\n\n // Update attribute. \n if( record._attributes[ name ].doUpdate( value, record, options ) ){\n // Notify listeners on changes.\n markAsDirty( record, options );\n trigger3( record, 'change:' + name, record, record.attributes[ name ], options );\n }\n\n // Close the transaction.\n isRoot && commit( record );\n}\n\nfunction begin( record : AttributesContainer ){\n if( _begin( record ) ){\n record._previousAttributes = new record.AttributesCopy( record.attributes );\n record._changedAttributes = null;\n return true;\n }\n \n return false;\n}\n\nfunction markAsDirty( record : AttributesContainer, options : TransactionOptions ){\n // Need to recalculate changed attributes, when we have nested set in change:attr handler\n if( record._changedAttributes ){\n record._changedAttributes = null;\n }\n\n return _markAsDirty( record, options );\n}\n\n/**\n * TODO: There's an opportunity to create an optimized pipeline for primitive types and Date, which makes the majority\n * of attributes. It might create the major speedup.\n * \n * Create the dedicated pipeline for owned and shared attributes as well.\n * \n * Three elements of the pipeline:\n * - from constructor\n * - from assignment\n * - from `set`\n */\n\nexport const UpdateRecordMixin = {\n// Need to override it here, since begin/end transaction brackets are overriden. \n transaction( this : AttributesContainer, fun : ( self : AttributesContainer ) => void, options : TransactionOptions = {} ) : void{\n const isRoot = begin( this );\n fun.call( this, this );\n isRoot && commit( this );\n },\n \n // Handle nested changes. TODO: propagateChanges == false, same in transaction.\n _onChildrenChange( child : Transactional, options : TransactionOptions ) : void {\n const { _ownerKey } = child,\n attribute = this._attributes[ _ownerKey ];\n\n if( !attribute /* TODO: Must be an opposite, likely the bug */ || attribute.propagateChanges ) this.forceAttributeChange( _ownerKey, options );\n },\n\n // Simulate attribute change \n forceAttributeChange( key : string, options : TransactionOptions = {} ){\n // Touch an attribute in bounds of transaction\n const isRoot = begin( this );\n\n if( markAsDirty( this, options ) ){\n trigger3( this, 'change:' + key, this, this.attributes[ key ], options );\n }\n \n isRoot && commit( this );\n },\n\n _createTransaction( this : AttributesContainer, a_values : {}, options : TransactionOptions = {} ) : Transaction {\n const isRoot = begin( this ),\n changes : string[] = [],\n nested : RecordTransaction[]= [],\n { _attributes } = this,\n values = options.parse ? this.parse( a_values, options ) : a_values;\n\n let unknown;\n\n if( shouldBeAnObject( this, values, options ) ){\n for( let name in values ){\n const spec = _attributes[ name ];\n\n if( spec ){\n if( spec.doUpdate( values[ name ], this, options, nested ) ){\n changes.push( name );\n }\n }\n else{\n unknown || ( unknown = [] );\n unknown.push( `'${ name }'` );\n }\n }\n\n if( unknown ){\n unknownAttrsWarning( this, unknown, { values }, options );\n }\n }\n \n if( changes.length && markAsDirty( this, options ) ){\n return new RecordTransaction( this, isRoot, nested, changes );\n }\n \n // No changes, but there might be silent attributes with open transactions.\n for( let pendingTransaction of nested ){\n pendingTransaction.commit( this );\n }\n\n isRoot && commit( this );\n }\n};\n\nexport function unknownAttrsWarning( record : AttributesContainer, unknown : string[], props, options ){\n record._log( 'warn', 'Type-R:UnknownAttrs', `undefined attributes ${ unknown.join(', ')} are ignored.`, props, options.logger );\n}\n\n// One of the main performance tricks of Type-R.\n// Create loop unrolled constructors for internal attribute hash,\n// so the hidden class JIT optimization will be engaged and they will become static structs.\n// It dramatically improves record performance.\nexport function constructorsMixin( attrDefs : AttributesDescriptors ) : ConstructorsMixin {\n const attrs = Object.keys( attrDefs );\n\n const AttributesCopy : AttributesCopyConstructor = new Function( 'values', `\n ${ attrs.map( attr =>`\n this.${ attr } = values.${ attr };\n `).join( '' ) }\n `) as any;\n\n AttributesCopy.prototype = Object.prototype;\n\n const Attributes : AttributesConstructor = new Function( 'record', 'values', 'options', `\n var _attrs = record._attributes;\n\n ${ attrs.map( attr =>`\n this.${ attr } = _attrs.${ attr }.doInit( values.${ attr }, record, options );\n `).join( '' ) }\n `) as any;\n\n Attributes.prototype = Object.prototype;\n\n return { Attributes, AttributesCopy };\n}\n\nexport function shouldBeAnObject( record : AttributesContainer, values : object, options ){\n if( values && values.constructor === Object ) return true;\n\n record._log( 'error', 'Type-R:InvalidObject', 'update with non-object is ignored!', { values }, options.logger );\n return false;\n}\n\n// Transaction class. Implements two-phase transactions on object's tree. \n// Transaction must be created if there are actual changes and when markIsDirty returns true. \nexport class RecordTransaction implements Transaction {\n // open transaction\n constructor( public object : AttributesContainer,\n public isRoot : boolean,\n public nested : Transaction[],\n public changes : string[] ){}\n\n // commit transaction\n commit( initiator? : AttributesContainer ) : void {\n const { nested, object, changes } = this;\n\n // Commit all pending nested transactions...\n for( let transaction of nested ){ \n transaction.commit( object );\n }\n\n // Notify listeners on attribute changes...\n // Transaction is never created when silent option is set, so just send events out.\n const { attributes, _isDirty } = object;\n for( let key of changes ){\n trigger3( object, 'change:' + key, object, attributes[ key ], _isDirty );\n }\n\n this.isRoot && commit( object, initiator );\n }\n}","import { IOEndpoint } from '../../io-tools';\nimport { LogLevel, tools, Logger } from '../../object-plus';\nimport { TransactionOptions } from '../../transactions';\nimport { AttributesContainer, AttributeUpdatePipeline, RecordTransaction, setAttribute } from '../updates';\n\nconst { notEqual, assign} = tools;\n\nexport type Transform = ( this : AnyType, next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) => any;\nexport type ChangeHandler = ( this : AnyType, next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) => void;\n\nexport interface AttributeOptions {\n _metatype? : typeof AnyType\n validate? : ( record : AttributesContainer, value : any, key : string ) => any\n isRequired? : boolean\n changeEvents? : boolean\n\n endpoint? : IOEndpoint\n\n type? : Function\n value? : any\n hasCustomDefault? : boolean\n\n parse? : Parse\n toJSON? : AttributeToJSON\n \n getHooks? : GetHook[]\n transforms? : Transform[]\n changeHandlers? : ChangeHandler[]\n\n _onChange? : ChangeAttrHandler\n}\n\nexport type Parse = ( value : any, key : string ) => any;\nexport type GetHook = ( value : any, key : string ) => any;\nexport type AttributeToJSON = ( value : any, key : string ) => any\nexport type AttributeParse = ( value : any, key : string ) => any\nexport type ChangeAttrHandler = ( ( value : any, attr : string ) => void ) | string;\n\n// TODO: interface differs from options, do something obout it\nconst emptyOptions : TransactionOptions = {};\n\n/**\n * Typeless attribute. Is the base class for all other attributes.\n */\nexport class AnyType implements AttributeUpdatePipeline {\n // Factory method to create attribute from options \n static create : ( options : AttributeOptions, name : string ) => AnyType;\n \n /**\n * Update pipeline functions\n * =========================\n *\n * Stage 0. canBeUpdated( value )\n * - presence of this function implies attribute's ability to update in place.\n */\n canBeUpdated( prev, next, options : TransactionOptions ) : any {}\n\n /**\n * Stage 1. Transform stage\n */\n transform( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) : any { return next; }\n\n // convert attribute type to `this.type`.\n convert( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) : any { return next; }\n\n /**\n * Stage 2. Check if attr value is changed\n */\n isChanged( a : any, b : any ) : boolean {\n return notEqual( a, b );\n }\n\n /**\n * Stage 3. Handle attribute change\n */\n handleChange( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) {}\n\n /**\n * End update pipeline definitions.\n */\n\n // create empty object passing backbone options to constructor...\n create() { return void 0; }\n\n // generic clone function for typeless attributes\n // Must be overriden in sublass\n clone( value : any, record : AttributesContainer ) {\n return value;\n }\n\n dispose( record : AttributesContainer, value : any ) : void {\n this.handleChange( void 0, value, record, emptyOptions );\n }\n\n validate( record : AttributesContainer, value : any, key : string ) : any {}\n\n toJSON( value, key, options? : object ) {\n return value && value.toJSON ? value.toJSON( options ) : value;\n }\n\n createPropertyDescriptor() : PropertyDescriptor | void {\n const { name, getHook } = this;\n\n if( name !== 'id' ){\n return {\n // call to optimized set function for single argument.\n set( value ){\n setAttribute( this, name, value );\n },\n\n // attach get hook to the getter function, if it present\n get : (\n getHook ?\n function() {\n return getHook.call( this, this.attributes[ name ], name );\n } :\n function() { return this.attributes[ name ]; }\n ),\n\n configurable : true\n }\n }\n }\n\n value : any\n\n // Used as global default value for the given metatype\n static defaultValue : any;\n\n type : Function\n\n initialize( name : string, options : TransactionOptions ){}\n\n options : AttributeOptions\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n const v = value === void 0 ? this.defaultValue() : value,\n x = this.transform( v, void 0, record, options );\n \n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record : AttributesContainer, options : TransactionOptions, nested? : RecordTransaction[] ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n\n const next = this.transform( value, prev, record, options );\n attributes[ name ] = next;\n\n if( this.isChanged( next, prev ) ) {\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n return true;\n }\n\n return false;\n }\n\n propagateChanges : boolean\n\n protected _log( level : LogLevel, code : string, text : string, value, record : AttributesContainer, logger : Logger ){\n record._log( level, code, `${record.getClassName()}.${ this.name } ${ text }`, {\n 'New value' : value,\n 'Prev. value' : record.attributes[ this.name ]\n }, logger );\n }\n\n defaultValue(){\n return this.value;\n }\n\n constructor( public name : string, a_options : AttributeOptions ) { \n // Save original options...\n this.options = a_options;\n\n // Clone options.\n const options : AttributeOptions = assign( { getHooks : [], transforms : [], changeHandlers : [] }, a_options );\n options.getHooks = options.getHooks.slice();\n options.transforms = options.transforms.slice();\n options.changeHandlers = options.changeHandlers.slice();\n\n const {\n value, type, parse, toJSON, changeEvents,\n validate, getHooks, transforms, changeHandlers\n } = options;\n\n // Initialize default value...\n this.value = value;\n this.type = type;\n\n // TODO: An opportunity to optimize for attribute subtype.\n if( !options.hasCustomDefault && type ){\n this.defaultValue = this.create;\n }\n else if( tools.isValidJSON( value ) ){ \n // JSON literals must be deep copied.\n this.defaultValue = new Function( `return ${ JSON.stringify( value ) };` ) as any;\n }\n else{\n this.defaultValue = this.defaultValue;\n }\n\n // Changes must be bubbled when they are not disabled for an attribute and transactional object.\n this.propagateChanges = changeEvents !== false;\n\n this.toJSON = toJSON === void 0 ? this.toJSON : toJSON;\n\n this.validate = validate || this.validate;\n \n if( options.isRequired ){\n this.validate = wrapIsRequired( this.validate );\n }\n\n /**\n * Assemble pipelines...\n */\n\n // `convert` is default transform, which is always present...\n transforms.unshift( this.convert );\n\n // Get hook from the attribute will be used first...\n if( this.get ) getHooks.unshift( this.get );\n\n // let subclasses configure the pipeline...\n this.initialize.call( this, options );\n\n // let attribute spec configure the pipeline...\n if( getHooks.length ){\n const getHook = this.getHook = getHooks.reduce( chainGetHooks );\n\n const { validate } = this;\n this.validate = function( record : AttributesContainer, value : any, key : string ){\n return validate.call( this, record, getHook.call( record, value, key ), key );\n }\n }\n \n this.transform = transforms.length ? transforms.reduce( chainTransforms ) : this.transform;\n \n this.handleChange = changeHandlers.length ? changeHandlers.reduce( chainChangeHandlers ) : this.handleChange;\n\n // Attribute-level parse transform are attached as update hooks modifiers...\n const { doInit, doUpdate } = this;\n this.doInit = parse ? function( value, record : AttributesContainer, options : TransactionOptions ){\n return doInit.call( this, options.parse && value !== void 0 ? parse.call( record, value, this.name ) : value, record, options );\n } : doInit;\n\n this.doUpdate = parse ? function( value, record : AttributesContainer, options : TransactionOptions, nested? : RecordTransaction[] ){\n return doUpdate.call( this, options.parse && value !== void 0 ? parse.call( record, value, this.name ) : value, record, options, nested );\n } : doUpdate;\n }\n\n getHook : ( value, key : string ) => any = null\n get : ( value, key : string ) => any\n}\n\n\nfunction chainGetHooks( prevHook : GetHook, nextHook : GetHook ) : GetHook {\n return function( value, name ) {\n return nextHook.call( this, prevHook.call( this, value, name ), name );\n }\n}\n\nfunction chainTransforms( prevTransform : Transform, nextTransform : Transform ) : Transform {\n return function( next, prev, record, options ) {\n return nextTransform.call( this, prevTransform.call( this, next, prev, record, options ), prev, record, options );\n }\n}\n\nfunction chainChangeHandlers( prevHandler : ChangeHandler, nextHandler : ChangeHandler ) : ChangeHandler {\n return function( next, prev, record, options ) {\n prevHandler.call( this, next, prev, record, options );\n nextHandler.call( this, next, prev, record, options );\n }\n}\n\nfunction wrapIsRequired( validate ){\n return function( record : AttributesContainer, value : any, key : string ){\n return value ? validate.call( this, record, value, key ) : 'Required';\n }\n}","/**\n * Built-in JSON types attributes: Object, Array, Number, String, Boolean, and immutable class.\n * \n * Adds type assertions, default validation, and optimized update pipeline.\n */\n\nimport { TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer } from '../updates';\n\n/**\n * Custom class must be immutable class which implements toJSON() method\n * with a constructor taking json.\n */\nexport class ImmutableClassType extends AnyType {\n type : new ( value? : any ) => {}\n\n create(){\n return new this.type();\n }\n\n convert( next : any ) : any {\n return next == null || next instanceof this.type ? next : new this.type( next );\n }\n\n toJSON( value, key? : string, options? : object ){\n return value && value.toJSON ? value.toJSON( options ) : value;\n }\n\n clone( value ) {\n return new this.type( this.toJSON( value ) );\n }\n\n isChanged( a, b ){\n return a !== b;\n }\n}\n\n/**\n * Optimized attribute of primitive type.\n * \n * Primitives has specialized simplified pipeline.\n */\nexport class PrimitiveType extends AnyType {\n type : NumberConstructor | StringConstructor | BooleanConstructor\n\n dispose(){}\n create() { return this.type(); }\n\n toJSON( value ) { return value; }\n\n convert( next ) { return next == null ? next : this.type( next ); }\n\n isChanged( a, b ) { return a !== b; }\n\n clone( value ) { return value; }\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n return this.transform( value === void 0 ? this.value : value, void 0, record, options );\n }\n\n doUpdate( value, record, options, nested ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n \n return prev !== ( attributes[ name ] = this.transform( value, prev, record, options ) );\n }\n\n initialize(){\n if( !this.options.hasCustomDefault ){\n this.value = this.type();\n }\n }\n}\n\n// Number type with special validation algothim.\n/** @private */ \nexport class NumericType extends PrimitiveType {\n type : NumberConstructor\n\n create(){\n return 0;\n }\n\n convert( next, prev?, record?, options? ) {\n const num = next == null ? next : this.type( next );\n\n if( num !== num ){\n this._log( 'error', 'Type-R:InvalidNumber', 'Number attribute is assigned with an invalid number', next, record, options.logger );\n }\n \n return num;\n }\n\n validate( model, value, name ) {\n // Whatever is not symmetrically serializable to JSON, is not valid by default.\n if( value != null && !isFinite( value ) ) {\n return name + ' is not valid number';\n }\n }\n}\n\n/**\n * Compatibility wrapper for Array type.\n * @private\n */ \nexport class ArrayType extends AnyType {\n toJSON( value ) { return value; }\n dispose(){}\n create(){ return []; }\n\n convert( next, prev, record, options ) {\n // Fix incompatible constructor behaviour of Array...\n if( next == null || Array.isArray( next ) ) return next;\n\n this._log( 'error', 'Type-R:InvalidArray', 'Array attribute assigned with non-array value', next, record, options.logger );\n\n return [];\n }\n\n clone( value ){\n return value && value.slice();\n }\n}\n\nexport class ObjectType extends AnyType {\n create(){ return {}; }\n\n convert( next, prev, record, options ) {\n if( next == null || typeof next === 'object' ) return next;\n \n this._log( 'error', 'Type-R:InvalidObject', 'Object attribute is assigned with non-object value', next, record, options.logger );\n return {};\n }\n}\n\nexport function doNothing(){}\n\nexport class FunctionType extends AnyType {\n // Functions are not serialized.\n toJSON( value ) { return void 0; }\n create(){ return doNothing; }\n dispose(){}\n\n convert( next, prev, record, options ) {\n // Fix incompatible constructor behaviour of Function...\n if( next == null || typeof next === 'function' ) return next;\n\n this._log( 'error', 'Type-R:InvalidFunction', 'Function attribute assigned with non-function value', next, record, options.logger );\n\n return doNothing;\n }\n\n // Functions are not cloned.\n clone( value ){ return value; }\n}\n","/**\n * Date attribute type.\n * \n * Implements validation, cross-browser compatibility fixes, variety of Date serialization formats,\n * and optimized update pipeline.\n */\nimport { TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer } from '../updates';\n\n// Date Attribute\n/** @private */\nexport class DateType extends AnyType {\n create(){\n return new Date();\n }\n \n convert( next : any, a, record, options ){\n if( next == null || next instanceof Date ) return next;\n\n const date = new Date( next ),\n timestamp = date.getTime();\n\n if( timestamp !== timestamp ){\n this._log( 'error', 'Type-R:InvalidDate', 'Date attribute assigned with invalid date', next, record, options.logger );\n }\n\n return date;\n }\n\n validate( model, value, name ) {\n if( value != null ){\n const timestamp = value.getTime(); \n if( timestamp !== timestamp ) return name + ' is Invalid Date';\n }\n }\n\n toJSON( value ) { return value && value.toISOString(); }\n\n isChanged( a, b ) { return ( a && a.getTime() ) !== ( b && b.getTime() ); }\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n // Date don't have handleChanges step.\n return this.transform( value === void 0 ? this.defaultValue() : value, void 0, record, options );\n }\n\n doUpdate( value, record, options, nested ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n \n // Date don't have handleChanges step.\n return this.isChanged( prev , attributes[ name ] = this.transform( value, prev, record, options ) );\n }\n\n clone( value ) { return value && new Date( value.getTime() ); }\n dispose(){}\n}\n\n// If ISO date is not supported by date constructor (such as in Safari), polyfill it.\nfunction supportsDate( date ){\n return !isNaN( ( new Date( date ) ).getTime() );\n}\n\nif( !supportsDate('2011-11-29T15:52:30.5') ||\n !supportsDate('2011-11-29T15:52:30.52') ||\n !supportsDate('2011-11-29T15:52:18.867') ||\n !supportsDate('2011-11-29T15:52:18.867Z') ||\n !supportsDate('2011-11-29T15:52:18.867-03:30') ){\n\n DateType.prototype.convert = function( value ){\n return value == null || value instanceof Date ? value : new Date( safeParseDate( value ) );\n }\n}\n\nconst numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ],\n isoDatePattern = /^(\\d{4}|[+\\-]\\d{6})(?:-(\\d{2})(?:-(\\d{2}))?)?(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:(Z)|([+\\-])(\\d{2})(?::(\\d{2}))?)?)?$/;\n\nfunction safeParseDate( date : string ) : number {\n var timestamp, struct : any[], minutesOffset = 0;\n\n if( ( struct = isoDatePattern.exec( date )) ) {\n // avoid NaN timestamps caused by undefined values being passed to Date.UTC\n for( var i = 0, k; ( k = numericKeys[ i ] ); ++i ) {\n struct[ k ] = +struct[ k ] || 0;\n }\n\n // allow undefined days and months\n struct[ 2 ] = (+struct[ 2 ] || 1) - 1;\n struct[ 3 ] = +struct[ 3 ] || 1;\n\n if( struct[ 8 ] !== 'Z' && struct[ 9 ] !== undefined ) {\n minutesOffset = struct[ 10 ] * 60 + struct[ 11 ];\n\n if( struct[ 9 ] === '+' ) {\n minutesOffset = 0 - minutesOffset;\n }\n }\n\n timestamp =\n Date.UTC( struct[ 1 ], struct[ 2 ], struct[ 3 ], struct[ 4 ], struct[ 5 ] + minutesOffset, struct[ 6 ],\n struct[ 7 ] );\n }\n else {\n timestamp = Date.parse( date );\n }\n\n return timestamp;\n}","import { ItemsBehavior, Transactional, transactionApi, TransactionOptions } from '../../transactions';\nimport { ValidationError } from '../../validation';\nimport { AnyType } from './any';\nimport { AttributesContainer, ConstructorOptions } from '../updates';\n\nconst { free, aquire } = transactionApi;\n\nexport class AggregatedType extends AnyType {\n type : typeof Transactional\n\n clone( value : Transactional ) : Transactional {\n return value ? value.clone() : value;\n }\n\n toJSON( x, key : string, options : object ){ return x && x.toJSON( options ); }\n\n doInit( value, record : AttributesContainer, options : ConstructorOptions ){\n const v = options.clone ? this.clone( value ) : (\n value === void 0 ? this.defaultValue() : value\n );\n\n const x = this.transform( v, void 0, record, options );\n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record, options, nested : any[] ){ // Last to things can be wrapped to an object, either transaction or ad-hoc\n const key = this.name, { attributes } = record; \n const prev = attributes[ key ];\n let update;\n\n // This can be moved to transactional attribute. And chained with the rest.\n if( update = this.canBeUpdated( prev, value, options ) ) { // todo - skip empty updates.\n const nestedTransaction = prev._createTransaction( update, options );\n if( nestedTransaction ){\n if( nested ){\n nested.push( nestedTransaction );\n }\n else{\n nestedTransaction.commit( record );\n }\n\n if( this.propagateChanges ) return true;\n }\n\n return false;\n }\n\n const next = this.transform( value, prev, record, options );\n attributes[ key ] = next;\n\n if( this.isChanged( next, prev ) ) { // Primitives and nested comparison can be inlined.\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n\n return true;\n }\n\n return false;\n }\n\n canBeUpdated( prev : Transactional, next : any, options : TransactionOptions ) : any {\n // If an object already exists, and new value is of incompatible type, let object handle the update.\n if( prev && next != null ){\n if( next instanceof this.type ){\n // In case if merge option explicitly specified, force merge.\n if( options.merge ) return next.__inner_state__;\n }\n else{\n return next;\n }\n }\n }\n\n convert( next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) : Transactional {\n // Invoke class factory to handle abstract classes\n if( next == null ) return next;\n \n if( next instanceof this.type ){\n if( next._shared && !( next._shared & ItemsBehavior.persistent ) ) { // TODO: think more about shared types assignment compatibility. \n this._log( 'error', 'Type-R:InvalidCollection', 'aggregated collection attribute is assigned with shared collection type', next, record, options.logger );\n }\n\n // With explicit 'merge' option we need to clone an object if its previous value was 'null'.\n // This is an only case we could be here when merge === true.\n if( options.merge ) return next.clone();\n\n if( next._owner ){\n this._log( 'warn', 'Type-R:InvalidOwner', 'object alreay has an owner and was cloned. Use explicit object.clone() to dismiss this warning.', next, record, options.logger );\n return next.clone();\n }\n\n return next;\n }\n\n return ( this.type as any).create( next, options );\n }\n\n dispose ( record : AttributesContainer, value : Transactional ){\n if( value ){\n this.handleChange( void 0, value, record, {} );\n }\n }\n\n validate( record : AttributesContainer, value : Transactional ) : ValidationError {\n var error = value && value.validationError;\n if( error ) return error;\n }\n\n create() : Transactional {\n return (this.type).create(); // this the subclass of Transactional here.\n }\n\n initialize( options ){\n options.changeHandlers.unshift( this._handleChange );\n }\n\n _handleChange( next : Transactional, prev : Transactional, record : AttributesContainer, options : TransactionOptions ){\n if( prev ){\n free( record, prev );\n options.unset || prev.dispose();\n } \n \n if( next ) aquire( record, next, this.name );\n }\n}","import { eventsApi } from '../../object-plus';\nimport { ItemsBehavior, Transactional, transactionApi, TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer, ConstructorOptions } from '../updates';\nimport { ChainableAttributeSpec } from '../attrDef';\n\nconst { on, off } = eventsApi,\n { free, aquire } = transactionApi;\n\n/************************\n * Shared attribute definition.\n * - Not serialized.\n * - Listening to the changes.\n * - Doesn't take ownership when assigned with object of proper type.\n * - Takes ownership on objects which are converted.\n */\n\nconst shareAndListen = ItemsBehavior.listen | ItemsBehavior.share;\n\n/** @private */\nexport class SharedType extends AnyType {\n type : typeof Transactional\n\n doInit( value, record : AttributesContainer, options : ConstructorOptions ){\n const v = options.clone ? this.clone( value, record ) : (\n value === void 0 ? this.defaultValue() : value\n );\n\n const x = this.transform( v, void 0, record, options );\n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record, options, nested : any[] ){ // Last to things can be wrapped to an object, either transaction or ad-hoc\n const key = this.name, { attributes } = record; \n const prev = attributes[ key ];\n let update;\n\n // This can be moved to transactional attribute. And chained with the rest.\n if( update = this.canBeUpdated( prev, value, options ) ) { // todo - skip empty updates.\n const nestedTransaction = prev._createTransaction( update, options );\n if( nestedTransaction ){\n if( nested ){\n nested.push( nestedTransaction );\n }\n else{\n nestedTransaction.commit( record );\n }\n\n if( this.propagateChanges ) return true;\n }\n\n return false;\n }\n\n const next = this.transform( value, prev, record, options );\n attributes[ key ] = next;\n\n if( this.isChanged( next, prev ) ) { // Primitives and nested comparison can be inlined.\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n\n return true;\n }\n\n return false;\n }\n\n clone( value : Transactional, record : AttributesContainer ) : Transactional {\n // References are not cloned.\n if( !value || value._owner !== record ) return value;\n\n // Implicitly created objects are cloned.\n const clone = value.clone();\n aquire( record, clone, this.name );\n return clone;\n }\n\n // Do not serialize by default.\n toJSON(){}\n\n canBeUpdated( prev : Transactional, next : any, options : TransactionOptions ) : any {\n // If an object already exists, and new value is of incompatible type, let object handle the update.\n if( prev && next != null && !( next instanceof this.type ) ){\n return next;\n }\n }\n\n convert( next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) : Transactional {\n if( next == null || next instanceof this.type ) return next;\n\n // Convert type using implicitly created transactional object.\n const implicitObject = new ( this.type as any )( next, options, shareAndListen );\n\n // To prevent a leak, we need to take an ownership on it.\n aquire( record, implicitObject, this.name );\n\n return implicitObject;\n }\n\n // Refs are always valid.\n validate( model, value, name ){}\n\n // They are always created as null.\n create() : Transactional {\n return null;\n }\n\n // Listening to the change events\n _handleChange( next : Transactional, prev : Transactional, record : AttributesContainer, options ){\n if( prev ){\n // If there was an implicitly created object, remove an ownership.\n if( prev._owner === record ){\n free( record, prev );\n options.unset || prev.dispose();\n }\n else{\n off( prev, prev._changeEventName, this._onChange, record );\n }\n } \n \n if( next ){\n // No need to take an ownership for an implicit object - already done in convert or clone.\n if( next._owner !== record ){\n on( next, next._changeEventName, this._onChange, record );\n }\n } \n }\n\n dispose( record : AttributesContainer, value : Transactional ){\n if( value ){\n this.handleChange( void 0, value, record, {} );\n }\n }\n\n _onChange : ( child : Transactional, options : TransactionOptions, initiator : Transactional ) => void \n\n initialize( options ){\n // Create change event handler which knows current attribute name. \n const attribute = this;\n this._onChange = this.propagateChanges ? function( child, options, initiator ){\n this === initiator || this.forceAttributeChange( attribute.name, options );\n } : ignore;\n\n options.changeHandlers.unshift( this._handleChange );\n }\n}\n\nfunction ignore(){}","import { PrimitiveType, NumericType, ObjectType, ImmutableClassType, FunctionType, ArrayType } from './basic';\nimport { DateType } from './date';\nimport { AnyType, AttributeOptions } from './any';\n\nexport * from './any';\nexport * from './basic';\nexport * from './date';\nexport * from './owned';\nexport * from './shared';\n\n/**\n * Every record attribute type has the corresponding metatype controlling its behavior.\n * For built-in types, Type-R uses the predefined list to resolve metatype in order to avoid global objects modifications.\n * For user-defined types, static `_metatype` constructor member is used.\n */\n\nconst builtins : Function[] = [ String, Number, Boolean, Date, Object, Array, Function ],\n metatypes = [ PrimitiveType, NumericType, PrimitiveType, DateType, ObjectType, ArrayType, FunctionType ];\n\nexport function getMetatype( Ctor : Function ){\n return ( Ctor as any )._metatype || resolveBuiltins( Ctor );\n}\n\nAnyType.create = ( options : AttributeOptions, name : string ) => {\n const type = options.type,\n AttributeCtor = options._metatype || ( type ? getMetatype( type ): AnyType );\n\n return new AttributeCtor( name, options );\n}\n\nfunction resolveBuiltins( Ctor : Function ){\n const idx = builtins.indexOf( Ctor );\n return idx < 0 ? ImmutableClassType : metatypes[ idx ];\n}","/**\n * Type spec engine. Declare attributes using chainable syntax,\n * and returns object with spec.\n */\nimport { IOEndpoint } from '../io-tools';\nimport { definitionDecorator, EventMap, EventsDefinition, tools } from '../object-plus';\nimport { Transactional } from '../transactions';\nimport { AttributeOptions, Parse, AnyType, getMetatype, SharedType } from './metatypes';\nimport { AttributesContainer } from './updates';\n\nconst { assign } = tools;\n\nexport interface AttributeCheck {\n ( value : any, key : string ) : boolean\n error? : any\n}\n\n// Infer the proper TS type from a Type-R attribute spec.\nexport type Infer =\n A extends ChainableAttributeSpec ? TrueReturnType :\n A extends Function ? TrueReturnType :\n A;\n \n// Extract the proper TS return type for a function or constructor.\ntype TrueReturnType =\n F extends DateConstructor ? Date :\n F extends ( ...args : any[] ) => infer R ? R :\n F extends new ( ...args : any[] ) => infer R ? R :\n void;\n\nexport class ChainableAttributeSpec{\n options : AttributeOptions & { type? : F };\n\n constructor( options : AttributeOptions ) {\n // Shallow copy options, fill it with defaults.\n this.options = { getHooks : [], transforms : [], changeHandlers : []};\n if( options ) assign( this.options, options );\n }\n\n check( check : AttributeCheck, error? : any ) : this {\n function validate( model, value, name ){\n if( !check.call( model, value, name ) ){\n const msg = error || check.error || name + ' is not valid';\n return typeof msg === 'function' ? msg.call( model, name ) : msg;\n }\n }\n\n const prev = this.options.validate;\n\n return this.metadata({\n validate : prev ? (\n function( model, value, name ){\n return prev( model, value, name ) || validate( model, value, name );\n }\n ) : validate\n });\n }\n\n get as() : PropertyDecorator {\n return definitionDecorator( 'attributes', this );\n }\n\n get isRequired() : this {\n return this.required;\n }\n\n get required() : this {\n return this.metadata({ isRequired : true }); \n }\n\n endpoint( endpoint : IOEndpoint ) : this {\n return this.metadata({ endpoint });\n }\n\n watcher( ref : string | ( ( value : any, key : string ) => void ) ) : this {\n return this.metadata({ _onChange : ref });\n }\n\n // Attribute-specific parse transform\n parse( fun : Parse ) : this {\n return this.metadata({ parse : fun });\n }\n\n toJSON( fun ) : this {\n return this.metadata({\n toJSON : typeof fun === 'function' ? fun : ( fun ? ( x, k, o ) => x && x.toJSON( o ) : emptyFunction ) \n });\n }\n\n // Attribute get hook.\n get( fun ) : this {\n return this.metadata({\n getHooks : this.options.getHooks.concat( fun )\n });\n }\n\n // Attribute set hook.\n set( fun ) : this {\n function handleSetHook( next, prev, record : AttributesContainer, options ) {\n if( this.isChanged( next, prev ) ) {\n const changed = fun.call( record, next, this.name );\n return changed === void 0 ? prev : this.convert( changed, prev, record, options );\n }\n\n return prev;\n }\n\n return this.metadata({\n transforms : this.options.transforms.concat( handleSetHook )\n });\n }\n\n changeEvents( events : boolean ) : this {\n return this.metadata({ changeEvents : events });\n }\n\n // Subsribe to events from an attribute.\n events( map : EventsDefinition ) : this {\n const eventMap = new EventMap( map );\n\n function handleEventsSubscribtion( next, prev, record : AttributesContainer ){\n prev && prev.trigger && eventMap.unsubscribe( record, prev );\n\n next && next.trigger && eventMap.subscribe( record, next );\n }\n\n return this.metadata({\n changeHandlers : this.options.changeHandlers.concat( handleEventsSubscribtion )\n });\n }\n\n // Creates a copy of the spec.\n get has() : this {\n return this;\n }\n\n metadata( options : object ) : this {\n const cloned = new ChainableAttributeSpec( this.options );\n assign( cloned.options, options );\n return cloned as any;\n }\n\n value( x ) : this {\n return this.metadata({ value : x, hasCustomDefault : true });\n }\n\n static from( spec : any ) : ChainableAttributeSpec {\n // Pass metatype through untouched...\n if( spec && spec instanceof ChainableAttributeSpec ) {\n return spec;\n }\n\n return typeof spec === 'function' ? type( spec ) : value( spec );\n }\n}\n\nfunction emptyFunction(){}\n\nexport function type( this : void, Type : ChainableAttributeSpec | F, value? : any ) : ChainableAttributeSpec {\n if( Type instanceof ChainableAttributeSpec ) return Type;\n\n const attrDef = new ChainableAttributeSpec({ type : Type }),\n defaultValue = Type && value === void 0 ? getMetatype( Type ).defaultValue : value;\n\n return defaultValue === void 0 ? attrDef : attrDef.value( defaultValue );\n}\n\nexport function shared( this : void, Constructor : C ) : ChainableAttributeSpec {\n return new ChainableAttributeSpec({\n value : null,\n type : Constructor,\n _metatype : SharedType\n });\n}\n\n// Create attribute metatype inferring the type from the value.\nexport function value( this : void, x : any ) : ChainableAttributeSpec {\n const Type = inferType( x ),\n // Transactional types inferred from values must have shared type. \n AttrDef = Type && Type.prototype instanceof Transactional ? shared( Type ) :\n type( Type );\n\n return AttrDef.value( x );\n}\n\nfunction inferType( value : any ) : Function {\n switch( typeof value ) {\n case 'number' :\n return Number;\n case 'string' :\n return String;\n case 'boolean' :\n return Boolean;\n case 'function' :\n return Function;\n case 'undefined' :\n return void 0;\n case 'object' :\n return value ? value.constructor : void 0;\n }\n}","import { IOEndpoint } from '../io-tools';\nimport { eventsApi, tools as _ } from '../object-plus';\nimport { CompiledReference } from '../traversable';\nimport { ChainableAttributeSpec } from './attrDef';\nimport { AnyType } from './metatypes';\nimport { ConstructorsMixin, constructorsMixin } from './updates';\n\nexport interface RecordAttributesMixin extends ConstructorsMixin {\n // Attributes descriptors\n _attributes : AttributeDescriptors\n _attributesArray : AnyType[]\n \n // Attribute's property descriptors\n properties : PropertyDescriptorMap\n\n // Event map for record's local events.\n _localEvents? : eventsApi.EventMap,\n\n _endpoints : { [ name : string ] : IOEndpoint }\n}\n\nexport interface AttributeDescriptors {\n [ name : string ] : AnyType\n}\n\n// Create attribute from the type spec.\nexport function createAttribute( spec : any, name : string ) : AnyType {\n return AnyType.create( ChainableAttributeSpec.from( spec ).options, name );\n}\n\n// Create record mixin from the given record's attributes definition\nexport function createAttributesMixin( attributesDefinition : object, baseClassAttributes : AttributeDescriptors ) : RecordAttributesMixin {\n const myAttributes = _.transform( {} as AttributeDescriptors, attributesDefinition, createAttribute ),\n allAttributes = _.defaults( {} as AttributeDescriptors, myAttributes, baseClassAttributes );\n\n const ConstructorsMixin = constructorsMixin( allAttributes );\n\n return {\n ...ConstructorsMixin,\n _attributes : new ConstructorsMixin.AttributesCopy( allAttributes ),\n _attributesArray : Object.keys( allAttributes ).map( key => allAttributes[ key ] ),\n properties : _.transform( {}, myAttributes, x => x.createPropertyDescriptor() ),\n ...localEventsMixin( myAttributes ),\n _endpoints : _.transform( {}, allAttributes, attrDef => attrDef.options.endpoint )\n } \n}\n\ninterface LocalEventsMixin {\n _localEvents? : eventsApi.EventMap\n}\n\nfunction localEventsMixin( attrSpecs : AttributeDescriptors ) : LocalEventsMixin {\n let _localEvents : eventsApi.EventMap;\n\n for( var key in attrSpecs ){\n const attribute = attrSpecs[ key ],\n { _onChange } = attribute.options; \n\n if( _onChange ){\n _localEvents || ( _localEvents = new eventsApi.EventMap() );\n\n _localEvents.addEvent( 'change:' + key,\n typeof _onChange === 'string' ?\n createWatcherFromRef( _onChange, key ) : \n wrapWatcher( _onChange, key ) );\n }\n }\n\n return _localEvents ? { _localEvents } : {};\n}\n\nfunction wrapWatcher( watcher, key ){\n return function( record, value ){\n watcher.call( record, value, key );\n } \n}\n\nfunction createWatcherFromRef( ref : string, key : string ){\n const { local, resolve, tail } = new CompiledReference( ref, true );\n return local ?\n function( record, value ){\n record[ tail ]( value, key );\n } :\n function( record, value ){\n resolve( record )[ tail ]( value, key );\n }\n}","import { IOEndpoint, IONode, IOOptions, IOPromise, startIO } from '../io-tools';\n\nexport interface IORecord extends IONode {\n getEndpoint() : IOEndpoint\n save( options? : IOOptions ) : IOPromise\n fetch( options? : IOOptions ) : IOPromise\n destroy( options? : IOOptions ) : IOPromise\n toJSON( options? : object ) : any\n isNew() : boolean\n id : string | number\n set( json : object, options : object )\n}\n\nexport const IORecordMixin = {\n save( this : IORecord, options : IOOptions = {} ){\n const endpoint = this.getEndpoint(),\n json = this.toJSON( options );\n\n return startIO(\n this,\n this.isNew() ?\n endpoint.create( json, options, this ) :\n endpoint.update( this.id, json, options, this ),\n options,\n\n update => {\n this.set( update, { parse : true, ...options } );\n }\n );\n },\n\n fetch( options : IOOptions = {} ){\n return startIO(\n this,\n this.getEndpoint().read( this.id, options, this ),\n options,\n\n json => this.set( json, { parse : true, ...options } )\n );\n },\n\n destroy( options : IOOptions = {} ){ \n return startIO(\n this,\n this.getEndpoint().destroy( this.id, options, this ),\n options,\n\n () => {\n const { collection } = this;\n if( collection ){\n collection.remove( this, options );\n }\n else{\n this.dispose();\n }\n\n return this;\n }\n )\n }\n}","/**\n * Record core implementing transactional updates.\n * The root of all definitions. \n */\n\nimport { CollectionConstructor } from '../collection';\nimport { IOEndpoint, IOPromise } from '../io-tools';\nimport { define, definitions, isProduction, Logger, logger, LogLevel, mixinRules, tools } from '../object-plus';\nimport { CloneOptions, Owner, Transaction, Transactional, TransactionalDefinition, TransactionOptions } from '../transactions';\nimport { ChildrenErrors } from '../validation';\nimport { AggregatedType, AnyType } from './metatypes';\nimport { IORecord, IORecordMixin } from './io-mixin';\nimport { AttributesConstructor, AttributesContainer, AttributesCopyConstructor, AttributesValues, setAttribute, shouldBeAnObject, unknownAttrsWarning, UpdateRecordMixin } from './updates';\nimport { type } from './attrDef';\n\n\nconst { assign, isEmpty } = tools;\n\n/*******************************************************\n * Record core implementation\n */\n\nexport interface ConstructorOptions extends TransactionOptions{\n clone? : boolean\n}\n\n// Client unique id counter\nlet _cidCounter : number = 0;\n\n/***************************************************************\n * Record Definition as accepted by Record.define( definition )\n */\nexport interface RecordDefinition extends TransactionalDefinition {\n idAttribute? : string\n attributes? : AttributesValues\n collection? : object\n Collection? : typeof Transactional\n}\n\n@define({\n // Default client id prefix \n cidPrefix : 'm',\n\n // Name of the change event\n _changeEventName : 'change',\n\n // Default id attribute name\n idAttribute : 'id'\n})\n@definitions({\n defaults : mixinRules.merge,\n attributes : mixinRules.merge,\n collection : mixinRules.merge,\n Collection : mixinRules.value,\n idAttribute : mixinRules.protoValue\n})\nexport class Record extends Transactional implements IORecord, AttributesContainer, Iterable {\n static _metatype = AggregatedType;\n\n // Hack\n static onDefine( definition, BaseClass ){}\n\n static Collection : CollectionConstructor;\n static DefaultCollection : CollectionConstructor;\n \n // Attribute type for the record id.\n static id = type( String ).value( null );\n \n // Lazy object reference, serializable as id.\n static get ref(){\n return type( this )\n .toJSON( x => x ? x.id : null )\n .parse( x => {\n return { [ this.prototype.idAttribute ] : x };\n });\n }\n\n static defaults( attrs : AttributesValues ) : typeof Record {\n return this.extend({ attributes : attrs });\n }\n \n static attributes : AttributesValues\n\n /********************\n * IO Methods\n */\n _endpoints : { [ name : string ] : IOEndpoint }\n\n // Save record\n save( options? : object ) : IOPromise { throw new Error( 'Implemented by mixin' ); }\n\n // Destroy record\n destroy( options? : object ) : IOPromise { throw new Error( 'Implemented by mixin' ); }\n\n /***********************************\n * Core Members\n */\n // Previous attributes\n _previousAttributes : {}\n\n previousAttributes(){ return new this.AttributesCopy( this._previousAttributes ); } \n\n // Current attributes \n attributes : AttributesValues\n\n // Polymorphic accessor for aggregated attribute's canBeUpdated().\n get __inner_state__(){ return this.attributes; }\n\n // Lazily evaluated changed attributes hash\n _changedAttributes : AttributesValues\n\n get changed(){\n let changed = this._changedAttributes;\n\n if( !changed ){\n const prev = this._previousAttributes;\n changed = {};\n\n const { attributes } = this;\n\n for( let attr of this._attributesArray ){\n const key = attr.name,\n value = attributes[ key ];\n\n if( attr.isChanged( value, prev[ key ] ) ){\n changed[ key ] = value;\n }\n }\n\n this._changedAttributes = changed;\n }\n\n return changed; \n }\n\n changedAttributes( diff? : {} ) : boolean | {} {\n if( !diff ) return this.hasChanged() ? assign( {}, this.changed ) : false;\n\n var val, changed : {} | boolean = false,\n old = this._transaction ? this._previousAttributes : this.attributes,\n attrSpecs = this._attributes;\n\n for( var attr in diff ){\n if( !attrSpecs[ attr ].isChanged( old[ attr ], ( val = diff[ attr ] ) ) ) continue;\n (changed || (changed = {}))[ attr ] = val;\n }\n\n return changed; \n }\n\n hasChanged( key? : string ) : boolean {\n const { _previousAttributes } = this;\n if( !_previousAttributes ) return false;\n\n return key ?\n this._attributes[ key ].isChanged( this.attributes[ key ], _previousAttributes[ key ] ) :\n !isEmpty( this.changed );\n }\n\n previous( key : string ) : any {\n if( key ){\n const { _previousAttributes } = this;\n if( _previousAttributes ) return _previousAttributes[ key ];\n }\n \n return null;\n }\n\n isNew() : boolean {\n return this.id == null;\n }\n\n has( key : string ) : boolean {\n return this[ key ] != void 0;\n }\n\n // Return attribute value, setting an attribute to undefined.\n // TODO: If attribute was aggregated, don't dispose it.\n unset( key : string, options? ) : any {\n const value = this[ key ];\n this.set({ [ key ] : void 0 }, { unset : true, ...options });\n return value;\n }\n\n // Undocumented. Move to NestedTypes?\n clear( options? ) : this {\n const nullify = options && options.nullify;\n\n this.transaction( () =>{\n this.forEach( ( value, key ) => this[ key ] = nullify ? null : void 0 );\n }, options );\n\n return this;\n }\n\n // Returns Record owner skipping collections. TODO: Move out\n getOwner() : Owner {\n const owner : any = this._owner;\n\n // If there are no key, owner must be transactional object, and it's the collection.\n // We don't expect that collection can be the member of collection, so we're skipping just one level up. An optimization.\n return this._ownerKey ? owner : owner && owner._owner;\n }\n\n /***********************************\n * Identity managements\n */\n\n // Id attribute name ('id' by default)\n idAttribute : string;\n\n // Fixed 'id' property pointing to id attribute\n get id() : string { return this.attributes[ this.idAttribute ]; }\n set id( x : string ){ setAttribute( this, this.idAttribute, x ); }\n\n /***********************************\n * Dynamically compiled stuff\n */\n\n // Attributes specifications \n _attributes : { [ key : string ] : AnyType }\n _attributesArray : AnyType[]\n\n // Attributes object copy constructor\n Attributes : AttributesConstructor\n AttributesCopy : AttributesCopyConstructor\n\n // Create record default values, optionally augmenting given values.\n defaults( values = {} ){\n const defaults = {},\n { _attributesArray } = this;\n\n for( let attr of _attributesArray ){\n const key = attr.name,\n value = values[ key ];\n\n defaults[ key ] = value === void 0 ? attr.defaultValue() : value;\n }\n\n return defaults;\n }\n\n /***************************************************\n * Record construction\n */\n // Create record, optionally setting an owner\n constructor( a_values? : any, a_options? : ConstructorOptions ){\n super( _cidCounter++ );\n this.attributes = {};\n \n const options = a_options || {},\n values = ( options.parse ? this.parse( a_values, options ) : a_values ) || {};\n\n isProduction || typeCheck( this, values, options );\n\n this._previousAttributes = this.attributes = new this.Attributes( this, values, options );\n\n this.initialize( a_values, a_options );\n\n if( this._localEvents ) this._localEvents.subscribe( this, this );\n }\n\n // Initialization callback, to be overriden by the subclasses \n initialize( values? : Partial, options? ){}\n\n // Deeply clone record, optionally setting new owner.\n clone( options : CloneOptions = {} ) : this {\n const copy : this = new (this.constructor)( this.attributes, { clone : true } );\n \n if( options.pinStore ) copy._defaultStore = this.getStore();\n\n return copy;\n }\n\n // Validate attributes.\n _validateNested( errors : ChildrenErrors ) : number {\n var length = 0;\n\n const { attributes } = this;\n\n for( let attribute of this._attributesArray ){\n const { name } = attribute,\n error = attribute.validate( this, attributes[ name ], name );\n\n if( error ){\n errors[ name ] = error;\n length++;\n }\n }\n\n return length;\n }\n\n // Get attribute by key\n get( key : string ) : any {\n return this[ key ];\n }\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n set( values : any, options? : TransactionOptions ) : this {\n if( values ){ \n const transaction = this._createTransaction( values, options );\n transaction && transaction.commit();\n }\n\n return this;\n }\n\n /**\n * Serialization control\n */\n\n // Default record-level serializer, to be overriden by subclasses \n toJSON( options? : object ) : any {\n const json = {},\n { attributes } = this;\n\n for( let attribute of this._attributesArray ){\n const { name } = attribute,\n value = attributes[ name ];\n\n if( value !== void 0 ){\n // ...serialize it according to its spec.\n const asJson = attribute.toJSON.call( this, value, name, options );\n\n // ...skipping undefined values. Such an attributes are excluded.\n if( asJson !== void 0 ) json[ name ] = asJson; \n }\n }\n\n return json;\n }\n \n // Default record-level parser, to be overriden by the subclasses.\n parse( data, options? : TransactionOptions ){\n return data;\n }\n\n /**\n * Transactional control\n */\n deepSet( name : string, value : any, options? : any ){\n // Operation might involve series of nested object updates, thus it's wrapped in transaction.\n this.transaction( () => {\n const path = name.split( '.' ),\n l = path.length - 1,\n attr = path[ l ];\n\n let model = this;\n\n // Locate the model, traversing the path.\n for( let i = 0; i < l; i++ ){\n const key = path[ i ];\n\n // There might be collections in path, so use `get`.\n let next = model.get ? model.get( key ) : model[ key ];\n\n // Create models, if they are not exist.\n if( !next ){\n const attrSpecs = model._attributes;\n if( attrSpecs ){\n // If current object is model, create default attribute\n var newModel = attrSpecs[ key ].create();\n\n // If created object is model, nullify attributes when requested\n if( options && options.nullify && newModel._attributes ){\n newModel.clear( options );\n }\n\n model[ key ] = next = newModel;\n }\n // Silently fail in other case.\n else return;\n }\n \n model = next;\n }\n\n // Set model attribute.\n if( model.set ){\n model.set({ [ attr ] : value }, options );\n }\n else{\n model[ attr ] = value;\n }\n });\n\n return this;\n }\n \n // Returns owner without the key (usually it's collection)\n get collection() : any {\n return this._ownerKey ? null : this._owner;\n }\n\n // Dispose object and all childrens\n dispose(){\n if( this._disposed ) return;\n\n const { attributes } = this;\n\n for( let attr of this._attributesArray ){\n attr.dispose( this, attributes[ attr.name ] );\n }\n \n super.dispose();\n }\n\n _log( level : LogLevel, topic: string, text : string, props : object, a_logger? : Logger ) : void {\n ( a_logger || logger ).trigger( level, topic, this.getClassName() + ' ' + text, {\n ...props,\n 'Record' : this,\n 'Attributes definition' : this._attributes\n });\n }\n\n getClassName() : string {\n return super.getClassName() || 'Record';\n }\n\n // Dummies to \n _createTransaction( values : object, options : TransactionOptions ) : Transaction { return void 0; }\n // Simulate attribute change \n forceAttributeChange : ( key : string, options : TransactionOptions ) => void\n _onChildrenChange : ( child : Transactional, options : TransactionOptions ) => void\n\n\n /**\n * Map methods\n */\n\n forEach( iteratee : ( value? : any, key? : string ) => void, context? : any ){\n const fun = context !== void 0 ? ( v, k ) => iteratee.call( context, v, k ) : iteratee,\n { attributes } = this;\n\n for( const key in this.attributes ){\n const value = attributes[ key ];\n if( value !== void 0 ) fun( value, key );\n }\n }\n\n mapObject( a_fun : ( value, key ) => any, context? : any ) : object {\n const fun = context === void 0 ? a_fun : a_fun.bind( context );\n return tools.transform( {}, this.attributes, fun );\n }\n\n [ Symbol.iterator ](){\n return new RecordEntriesIterator( this );\n }\n\n entries(){\n return new RecordEntriesIterator( this );\n }\n\n // Get array of attribute keys (Record) or record ids (Collection) \n keys() : string[] {\n const keys : string[] = [];\n\n this.forEach( ( value, key ) => keys.push( key ) );\n\n return keys;\n }\n};\n\nassign( Record.prototype, UpdateRecordMixin, IORecordMixin );\n\n/***********************************************\n * Helper functions\n */\n\nclass BaseRecordAttributes {\n id : string\n\n constructor( record : Record, x : AttributesValues, options : TransactionOptions ) {\n this.id = x.id;\n }\n}\n\nRecord.prototype.Attributes = BaseRecordAttributes;\n\nclass BaseRecordAttributesCopy {\n id : string\n\n constructor( x : AttributesValues ) {\n this.id = x.id;\n }\n}\n\nRecord.prototype.AttributesCopy = BaseRecordAttributesCopy;\n\nconst IdAttribute = AnyType.create({ value : void 0 }, 'id' );\nRecord.prototype._attributes = { id : IdAttribute };\nRecord.prototype._attributesArray = [ IdAttribute ];\n\nfunction typeCheck( record : Record, values : object, options ){\n if( shouldBeAnObject( record, values, options ) ){\n const { _attributes } = record;\n let unknown : string[];\n\n for( let name in values ){\n if( !_attributes[ name ] ){\n unknown || ( unknown = [] );\n unknown.push( `'${ name }'` );\n }\n }\n\n if( unknown ){\n unknownAttrsWarning( record, unknown, { values }, options );\n }\n }\n}\n\nexport class RecordEntriesIterator implements Iterator<[string, any]> {\n private idx = 0;\n \n constructor( private readonly record : Record){}\n\n next() : IteratorResult<[string, any]> {\n const { record } = this,\n metatype = record._attributesArray[ this.idx++ ];\n\n return {\n done : !metatype,\n value : metatype ? [ metatype.name, record[ metatype.name ] ] : void 0\n };\n }\n}","import { CollectionConstructor } from '../collection';\nimport { define, predefine, TheType, tools } from '../object-plus';\nimport { Transactional } from '../transactions';\nimport { Infer, type } from './attrDef';\nimport { createAttributesMixin } from './mixin';\nimport { Record, RecordDefinition } from './record';\n\nexport * from './attrDef';\nexport * from './metatypes';\nexport { Record };\n\nconst { assign, defaults } = tools;\n\nexport type InferAttrs = {\n [K in keyof A]: Infer\n};\n\nexport interface RecordConstructor extends TheType {\n new ( attrs? : Partial, options? : object ) : Record & A\n prototype : Record\n Collection : CollectionConstructor\n}\n\nexport function attributes( attrDefs : D ) : RecordConstructor> {\n @define class DefaultRecord extends Record {\n static attributes = attrDefs;\n }\n\n return DefaultRecord as any;\n}\n\nRecord.onExtend = function( this : typeof Record, BaseClass : typeof Record ){\n Transactional.onExtend.call( this, BaseClass );\n\n // Create the default collection\n const Class = this;\n\n @predefine class DefaultCollection extends BaseClass.Collection {\n static model = Class;\n }\n\n this.DefaultCollection = DefaultCollection;\n\n // If there are no collection defined in statics, use the default collection.\n // It will appear in onDefine's definition, overriding all other settings.\n if( Class.Collection === BaseClass.Collection ){\n this.Collection = DefaultCollection;\n }\n}\n\nRecord.onDefine = function( definition : RecordDefinition, BaseClass : typeof Record ){\n const baseProto : Record = BaseClass.prototype;\n\n // Compile attributes spec, creating definition mixin.\n const { properties, _localEvents, ...dynamicMixin } = createAttributesMixin( this.attributes = getAttributes( definition ), baseProto._attributes );\n assign( this.prototype, dynamicMixin );\n \n definition.properties = defaults( definition.properties || {}, properties );\n definition._localEvents = _localEvents;\n \n Transactional.onDefine.call( this, definition, BaseClass );\n\n // Finalize the definition of the default collection.\n this.DefaultCollection.define( definition.collection || {} );\n\n // assign collection from the definition.\n this.Collection = definition.Collection;\n this.Collection.prototype.model = this;\n\n if( definition.endpoint ) this.Collection.prototype._endpoint = definition.endpoint; \n}\n\nfunction getAttributes({ defaults, attributes, idAttribute } : RecordDefinition ) {\n const definition = attributes || defaults || {};\n \n // If there is an undeclared idAttribute, add its definition as untyped generic attribute.\n if( idAttribute && !( idAttribute in definition ) ){\n definition[ idAttribute ] = void 0;\n }\n\n return definition;\n}\n\ndeclare var Reflect;\n\nexport function auto( value : any ) : PropertyDecorator;\nexport function auto( proto : object, attrName : string ) : void;\nexport function auto( proto, attrName? : string ) : any {\n if( typeof Reflect !== 'undefined' && Reflect.getMetadata ){\n if( attrName ){\n type( Reflect.getMetadata( \"design:type\", proto, attrName ) ).as( proto, attrName );\n }\n else{\n const value = proto;\n return ( proto : object, attrName : string ) : void => {\n type( Reflect.getMetadata( \"design:type\", proto, attrName ) ).value( value ).as( proto, attrName );\n }\n } \n }\n else{\n proto._log( 'error', 'Type-R:MissingImport', 'Add import \"reflect-metadata\"; as the first line of your app.' );\n } \n}","import { eventsApi, Logger } from '../object-plus';\nimport { Record } from '../record';\nimport { ItemsBehavior, Owner, Transaction, Transactional, transactionApi, TransactionOptions } from '../transactions';\n\n\nconst { trigger2, trigger3, on, off } = eventsApi,\n { commit } = transactionApi,\n _aquire = transactionApi.aquire, _free = transactionApi.free;\n\n/** @private */\nexport interface CollectionCore extends Transactional, Owner {\n _byId : IdIndex\n models : Record[]\n model : typeof Record\n idAttribute : string // TODO: Refactor inconsistent idAttribute usage\n _comparator : Comparator\n get( objOrId : string | Record | Object ) : Record \n _itemEvents? : eventsApi.EventMap\n _shared : number\n _aggregationError : Record[]\n\n _log( level : string, topic : string, text : string, value : any, logger : Logger ) : void\n}\n\n// Collection's manipulation methods elements\nexport type Elements = ( Object | Record )[];\n\nexport interface CollectionOptions extends TransactionOptions {\n sort? : boolean\n}\n\nexport type Comparator = ( a : Record, b : Record ) => number; \n\n/** @private */\nexport function dispose( collection : CollectionCore ) : Record[]{\n const { models } = collection;\n\n collection.models = [];\n collection._byId = {};\n\n freeAll( collection, models );\n return models;\n}\n\n/** @private */\nexport function convertAndAquire( collection : CollectionCore, attrs : {} | Record, options : CollectionOptions ){\n const { model } = collection;\n \n let record : Record;\n\n if( collection._shared ){\n record = attrs instanceof model ? attrs : model.create( attrs, options );\n\n if( collection._shared & ItemsBehavior.listen ){\n on( record, record._changeEventName, collection._onChildrenChange, collection );\n }\n }\n else{\n record = attrs instanceof model ? ( options.merge ? attrs.clone() : attrs ) : model.create( attrs, options );\n\n if( record._owner ){\n if( record._owner !== collection ){\n _aquire( collection, record.clone() );\n const errors = collection._aggregationError || ( collection._aggregationError = [] );\n errors.push( record );\n }\n }\n else{\n _aquire( collection, record ); \n }\n } \n\n // Subscribe for events...\n const { _itemEvents } = collection;\n _itemEvents && _itemEvents.subscribe( collection, record );\n\n return record;\n}\n\n/** @private */\nexport function free( owner : CollectionCore, child : Record, unset? : boolean ) : void {\n if( owner._shared ){\n if( owner._shared & ItemsBehavior.listen ){\n off( child, child._changeEventName, owner._onChildrenChange, owner );\n }\n }\n else{\n _free( owner, child );\n unset || child.dispose();\n }\n\n const { _itemEvents } = owner;\n _itemEvents && _itemEvents.unsubscribe( owner, child );\n}\n\n/** @private */\nexport function freeAll( collection : CollectionCore, children : Record[] ) : Record[] {\n for( let child of children ){\n free( collection, child );\n }\n\n return children;\n}\n\n/**\n * Silently sort collection, if its required. Returns true if sort happened.\n * @private\n */ \nexport function sortElements( collection : CollectionCore, options : CollectionOptions ) : boolean {\n let { _comparator } = collection;\n if( _comparator && options.sort !== false ){\n collection.models.sort( _comparator );\n return true;\n }\n\n return false;\n}\n\n/**********************************\n * Collection Index\n * @private \n */\nexport interface IdIndex {\n [ id : string ] : Record\n}\n\n/** @private Add record */ \nexport function addIndex( index : IdIndex, model : Record ) : void {\n index[ model.cid ] = model;\n var id = model.id;\n \n if( id || ( id as any ) === 0 ){\n index[ id ] = model;\n }\n}\n\n/** @private Remove record */ \nexport function removeIndex( index : IdIndex, model : Record ) : void {\n delete index[ model.cid ];\n var id = model.id;\n if( id || ( id as any ) === 0 ){\n delete index[ id ];\n }\n}\n\nexport function updateIndex( index : IdIndex, model : Record ){\n delete index[ model.previous( model.idAttribute ) ];\n\n const { id } = model;\n id == null || ( index[ id ] = model );\n}\n\n/***\n * In Collections, transactions appears only when\n * add remove or change events might be emitted.\n * reset doesn't require transaction.\n * \n * Transaction holds information regarding events, and knows how to emit them.\n * \n * Two major optimization cases.\n * 1) Population of an empty collection\n * 2) Update of the collection (no or little changes) - it's crucial to reject empty transactions.\n */\n\n\n// Transaction class. Implements two-phase transactions on object's tree.\n/** @private */ \nexport class CollectionTransaction implements Transaction {\n // open transaction\n constructor( public object : CollectionCore,\n public isRoot : boolean,\n public added : Record[],\n public removed : Record[],\n public nested : Transaction[],\n public sorted : boolean ){}\n\n // commit transaction\n commit( initiator? : Transactional ){\n const { nested, object } = this,\n { _isDirty } = object;\n\n // Commit all nested transactions...\n for( let transaction of nested ){\n transaction.commit( object );\n }\n\n if( object._aggregationError ){\n logAggregationError( object, _isDirty );\n }\n\n // Just trigger 'change' on collection, it must be already triggered for models during nested commits.\n // ??? TODO: do it in nested transactions loop? This way appears to be more correct. \n for( let transaction of nested ){\n trigger2( object, 'change', transaction.object, _isDirty );\n }\n\n // Notify listeners on attribute changes...\n const { added, removed } = this;\n\n // Trigger `add` events for both model and collection.\n for( let record of added ){\n trigger3( record, 'add', record, object, _isDirty );\n trigger3( object, 'add', record, object, _isDirty );\n }\n\n // Trigger `remove` events for both model and collection.\n for( let record of removed ){\n trigger3( record, 'remove', record, object, _isDirty );\n trigger3( object, 'remove', record, object, _isDirty );\n }\n\n if( this.sorted ){\n trigger2( object, 'sort', object, _isDirty );\n }\n\n if( added.length || removed.length ){\n trigger2( object, 'update', object, _isDirty );\n }\n\n this.isRoot && commit( object, initiator );\n }\n}\n\nexport function logAggregationError( collection : CollectionCore, options : TransactionOptions ){\n collection._log( 'warn', 'Type-R:InvalidOwner', 'added records already have an owner and were cloned. Use explicit record.clone() to dismiss this warning.', collection._aggregationError, options.logger );\n collection._aggregationError = void 0;\n}","import { Record } from '../record';\nimport { Transaction, transactionApi } from '../transactions';\nimport { addIndex, CollectionCore, CollectionOptions, CollectionTransaction, convertAndAquire, logAggregationError, sortElements, updateIndex } from './commons';\n\nconst { begin, commit, markAsDirty } = transactionApi;\n\nexport interface AddOptions extends CollectionOptions {\n at? : number \n}\n\n/** @private */\nexport function addTransaction( collection : CollectionCore, items : any[], options : AddOptions, merge? : boolean ){\n const isRoot = begin( collection ),\n nested : Transaction[]= [];\n\n var added = appendElements( collection, items, nested, options, merge );\n\n if( added.length || nested.length ){\n let needSort = sortOrMoveElements( collection, added, options );\n if( markAsDirty( collection, options ) ){\n return new CollectionTransaction( collection, isRoot, added, [], nested, needSort );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n // No changes...\n isRoot && commit( collection );\n};\n\n// Handle sort or insert at options for add operation. Reurns true if sort happened.\n/** @private */ \nfunction sortOrMoveElements( collection : CollectionCore, added : Record[], options : AddOptions ) : boolean {\n let at = options.at;\n\n // if `at` option is given, it overrides sorting option...\n if( at != null ){\n // Take an original collection's length. \n const length = collection.models.length - added.length;\n\n // Crazy Backbone rules about `at` index. I don't know what that guys smoke.\n at = Number( at );\n if( at < 0 ) at += length + 1;\n if( at < 0 ) at = 0;\n if( at > length ) at = length;\n\n // Move added elements to desired position. In place.\n moveElements( collection.models, at, added );\n return false;\n }\n\n return sortElements( collection, options );\n}\n\n/** @private */\nfunction moveElements( source : any[], at : number, added : any[] ) : void {\n for( var j = source.length - 1, i = j - added.length; i >= at; i--, j-- ){\n source[ j ] = source[ i ];\n }\n\n for( i = 0, j = at; i < added.length; i++, j++ ){\n source[ j ] = added[ i ];\n }\n}\n\n// append data to model and index\n/** @private */\nfunction appendElements( collection : CollectionCore, a_items : any[], nested : Transaction[], a_options : AddOptions, forceMerge : boolean ){\n var { _byId, models } = collection,\n merge = ( forceMerge || a_options.merge ) && !collection._shared,\n parse = a_options.parse,\n idAttribute = collection.model.prototype.idAttribute,\n prevLength = models.length;\n\n for( const item of a_items ){\n let model = item ? _byId[ item[ idAttribute ] ] || _byId[ item.cid ] : null;\n\n if( model ){\n if( merge && item !== model ){\n var attrs = item.attributes || item;\n const transaction = model._createTransaction( attrs, a_options );\n transaction && nested.push( transaction );\n\n if( model.hasChanged( idAttribute ) ){\n updateIndex( _byId, model );\n }\n }\n }\n else{\n model = convertAndAquire( collection, item, a_options );\n models.push( model );\n addIndex( _byId, model );\n }\n }\n\n return models.slice( prevLength );\n}\n","/*************\n * Remove items from collections.\n * \n * Cannot be a part of two-phase transaction on object tree.\n * Can be executed in the scope of ad-hoc transaction or from the trigger, though.\n *\n * Implemented with low-level API. \n * Most frequent operation - single element remove. Thus, it have the fast-path.\n */\n\nimport { eventsApi } from '../object-plus';\nimport { Record } from '../record';\nimport { transactionApi, TransactionOptions } from '../transactions';\nimport { CollectionCore, CollectionTransaction, free, removeIndex } from './commons';\n\nconst { trigger2, trigger3 } = eventsApi,\n { markAsDirty, begin, commit } = transactionApi;\n\n/** @private */\nexport function removeOne( collection : CollectionCore, el : Record | {} | string, options : TransactionOptions ) : Record {\n var model : Record = collection.get( el );\n\n if( model ){\n const isRoot = begin( collection ),\n models = collection.models;\n\n // Remove model form the collection. \n models.splice( models.indexOf( model ), 1 );\n removeIndex( collection._byId, model );\n \n // Mark transaction as dirty. \n const notify = markAsDirty( collection, options );\n\n // Send out events.\n if( notify ){\n trigger3( model, 'remove', model, collection, options );\n trigger3( collection, 'remove', model, collection, options );\n } \n\n free( collection, model, options.unset );\n\n notify && trigger2( collection, 'update', collection, options );\n\n // Commit transaction.\n isRoot && commit( collection );\n\n return model;\n }\n};\n\n/** Optimized for removing many elements\n * 1. Remove elements from the index, checking for duplicates\n * 2. Create new models array matching index\n * 3. Send notifications and remove references\n */\n\n/** @private */\nexport function removeMany( collection : CollectionCore, toRemove : any[], options ){\n const removed = _removeFromIndex( collection, toRemove, options.unset );\n if( removed.length ){\n const isRoot = begin( collection );\n\n _reallocate( collection, removed.length );\n\n if( markAsDirty( collection, options ) ){\n const transaction = new CollectionTransaction( collection, isRoot, [], removed, [], false );\n transaction.commit();\n }\n else{\n // Commit transaction.\n isRoot && commit( collection );\n }\n }\n\n return removed;\n};\n\n// remove models from the index...\n/** @private */\nfunction _removeFromIndex( collection, toRemove, unset : boolean ){\n var removed = Array( toRemove.length ),\n _byId = collection._byId;\n\n for( var i = 0, j = 0; i < toRemove.length; i++ ){\n var model = collection.get( toRemove[ i ] );\n if( model ){\n removed[ j++ ] = model;\n removeIndex( _byId, model );\n free( collection, model, unset );\n }\n }\n\n removed.length = j;\n\n return removed;\n}\n\n// Allocate new models array removing models not present in the index.\n/** @private */\nfunction _reallocate( collection, removed ){\n var prev = collection.models,\n models = collection.models = Array( prev.length - removed ),\n _byId = collection._byId;\n\n for( var i = 0, j = 0; i < prev.length; i++ ){\n var model = prev[ i ];\n\n if( _byId[ model.cid ] ){\n models[ j++ ] = model;\n }\n }\n\n models.length = j;\n}","import { Record } from '../record';\nimport { Transaction, transactionApi } from '../transactions';\nimport { addIndex, CollectionCore, CollectionOptions, CollectionTransaction, convertAndAquire, Elements, free, freeAll, IdIndex, logAggregationError, sortElements } from './commons';\n\nconst { begin, commit, markAsDirty } = transactionApi;\n\n/** @private */\nconst silentOptions = { silent : true };\n\n/** @private */\nexport function emptySetTransaction( collection : CollectionCore, items : Elements, options : CollectionOptions, silent? : boolean ){\n const isRoot = begin( collection );\n\n const added = _reallocateEmpty( collection, items, options );\n\n if( added.length ){\n const needSort = sortElements( collection, options );\n\n if( markAsDirty( collection, silent ? silentOptions : options ) ){\n // 'added' is the reference to this.models. Need to copy it.\n return new CollectionTransaction( collection, isRoot, added.slice(), [], [], needSort );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n // No changes...\n isRoot && commit( collection );\n};\n\n/** @private */\nexport function setTransaction( collection, items, options ){\n const isRoot = begin( collection ),\n nested = [];\n\n var previous = collection.models,\n added = _reallocate( collection, items, nested, options );\n\n const reusedCount = collection.models.length - added.length,\n removed = reusedCount < previous.length ? (\n reusedCount ? _garbageCollect( collection, previous ) :\n freeAll( collection, previous )\n ) : []; \n \n const addedOrChanged = nested.length || added.length,\n // As we are reallocating models array, it needs to be sorted even if there are no changes.\n sorted = ( sortElements( collection, options ) && addedOrChanged ) || added.length || options.sorted;\n\n if( addedOrChanged || removed.length || sorted ){\n if( markAsDirty( collection, options ) ){ \n return new CollectionTransaction( collection, isRoot, added, removed, nested, sorted );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n isRoot && commit( collection );\n};\n\n// Remove references to all previous elements, which are not present in collection.\n// Returns an array with removed elements.\n/** @private */\nfunction _garbageCollect( collection : CollectionCore, previous : Record[] ) : Record[]{\n const { _byId } = collection,\n removed = [];\n\n // Filter out removed models and remove them from the index...\n for( let record of previous ){\n if( !_byId[ record.cid ] ){\n removed.push( record );\n free( collection, record );\n }\n }\n\n return removed;\n}\n\n// reallocate model and index\n/** @private */\nfunction _reallocate( collection : CollectionCore, source : any[], nested : Transaction[], options ){\n var models = Array( source.length ),\n _byId : IdIndex = {},\n merge = ( options.merge == null ? true : options.merge ) && !collection._shared,\n _prevById = collection._byId,\n prevModels = collection.models, \n idAttribute = collection.model.prototype.idAttribute,\n toAdd = [],\n orderKept = true;\n\n // for each item in source set...\n for( var i = 0, j = 0; i < source.length; i++ ){\n var item = source[ i ],\n model : Record = null;\n\n if( item ){\n var id = item[ idAttribute ],\n cid = item.cid;\n\n if( _byId[ id ] || _byId[ cid ] ) continue;\n\n model = _prevById[ id ] || _prevById[ cid ];\n }\n\n if( model ){\n if( merge && item !== model ){\n if( orderKept && prevModels[ j ] !== model ) orderKept = false;\n\n var attrs = item.attributes || item;\n const transaction = model._createTransaction( attrs, options );\n transaction && nested.push( transaction );\n }\n }\n else{\n model = convertAndAquire( collection, item, options );\n toAdd.push( model );\n }\n\n models[ j++ ] = model;\n addIndex( _byId, model );\n }\n\n models.length = j;\n collection.models = models;\n collection._byId = _byId;\n\n if( !orderKept ) options.sorted = true;\n\n return toAdd;\n}\n\n/** @private */\nfunction _reallocateEmpty( self, source, options ){\n var len = source ? source.length : 0,\n models = Array( len ),\n _byId : IdIndex = {},\n idAttribute = self.model.prototype.idAttribute;\n\n for( var i = 0, j = 0; i < len; i++ ){\n var src = source[ i ];\n\n if( src && ( _byId[ src[ idAttribute ] ] || _byId[ src.cid ] ) ){\n continue;\n }\n\n var model = convertAndAquire( self, src, options );\n models[ j++ ] = model;\n addIndex( _byId, model );\n }\n\n models.length = j;\n self._byId = _byId;\n\n return self.models = models;\n}","import { IOPromise, startIO } from '../io-tools';\nimport { define, definitions, EventMap, eventsApi, EventsDefinition, Logger, logger, LogLevel, Mixable, mixinRules, TheType, tools } from '../object-plus';\nimport { AggregatedType, Record, SharedType } from '../record';\nimport { CloneOptions, ItemsBehavior, Transactional, TransactionalDefinition, transactionApi, TransactionOptions } from '../transactions';\nimport { AddOptions, addTransaction } from './add';\nimport { CollectionCore, CollectionTransaction, Elements, free, sortElements, updateIndex } from './commons';\nimport { removeMany, removeOne } from './remove';\nimport { emptySetTransaction, setTransaction } from './set';\n\n\nconst { trigger2 } = eventsApi,\n { begin, commit, markAsDirty } = transactionApi,\n { assign, defaults } = tools;\n\nlet _count = 0;\n\nexport type GenericComparator = string | ( ( x : Record ) => number ) | ( ( a : Record, b : Record ) => number ); \n\nexport interface CollectionOptions extends TransactionOptions {\n comparator? : GenericComparator\n model? : typeof Record\n}\n\nexport type Predicate = ( ( val : R, key? : number ) => boolean ) | Partial;\n\nexport interface CollectionDefinition extends TransactionalDefinition {\n model? : typeof Record,\n itemEvents? : EventsDefinition\n _itemEvents? : EventMap\n}\n\nclass CollectionRefsType extends SharedType {\n static defaultValue = [];\n}\n\nexport interface CollectionConstructor extends TheType {\n new ( records? : ElementsArg, options?: CollectionOptions ) : Collection\n prototype : Collection\n Refs : CollectionConstructor\n};\n\n@define({\n // Default client id prefix \n cidPrefix : 'c',\n model : Record,\n _changeEventName : 'changes',\n _aggregationError : null\n})\n@definitions({\n comparator : mixinRules.value,\n model : mixinRules.protoValue,\n itemEvents : mixinRules.merge\n})\nexport class Collection< R extends Record = Record> extends Transactional implements CollectionCore, Iterable {\n _shared : number\n _aggregationError : R[]\n\n static Subset : typeof Collection\n static Refs : CollectionConstructor\n static _SubsetOf : typeof Collection\n \n createSubset( models : ElementsArg, options? : CollectionOptions) : Collection{\n throw new ReferenceError( 'Failed dependency injection' )\n }\n\n static onExtend( BaseClass : typeof Transactional ){\n // Cached subset collection must not be inherited.\n const Ctor = this;\n this._SubsetOf = null;\n\n function RefsCollection( a, b, listen? ){\n Ctor.call( this, a, b, ItemsBehavior.share | ( listen ? ItemsBehavior.listen : 0 ) );\n }\n\n Mixable.mixins.populate( RefsCollection );\n \n RefsCollection.prototype = this.prototype;\n RefsCollection._metatype = CollectionRefsType;\n\n this.Refs = this.Subset = RefsCollection;\n\n Transactional.onExtend.call( this, BaseClass );\n }\n \n static onDefine( definition : CollectionDefinition, BaseClass : any ){\n if( definition.itemEvents ){\n const eventsMap = new EventMap( BaseClass.prototype._itemEvents );\n eventsMap.addEventsMap( definition.itemEvents );\n this.prototype._itemEvents = eventsMap;\n }\n\n if( definition.comparator !== void 0 ) this.prototype.comparator = definition.comparator;\n\n Transactional.onDefine.call( this, definition );\n }\n \n _itemEvents : EventMap\n\n /***********************************\n * Core Members\n */\n // Array of the records\n models : R[]\n\n // Polymorphic accessor for aggregated attribute's canBeUpdated().\n get __inner_state__(){ return this.models; }\n\n // Index by id and cid\n _byId : { [ id : string ] : R }\n\n set comparator( x : GenericComparator ){\n\n switch( typeof x ){\n case 'string' :\n this._comparator = ( a, b ) => {\n const aa = a[ x ], bb = b[ x ];\n if( aa === bb ) return 0;\n return aa < bb ? -1 : + 1;\n } \n break;\n case 'function' :\n if( x.length === 1 ){\n this._comparator = ( a, b ) => {\n const aa = (x).call( this, a ), bb = (x).call( this, b );\n if( aa === bb ) return 0;\n return aa < bb ? -1 : + 1;\n }\n }\n else{\n this._comparator = ( a, b ) => (x).call( this, a, b );\n }\n break;\n \n default :\n this._comparator = null;\n }\n }\n \n // TODO: Improve typing\n getStore() : Transactional {\n return this._store || ( this._store = this._owner ? this._owner.getStore() : this._defaultStore );\n }\n\n _store : Transactional\n\n get comparator(){ return this._comparator; }\n _comparator : ( a : R, b : R ) => number\n\n _onChildrenChange( record : R, options : TransactionOptions = {}, initiator? : Transactional ){\n // Ignore updates from nested transactions.\n if( initiator === this ) return;\n\n const { idAttribute } = this;\n\n if( record.hasChanged( idAttribute ) ){\n updateIndex( this._byId, record );\n }\n\n const isRoot = begin( this );\n\n if( markAsDirty( this, options ) ){\n // Forward change event from the record.\n trigger2( this, 'change', record, options )\n }\n\n isRoot && commit( this );\n }\n\n get( objOrId : string | { id? : string, cid? : string } ) : R {\n if( objOrId == null ) return;\n\n if( typeof objOrId === 'object' ){\n const id = objOrId[ this.idAttribute ];\n return ( id !== void 0 && this._byId[ id ] ) || this._byId[ objOrId.cid ];\n }\n else{\n return this._byId[ objOrId ];\n } \n }\n\n each( iteratee : ( val : R, key? : number ) => void, context? : any ) : void {\n this.models.forEach( iteratee, context );\n }\n\n // Loop through the members in the scope of transaction.\n // Transactional version of each()\n updateEach( iteratee : ( val : R, key? : number ) => void ){\n const isRoot = transactionApi.begin( this );\n this.models.forEach( iteratee );\n isRoot && transactionApi.commit( this );\n }\n\n _validateNested( errors : {} ) : number {\n // Don't validate if not aggregated.\n if( this._shared ) return 0;\n\n let count = 0;\n\n this.each( record => {\n const error = record.validationError;\n if( error ){\n errors[ record.cid ] = error;\n count++;\n }\n });\n\n return count;\n }\n\n model : typeof Record\n\n // idAttribute extracted from the model type.\n idAttribute : string\n\n constructor( records? : ElementsArg, options : CollectionOptions = {}, shared? : number ){\n super( _count++ );\n this.models = [];\n this._byId = {};\n \n this.comparator = this.comparator;\n\n if( options.comparator !== void 0 ){\n this.comparator = options.comparator;\n options.comparator = void 0;\n }\n \n this.model = this.model;\n \n if( options.model ){\n this.model = options.model;\n options.model = void 0;\n }\n\n this.idAttribute = this.model.prototype.idAttribute; //TODO: Remove?\n\n this._shared = shared || 0;\n\n if( records ){\n const elements = toElements( this, records, options );\n emptySetTransaction( this, elements, options, true );\n }\n\n this.initialize.apply( this, arguments );\n\n if( this._localEvents ) this._localEvents.subscribe( this, this );\n }\n\n initialize(){}\n\n first() : R { return this.models[ 0 ]; }\n last() : R { return this.models[ this.models.length - 1 ]; }\n at( a_index : number ) : R {\n const index = a_index < 0 ? a_index + this.models.length : a_index; \n return this.models[ index ];\n }\n\n // Deeply clone collection, optionally setting new owner.\n clone( options : CloneOptions = {} ) : this {\n const models = this._shared & ItemsBehavior.share ? this.models : this.map( model => model.clone() ),\n copy : this = new (this.constructor)( models, { model : this.model, comparator : this.comparator }, this._shared );\n \n if( options.pinStore ) copy._defaultStore = this.getStore();\n \n return copy;\n }\n\n toJSON( options? : object ) : any {\n return this.models.map( model => model.toJSON( options ) );\n }\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n set( elements : ElementsArg = [], options : TransactionOptions = {} ) : this {\n if( (options).add !== void 0 ){\n this._log( 'warn', \"Type-R:InvalidOption\", \"Collection.set doesn't support 'add' option, behaving as if options.add === true.\", options );\n }\n\n // Handle reset option here - no way it will be populated from the top as nested transaction.\n if( options.reset ){\n this.reset( elements, options )\n }\n else{\n const transaction = this._createTransaction( elements, options );\n transaction && transaction.commit();\n } \n\n return this; \n }\n\n /**\n * Enable or disable live updates.\n * \n * `true` enables full collection synchronization.\n * `false` cancel live updates.\n * `json => true | false` - filter updates\n */\n liveUpdates( enabled : LiveUpdatesOption ) : IOPromise {\n if( enabled ){\n this.liveUpdates( false );\n\n const filter = typeof enabled === 'function' ? enabled : () => true;\n\n this._liveUpdates = {\n updated : json => {\n filter( json ) && this.add( json, { parse : true, merge : true } );\n },\n\n removed : id => this.remove( id )\n };\n\n return this.getEndpoint().subscribe( this._liveUpdates, this ).then( () => this );\n }\n else{\n if( this._liveUpdates ){\n this.getEndpoint().unsubscribe( this._liveUpdates, this );\n this._liveUpdates = null;\n }\n\n // TODO: Return the resolved promise.\n }\n }\n\n _liveUpdates : object\n\n fetch( a_options : { liveUpdates? : LiveUpdatesOption } & TransactionOptions = {} ) : IOPromise {\n const options = { parse : true, ...a_options },\n endpoint = this.getEndpoint();\n\n return startIO(\n this,\n endpoint.list( options, this ),\n options,\n\n json => {\n let result : any = this.set( json, { parse : true, ...options } as TransactionOptions );\n \n if( options.liveUpdates ){\n result = this.liveUpdates( options.liveUpdates );\n }\n\n return result;\n }\n );\n }\n\n dispose() : void {\n if( this._disposed ) return;\n\n const aggregated = !this._shared;\n\n for( let record of this.models ){\n free( this, record );\n\n if( aggregated ) record.dispose();\n }\n\n this.liveUpdates( false );\n\n super.dispose();\n }\n\n reset( a_elements? : ElementsArg, options : TransactionOptions = {} ) : R[] {\n const isRoot = begin( this ),\n previousModels = this.models;\n\n // Make all changes required, but be silent.\n if( a_elements ){ \n emptySetTransaction( this, toElements( this, a_elements, options ), options, true );\n }\n else{\n this._byId = {};\n this.models = [];\n }\n\n markAsDirty( this, options );\n\n options.silent || trigger2( this, 'reset', this, defaults( { previousModels : previousModels }, options ) );\n\n // Dispose models which are not in the updated collection.\n const { _byId } = this;\n \n for( let toDispose of previousModels ){\n _byId[ toDispose.cid ] || free( this, toDispose );\n }\n\n isRoot && commit( this );\n return this.models;\n }\n\n // Add elements to collection.\n add( a_elements : ElementsArg , options : AddOptions = {} ){\n const elements = toElements( this, a_elements, options ),\n transaction = this.models.length ?\n addTransaction( this, elements, options ) :\n emptySetTransaction( this, elements, options );\n\n if( transaction ){\n transaction.commit();\n return transaction.added;\n }\n }\n\n // Remove elements. \n remove( recordsOrIds : any, options : CollectionOptions = {} ) : R[] | R {\n if( recordsOrIds ){\n return Array.isArray( recordsOrIds ) ?\n removeMany( this, recordsOrIds, options ) as R[]:\n removeOne( this, recordsOrIds, options ) as R;\n }\n\n return [];\n }\n\n // Apply bulk object update without any notifications, and return open transaction.\n // Used internally to implement two-phase commit. \n _createTransaction( a_elements : ElementsArg, options : TransactionOptions = {} ) : CollectionTransaction | void {\n const elements = toElements( this, a_elements, options );\n\n if( this.models.length ){\n return options.remove === false ?\n addTransaction( this, elements, options, true ) :\n setTransaction( this, elements, options );\n }\n else{\n return emptySetTransaction( this, elements, options );\n }\n }\n\n static _metatype = AggregatedType;\n\n /***********************************\n * Collection manipulation methods\n */\n\n pluck( key : K ) : R[K][] {\n return this.models.map( model => model[ key ] );\n }\n\n sort( options : TransactionOptions = {} ) : this {\n if( sortElements( this, options ) ){\n const isRoot = begin( this );\n \n if( markAsDirty( this, options ) ){\n trigger2( this, 'sort', this, options );\n }\n\n isRoot && commit( this );\n }\n\n return this;\n }\n\n // Remove and return given model.\n unset( modelOrId : R | string, options? ) : R {\n const value = this.get( modelOrId );\n this.remove( modelOrId, { unset : true, ...options } );\n return value;\n }\n\n modelId( attrs : {} ) : any {\n return attrs[ this.model.prototype.idAttribute ];\n }\n\n // Toggle model in collection.\n toggle( model : R, a_next? : boolean ) : boolean {\n var prev = Boolean( this.get( model ) ),\n next = a_next === void 0 ? !prev : Boolean( a_next );\n\n if( prev !== next ){\n if( prev ){\n this.remove( model );\n }\n else{\n this.add( model );\n }\n }\n\n return next;\n }\n\n _log( level : LogLevel, topic : string, text : string, value : object, a_logger? : Logger ) : void {\n ( a_logger || logger ).trigger( level, topic, `${ this.model.prototype.getClassName() }.${ this.getClassName() }: ` + text, {\n Argument : value,\n 'Attributes spec' : this.model.prototype._attributes\n });\n }\n\n getClassName() : string {\n return super.getClassName() || 'Collection';\n }\n\n /***********************************\n * Proxied Array methods\n */\n\n get length() : number { return this.models.length; }\n\n // Add a model to the end of the collection.\n push(model : ElementsArg, options? : CollectionOptions ) {\n return this.add(model, assign({at: this.length}, options));\n }\n\n // Remove a model from the end of the collection.\n pop( options? : CollectionOptions ) : R {\n var model = this.at(this.length - 1);\n this.remove(model, { unset : true, ...options });\n return model;\n }\n\n // Add a model to the beginning of the collection.\n unshift(model : ElementsArg, options? : CollectionOptions ) {\n return this.add(model, assign({at: 0}, options));\n }\n \n // Remove a model from the beginning of the collection.\n shift( options? : CollectionOptions ) : R {\n const model = this.at(0);\n this.remove( model, { unset : true, ...options } );\n return model;\n }\n\n // Slice out a sub-array of models from the collection.\n slice( begin? : number, end? : number ) : R[] {\n return this.models.slice( begin, end );\n }\n \n indexOf( modelOrId : string | Partial ) : number {\n return this.models.indexOf( this.get( modelOrId ) );\n }\n\n filter( iteratee : Predicate, context? : any ) : R[] {\n return this.models.filter( toPredicateFunction( iteratee ), context );\n }\n\n find( iteratee : Predicate, context? : any ) : R {\n return this.models.find( toPredicateFunction( iteratee ), context );\n }\n\n some( iteratee : Predicate, context? : any ) : boolean {\n return this.models.some( toPredicateFunction( iteratee ), context );\n }\n\n forEach( iteratee : ( val : R, key? : number ) => void, context? : any ) : void {\n this.models.forEach( iteratee, context );\n }\n \n [ Symbol.iterator ]() : IterableIterator {\n return this.models[ Symbol.iterator ]();\n }\n\n values() : IterableIterator {\n return this.models.values();\n }\n\n entries() : IterableIterator<[ number, R ]>{\n return this.models.entries();\n }\n\n every( iteratee : Predicate, context? : any ) : boolean {\n return this.models.every( toPredicateFunction( iteratee ), context );\n }\n\n includes( idOrObj : string | Partial ){\n return Boolean( this.get( idOrObj ) );\n }\n\n // Map members to an array\n map( iteratee : ( val : R, key? : number ) => T, context? : any ) : T[]{\n return this.models.map( iteratee, context );\n }\n\n reduce( iteratee : (previousValue: R, currentValue: R, currentIndex?: number ) => R ) : R\n reduce( iteratee : (previousValue: T, currentValue: R, currentIndex?: number ) => T, init? : any ) : T\n reduce( iteratee : (previousValue: any, currentValue: any, currentIndex?: number ) => any, init? : any ) : T | R {\n return init === void 0 ? this.models.reduce( iteratee ) : this.models.reduce( iteratee, init );\n }\n}\n\nexport type LiveUpdatesOption = boolean | ( ( x : any ) => boolean );\n\nexport type ElementsArg = Partial | Partial[]\n\n// TODO: make is safe for parse to return null (?)\nfunction toElements( collection : Collection, elements : ElementsArg, options : CollectionOptions ) : Elements {\n const parsed = options.parse ? collection.parse( elements, options ) : elements; \n return Array.isArray( parsed ) ? parsed : [ parsed ];\n}\n\nRecord.Collection = Collection;\n\nfunction toPredicateFunction( iteratee : Predicate ){\n switch( typeof iteratee ){\n case 'function' : return iteratee;\n case 'object' :\n const keys = Object.keys( iteratee );\n \n return x => {\n for( let key of keys ){\n if( iteratee[ key ] !== x[ key ] )\n return false;\n }\n\n return true;\n }\n default : throw new Error( 'Invalid iteratee' );\n }\n}","import { Collection } from '../collection';\nimport { Record } from '../record';\nimport { CompiledReference } from '../traversable';\n\nexport type CollectionReference = ( () => Collection ) | Collection | string; \n\n/** @private */\nexport function parseReference( collectionRef : CollectionReference ) : ( root : Record ) => Collection {\n switch( typeof collectionRef ){\n case 'function' :\n return root => (collectionRef).call( root );\n case 'object' :\n return () => collectionRef;\n case 'string' :\n const { resolve } = new CompiledReference( collectionRef );\n return resolve;\n }\n}","import { AnyType, ChainableAttributeSpec, Record } from '../record';\nimport { CollectionReference, parseReference } from './commons';\n\n\n/********\n * Reference to model by id.\n * \n * Untyped attribute. Holds model id, when unresolved. When resolved, is substituted\n * with a real model.\n * \n * No model changes are detected and counted as owner's change. That's intentional.\n */\n\n/** @private */\ntype RecordRefValue = Record | string;\n\n/** @private */\nclass RecordRefType extends AnyType {\n // It is always serialized as an id, whenever it's resolved or not. \n toJSON( value : RecordRefValue ){\n return value && typeof value === 'object' ? value.id : value;\n }\n\n // Wne \n clone( value : RecordRefValue ){\n return value && typeof value === 'object' ? value.id : value;\n }\n\n // Model refs by id are equal when their ids are equal.\n isChanged( a : RecordRefValue, b : RecordRefValue){\n var aId = a && ( (a).id == null ? a : (a).id ),\n bId = b && ( (b).id == null ? b : (b).id );\n\n return aId !== bId;\n }\n\n // Refs are always valid.\n validate( model, value, name ){}\n}\n\nexport function memberOf( this : void, masterCollection : CollectionReference, T? : R ) : ChainableAttributeSpec {\n const getMasterCollection = parseReference( masterCollection );\n\n const typeSpec = new ChainableAttributeSpec({\n value : null,\n _metatype : RecordRefType\n });\n \n return typeSpec\n .get( function( objOrId : RecordRefValue, name : string ) : Record {\n if( typeof objOrId === 'object' ) return objOrId;\n\n // So, we're dealing with an id reference. Resolve it.\n const collection = getMasterCollection( this );\n let record : Record = null;\n\n // If master collection exists and is not empty...\n if( collection && collection.length ){\n // Silently update attribute with record from this collection.\n record = collection.get( objOrId ) || null;\n this.attributes[ name ] = record;\n\n // Subscribe for events manually. delegateEvents won't be invoked.\n record && this._attributes[ name ].handleChange( record, null, this, {} );\n }\n\n return record;\n });\n}","import { Collection, CollectionConstructor } from '../collection';\nimport { define, tools } from '../object-plus';\nimport { AggregatedType, ChainableAttributeSpec, Record, type } from '../record';\nimport { ItemsBehavior, transactionApi } from '../transactions';\nimport { CollectionReference, parseReference } from './commons';\n\n\ntype RecordsIds = ( string | number )[];\n\nexport function subsetOf, R extends Record>( this : void, masterCollection : CollectionReference, T? : X ) : ChainableAttributeSpec{\n const CollectionClass = T || Collection,\n // Lazily define class for subset collection, if it's not defined already...\n SubsetOf = CollectionClass._SubsetOf || ( CollectionClass._SubsetOf = defineSubsetCollection( CollectionClass as any ) as any ),\n getMasterCollection = parseReference( masterCollection );\n\n return type( SubsetOf ).get(\n function( refs ){\n !refs || refs.resolvedWith || refs.resolve( getMasterCollection( this ) );\n return refs;\n }\n );\n}\n\nCollection.prototype.createSubset = function( models : any, options ) : Collection {\n const SubsetOf = subsetOf( this, this.constructor ).options.type,\n subset = new SubsetOf( models, options );\n \n subset.resolve( this );\n return subset;\n}\n\nconst subsetOfBehavior = ItemsBehavior.share | ItemsBehavior.persistent;\n\nfunction defineSubsetCollection( CollectionClass : typeof Collection ) {\n @define class SubsetOfCollection extends CollectionClass {\n refs : any[];\n resolvedWith : Collection = null;\n\n _metatype : AggregatedType\n\n get __inner_state__(){ return this.refs || this.models; }\n\n constructor( recordsOrIds?, options? ){\n super( [], options, subsetOfBehavior );\n this.refs = toArray( recordsOrIds );\n }\n\n // Remove should work fine as it already accepts ids. Add won't...\n add( a_elements, options = {} ){\n const { resolvedWith } = this,\n toAdd = toArray( a_elements );\n \n if( resolvedWith ){\n // If the collection is resolved already, everything is simple.\n return super.add( resolveRefs( resolvedWith, toAdd ), options );\n }\n else{\n // Collection is not resolved yet. So, we prepare the delayed computation.\n if( toAdd.length ){\n const isRoot = transactionApi.begin( this );\n\n // Save elements to resolve in future...\n this.refs = this.refs ? this.refs.concat( toAdd ) : toAdd.slice();\n\n transactionApi.markAsDirty( this, options );\n\n // And throw the 'changes' event.\n isRoot && transactionApi.commit( this );\n }\n }\n }\n\n reset( a_elements?, options = {} ){\n const { resolvedWith } = this,\n elements = toArray( a_elements );\n \n return resolvedWith ?\n // Collection is resolved, so parse ids and forward the call to set.\n super.reset( resolveRefs( resolvedWith, elements ), options ) :\n // Collection is not resolved yet. So, we prepare the delayed computation.\n delaySet( this, elements, options ) as any || [];\n }\n\n _createTransaction( a_elements, options? ){\n const { resolvedWith } = this,\n elements = toArray( a_elements );\n \n return resolvedWith ?\n // Collection is resolved, so parse ids and forward the call to set.\n super._createTransaction( resolveRefs( resolvedWith, elements ), options ) :\n // Collection is not resolved yet. So, we prepare the delayed computation.\n delaySet( this, elements, options );\n }\n\n // Serialized as an array of model ids.\n toJSON() : RecordsIds {\n return this.refs ?\n this.refs.map( objOrId => objOrId.id || objOrId ) :\n this.models.map( model => model.id );\n }\n\n // Subset is always valid.\n _validateNested(){ return 0; }\n\n get length() : number {\n return this.models.length || ( this.refs ? this.refs.length : 0 );\n }\n\n // Must be shallow copied on clone.\n clone( owner? ){\n var Ctor = (this).constructor,\n copy = new Ctor( [], {\n model : this.model,\n comparator : this.comparator\n });\n\n if( this.resolvedWith ){\n // TODO: bug here. \n copy.resolvedWith = this.resolvedWith;\n copy.refs = null;\n copy.reset( this.models, { silent : true } );\n }\n else{\n copy.refs = this.refs.slice();\n }\n\n return copy;\n }\n\n // Clean up the custom parse method possibly defined in the base class.\n parse( raw : any ) : Record[] {\n return raw;\n }\n\n resolve( collection : Collection ) : this {\n if( collection && collection.length ){\n this.resolvedWith = collection;\n\n if( this.refs ){\n this.reset( this.refs, { silent : true } );\n this.refs = null;\n }\n }\n\n return this;\n }\n\n getModelIds() : RecordsIds { return this.toJSON(); }\n\n toggle( modelOrId : any, val : boolean ) : boolean {\n return super.toggle( this.resolvedWith.get( modelOrId ), val );\n }\n\n addAll() : Record[] {\n if( this.resolvedWith ){\n this.set( this.resolvedWith.models );\n return this.models;\n }\n\n throw new Error( \"Cannot add elemens because the subset collection is not resolved yet.\" );\n }\n\n toggleAll() : Record[] {\n return this.length ? this.reset() : this.addAll();\n }\n }\n\n // Clean up all custom item events to prevent memory leaks.\n SubsetOfCollection.prototype._itemEvents = void 0;\n\n return SubsetOfCollection;\n}\n\nfunction resolveRefs( master, elements ){\n const records = [];\n \n for( let el of elements ){\n const record = master.get( el );\n if( record ) records.push( record );\n }\n\n return records;\n}\n\nfunction delaySet( collection, elements, options ) : void {\n if( tools.notEqual( collection.refs, elements ) ){\n const isRoot = transactionApi.begin( collection );\n\n // Save elements to resolve in future...\n collection.refs = elements.slice();\n\n transactionApi.markAsDirty( collection, options );\n \n // And throw the 'changes' event.\n isRoot && transactionApi.commit( collection );\n }\n}\n\nfunction toArray( elements ){\n return elements ? ( \n Array.isArray( elements ) ? elements : [ elements ]\n ) : [];\n}","import { Record } from '../record';\nimport { Transactional } from '../transactions';\n\nlet _store : Store = null;\n\nexport class Store extends Record {\n getStore() : Store { return this; }\n \n // delegate item lookup to owner, and to the global store if undefined\n get( name : string ) : any {\n // Lookup for resource in the current store. \n let local = this[ name ];\n\n // If something is found or it's the global store, return result.\n if( local || this === this._defaultStore ) return local;\n\n // Forward failed lookup to owner or global store.\n return this._owner ? this._owner.get( name ) : this._defaultStore.get( name ); \n }\n\n static get global(){ return _store; }\n static set global( store : Store ){\n if( _store ){\n _store.dispose();\n }\n\n Transactional.prototype._defaultStore = _store = store;\n }\n}\n\nStore.global = new Store();","// Dummy polyfill to prevent exception in IE.\nif( typeof Symbol === 'undefined' ){\n Object.defineProperty( window, 'Symbol', { value : { iterator : 'Symbol.iterator' }, configurable : true });\n}\n\nimport { Events, Mixable as Class } from './object-plus/';\n// Define synonims for NestedTypes backward compatibility.\nimport { Record as Model } from './record';\n\n/**\n * Export everything \n */\nexport * from './collection';\nexport * from './io-tools';\nexport * from './object-plus';\nexport * from './record';\nexport * from './relations';\nexport * from './transactions';\nexport { Model, Class };\n\n\nexport const { on, off, trigger, once, listenTo, stopListening, listenToOnce } = Events;\n\n/** Wrap model or collection method in transaction. */\nexport function transaction< F extends Function >( method : F ) : F {\n return function( ...args ){\n let result;\n \n this.transaction( () => {\n result = method.apply( this, args );\n });\n \n return result;\n }\n}"],"names":["defaults","dest","source","name","hasOwnProperty","arguments","length","i","other","isValidJSON","value","proto","Object","getPrototypeOf","prototype","Array","every","getBaseClass","Class","constructor","isEmpty","obj","key","some","fun","ArrayProto","arr","result","someArray","someObject","predicate","x","omit","discard","transform","assign","once","func","memo","first","apply","this","DateProto","Date","ObjectProto","notEqual","a","b","protoA","arraysNotEqual","keysA","keys","objectsNotEqual","HashProto","create","hashMap","hash","definition","_i","names","names_1","_a","name_1","prop","desc","getOwnPropertyDescriptor","o","map","EventMap","handlers","slice","addEventsMap","concat","addEvent","split","eventSplitter","getBubblingHandler","callback","name_2","push","EventDescriptor","target","event_1","on","event_2","off","handler","_bubblingHandlers","event","c","d","e","trigger5","trigger3","trigger2","context","next","listOff","_events","filteredHead","prev","head","ev","_callback","listSend3","call","EventHandler","once_1","_once","name_3","strings","api","events","test","self","queue","all","listSend2","listSend4","listSend5","f","listSend6","extendStatics","setPrototypeOf","__proto__","p","__extends","__","__assign","t","s","n","__rest","indexOf","getOwnPropertySymbols","__decorate","decorators","r","Reflect","decorate","defineProperty","Mixable","protoProps","staticProps","BaseClass","mixins","defineMixin","merge","mergeObject","getStaticDefinitions","onDefine","definitions","mergeInheritedMembers","spec","statics","TheSubclass","tslib_1.__extends","predefine","define","Constructor","__super__","MixinsState","get","populate","onExtend","ClassOrDefinition","Ctor","rules","definitionRules","definitionDecorator","definitionKey","mergeRules","appliedMixins","rule","mixins_1","mixin","isArray","sourceMixins","ctors","ctors_1","unshift","object","ignore","dontMix","getOwnPropertyNames","forEachOwnProp","sourceProp","_this","assignProperty","mixinRules","protoValue","baseProto","resolveRule","function","caller","list","destProp","configurable","pipe","classFirst","classLast","_idCount","uniqueId","cid","initialize","Messenger","localEvents","_localEvents","properties","eventsMap","defineProperties","toPropertyDescriptor","addReference","a_source","_listeningTo","removeAll","second","_disposed","stopListening","Events","listener","isProduction","process","env","NODE_ENV","logEvents","Logger","level","filter","topic","msg","props","args","toString","console","Error","counter","_super","window","something","body","join","JSON","stringify","logger","logEvents_1","logToConsole","throwingLogger","throwOn","log","trigger","bind","startIO","promise","options","thenDo","abortIO","ioUpdate","_ioPromise","then","resp","triggerAndBubble","catch","err","abort","eventSource","collection","referenceMask","reference","splitTail","path","match","substr","tail","pop","local","resolve","Function","shift","resolveReference","root","action","skip","getStore","getOwner","ItemsBehavior","_validateNested","nested","error","validate","ValidationError","iteratee","each","eachError","cidPrefix","Transactional","endpoint","_endpoint","Transactional_1","_owner","_ownerKey","_changeEventName","listenTo","isRoot","transactionApi","begin","update","set","commit","transaction","__inner_state__","_changeToken","json","strict","validationError","eachValidationError","getClassName","data","_defaultStore","getOwnerEndpoint","_endpoints","_validationError","getValidationError","_transaction","markAsDirty","dirty","silent","_isDirty","initiator","originalOptions","_onChildrenChange","aquire","owner","child","ReferenceError","free","_begin","_markAsDirty","setAttribute","record","_attributes","doUpdate","attributes","_previousAttributes","AttributesCopy","_changedAttributes","UpdateRecordMixin","attribute","propagateChanges","forceAttributeChange","_createTransaction","a_values","unknown","changes","values","parse","shouldBeAnObject","unknownAttrsWarning","RecordTransaction","nested_1","_log","nested_2","changes_1","_b","emptyOptions","a_options","getHooks","transforms","changeHandlers","type","toJSON","changeEvents","hasCustomDefault","defaultValue","tools.isValidJSON","isRequired","convert","getHook_1","getHook","reduce","chainGetHooks","validate_1","chainTransforms","handleChange","chainChangeHandlers","doInit","AnyType","model","v","isChanged","code","text","New value","Prev. value","prevHook","nextHook","prevTransform","nextTransform","prevHandler","nextHandler","ImmutableClassType","PrimitiveType","NumericType","num","isFinite","ArrayType","ObjectType","doNothing","FunctionType","DateType","date","timestamp","getTime","toISOString","supportsDate","isNaN","struct","minutesOffset","isoDatePattern","exec","k","numericKeys","undefined","UTC","safeParseDate","AggregatedType","clone","canBeUpdated","nestedTransaction","_shared","persistent","_handleChange","unset","dispose","shareAndListen","listen","share","SharedType","implicitObject","_onChange","builtins","String","Number","Boolean","metatypes","getMetatype","_metatype","idx","ChainableAttributeSpec","check","metadata","required","ref","emptyFunction","changed","eventMap","unsubscribe","subscribe","cloned","Type","attrDef","shared","inferType","createAttribute","from","createAttributesMixin","attributesDefinition","baseClassAttributes","myAttributes","_.transform","allAttributes","_.defaults","ConstructorsMixin","attrDefs","attrs","attr","Attributes","constructorsMixin","_attributesArray","createPropertyDescriptor","attrSpecs","eventsApi.EventMap","createWatcherFromRef","wrapWatcher","localEventsMixin","watcher","IORecordMixin","save","getEndpoint","isNew","id","fetch","read","destroy","remove","_cidCounter","typeCheck","Record","idAttribute","extend","diff","hasChanged","val","old","nullify","forEach","_attributesArray_1","copy","pinStore","errors","asJson","l","newModel","clear","a_logger","Attributes definition","a_fun","tools.transform","Symbol","iterator","RecordEntriesIterator","Collection","BaseRecordAttributes","BaseRecordAttributesCopy","IdAttribute","metatype","done","DefaultCollection","dynamicMixin","_aquire","_free","convertAndAquire","_aggregationError","_itemEvents","sortElements","_comparator","sort","models","addIndex","index","removeIndex","updateIndex","previous","added","removed","sorted","CollectionTransaction","logAggregationError","added_1","_d","removed_1","_e","addTransaction","items","a_items","forceMerge","_byId","prevLength","a_items_1","item","appendElements","needSort","at","length_1","j","moveElements","sortOrMoveElements","removeMany","toRemove","_removeFromIndex","_reallocate","silentOptions","emptySetTransaction","len","src","_reallocateEmpty","setTransaction","_prevById","prevModels","toAdd","orderKept","reusedCount","previous_1","_garbageCollect","children","children_1","freeAll","addedOrChanged","_count","CollectionRefsType","records","comparator","toElements","RefsCollection","_SubsetOf","Refs","Subset","itemEvents","aa","bb","_store","objOrId","count","a_index","elements","add","reset","enabled","liveUpdates","filter_1","_liveUpdates","updated","tslib_1.__assign","aggregated","a_elements","previousModels","previousModels_1","toDispose","recordsOrIds","el","splice","notify","removeOne","modelOrId","a_next","Argument","Attributes spec","end","toPredicateFunction","find","entries","idOrObj","init","parsed","keys_1","keys_2","parseReference","collectionRef","RecordRefType","subsetOf","masterCollection","T","CollectionClass","SubsetOf","subsetOfBehavior","refs","toArray","SubsetOfCollection","resolvedWith","resolveRefs","delaySet","raw","toggle","addAll","getMasterCollection","createSubset","subset","master","elements_1","tools.notEqual","Store","store","global","listenToOnce","method","reject","onAbort","fn","Promise","a_resolve","a_reject","listName","DefaultRecord","attrName","getMetadata","value_1","as"],"mappings":"kMAEgBA,EAAeC,EAAUC,GACrC,IAAK,IAAIC,KAAQD,EACTA,EAAOE,eAAgBD,KAAWF,EAAKG,eAAgBD,KACvDF,EAAME,GAASD,EAAQC,IAI/B,GAAuB,EAAnBE,UAAUC,OACV,IAAK,IAAIC,EAAI,EAAGA,EAAIF,UAAUC,OAAQC,IAAK,CACvC,IAAMC,EAAQH,UAAWE,GACzBC,GAASR,EAAUC,EAAMO,GAIjC,OAAOP,WAIKQ,EAAaC,GACzB,GAAc,OAAVA,EACA,OAAO,EAGX,cAAeA,GACf,IAAK,SACL,IAAK,SACL,IAAK,UACD,OAAO,EAEX,IAAK,SACD,IAAIC,EAAQC,OAAOC,eAAgBH,GAEnC,GAAIC,IAAUC,OAAOE,WAAaH,IAAUI,MAAMD,UAC9C,OAAOE,EAAON,EAAOD,GAI7B,OAAO,WAOKQ,EAAcC,GAC1B,OAAON,OAAOC,eAAgBK,EAAMJ,WAAYK,qBAWpCC,EAASC,GACrB,GAAIA,EACA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AAStY,EAASqY,GAAWA,EAAQ,IAAI9a,MAAO,iBAGvDkB,+RHmE4Bka,GACnC,OAAO,SAAkBppB,EAAOR,IACfQ,EAAMP,eAAgB2pB,GAC/BppB,EAAOopB,GAAcppB,EAAOopB,IAAcppB,EAAOopB,IAAc,IAAIzlB,SAElES,KAAK5E,yGkBpH4Bsd,GAK1C,mBAJQ,4DAER,OAFoC7T,OACzBogB,aAAavM,EADVuM,KAAblgB,GAAakgB,IAAsB/K,qBA+DlBte,EAAOspB,GACzB,GAAuB,oBAAZvhB,SAA2BA,QAAQwhB,YAAa,CACvD,IAAID,EAGA,CACA,IAAME,EAAQxpB,EACd,OAAO,SAAEA,EAAgBspB,GACrBhT,GAAMvO,QAAQwhB,YAAa,cAAevpB,EAAOspB,IAAavpB,MAAOypB,GAAQC,GAAIzpB,EAAOspB,IAL5FhT,GAAMvO,QAAQwhB,YAAa,cAAevpB,EAAOspB,IAAaG,GAAIzpB,EAAOspB,QAU7EtpB,EAAM6V,KAAM,QAAS,uBAAwB,+VO5DWwR,EAAwCC,GACpG,IAAMa,EAAsBlB,GAAgBI,GAO5C,OALiB,IAAIhM,GAA0B,CAC3Ctb,MAAQ,KACRob,UAAYgM,KAIX5d,IAAK,SAAUub,EAA0BtlB,GACtC,GAAuB,iBAAZslB,EAAuB,OAAOA,EAGzC,IAAM/U,EAAaoY,EAAqBrmB,MAClC0S,EAAkB,KAYxB,OATIzE,GAAcA,EAAWpQ,SAEzB6U,EAASzE,EAAWxG,IAAKub,IAAa,MACtChjB,KAAK6S,WAAYnV,GAASgV,IAGhB1S,KAAK2S,YAAajV,GAAO4X,aAAc5C,EAAQ,KAAM1S,KAAM,KAGlE0S"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../src/object-plus/tools.ts","../src/object-plus/eventsource.ts","../node_modules/tslib/tslib.es6.js","../src/object-plus/mixins.ts","../src/object-plus/events.ts","../src/object-plus/logging.ts","../src/io-tools.ts","../src/traversable.ts","../src/validation.ts","../src/transactions.ts","../src/record/updates.ts","../src/record/metatypes/any.ts","../src/record/metatypes/basic.ts","../src/record/metatypes/date.ts","../src/record/metatypes/owned.ts","../src/record/metatypes/shared.ts","../src/record/metatypes/index.ts","../src/record/attrDef.ts","../src/record/mixin.ts","../src/record/io-mixin.ts","../src/record/record.ts","../src/record/index.ts","../src/collection/commons.ts","../src/collection/add.ts","../src/collection/remove.ts","../src/collection/set.ts","../src/collection/arrayMethods.ts","../src/collection/index.ts","../src/relations/commons.ts","../src/relations/from.ts","../src/relations/subsetOf.ts","../src/relations/store.ts","../src/index.ts"],"sourcesContent":[" /** Similar to underscore `_.defaults` */\nexport function defaults< T >( dest : T, ...sources : Object[] ) : T\nexport function defaults< T >( dest : T, source : Object ) : T {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) && !dest.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n if( arguments.length > 2 ){\n for( let i = 2; i < arguments.length; i++ ){\n const other = arguments[ i ];\n other && defaults( dest, other );\n }\n }\n\n return dest;\n}\n\n/** Check if value is raw JSON */\nexport function isValidJSON( value : any ) : boolean {\n if( value === null ){\n return true;\n }\n\n switch( typeof value ){\n case 'number' :\n case 'string' :\n case 'boolean' :\n return true;\n\n case 'object':\n var proto = Object.getPrototypeOf( value );\n\n if( proto === Object.prototype || proto === Array.prototype ){\n return every( value, isValidJSON );\n }\n }\n\n return false;\n}\n\n/** Get the base class constructor function.\n * @param Class Subclass constructor function.\n * @returns Base class constructor function.\n */\nexport function getBaseClass( Class : Function ) {\n return Object.getPrototypeOf( Class.prototype ).constructor\n}\n\nexport function assignToClassProto( Class, definition : T, ...names : K[] ) : void {\n for( let name of names ){\n const value = definition[ name ];\n value === void 0 || ( Class.prototype[ name ] = value );\n }\n}\n\n/** Checks whenever given object is an empty hash `{}` */\nexport function isEmpty( obj : {} ) : boolean {\n if( obj ){\n for( let key in obj ){\n if( obj.hasOwnProperty( key ) ){\n return false;\n }\n }\n }\n\n return true;\n}\n\nexport type Iteratee = ( value : any, key? : string | number ) => any;\n\nfunction someArray( arr : any[], fun : Iteratee ) : any {\n let result;\n\n for( let i = 0; i < arr.length; i++ ){\n if( result = fun( arr[ i ], i ) ){\n return result;\n }\n }\n}\n\nfunction someObject( obj : {}, fun : Iteratee ) : any {\n let result;\n\n for( let key in obj ){\n if( obj.hasOwnProperty( key ) ){\n if( result = fun( obj[ key ], key ) ){\n return result;\n }\n }\n }\n}\n\n/** Similar to underscore `_.some` */\nexport function some( obj, fun : Iteratee ) : any {\n if( Object.getPrototypeOf( obj ) === ArrayProto ){\n return someArray( obj, fun );\n }\n else{\n return someObject( obj, fun );\n }\n}\n\n/** Similar to underscore `_.every` */\nexport function every( obj : { }, predicate : Iteratee ) : boolean {\n return !some( obj, x => !predicate( x ) );\n}\n\n/** Similar to `getOwnPropertyDescriptor`, but traverse the whole prototype chain. */\nexport function getPropertyDescriptor( obj : {}, prop : string ) : PropertyDescriptor {\n let desc : PropertyDescriptor;\n\n for( let proto = obj; !desc && proto; proto = Object.getPrototypeOf( proto ) ) {\n desc = Object.getOwnPropertyDescriptor( proto, prop );\n }\n\n return desc;\n}\n\n/** Similar to underscore `_.omit` */\nexport function omit( source : {}, ...rest : string[] ) : {}\nexport function omit( source ) : {} {\n const dest = {}, discard = {};\n\n for( let i = 1; i < arguments.length; i ++ ){\n discard[ arguments[ i ] ] = true;\n }\n\n for( var name in source ) {\n if( !discard.hasOwnProperty( name ) && source.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n return dest;\n}\n\n/** map `source` object properties with a given function, and assign the result to the `dest` object.\n * When `fun` returns `undefined`, skip this value. \n */\nexport function transform< A, B >( dest : { [ key : string ] : A }, source : { [ key : string ] : B }, fun : ( value : B, key : string ) => A | void ) : { [ key : string ] : A } {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) ) {\n var value = fun( source[ name ], name );\n value === void 0 || ( dest[ name ] = < A >value );\n }\n }\n\n return dest;\n}\n\nexport function fastAssign< A >( dest : A, source : {} ) : A {\n for( var name in source ) {\n dest[ name ] = source[ name ];\n }\n\n return dest;\n}\n\nexport function fastDefaults< A >( dest : A, source : {} ) : A {\n for( var name in source ) {\n if( dest[ name ] === void 0 ){\n dest[ name ] = source[ name ];\n }\n }\n\n return dest;\n}\n\n/** Similar to underscore `_.extend` and `Object.assign` */\nexport function assign< T >( dest : T, ...sources : Object[] ) : T\nexport function assign< T >( dest : T, source : Object ) : T {\n for( var name in source ) {\n if( source.hasOwnProperty( name ) ) {\n dest[ name ] = source[ name ];\n }\n }\n\n if( arguments.length > 2 ){\n for( let i = 2; i < arguments.length; i++ ){\n const other = arguments[ i ];\n other && assign( dest, other );\n }\n }\n\n return dest;\n}\n\n/** Similar to underscore `_.keys` */\nexport function keys( o : any ) : string[]{\n return o ? Object.keys( o ) : [];\n}\n\n/** Similar to underscore `_.once` */\nexport function once( func : Function ) : Function {\n var memo, first = true;\n return function() {\n if ( first ) {\n first = false;\n memo = func.apply(this, arguments);\n func = null;\n }\n return memo;\n };\n}\n\nconst ArrayProto = Array.prototype,\n DateProto = Date.prototype,\n ObjectProto = Object.prototype;\n\n/**\n * Determine whenever two values are not equal, deeply traversing \n * arrays and plain JS objects (hashes). Dates are compared by enclosed timestamps, all other\n * values are compared with strict comparison.\n */\nexport function notEqual( a : any, b : any) : boolean {\n if( a === b ) return false;\n\n if( a && b && typeof a == 'object' && typeof b == 'object' ) {\n const protoA = Object.getPrototypeOf( a );\n\n if( protoA !== Object.getPrototypeOf( b ) ) return true;\n\n switch( protoA ){\n case DateProto : return +a !== +b;\n case ArrayProto : return arraysNotEqual( a, b );\n case ObjectProto :\n case null:\n return objectsNotEqual( a, b );\n }\n }\n\n return true;\n}\n\nfunction objectsNotEqual( a, b ) {\n const keysA = Object.keys( a );\n\n if( keysA.length !== Object.keys( b ).length ) return true;\n\n for( let i = 0; i < keysA.length; i++ ) {\n const key = keysA[ i ];\n\n if( !b.hasOwnProperty( key ) || notEqual( a[ key ], b[ key ] ) ) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction arraysNotEqual( a, b ) {\n if( a.length !== b.length ) return true;\n\n for( let i = 0; i < a.length; i++ ) {\n if( notEqual( a[ i ], b[ i ] ) ) return true;\n }\n\n return false;\n}\n\n/**\n * Create an object without Object prototype members except hasOwnProperty.\n * @param obj - optional parameter to populate the hash map from.\n */\nconst HashProto = Object.create( null );\nHashProto.hasOwnProperty = ObjectProto.hasOwnProperty;\n\nexport function hashMap( obj? ){\n const hash = Object.create( HashProto );\n return obj ? assign( hash, obj ) : hash;\n}","import { once as _once } from './tools'\n\n/*******************\n * Prebuilt events map, used for optimized bulk event subscriptions.\n *\n * const events = new EventMap({\n * 'change' : true, // Resend this event from self as it is.\n * 'change:attr' : 'localTargetFunction',\n * 'executedInTargetContext' : function(){ ... }\n * 'executedInNativeContext' : '^props.handler'\n * })\n */\nexport interface EventsDefinition {\n [ events : string ] : Function | string | boolean\n}\n\n\nexport class EventMap {\n handlers : EventDescriptor[] = [];\n\n constructor( map? : EventsDefinition | EventMap ){\n if( map ){\n if( map instanceof EventMap ){\n this.handlers = map.handlers.slice();\n }\n else{\n map && this.addEventsMap( map );\n }\n }\n }\n\n merge( map : EventMap ){\n this.handlers = this.handlers.concat( map.handlers );\n }\n\n addEventsMap( map : EventsDefinition ){\n for( let names in map ){\n this.addEvent( names, map[ names ] )\n }\n }\n\n bubbleEvents( names : string ){\n for( let name of names.split( eventSplitter ) ){\n this.addEvent( name, getBubblingHandler( name ) );\n }\n }\n\n addEvent( names : string, callback : Function | string | boolean ){\n const { handlers } = this;\n\n for( let name of names.split( eventSplitter ) ){\n handlers.push( new EventDescriptor( name, callback ) );\n }\n }\n\n subscribe( target : {}, source : EventSource ){\n for( let event of this.handlers ){\n on( source, event.name, event.callback, target );\n }\n }\n\n unsubscribe( target : {}, source : EventSource ){\n for( let event of this.handlers ){\n off( source, event.name, event.callback, target );\n }\n }\n}\n\nexport class EventDescriptor {\n callback : Function\n\n constructor(\n public name : string,\n callback : Function | string | boolean\n ){\n if( callback === true ){\n this.callback = getBubblingHandler( name );\n }\n else if( typeof callback === 'string' ){\n this.callback =\n function localCallback(){\n const handler = this[ callback ];\n handler && handler.apply( this, arguments );\n };\n }\n else{\n this.callback = callback;\n }\n }\n}\n\nconst _bubblingHandlers = {};\n\nfunction getBubblingHandler( event : string ){\n return _bubblingHandlers[ event ] || (\n _bubblingHandlers[ event ] = function( a?, b?, c?, d?, e? ){\n if( d !== void 0 || e !== void 0 ) trigger5( this, event, a, b, c, d, e );\n if( c !== void 0 ) trigger3( this, event, a, b, c );\n else trigger2( this, event, a, b );\n }\n );\n}\n\nexport interface HandlersByEvent {\n [ name : string ] : EventHandler\n}\n\nexport class EventHandler {\n constructor( public callback : Callback, public context : any, public next = null ){}\n}\n\nfunction listOff( _events : HandlersByEvent, name : string, callback : Callback, context : any ){\n const head = _events[ name ];\n\n let filteredHead, prev;\n\n for( let ev = head; ev; ev = ev.next ){\n // Element must be kept\n if( ( callback && callback !== ev.callback && callback !== ev.callback._callback ) ||\n ( context && context !== ev.context ) ){\n \n prev = ev;\n filteredHead || ( filteredHead = ev );\n }\n // Element must be skipped\n else{\n if( prev ) prev.next = ev.next;\n }\n }\n\n if( head !== filteredHead ) _events[ name ] = filteredHead;\n}\n\nfunction listSend2( head : EventHandler, a, b ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b );\n}\n\nfunction listSend3( head : EventHandler, a, b, c ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c );\n}\n\nfunction listSend4( head : EventHandler, a, b, c, d ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d );\n}\n\nfunction listSend5( head : EventHandler, a, b, c, d, e ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d, e );\n}\n\nfunction listSend6( head : EventHandler, a, b, c, d, e, f ){\n for( let ev = head; ev; ev = ev.next ) ev.callback.call( ev.context, a, b, c, d, e, f );\n}\n\nexport interface Callback extends Function {\n _callback? : Function\n}\n\n/** @internal */\nexport function on( source : EventSource, name : string, callback : Callback, context? : any ) : void {\n if( callback ){\n const _events = source._events || ( source._events = Object.create( null ) );\n _events[ name ] = new EventHandler( callback, context, _events[ name ] );\n }\n}\n\n/** @internal */\nexport function once( source : EventSource, name : string, callback : Callback, context? : any ) : void {\n if( callback ){\n const once : Callback = _once( function(){\n off( source, name, once );\n callback.apply(this, arguments);\n });\n\n once._callback = callback;\n on( source, name, once, context );\n }\n}\n\n/** @internal */\nexport function off( source : EventSource, name? : string, callback? : Callback, context? : any ) : void {\n const { _events } = source;\n if( _events ){\n if( callback || context ) {\n if( name ){\n listOff( _events, name, callback, context );\n }\n else{\n for( let name in _events ){\n listOff( _events, name, callback, context );\n }\n }\n }\n else if( name ){\n _events[ name ] = void 0;\n }\n else{\n source._events = void 0;\n }\n }\n}\n\nexport interface EventSource {\n /** @internal */\n _events : HandlersByEvent\n}\n\nconst eventSplitter = /\\s+/;\n\n/** @internal */\nexport function strings( api : ApiEntry, source : EventSource, events : string, callback : Callback, context ){\n if( eventSplitter.test( events ) ){\n const names = events.split( eventSplitter );\n for( let name of names ) api( source, name, callback, context );\n }\n else api( source, events, callback, context );\n}\n\n/** @internal */\nexport type ApiEntry = ( source : EventSource, event : string, callback : Callback, context? : any ) => void\n\n/*********************************\n * Event-triggering API\n */\n\n/** @internal */\nexport function trigger2( self : EventSource, name : string, a, b ) : void {\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend2( queue, a, b );\n listSend3( all, name, a, b );\n }\n};\n\n/** @internal */\nexport function trigger3( self : EventSource, name : string, a, b, c ) : void{\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend3( queue, a, b, c );\n listSend4( all, name, a, b, c );\n }\n};\n\n/** @internal */\nexport function trigger5( self : EventSource, name : string, a, b, c, d, e ) : void{\n const { _events } = self;\n if( _events ){\n const queue = _events[ name ],\n { all } = _events;\n\n listSend5( queue, a, b, c, d, e );\n listSend6( all, name, a, b, c, d, e );\n }\n};","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","/*****************************************************************\n * Mixins engine and @define metaprogramming class extensions\n *\n * Vlad Balin & Volicon, (c) 2016-2017\n */\nimport { __extends } from 'tslib';\nimport { assign, defaults, getBaseClass, hashMap, transform } from './tools';\n\nexport interface Subclass< T > extends MixableConstructor {\n new ( ...args ) : T\n prototype : T\n}\n\nexport interface MixableConstructor extends Function{\n __super__? : object;\n mixins? : MixinsState;\n onExtend? : ( BaseClass : Function ) => void;\n onDefine? : ( definition : object, BaseClass : Function ) => void;\n define? : ( definition? : object, statics? : object ) => MixableConstructor;\n extend? : ( definition? : T, statics? : object ) => Subclass;\n}\n\nexport interface MixableDefinition {\n mixins? : Mixin[]\n}\n\n/**\n * Base class, holding metaprogramming class extensions.\n * Supports mixins and Class.define metaprogramming method.\n */\nexport class Mixable {\n static onExtend : ( BaseClass : Function ) => void;\n static onDefine : ( definition : object, BaseClass : Function ) => object; \n static __super__ : object\n static mixins : MixinsState;\n\n /** \n * Must be called after inheritance and before 'define'.\n */\n static define( protoProps : MixableDefinition = {}, staticProps? : object ) : MixableConstructor {\n const BaseClass : MixableConstructor = getBaseClass( this );\n\n // Assign statics.\n staticProps && assign( this, staticProps );\n\n // Extract and apply mixins from the definition.\n const { mixins, ...defineMixin } = protoProps;\n mixins && this.mixins.merge( mixins );\n\n // Unshift definition to the the prototype.\n this.mixins.mergeObject( this.prototype, defineMixin, true );\n\n // Unshift definition from statics to the prototype.\n this.mixins.mergeObject( this.prototype, this.mixins.getStaticDefinitions( BaseClass ), true );\n\n // Call onDefine hook, if it's present.\n this.onDefine && this.onDefine( this.mixins.definitions, BaseClass );\n \n // Apply merge rules to inherited members. No mixins can be added after this point.\n this.mixins.mergeInheritedMembers( BaseClass );\n\n return this;\n }\n\n /** Backbone-compatible extend method to be used in ES5 and for backward compatibility */\n static extend< T extends object>(spec? : T, statics? : {} ) : Subclass< T > {\n let TheSubclass : Subclass< T >;\n\n // 1. Create the subclass (ES5 compatibility shim).\n // If constructor function is given...\n if( spec && spec.hasOwnProperty( 'constructor' ) ){\n // ...we need to manually call internal TypeScript __extend function. Hack! Hack!\n TheSubclass = spec.constructor as any;\n __extends( TheSubclass, this );\n }\n // Otherwise, create the subclall in usual way.\n else{\n TheSubclass = class Subclass extends this {} as any;\n }\n\n predefine( TheSubclass );\n spec && TheSubclass.define( spec, statics );\n\n return TheSubclass;\n }\n}\n\n/** @decorator `@predefine` for forward definitions. Can be used with [[Mixable]] classes only.\n * Forwards the call to the [[Mixable.predefine]];\n */\nexport function predefine( Constructor : MixableConstructor ) : void {\n const BaseClass : MixableConstructor = getBaseClass( Constructor );\n\n // Legacy systems support\n Constructor.__super__ = BaseClass.prototype;\n \n // Initialize mixins structures...\n Constructor.define || MixinsState.get( Mixable ).populate( Constructor );\n\n // Make sure Ctor.mixins are ready before the callback...\n MixinsState.get( Constructor );\n\n // Call extend hook.\n Constructor.onExtend && Constructor.onExtend( BaseClass );\n}\n\n/** @decorator `@define` for metaprogramming magic. Can be used with [[Mixable]] classes only.\n * Forwards the call to [[Mixable.define]].\n */\nexport function define( ClassOrDefinition : Function ) : void;\nexport function define( ClassOrDefinition : object ) : ClassDecorator;\nexport function define( ClassOrDefinition : object | MixableConstructor ){\n // @define class\n if( typeof ClassOrDefinition === 'function' ){\n predefine( ClassOrDefinition );\n ( ClassOrDefinition as MixableConstructor ).define();\n }\n // @define({ prop : val, ... }) class\n else{\n return function( Ctor : MixableConstructor ){\n predefine( Ctor );\n Ctor.define( ClassOrDefinition );\n } as any;\n }\n}\n\nexport function definitions( rules : MixinMergeRules ) : ClassDecorator {\n return ( Class : Function ) => {\n const mixins = MixinsState.get( Class );\n mixins.definitionRules = defaults( hashMap(), rules, mixins.definitionRules );\n }\n}\n\n// Create simple property list decorator\nexport function propertyListDecorator( listName: string ) : PropertyDecorator {\n return function propList(proto, name : string) {\n const list = proto.hasOwnProperty( listName ) ?\n proto[ listName ] : (proto[ listName ] = (proto[ listName ] || []).slice()); \n\n list.push(name);\n }\n}\n\nexport function definitionDecorator( definitionKey, value ){\n return ( proto : object, name : string ) => {\n MixinsState\n .get( proto.constructor )\n .mergeObject( proto, {\n [ definitionKey ] : {\n [ name ] : value\n }\n });\n }\n}\n\nexport class MixinsState {\n mergeRules : MixinMergeRules;\n definitionRules : MixinMergeRules;\n definitions : object = {};\n appliedMixins : Mixin[];\n\n // Return mixins state for the class. Initialize if it's not exist.\n static get( Class ) : MixinsState {\n const { mixins } = Class;\n \n return mixins && Class === mixins.Class ? mixins :\n Class.mixins = new MixinsState( Class );\n }\n\n constructor( public Class : MixableConstructor ){\n const { mixins } = getBaseClass( Class );\n\n this.mergeRules = ( mixins && mixins.mergeRules ) || hashMap();\n this.definitionRules = ( mixins && mixins.definitionRules ) || hashMap();\n this.appliedMixins = ( mixins && mixins.appliedMixins ) || [];\n }\n\n getStaticDefinitions( BaseClass : Function ){\n const definitions = hashMap(),\n { Class } = this;\n\n return transform( definitions, this.definitionRules, ( rule, name ) =>{\n if( BaseClass[ name ] !== Class[ name ]){\n return Class[ name ];\n }\n });\n }\n\n merge( mixins : Mixin[] ){\n const proto = this.Class.prototype,\n { mergeRules } = this;\n\n // Copy applied mixins array as it's going to be updated.\n const appliedMixins = this.appliedMixins = this.appliedMixins.slice();\n\n // Apply mixins in sequence...\n for( let mixin of mixins ) {\n // Mixins array should be flattened.\n if( Array.isArray( mixin ) ) {\n this.merge( mixin );\n }\n // Don't apply mixins twice.\n else if( appliedMixins.indexOf( mixin ) < 0 ){\n appliedMixins.push( mixin );\n\n // For constructors, merge _both_ static and prototype members.\n if( typeof mixin === 'function' ){\n // Merge static members\n this.mergeObject( this.Class, mixin );\n\n // merge definitionRules and mergeRules\n const sourceMixins = ( mixin as any ).mixins;\n if( sourceMixins ){\n this.mergeRules = defaults( hashMap(), this.mergeRules, sourceMixins.mergeRules );\n this.definitionRules = defaults( hashMap(), this.definitionRules, sourceMixins.definitionRules );\n this.appliedMixins = this.appliedMixins.concat( sourceMixins.appliedMixins );\n }\n\n // Prototypes are merged according with rules.\n this.mergeObject( proto, mixin.prototype );\n }\n // Handle plain object mixins.\n else {\n this.mergeObject( proto, mixin );\n }\n }\n }\n }\n\n populate( ...ctors : Function[] ){\n for( let Ctor of ctors ) {\n MixinsState.get( Ctor ).merge([ this.Class ]);\n }\n }\n\n mergeObject( dest : object, source : object, unshift? : boolean ) {\n forEachOwnProp( source, name => {\n const sourceProp = Object.getOwnPropertyDescriptor( source, name );\n let rule : MixinMergeRule;\n\n if( rule = this.definitionRules[ name ] ){\n assignProperty( this.definitions, name, sourceProp, rule, unshift );\n }\n\n if( !rule || rule === mixinRules.protoValue ){\n assignProperty( dest, name, sourceProp, this.mergeRules[ name ], unshift );\n }\n });\n }\n\n mergeInheritedMembers( BaseClass : Function ){\n const { mergeRules, Class } = this;\n\n if( mergeRules ){\n const proto = Class.prototype,\n baseProto = BaseClass.prototype;\n\n for( let name in mergeRules ) {\n const rule = mergeRules[ name ];\n\n if( proto.hasOwnProperty( name ) && name in baseProto ){\n proto[ name ] = resolveRule( proto[ name ], baseProto[ name ], rule );\n }\n }\n }\n }\n}\n\nconst dontMix = {\n function : hashMap({\n length : true,\n prototype : true,\n caller : true,\n arguments : true,\n name : true,\n __super__ : true\n }),\n \n object : hashMap({\n constructor : true\n }) \n}\n\nfunction forEachOwnProp( object : object, fun : ( name : string ) => void ){\n const ignore = dontMix[ typeof object ];\n\n for( let name of Object.getOwnPropertyNames( object ) ) {\n ignore[ name ] || fun( name );\n }\n}\n\nexport interface MixinMergeRules {\n [ name : string ] : MixinMergeRule\n}\n\nexport type MixinMergeRule = ( a : any, b : any ) => any\nexport type Mixin = { [ key : string ] : any } | Function\n\n// @mixins( A, B, ... ) decorator.\nexport interface MixinRulesDecorator {\n ( rules : MixinMergeRules ) : ClassDecorator\n value( a : object, b : object) : object;\n protoValue( a : object, b : object) : object;\n merge( a : object, b : object ) : object;\n pipe( a: Function, b : Function ) : Function;\n defaults( a: Function, b : Function ) : Function;\n classFirst( a: Function, b : Function ) : Function;\n classLast( a: Function, b : Function ) : Function;\n every( a: Function, b : Function ) : Function;\n some( a: Function, b : Function ) : Function;\n}\n\nexport const mixins = ( ...list : Mixin[] ) => (\n ( Class : Function ) => MixinsState.get( Class ).merge( list )\n);\n\n// @mixinRules({ name : rule, ... }) decorator.\nexport const mixinRules = ( ( rules : MixinMergeRules ) => (\n ( Class : Function ) => {\n const mixins = MixinsState.get( Class );\n mixins.mergeRules = defaults( rules, mixins.mergeRules );\n }\n) ) as MixinRulesDecorator;\n\n// Pre-defined mixin merge rules\n\nmixinRules.value = ( a, b ) => a;\n\nmixinRules.protoValue = ( a, b ) => a;\n\n// Recursively merge members\nmixinRules.merge = ( a, b ) => defaults( {}, a, b );\n\n // Execute methods in pipe, with the class method executed last.\nmixinRules.pipe = ( a, b ) => (\n function( x : any ) : any {\n return a.call( this, b.call( this, x ) );\n }\n);\n\n // Assume methods return an object, and merge results with defaults (class method executed first)\nmixinRules.defaults = ( a : Function, b : Function ) => (\n function() : object {\n return defaults( a.apply( this, arguments ), b.apply( this, arguments ) );\n }\n);\n\n// Execute methods in sequence staring with the class method.\nmixinRules.classFirst = ( a : Function, b : Function ) => (\n function() : void {\n a.apply( this, arguments );\n b.apply( this, arguments );\n }\n);\n\n // Execute methods in sequence ending with the class method.\nmixinRules.classLast = ( a : Function, b : Function ) => (\n function() : void {\n b.apply( this, arguments );\n a.apply( this, arguments );\n }\n)\n\n // Execute methods in sequence returning the first falsy result.\nmixinRules.every = ( a : Function, b : Function ) =>(\n function() : any {\n return a.apply( this, arguments ) && b.apply( this, arguments );\n }\n);\n // Execute methods in sequence returning the first truthy result.\nmixinRules.some = ( a : Function, b : Function ) =>(\n function() : any {\n return a.apply( this, arguments ) || b.apply( this, arguments );\n }\n);\n\n/**\n * Helpers\n */\n\nfunction assignProperty( dest : object, name : string, sourceProp : PropertyDescriptor, rule : MixinMergeRule, unshift? : boolean ){\n// Destination prop is defined, thus the merge rules must be applied.\n if( dest.hasOwnProperty( name ) ){\n const destProp = Object.getOwnPropertyDescriptor( dest, name );\n\n if( destProp.configurable && 'value' in destProp ){\n dest[ name ] = unshift ?\n resolveRule( sourceProp.value, destProp.value, rule ) :\n resolveRule( destProp.value, sourceProp.value, rule ) ;\n }\n }\n // If destination is empty, just copy the prop over.\n else{\n Object.defineProperty( dest, name, sourceProp );\n }\n}\n\nfunction resolveRule( dest, source, rule : MixinMergeRule ){\n // When destination is empty, take the source.\n if( dest === void 0 ) return source;\n\n // In these cases we take non-empty destination:\n if( !rule || source === void 0 ) return dest;\n\n // In other cases we must merge values.\n return rule( dest, source );\n}","import * as _eventsApi from './eventsource';\nimport { EventMap, EventsDefinition, EventSource, HandlersByEvent } from './eventsource';\nimport { define, definitions, Mixable, MixableConstructor, mixinRules, MixinsState } from './mixins';\nimport { omit, transform } from './tools';\n\nconst { strings, on, off, once, trigger5, trigger2, trigger3 } = _eventsApi;\n\nlet _idCount = 0;\n\nfunction uniqueId() : string {\n return 'l' + _idCount++;\n}\n\nexport { EventMap, EventsDefinition };\n\nexport interface MessengerDefinition {\n _localEvents? : EventMap\n localEvents? : EventsDefinition\n properties? : PropertyMap\n [ name : string ] : any\n}\n\nexport interface PropertyMap {\n [ name : string ] : Property\n}\n\nexport type Property = PropertyDescriptor | ( () => any )\n\nexport interface MessengersByCid {\n [ cid : string ] : Messenger\n}\n\nexport type EventCallbacks = { [ events : string ] : EventCallback }\nexport type EventCallback = ( this : Context, ...args : any[] ) => void\n\n/*************************\n * Messenger is mixable class with capabilities of sending and receiving synchronous events.\n * This class itself can serve as both mixin and base class.\n */\n\n@define\n@definitions({\n properties : mixinRules.merge,\n localEvents : mixinRules.merge\n})\nexport class Messenger implements Mixable, EventSource {\n // Define extendable mixin static properties.\n /** @internal */\n static __super__ : object;\n static mixins : MixinsState;\n static onExtend : ( BaseClass : Function ) => void;\n static define : ( definition? : MessengerDefinition, statics? : object ) => MixableConstructor;\n static extend : ( definition? : MessengerDefinition, statics? : object ) => MixableConstructor;\n static onDefine({ localEvents, _localEvents, properties } : MessengerDefinition, BaseClass? : typeof Mixable ){\n // Handle localEvents definition\n if( localEvents || _localEvents ){\n const eventsMap = new EventMap( this.prototype._localEvents );\n\n localEvents && eventsMap.addEventsMap( localEvents );\n _localEvents && eventsMap.merge( _localEvents );\n \n this.prototype._localEvents = eventsMap;\n }\n\n // Handle properties definitions...\n if( properties ){\n Object.defineProperties( this.prototype, transform( {}, properties, toPropertyDescriptor ) );\n }\n }\n\n /** @internal */ \n _events : HandlersByEvent = void 0;\n\n /** @internal */ \n _listeningTo : MessengersByCid = void 0\n\n /** Unique client-only id. */\n cid : string\n\n /** @internal Prototype-only property to manage automatic local events subscription */ \n _localEvents : EventMap\n\n constructor(){\n this.cid = uniqueId();\n this.initialize.apply( this, arguments );\n\n // TODO: local events subscribe?\n }\n\n /** Method is called at the end of the constructor */\n initialize() : void {}\n \n on( events : string | EventCallbacks, callback?, context? ) : this {\n if( typeof events === 'string' ) strings( on, this, events, callback, context );\n else for( let name in events ) strings( on, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n once( events : string | EventCallbacks, callback?, context? ) : this {\n if( typeof events === 'string' ) strings( once, this, events, callback, context );\n else for( let name in events ) strings( once, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n off( events? : string | EventCallbacks, callback?, context? ) : this {\n if( !events ) off( this, void 0, callback, context );\n else if( typeof events === 'string' ) strings( off, this, events, callback, context );\n else for( let name in events ) strings( off, this, name, events[ name ], context || callback );\n\n return this;\n }\n\n // Trigger one or many events, firing all bound callbacks. Callbacks are\n // passed the same arguments as `trigger` is, apart from the event name\n // (unless you're listening on `\"all\"`, which will cause your callback to\n // receive the true name of the event as the first argument).\n trigger(name : string, a?, b?, c?, d?, e? ) : this {\n if( d !== void 0 || e !== void 0 ) trigger5( this, name, a, b, c, d, e );\n else if( c !== void 0 ) trigger3( this, name, a, b, c );\n else trigger2( this, name, a, b );\n return this;\n }\n\n listenTo( source : Messenger, a : string | EventCallbacks, b? : Function ) : this {\n if( source ){\n addReference( this, source );\n source.on( a, !b && typeof a === 'object' ? this : b, this );\n }\n\n return this;\n }\n\n listenToOnce( source : Messenger, a : string | EventCallbacks, b? : Function ) : this {\n if( source ){\n addReference( this, source );\n source.once( a, !b && typeof a === 'object' ? this : b, this );\n }\n\n return this;\n }\n\n stopListening( a_source? : Messenger, a? : string | EventCallbacks, b? : Function ) : this {\n const { _listeningTo } = this;\n if( _listeningTo ){\n const removeAll = !( a || b ),\n second = !b && typeof a === 'object' ? this : b;\n\n if( a_source ){\n const source = _listeningTo[ a_source.cid ];\n if( source ){\n if( removeAll ) delete _listeningTo[ a_source.cid ];\n source.off( a, second, this );\n }\n }\n else if( a_source == null ){\n for( let cid in _listeningTo ) _listeningTo[ cid ].off( a, second, this );\n\n if( removeAll ) ( this._listeningTo = void 0 );\n }\n }\n\n return this;\n }\n\n /**\n * Destructor. Stops messenger from listening to all objects,\n * and stop others from listening to the messenger. \n */\n _disposed : boolean\n\n dispose() : void {\n if( this._disposed ) return;\n\n this.stopListening();\n this.off();\n\n this._disposed = true;\n }\n}\n\n/**\n * Backbone 1.2 API conformant Events mixin.\n */\nexport const Events : Messenger = omit( Messenger.prototype, 'constructor', 'initialize' );\n\n/**\n * Messenger Private Helpers \n */\n\nfunction toPropertyDescriptor( x : Property ) : PropertyDescriptor {\n if( x ){\n return typeof x === 'function' ? { get : < () => any >x, configurable : true } : x;\n }\n}\n\nfunction addReference( listener : Messenger, source : Messenger ){\n const listeningTo = listener._listeningTo || (listener._listeningTo = Object.create( null ) ),\n cid = source.cid || ( source.cid = uniqueId() );\n\n listeningTo[ cid ] = source;\n}","import { Messenger } from './events'\nimport { define } from './mixins';\n\nexport type LogLevel = 'error' | 'warn' | 'debug' | 'info' | 'log';\nexport type LoggerEventHandler = ( topic : string, msg : string, props : object ) => void;\n\nexport const isProduction = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production',\n logEvents : LogLevel[] = isProduction ?\n [ 'error', 'info' ] :\n [ 'error', 'warn', 'debug', 'info', 'log' ];\n\n@define\nexport class Logger extends Messenger {\n counter : { [ level in LogLevel ]? : number } = {}\n\n // Log events of the given log level to the console, optionally filtered by topic\n logToConsole( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n const args = [ `[${topic}] ${msg}` ];\n \n for( let name in props ){\n args.push( `\\n\\t${name}:`, toString( props[ name ] ) );\n }\n \n console[ level ].apply( console, args );\n }\n });\n }\n\n // Fire exception on the events of the given log level, optionally filtered by topic\n throwOn( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n throw new Error( `[${topic}] ${msg}` );\n }\n });\n }\n\n // Count log events of the given level, optionally filtered by topic\n count( level : LogLevel, filter? : RegExp ) : this {\n return this.on( level, ( topic, msg, props ) => {\n if( !filter || filter.test( topic ) ){\n this.counter[ level ] = ( this.counter[ level ] || 0 ) + 1;\n }\n });\n }\n\n trigger : ( level : LogLevel, topic : string, message : string, props? : object ) => this;\n \n off : ( event? : LogLevel ) => this;\n\n\n on( handlers : { [ name in LogLevel ] : LoggerEventHandler } ) : this;\n on( handlers : LogLevel, handler : LoggerEventHandler ) : this;\n on( handlers : 'all', handler : ( level : LogLevel, topic : string, msg : string, props : object ) => void ) : this;\n on( a : any, b? : any ){\n return super.on( a, b );\n }\n}\n\n/**\n * Convert objects to the plain text friendly format.\n * primitives as in JSON.\n */\nlet toString = typeof window === 'undefined' ? \n something => {\n if( something && typeof something === 'object' ){\n const { __inner_state__ } = something,\n value = __inner_state__ || something,\n isArray = Array.isArray( value );\n\n const body = isArray ? `[ length = ${ value.length } ]` : `{ ${ Object.keys( value ).join( ', ' )} }`;\n\n return something.constructor.name + ' ' + body;\n }\n\n return JSON.stringify( something );\n }\n : x => x;\n\nexport const logger = new Logger();\n\nif( typeof console !== 'undefined' ) {\n for( let event of logEvents ){\n logger.logToConsole( event );\n }\n}\n\nexport const throwingLogger = new Logger();\nthrowingLogger.throwOn( 'error' ).throwOn( 'warn' );\n\nexport const log : typeof logger.trigger = logger.trigger.bind( logger );","export interface IONode {\n /** @internal */\n _endpoint : IOEndpoint\n\n /** @internal */\n _ioPromise : IOPromise< this >\n}\n\nexport interface IOPromise extends Promise {\n abort? : () => void\n}\n\nexport interface IOEndpoint {\n list( options : IOOptions, collection? ) : IOPromise\n create( json : any, options : IOOptions, record? ) : IOPromise\n update( id : string | number, json :any, options : IOOptions, record? ) : IOPromise\n read( id : string | number, options : IOOptions, record? ) : IOPromise\n destroy( id : string | number, options : IOOptions, record? ) : IOPromise\n subscribe( events : IOEvents, collection? ) : IOPromise\n unsubscribe( events : IOEvents, collection? ) : void\n}\n\nexport interface IOOptions {\n ioMethod? : 'save' | 'fetch'\n}\n\nexport interface IOEvents {\n updated? : ( json : any ) => void\n removed? : ( json : any ) => void\n}\n\nexport function getOwnerEndpoint( self ) : IOEndpoint {\n // Check if we are the member of the collection...\n const { collection } = self;\n if( collection ){\n return getOwnerEndpoint( collection );\n }\n\n // Now, if we're the member of the model...\n if( self._owner ){\n const { _endpoints } = self._owner;\n return _endpoints && _endpoints[ self._ownerKey ];\n }\n}\n\n/**\n * Create abortable promise.\n * Adds `promise.abort()` function which rejects the promise by default\n * initialize() function takes third optional argument `abort : ( resolve, reject ) => void`,\n * which can be used to add custom abort handling.\n */\ndeclare var Promise: PromiseConstructorLike;\n\nexport function createIOPromise( initialize : InitIOPromise ) : IOPromise{\n let resolve, reject, onAbort;\n\n function abort( fn ){\n onAbort = fn;\n }\n\n const promise : IOPromise = new Promise( ( a_resolve, a_reject ) =>{\n reject = a_reject;\n resolve = a_resolve;\n initialize( resolve, reject, abort );\n }) as IOPromise;\n\n promise.abort = () => {\n onAbort ? onAbort( resolve, reject ) : reject( new Error( \"I/O Aborted\" ) );\n }\n\n return promise;\n}\n\nexport type InitIOPromise = ( resolve : ( x? : any ) => void, reject : ( x? : any ) => void, abort? : ( fn : Function ) => void ) => void;\n\nexport function startIO( self : IONode, promise : IOPromise, options : IOOptions, thenDo : ( json : any ) => any ) : IOPromise {\n // Stop pending I/O first...\n abortIO( self );\n\n self._ioPromise = promise\n .then( resp => {\n self._ioPromise = null;\n \n const result = thenDo ? thenDo( resp ) : resp;\n \n triggerAndBubble( self, 'sync', self, resp, options );\n \n return result;\n } ) \n .catch( err => {\n self._ioPromise = null;\n \n // Overlaps with a new `error` event.\n triggerAndBubble( self, 'error', self, err, options );\n \n throw err;\n } ) as IOPromise;\n\n self._ioPromise.abort = promise.abort;\n\n return self._ioPromise;\n}\n\nexport function abortIO( self : IONode ){\n if( self._ioPromise && self._ioPromise.abort ){\n self._ioPromise.abort();\n self._ioPromise = null;\n }\n}\n\nexport function triggerAndBubble( eventSource, ...args ){\n eventSource.trigger.apply( eventSource, args );\n const { collection } = eventSource;\n collection && collection.trigger.apply( collection, args ); \n}","/**\n * Traversable objects and symbolic references\n */\nexport interface Traversable {\n getStore() : Traversable\n getOwner() : Traversable\n get( key : string ) : any \n}\n\nconst referenceMask = /\\^|(store\\.[^.]+)|([^.]+)/g;\n\n// Compile reference to function\nexport type ResolveReference = ( root : Traversable ) => any; \n\nexport class CompiledReference {\n resolve : ResolveReference\n tail : string\n local : boolean\n\n constructor( reference : string, splitTail : boolean = false ){\n const path = reference\n .match( referenceMask )\n .map( key => {\n if( key === '^' || key === 'owner' ) return 'getOwner()';\n\n if( key[ 0 ] === '~' ) return `getStore().get(\"${ key.substr( 1 ) }\")`;\n\n if( key.indexOf( 'store.' ) === 0 ) return `getStore().get(\"${ key.substr( 6 ) }\")`;\n \n return key;\n } );\n \n this.tail = splitTail && path.pop();\n this.local = !path.length;\n \n this.resolve = new Function( 'self', `\n var v = self.${ path.shift() };\n \n ${ path.map( x => `\n v = v && v.${ x };\n `).join('')}\n\n return v;\n ` );\n }\n}\n\nexport function resolveReference( root : Traversable, reference : string, action : ( object, key : string ) => any ) : any {\n const path = reference.match( referenceMask ),\n skip = path.length - 1;\n \n let self = root;\n\n for( var i = 0; i < skip; i++ ){\n const key = path[ i ];\n switch( key ){\n case '~' : self = self.getStore(); break;\n case '^' : self = self.getOwner(); break;\n default : self = self.get( key );\n }\n\n // Do nothing if object on the path doesn't exist.\n if( !self ) return;\n }\n\n return action( self, path[ skip ] );\n}","export interface ChildrenErrors {\n [ key : string ] : ValidationError | any\n} \n\nexport interface Validatable {\n /** @internal */\n _validateNested( errors : ChildrenErrors ) : number;\n \n validate( self : any ) : any\n get( key : string ) : any\n}\n\n// Validation error object.\nexport class ValidationError {\n // Invalid nested object keys \n nested : ChildrenErrors \n length : number\n\n // Local error\n error : any\n\n constructor( obj : Validatable ){\n this.length = obj._validateNested( this.nested = {} );\n\n if( this.error = obj.validate( obj ) ){\n this.length++;\n }\n }\n\n each( iteratee : ( value : any, key : string ) => void ) : void {\n const { error, nested } = this;\n\n if( error ) iteratee( error, null );\n\n for( const key in nested ){\n iteratee( nested[ key ], key );\n }\n }\n\n eachError( iteratee : ( error : any, key : string, object : Validatable ) => void, object : Validatable ) : void {\n this.each( ( value : any, key : string ) => {\n if( value instanceof ValidationError ){\n (value).eachError( iteratee, object.get( key ) );\n }\n else{\n iteratee( value, key, object );\n }\n });\n }\n}","import { abortIO, IOEndpoint, IONode, IOPromise } from './io-tools';\nimport { EventCallbacks, define, definitions, eventsApi, Logger, LogLevel, Messenger, MessengerDefinition, MessengersByCid, mixinRules, mixins, MixinsState, throwingLogger } from './object-plus';\nimport { resolveReference, Traversable } from './traversable';\nimport { ChildrenErrors, Validatable, ValidationError } from './validation';\n\nconst { trigger3, on, off } = eventsApi;\n/***\n * Abstract class implementing ownership tree, tho-phase transactions, and validation. \n * 1. createTransaction() - apply changes to an object tree, and if there are some events to send, transaction object is created.\n * 2. transaction.commit() - send and process all change events, and close transaction.\n */\n\n/** @private */\nexport interface TransactionalDefinition extends MessengerDefinition {\n endpoint? : IOEndpoint\n}\n\nexport enum ItemsBehavior {\n share = 0b0001,\n listen = 0b0010,\n persistent = 0b0100\n}\n\n// Transactional object interface\n\nexport interface Transactional extends Messenger {}\n\n@define\n@definitions({\n endpoint : mixinRules.value\n})\n@mixins( Messenger )\nexport abstract class Transactional implements Messenger, IONode, Validatable, Traversable {\n // Mixins are hard in TypeScript. We need to copy type signatures over...\n // Here goes 'Mixable' mixin.\n static endpoint : IOEndpoint;\n \n /** @internal */\n static __super__ : object;\n \n static mixins : MixinsState;\n static define : ( definition? : TransactionalDefinition, statics? : object ) => typeof Transactional;\n static extend : ( definition? : T, statics? : object ) => any;\n\n static onDefine( definitions : TransactionalDefinition, BaseClass : typeof Transactional ){\n if( definitions.endpoint ) this.prototype._endpoint = definitions.endpoint;\n Messenger.onDefine.call( this, definitions, BaseClass );\n };\n\n static onExtend( BaseClass : typeof Transactional ) : void {\n // Make sure we don't inherit class factories.\n if( BaseClass.create === this.create ) {\n this.create = Transactional.create;\n }\n }\n\n // Define extendable mixin static properties.\n static create any>( this : M, a? : any, b? : any ) : InstanceType {\n return new (this as any)( a, b );\n }\n\n // State accessor.\n /** @internal */\n readonly __inner_state__ : any;\n\n // Shared modifier (used by collections of shared models)\n /** @internal */\n _shared? : number; \n \n dispose() : void {\n if( this._disposed ) return;\n \n abortIO( this );\n this._owner = void 0;\n this._ownerKey = void 0;\n this.off();\n this.stopListening();\n this._disposed = true;\n }\n \n cidPrefix : string\n\n // Unique version token replaced on change\n /** @internal */\n _changeToken : {} = {}\n\n // true while inside of the transaction\n /** @internal */\n _transaction : boolean = false;\n\n // Holds current transaction's options, when in the middle of transaction and there're changes but is an unsent change event\n /** @internal */\n _isDirty : TransactionOptions = null;\n\n // Backreference set by owner (Record, Collection, or other object)\n /** @internal */\n _owner : Owner = void 0;\n\n // Key supplied by owner. Used by record to identify attribute key.\n // Only collections doesn't set the key, which is used to distinguish collections.\n /** @internal */ \n _ownerKey : string = void 0;\n\n // Name of the change event\n /** @internal */\n _changeEventName : string\n\n /**\n * Subsribe for the changes.\n */\n onChanges( handler : Function, target? : Messenger ){\n on( this, this._changeEventName, handler, target );\n }\n\n /**\n * Unsubscribe from changes.\n */\n offChanges( handler? : Function, target? : Messenger ){\n off( this, this._changeEventName, handler, target );\n }\n\n /**\n * Listen to changes event. \n */\n listenToChanges( target : Transactional, handler ){\n this.listenTo( target, target._changeEventName, handler );\n }\n\n constructor( cid : string | number ){\n this.cid = this.cidPrefix + cid;\n }\n\n // Deeply clone ownership subtree\n abstract clone( options? : CloneOptions ) : this\n \n // Execute given function in the scope of ad-hoc transaction.\n transaction( fun : ( self : this ) => void, options : TransactionOptions = {} ) : void{\n const isRoot = transactionApi.begin( this );\n const update = fun.call( this, this );\n update && this.set( update );\n isRoot && transactionApi.commit( this );\n }\n\n // Assign transactional object \"by value\", copying aggregated items.\n assignFrom( source : Transactional | Object ) : this {\n // Need to delay change events until change token willl by synced.\n this.transaction( () =>{\n this.set( ( source ).__inner_state__ || source, { merge : true } );\n\n // Synchronize change tokens\n const { _changeToken } = source as any;\n \n if( _changeToken ){\n this._changeToken = _changeToken;\n } \n });\n\n return this;\n }\n\n // Create object from JSON. Throw if validation fail.\n static from Transactional >( this : T, json : any, { strict, ...options } : { strict? : boolean } & TransactionOptions = {} ) : InstanceType{\n const obj : Transactional = ( this as any ).create( json, { ...options, logger : strict ? throwingLogger : void 0 } );\n\n if( strict && obj.validationError ){\n obj.eachValidationError( ( error, key, obj ) => {\n throw new Error( `${ obj.getClassName() }.${ key }: ${ error }` );\n });\n }\n\n return obj as any;\n }\n\n // Apply bulk object update without any notifications, and return open transaction.\n // Used internally to implement two-phase commit.\n // Returns null if there are no any changes.\n /** @internal */\n abstract _createTransaction( values : any, options? : TransactionOptions ) : Transaction | void\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n abstract set( values : any, options? : TransactionOptions ) : this;\n\n \n // Parse function applied when 'parse' option is set for transaction.\n parse( data : any, options? : TransactionOptions ) : any { return data }\n\n // Convert object to the serializable JSON structure\n abstract toJSON( options? : object ) : {}\n\n /*******************\n * Traversals and member access\n */\n \n // Get object member by its key.\n abstract get( key : string ) : any\n\n // Get object member by symbolic reference.\n deepGet( reference : string ) : any {\n return resolveReference( this, reference, ( object, key ) => object.get ? object.get( key ) : object[ key ] );\n }\n\n //_isCollection : boolean\n\n // Return owner skipping collections.\n getOwner() : Owner {\n return this._owner;\n }\n\n // Store used when owner chain store lookup failed. Static value in the prototype. \n /** @internal */\n _defaultStore : Transactional\n\n // Locate the closest store. Store object stops traversal by overriding this method. \n getStore() : Transactional {\n const { _owner } = this;\n return _owner ? _owner.getStore() : this._defaultStore;\n }\n\n\n /***************************************************\n * Iteration API\n */\n\n // Loop through the members. Must be efficiently implemented in container class.\n\n /** @internal */\n _endpoint : IOEndpoint\n \n /** @internal */\n _ioPromise : IOPromise\n\n hasPendingIO() : IOPromise { return this._ioPromise; }\n\n //fetch( options? : object ) : IOPromise { throw new Error( \"Not implemented\" ); }\n\n getEndpoint() : IOEndpoint {\n return getOwnerEndpoint( this ) || this._endpoint;\n }\n \n /*********************************\n * Validation API\n */\n\n // Lazily evaluated validation error\n /** @internal */\n _validationError : ValidationError = void 0\n\n // Validate ownership tree and return valudation error \n get validationError() : ValidationError {\n const error = this._validationError || ( this._validationError = new ValidationError( this ) );\n return error.length ? error : null; \n }\n\n // Validate nested members. Returns errors count.\n /** @internal */\n abstract _validateNested( errors : ChildrenErrors ) : number\n\n // Object-level validator. Returns validation error.\n validate( obj? : Transactional ) : any {}\n\n // Return validation error (or undefined) for nested object with the given key. \n getValidationError( key? : string ) : any {\n var error = this.validationError;\n return ( key ? error && error.nested[ key ] : error ) || null;\n }\n\n // Get validation error for the given symbolic reference.\n deepValidationError( reference : string ) : any {\n return resolveReference( this, reference, ( object, key ) => object.getValidationError( key ) );\n }\n\n // Iterate through all validation errors across the ownership tree.\n eachValidationError( iteratee : ( error : any, key : string, object : Transactional ) => void ) : void {\n const { validationError } = this;\n validationError && validationError.eachError( iteratee, this );\n }\n\n // Check whenever member with a given key is valid. \n isValid( key? : string ) : boolean {\n return !this.getValidationError( key );\n }\n\n valueOf() : Object { return this.cid; }\n toString(){ return this.cid; }\n\n // Get class name for an object instance. Works fine with ES6 classes definitions (not in IE).\n getClassName() : string {\n const { name } = this.constructor;\n if( name !== 'Subclass' ) return name;\n }\n\n // Logging interface for run time errors and warnings.\n /** @internal */\n abstract _log( level : LogLevel, topic : string, text : string, value : any, logger? : Logger ) : void\n}\n\nexport interface CloneOptions {\n // 'Pin store' shall assign this._defaultStore = this.getStore();\n pinStore? : boolean\n}\n\n// Owner must accept children update events. It's an only way children communicates with an owner.\n/** @private */\nexport interface Owner extends Traversable, Messenger {\n /** @internal */\n _onChildrenChange( child : Transactional, options : TransactionOptions ) : void;\n \n getOwner() : Owner\n getStore() : Transactional\n}\n\n// Transaction object used for two-phase commit protocol.\n// Must be implemented by subclasses.\n// Transaction must be created if there are actual changes and when markIsDirty returns true.\n/** @private */ \nexport interface Transaction {\n // Object transaction is being made on.\n object : Transactional\n\n // Send out change events, process update triggers, and close transaction.\n // Nested transactions must be marked with isNested flag (it suppress owner notification).\n commit( initiator? : Transactional )\n}\n\n// Options for distributed transaction \nexport interface TransactionOptions {\n // Invoke parsing \n parse? : boolean\n\n // Optional logger\n logger? : Logger\n\n // Suppress change notifications and update triggers\n silent? : boolean\n\n // Update existing transactional members in place, or skip the update (ignored by models)\n merge? : boolean // =true\n\n // Should collections remove elements in set (ignored by models) \n remove? : boolean // =true\n\n // Always replace enclosed objects with new instances\n reset? : boolean // = false\n\n // Do not dispose aggregated members\n unset? : boolean\n\n validate? : boolean\n\n // IO method name if the transaction is initiated as a result of IO operation\n ioMethod? : 'save' | 'fetch'\n\n // The hint for IOEndpoint\n // If `true`, `record.save()` will behave as \"upsert\" operation for the records having id.\n upsert? : boolean\n}\n\n/**\n * Low-level transactions API. Must be used like this:\n * const isRoot = begin( record );\n * ...\n * isRoot && commit( record, options );\n * \n * When committing nested transaction, the flag must be set to true. \n * commit( object, options, isNested ) \n */\n\nexport const transactionApi = {\n // Start transaction. Return true if it's the root one.\n /** @private */\n begin( object : Transactional ) : boolean {\n return object._transaction ? false : ( object._transaction = true ); \n },\n\n // Mark object having changes inside of the current transaction.\n // Returns true whenever there notifications are required.\n /** @private */\n markAsDirty( object : Transactional, options : TransactionOptions ) : boolean {\n // If silent option is in effect, don't set isDirty flag.\n const dirty = !options.silent;\n if( dirty ) object._isDirty = options;\n \n // Reset version token.\n object._changeToken = {};\n\n // Object is changed, so validation must happen again. Clear the cache.\n object._validationError = void 0;\n\n return dirty;\n },\n\n // Commit transaction. Send out change event and notify owner. Returns true if there were changes.\n // Must be executed for the root transaction only.\n /** @private */\n commit( object : Transactional, initiator? : Transactional ){\n let originalOptions = object._isDirty;\n\n if( originalOptions ){\n // Send the sequence of change events, handling chained handlers.\n while( object._isDirty ){\n const options = object._isDirty;\n object._isDirty = null; \n trigger3( object, object._changeEventName, object, options, initiator );\n }\n \n // Mark transaction as closed.\n object._transaction = false;\n\n // Notify owner on changes out of transaction scope. \n const { _owner } = object; \n if( _owner && _owner !== initiator ){ // If it's the nested transaction, owner is already aware there are some changes.\n _owner._onChildrenChange( object, originalOptions );\n }\n }\n else{\n // No changes. Silently close transaction.\n object._isDirty = null;\n object._transaction = false;\n }\n },\n\n /************************************\n * Ownership management\n */\n\n // Add reference to the record.\n /** @private */\n aquire( owner : Owner, child : Transactional, key? : string ) : void {\n if( child._owner ) throw new ReferenceError( 'Trying to aquire ownership for an object already having an owner' );\n\n child._owner = owner;\n child._ownerKey = key;\n },\n\n // Remove reference to the record.\n /** @private */\n free( owner : Owner, child : Transactional ) : void {\n if( owner === child._owner ){\n child._owner = void 0;\n child._ownerKey = void 0;\n }\n }\n}\n\nfunction getOwnerEndpoint( self : Transactional ) : IOEndpoint {\n // Check if we are the member of the collection...\n const { collection } = self as any;\n if( collection ){\n return getOwnerEndpoint( collection );\n }\n\n // Now, if we're the member of the model...\n if( self._owner ){\n const { _endpoints } = self._owner as any;\n return _endpoints && _endpoints[ self._ownerKey ];\n }\n}\n","import { eventsApi } from '../object-plus';\nimport { Owner, Transaction, Transactional, transactionApi, TransactionOptions } from \"../transactions\";\nconst { begin : _begin, markAsDirty : _markAsDirty, commit } = transactionApi;\n\nconst { trigger3 } = eventsApi;\n\nexport interface ConstructorsMixin {\n Attributes : AttributesConstructor\n AttributesCopy : AttributesCopyConstructor\n}\n\nexport interface ConstructorOptions extends TransactionOptions{\n clone? : boolean\n}\n\nexport type AttributesConstructor = new ( record : AttributesContainer, values : object, options : TransactionOptions ) => AttributesValues;\nexport type AttributesCopyConstructor = new ( values : object ) => AttributesValues;\n\nexport interface AttributesContainer extends Transactional, Owner, ConstructorsMixin {\n // Attribute descriptors.\n /** @internal */\n _attributes : AttributesDescriptors\n\n // Attribute values.\n attributes : AttributesValues\n\n // Previous attribute values.\n /** @internal */\n _previousAttributes : AttributesValues\n\n // Changed attributes cache. \n /** @internal */\n _changedAttributes : AttributesValues\n}\n\nexport interface AttributesValues {\n [ name : string ] : any\n}\n\nexport interface AttributesDescriptors {\n [ name : string ] : AttributeUpdatePipeline\n}\n\nexport interface AttributeUpdatePipeline{\n doUpdate( value, record : AttributesContainer, options : TransactionOptions, nested? : Transaction[] ) : boolean\n}\n\n // Optimized single attribute transactional update. To be called from attributes setters\n // options.silent === false, parse === false. \nexport function setAttribute( record : AttributesContainer, name : string, value : any ) : void {\n // Open the transaction.\n const isRoot = begin( record ),\n options = {};\n\n // Update attribute. \n if( record._attributes[ name ].doUpdate( value, record, options ) ){\n // Notify listeners on changes.\n markAsDirty( record, options );\n trigger3( record, 'change:' + name, record, record.attributes[ name ], options );\n }\n\n // Close the transaction.\n isRoot && commit( record );\n}\n\nfunction begin( record : AttributesContainer ){\n if( _begin( record ) ){\n record._previousAttributes = new record.AttributesCopy( record.attributes );\n record._changedAttributes = null;\n return true;\n }\n \n return false;\n}\n\nfunction markAsDirty( record : AttributesContainer, options : TransactionOptions ){\n // Need to recalculate changed attributes, when we have nested set in change:attr handler\n if( record._changedAttributes ){\n record._changedAttributes = null;\n }\n\n return _markAsDirty( record, options );\n}\n\n/**\n * TODO: There's an opportunity to create an optimized pipeline for primitive types and Date, which makes the majority\n * of attributes. It might create the major speedup.\n * \n * Create the dedicated pipeline for owned and shared attributes as well.\n * \n * Three elements of the pipeline:\n * - from constructor\n * - from assignment\n * - from `set`\n */\n\nexport const UpdateRecordMixin = {\n// Need to override it here, since begin/end transaction brackets are overriden. \n transaction( this : AttributesContainer, fun : ( self : AttributesContainer ) => void, options : TransactionOptions = {} ) : void{\n const isRoot = begin( this );\n fun.call( this, this );\n isRoot && commit( this );\n },\n \n // Handle nested changes. TODO: propagateChanges == false, same in transaction.\n _onChildrenChange( child : Transactional, options : TransactionOptions ) : void {\n const { _ownerKey } = child,\n attribute = this._attributes[ _ownerKey ];\n\n if( !attribute /* TODO: Must be an opposite, likely the bug */ || attribute.propagateChanges ) this.forceAttributeChange( _ownerKey, options );\n },\n\n // Simulate attribute change \n forceAttributeChange( key : string, options : TransactionOptions = {} ){\n // Touch an attribute in bounds of transaction\n const isRoot = begin( this );\n\n if( markAsDirty( this, options ) ){\n trigger3( this, 'change:' + key, this, this.attributes[ key ], options );\n }\n \n isRoot && commit( this );\n },\n\n _createTransaction( this : AttributesContainer, a_values : {}, options : TransactionOptions = {} ) : Transaction {\n const isRoot = begin( this ),\n changes : string[] = [],\n nested : RecordTransaction[]= [],\n { _attributes } = this,\n values = options.parse ? this.parse( a_values, options ) : a_values;\n\n let unknown;\n\n if( shouldBeAnObject( this, values, options ) ){\n for( let name in values ){\n const spec = _attributes[ name ];\n\n if( spec ){\n if( spec.doUpdate( values[ name ], this, options, nested ) ){\n changes.push( name );\n }\n }\n else{\n unknown || ( unknown = [] );\n unknown.push( `'${ name }'` );\n }\n }\n\n if( unknown ){\n unknownAttrsWarning( this, unknown, { values }, options );\n }\n }\n \n if( changes.length && markAsDirty( this, options ) ){\n return new RecordTransaction( this, isRoot, nested, changes );\n }\n \n // No changes, but there might be silent attributes with open transactions.\n for( let pendingTransaction of nested ){\n pendingTransaction.commit( this );\n }\n\n isRoot && commit( this );\n }\n};\n\nexport function unknownAttrsWarning( record : AttributesContainer, unknown : string[], props, options ){\n record._log( 'warn', 'Type-R:UnknownAttrs', `undefined attributes ${ unknown.join(', ')} are ignored.`, props, options.logger );\n}\n\n// One of the main performance tricks of Type-R.\n// Create loop unrolled constructors for internal attribute hash,\n// so the hidden class JIT optimization will be engaged and they will become static structs.\n// It dramatically improves record performance.\nexport function constructorsMixin( attrDefs : AttributesDescriptors ) : ConstructorsMixin {\n const attrs = Object.keys( attrDefs );\n\n const AttributesCopy : AttributesCopyConstructor = new Function( 'values', `\n ${ attrs.map( attr =>`\n this.${ attr } = values.${ attr };\n `).join( '' ) }\n `) as any;\n\n AttributesCopy.prototype = Object.prototype;\n\n const Attributes : AttributesConstructor = new Function( 'record', 'values', 'options', `\n var _attrs = record._attributes;\n\n ${ attrs.map( attr =>`\n this.${ attr } = _attrs.${ attr }.doInit( values.${ attr }, record, options );\n `).join( '' ) }\n `) as any;\n\n Attributes.prototype = Object.prototype;\n\n return { Attributes, AttributesCopy };\n}\n\nexport function shouldBeAnObject( record : AttributesContainer, values : object, options ){\n if( values && values.constructor === Object ) return true;\n\n record._log( 'error', 'Type-R:InvalidObject', 'update with non-object is ignored!', { values }, options.logger );\n return false;\n}\n\n// Transaction class. Implements two-phase transactions on object's tree. \n// Transaction must be created if there are actual changes and when markIsDirty returns true. \nexport class RecordTransaction implements Transaction {\n // open transaction\n constructor( public object : AttributesContainer,\n public isRoot : boolean,\n public nested : Transaction[],\n public changes : string[] ){}\n\n // commit transaction\n commit( initiator? : AttributesContainer ) : void {\n const { nested, object, changes } = this;\n\n // Commit all pending nested transactions...\n for( let transaction of nested ){ \n transaction.commit( object );\n }\n\n // Notify listeners on attribute changes...\n // Transaction is never created when silent option is set, so just send events out.\n const { attributes, _isDirty } = object;\n for( let key of changes ){\n trigger3( object, 'change:' + key, object, attributes[ key ], _isDirty );\n }\n\n this.isRoot && commit( object, initiator );\n }\n}","import { IOEndpoint } from '../../io-tools';\nimport { LogLevel, tools, Logger } from '../../object-plus';\nimport { TransactionOptions } from '../../transactions';\nimport { AttributesContainer, AttributeUpdatePipeline, RecordTransaction, setAttribute } from '../updates';\n\nconst { notEqual, assign} = tools;\n\nexport type Transform = ( this : AnyType, next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) => any;\nexport type ChangeHandler = ( this : AnyType, next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) => void;\n\nexport interface AttributeOptions {\n _metatype? : typeof AnyType\n validate? : ( record : AttributesContainer, value : any, key : string ) => any\n isRequired? : boolean\n changeEvents? : boolean\n\n endpoint? : IOEndpoint\n\n type? : Function\n value? : any\n hasCustomDefault? : boolean\n\n parse? : Parse\n toJSON? : AttributeToJSON\n \n getHooks? : GetHook[]\n transforms? : Transform[]\n changeHandlers? : ChangeHandler[]\n\n _onChange? : ChangeAttrHandler\n}\n\nexport type Parse = ( value : any, key? : string ) => any;\nexport type GetHook = ( value : any, key? : string ) => any;\nexport type AttributeToJSON = ( value : any, key? : string ) => any\nexport type AttributeParse = ( value : any, key? : string ) => any\nexport type ChangeAttrHandler = ( ( value : any, attr? : string ) => void ) | string;\n\n// TODO: interface differs from options, do something obout it\nconst emptyOptions : TransactionOptions = {};\n\n/**\n * Typeless attribute. Is the base class for all other attributes.\n */\nexport class AnyType implements AttributeUpdatePipeline {\n // Factory method to create attribute from options \n static create : ( options : AttributeOptions, name : string ) => AnyType;\n \n /**\n * Update pipeline functions\n * =========================\n *\n * Stage 0. canBeUpdated( value )\n * - presence of this function implies attribute's ability to update in place.\n */\n canBeUpdated( prev, next, options : TransactionOptions ) : any {}\n\n /**\n * Stage 1. Transform stage\n */\n transform( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) : any { return next; }\n\n // convert attribute type to `this.type`.\n convert( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) : any { return next; }\n\n /**\n * Stage 2. Check if attr value is changed\n */\n isChanged( a : any, b : any ) : boolean {\n return notEqual( a, b );\n }\n\n /**\n * Stage 3. Handle attribute change\n */\n handleChange( next : any, prev : any, model : AttributesContainer, options : TransactionOptions ) {}\n\n /**\n * End update pipeline definitions.\n */\n\n // create empty object passing backbone options to constructor...\n create() { return void 0; }\n\n // generic clone function for typeless attributes\n // Must be overriden in sublass\n clone( value : any, record : AttributesContainer ) {\n return value;\n }\n\n dispose( record : AttributesContainer, value : any ) : void {\n this.handleChange( void 0, value, record, emptyOptions );\n }\n\n validate( record : AttributesContainer, value : any, key : string ) : any {}\n\n toJSON( value, key, options? : object ) {\n return value && value.toJSON ? value.toJSON( options ) : value;\n }\n\n createPropertyDescriptor() : PropertyDescriptor | void {\n const { name, getHook } = this;\n\n if( name !== 'id' ){\n return {\n // call to optimized set function for single argument.\n set( value ){\n setAttribute( this, name, value );\n },\n\n // attach get hook to the getter function, if it present\n get : (\n getHook ?\n function() {\n return getHook.call( this, this.attributes[ name ], name );\n } :\n function() { return this.attributes[ name ]; }\n ),\n\n configurable : true\n }\n }\n }\n\n value : any\n\n // Used as global default value for the given metatype\n static defaultValue : any;\n\n type : Function\n\n initialize( name : string, options : TransactionOptions ){}\n\n options : AttributeOptions\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n const v = value === void 0 ? this.defaultValue() : value,\n x = this.transform( v, void 0, record, options );\n \n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record : AttributesContainer, options : TransactionOptions, nested? : RecordTransaction[] ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n\n const next = this.transform( value, prev, record, options );\n attributes[ name ] = next;\n\n if( this.isChanged( next, prev ) ) {\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n return true;\n }\n\n return false;\n }\n\n propagateChanges : boolean\n\n protected _log( level : LogLevel, code : string, text : string, value, record : AttributesContainer, logger : Logger ){\n record._log( level, code, `${record.getClassName()}.${ this.name } ${ text }`, {\n 'New value' : value,\n 'Prev. value' : record.attributes[ this.name ]\n }, logger );\n }\n\n defaultValue(){\n return this.value;\n }\n\n constructor( public name : string, a_options : AttributeOptions ) { \n // Save original options...\n this.options = a_options;\n\n // Clone options.\n const options : AttributeOptions = { getHooks : [], transforms : [], changeHandlers : [], ...a_options };\n options.getHooks = options.getHooks.slice();\n options.transforms = options.transforms.slice();\n options.changeHandlers = options.changeHandlers.slice();\n\n const {\n value, type, parse, toJSON, changeEvents,\n validate, getHooks, transforms, changeHandlers\n } = options;\n\n // Initialize default value...\n this.value = value;\n this.type = type;\n\n // TODO: An opportunity to optimize for attribute subtype.\n if( !options.hasCustomDefault && type ){\n this.defaultValue = this.create;\n }\n else if( tools.isValidJSON( value ) ){ \n // JSON literals must be deep copied.\n this.defaultValue = new Function( `return ${ JSON.stringify( value ) };` ) as any;\n }\n else{\n this.defaultValue = this.defaultValue;\n }\n\n // Changes must be bubbled when they are not disabled for an attribute and transactional object.\n this.propagateChanges = changeEvents !== false;\n\n this.toJSON = toJSON === void 0 ? this.toJSON : toJSON;\n\n this.validate = validate || this.validate;\n \n if( options.isRequired ){\n this.validate = wrapIsRequired( this.validate );\n }\n\n /**\n * Assemble pipelines...\n */\n\n // `convert` is default transform, which is always present...\n transforms.unshift( this.convert );\n\n // Get hook from the attribute will be used first...\n if( this.get ) getHooks.unshift( this.get );\n\n // let subclasses configure the pipeline...\n this.initialize.call( this, options );\n\n // let attribute spec configure the pipeline...\n if( getHooks.length ){\n const getHook = this.getHook = getHooks.reduce( chainGetHooks );\n\n const { validate } = this;\n this.validate = function( record : AttributesContainer, value : any, key : string ){\n return validate.call( this, record, getHook.call( record, value, key ), key );\n }\n }\n \n this.transform = transforms.length ? transforms.reduce( chainTransforms ) : this.transform;\n \n this.handleChange = changeHandlers.length ? changeHandlers.reduce( chainChangeHandlers ) : this.handleChange;\n\n // Attribute-level parse transform are attached as update hooks modifiers...\n const { doInit, doUpdate } = this;\n this.doInit = parse ? function( value, record : AttributesContainer, options : TransactionOptions ){\n return doInit.call( this, options.parse && value !== void 0 ? parse.call( record, value, this.name ) : value, record, options );\n } : doInit;\n\n this.doUpdate = parse ? function( value, record : AttributesContainer, options : TransactionOptions, nested? : RecordTransaction[] ){\n return doUpdate.call( this, options.parse && value !== void 0 ? parse.call( record, value, this.name ) : value, record, options, nested );\n } : doUpdate;\n }\n\n getHook : ( value, key : string ) => any = null\n get : ( value, key : string ) => any\n}\n\n\nfunction chainGetHooks( prevHook : GetHook, nextHook : GetHook ) : GetHook {\n return function( value, name ) {\n return nextHook.call( this, prevHook.call( this, value, name ), name );\n }\n}\n\nfunction chainTransforms( prevTransform : Transform, nextTransform : Transform ) : Transform {\n return function( next, prev, record, options ) {\n return nextTransform.call( this, prevTransform.call( this, next, prev, record, options ), prev, record, options );\n }\n}\n\nfunction chainChangeHandlers( prevHandler : ChangeHandler, nextHandler : ChangeHandler ) : ChangeHandler {\n return function( next, prev, record, options ) {\n prevHandler.call( this, next, prev, record, options );\n nextHandler.call( this, next, prev, record, options );\n }\n}\n\nfunction wrapIsRequired( validate ){\n return function( record : AttributesContainer, value : any, key : string ){\n return value ? validate.call( this, record, value, key ) : 'Required';\n }\n}","/**\n * Built-in JSON types attributes: Object, Array, Number, String, Boolean, and immutable class.\n * \n * Adds type assertions, default validation, and optimized update pipeline.\n */\n\nimport { TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer } from '../updates';\n\n/**\n * Custom class must be immutable class which implements toJSON() method\n * with a constructor taking json.\n */\nexport class ImmutableClassType extends AnyType {\n type : new ( value? : any ) => {}\n\n create(){\n return new this.type();\n }\n\n convert( next : any ) : any {\n return next == null || next instanceof this.type ? next : new this.type( next );\n }\n\n toJSON( value, key? : string, options? : object ){\n return value && value.toJSON ? value.toJSON( options ) : value;\n }\n\n clone( value ) {\n return new this.type( this.toJSON( value ) );\n }\n\n isChanged( a, b ){\n return a !== b;\n }\n}\n\n/**\n * Optimized attribute of primitive type.\n * \n * Primitives has specialized simplified pipeline.\n */\nexport class PrimitiveType extends AnyType {\n type : NumberConstructor | StringConstructor | BooleanConstructor\n\n dispose(){}\n create() { return this.type(); }\n\n toJSON( value ) { return value; }\n\n convert( next ) { return next == null ? next : this.type( next ); }\n\n isChanged( a, b ) { return a !== b; }\n\n clone( value ) { return value; }\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n return this.transform( value === void 0 ? this.value : value, void 0, record, options );\n }\n\n doUpdate( value, record, options, nested ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n \n return prev !== ( attributes[ name ] = this.transform( value, prev, record, options ) );\n }\n\n initialize(){\n if( !this.options.hasCustomDefault ){\n this.value = this.type();\n }\n }\n}\n\n// Number type with special validation algothim.\n/** @private */ \nexport class NumericType extends PrimitiveType {\n type : NumberConstructor\n\n create(){\n return 0;\n }\n\n convert( next, prev?, record?, options? ) {\n const num = next == null ? next : this.type( next );\n\n if( num !== num ){\n this._log( 'error', 'Type-R:InvalidNumber', 'Number attribute is assigned with an invalid number', next, record, options.logger );\n }\n \n return num;\n }\n\n validate( model, value, name ) {\n // Whatever is not symmetrically serializable to JSON, is not valid by default.\n if( value != null && !isFinite( value ) ) {\n return name + ' is not valid number';\n }\n }\n}\n\n/**\n * Compatibility wrapper for Array type.\n * @private\n */ \nexport class ArrayType extends AnyType {\n toJSON( value ) { return value; }\n dispose(){}\n create(){ return []; }\n\n convert( next, prev, record, options ) {\n // Fix incompatible constructor behaviour of Array...\n if( next == null || Array.isArray( next ) ) return next;\n\n this._log( 'error', 'Type-R:InvalidArray', 'Array attribute assigned with non-array value', next, record, options.logger );\n\n return [];\n }\n\n clone( value ){\n return value && value.slice();\n }\n}\n\nexport class ObjectType extends AnyType {\n create(){ return {}; }\n\n convert( next, prev, record, options ) {\n if( next == null || typeof next === 'object' ) return next;\n \n this._log( 'error', 'Type-R:InvalidObject', 'Object attribute is assigned with non-object value', next, record, options.logger );\n return {};\n }\n}\n\nexport function doNothing(){}\n\nexport class FunctionType extends AnyType {\n // Functions are not serialized.\n toJSON( value ) { return void 0; }\n create(){ return doNothing; }\n dispose(){}\n\n convert( next, prev, record, options ) {\n // Fix incompatible constructor behaviour of Function...\n if( next == null || typeof next === 'function' ) return next;\n\n this._log( 'error', 'Type-R:InvalidFunction', 'Function attribute assigned with non-function value', next, record, options.logger );\n\n return doNothing;\n }\n\n // Functions are not cloned.\n clone( value ){ return value; }\n}\n","/**\n * Date attribute type.\n * \n * Implements validation, cross-browser compatibility fixes, variety of Date serialization formats,\n * and optimized update pipeline.\n */\nimport { TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer } from '../updates';\n\n// Date Attribute\n/** @private */\nexport class DateType extends AnyType {\n create(){\n return new Date();\n }\n \n convert( next : any, a, record, options ){\n if( next == null || next instanceof Date ) return next;\n\n const date = new Date( next ),\n timestamp = date.getTime();\n\n if( timestamp !== timestamp ){\n this._log( 'error', 'Type-R:InvalidDate', 'Date attribute assigned with invalid date', next, record, options.logger );\n }\n\n return date;\n }\n\n validate( model, value, name ) {\n if( value != null ){\n const timestamp = value.getTime(); \n if( timestamp !== timestamp ) return name + ' is Invalid Date';\n }\n }\n\n toJSON( value ) { return value && value.toISOString(); }\n\n isChanged( a, b ) { return ( a && a.getTime() ) !== ( b && b.getTime() ); }\n\n doInit( value, record : AttributesContainer, options : TransactionOptions ){\n // Date don't have handleChanges step.\n return this.transform( value === void 0 ? this.defaultValue() : value, void 0, record, options );\n }\n\n doUpdate( value, record, options, nested ){\n const { name } = this,\n { attributes } = record,\n prev = attributes[ name ];\n \n // Date don't have handleChanges step.\n return this.isChanged( prev , attributes[ name ] = this.transform( value, prev, record, options ) );\n }\n\n clone( value ) { return value && new Date( value.getTime() ); }\n dispose(){}\n}\n\n// If ISO date is not supported by date constructor (such as in Safari), polyfill it.\nfunction supportsDate( date ){\n return !isNaN( ( new Date( date ) ).getTime() );\n}\n\nif( !supportsDate('2011-11-29T15:52:30.5') ||\n !supportsDate('2011-11-29T15:52:30.52') ||\n !supportsDate('2011-11-29T15:52:18.867') ||\n !supportsDate('2011-11-29T15:52:18.867Z') ||\n !supportsDate('2011-11-29T15:52:18.867-03:30') ){\n\n DateType.prototype.convert = function( value ){\n return value == null || value instanceof Date ? value : new Date( safeParseDate( value ) );\n }\n}\n\nconst numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ],\n isoDatePattern = /^(\\d{4}|[+\\-]\\d{6})(?:-(\\d{2})(?:-(\\d{2}))?)?(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:(Z)|([+\\-])(\\d{2})(?::(\\d{2}))?)?)?$/;\n\nfunction safeParseDate( date : string ) : number {\n var timestamp, struct : any[], minutesOffset = 0;\n\n if( ( struct = isoDatePattern.exec( date )) ) {\n // avoid NaN timestamps caused by undefined values being passed to Date.UTC\n for( var i = 0, k; ( k = numericKeys[ i ] ); ++i ) {\n struct[ k ] = +struct[ k ] || 0;\n }\n\n // allow undefined days and months\n struct[ 2 ] = (+struct[ 2 ] || 1) - 1;\n struct[ 3 ] = +struct[ 3 ] || 1;\n\n if( struct[ 8 ] !== 'Z' && struct[ 9 ] !== undefined ) {\n minutesOffset = struct[ 10 ] * 60 + struct[ 11 ];\n\n if( struct[ 9 ] === '+' ) {\n minutesOffset = 0 - minutesOffset;\n }\n }\n\n timestamp =\n Date.UTC( struct[ 1 ], struct[ 2 ], struct[ 3 ], struct[ 4 ], struct[ 5 ] + minutesOffset, struct[ 6 ],\n struct[ 7 ] );\n }\n else {\n timestamp = Date.parse( date );\n }\n\n return timestamp;\n}","import { ItemsBehavior, Transactional, transactionApi, TransactionOptions } from '../../transactions';\nimport { ValidationError } from '../../validation';\nimport { AnyType } from './any';\nimport { AttributesContainer, ConstructorOptions } from '../updates';\n\nconst { free, aquire } = transactionApi;\n\nexport class AggregatedType extends AnyType {\n type : typeof Transactional\n\n clone( value : Transactional ) : Transactional {\n return value ? value.clone() : value;\n }\n\n toJSON( x, key : string, options : object ){ return x && x.toJSON( options ); }\n\n doInit( value, record : AttributesContainer, options : ConstructorOptions ){\n const v = options.clone ? this.clone( value ) : (\n value === void 0 ? this.defaultValue() : value\n );\n\n const x = this.transform( v, void 0, record, options );\n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record, options, nested : any[] ){ // Last to things can be wrapped to an object, either transaction or ad-hoc\n const key = this.name, { attributes } = record; \n const prev = attributes[ key ];\n let update;\n\n // This can be moved to transactional attribute. And chained with the rest.\n if( update = this.canBeUpdated( prev, value, options ) ) { // todo - skip empty updates.\n const nestedTransaction = prev._createTransaction( update, options );\n if( nestedTransaction ){\n if( nested ){\n nested.push( nestedTransaction );\n }\n else{\n nestedTransaction.commit( record );\n }\n\n if( this.propagateChanges ) return true;\n }\n\n return false;\n }\n\n const next = this.transform( value, prev, record, options );\n attributes[ key ] = next;\n\n if( this.isChanged( next, prev ) ) { // Primitives and nested comparison can be inlined.\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n\n return true;\n }\n\n return false;\n }\n\n canBeUpdated( prev : Transactional, next : any, options : TransactionOptions ) : any {\n // If an object already exists, and new value is of incompatible type, let object handle the update.\n if( prev && next != null ){\n if( next instanceof this.type ){\n // In case if merge option explicitly specified, force merge.\n if( options.merge ) return next.__inner_state__;\n }\n else{\n return next;\n }\n }\n }\n\n convert( next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) : Transactional {\n // Invoke class factory to handle abstract classes\n if( next == null ) return next;\n \n if( next instanceof this.type ){\n if( next._shared && !( next._shared & ItemsBehavior.persistent ) ) { // TODO: think more about shared types assignment compatibility. \n this._log( 'error', 'Type-R:InvalidCollection', 'aggregated collection attribute is assigned with shared collection type', next, record, options.logger );\n }\n\n // With explicit 'merge' option we need to clone an object if its previous value was 'null'.\n // This is an only case we could be here when merge === true.\n if( options.merge ) return next.clone();\n\n if( next._owner ){\n this._log( 'warn', 'Type-R:InvalidOwner', 'object alreay has an owner and was cloned. Use explicit object.clone() to dismiss this warning.', next, record, options.logger );\n return next.clone();\n }\n\n return next;\n }\n\n return ( this.type as any).create( next, options );\n }\n\n dispose ( record : AttributesContainer, value : Transactional ){\n if( value ){\n this.handleChange( void 0, value, record, {} );\n }\n }\n\n validate( record : AttributesContainer, value : Transactional ) : ValidationError {\n var error = value && value.validationError;\n if( error ) return error;\n }\n\n create() : Transactional {\n return (this.type).create(); // this the subclass of Transactional here.\n }\n\n initialize( options ){\n options.changeHandlers.unshift( this._handleChange );\n }\n\n _handleChange( next : Transactional, prev : Transactional, record : AttributesContainer, options : TransactionOptions ){\n if( prev ){\n free( record, prev );\n options.unset || prev.dispose();\n } \n \n if( next ) aquire( record, next, this.name );\n }\n}","import { eventsApi } from '../../object-plus';\nimport { ItemsBehavior, Transactional, transactionApi, TransactionOptions } from '../../transactions';\nimport { AnyType } from './any';\nimport { AttributesContainer, ConstructorOptions } from '../updates';\nimport { ChainableAttributeSpec } from '../attrDef';\n\nconst { on, off } = eventsApi,\n { free, aquire } = transactionApi;\n\n/************************\n * Shared attribute definition.\n * - Not serialized.\n * - Listening to the changes.\n * - Doesn't take ownership when assigned with object of proper type.\n * - Takes ownership on objects which are converted.\n */\n\nconst shareAndListen = ItemsBehavior.listen | ItemsBehavior.share;\n\n/** @private */\nexport class SharedType extends AnyType {\n type : typeof Transactional\n\n doInit( value, record : AttributesContainer, options : ConstructorOptions ){\n const v = options.clone ? this.clone( value, record ) : (\n value === void 0 ? this.defaultValue() : value\n );\n\n const x = this.transform( v, void 0, record, options );\n this.handleChange( x, void 0, record, options );\n return x;\n }\n\n doUpdate( value, record, options, nested : any[] ){ // Last to things can be wrapped to an object, either transaction or ad-hoc\n const key = this.name, { attributes } = record; \n const prev = attributes[ key ];\n let update;\n\n // This can be moved to transactional attribute. And chained with the rest.\n if( update = this.canBeUpdated( prev, value, options ) ) { // todo - skip empty updates.\n const nestedTransaction = prev._createTransaction( update, options );\n if( nestedTransaction ){\n if( nested ){\n nested.push( nestedTransaction );\n }\n else{\n nestedTransaction.commit( record );\n }\n\n if( this.propagateChanges ) return true;\n }\n\n return false;\n }\n\n const next = this.transform( value, prev, record, options );\n attributes[ key ] = next;\n\n if( this.isChanged( next, prev ) ) { // Primitives and nested comparison can be inlined.\n // Do the rest of the job after assignment\n this.handleChange( next, prev, record, options );\n\n return true;\n }\n\n return false;\n }\n\n clone( value : Transactional, record : AttributesContainer ) : Transactional {\n // References are not cloned.\n if( !value || value._owner !== record ) return value;\n\n // Implicitly created objects are cloned.\n const clone = value.clone();\n aquire( record, clone, this.name );\n return clone;\n }\n\n // Do not serialize by default.\n toJSON(){}\n\n canBeUpdated( prev : Transactional, next : any, options : TransactionOptions ) : any {\n // If an object already exists, and new value is of incompatible type, let object handle the update.\n if( prev && next != null && !( next instanceof this.type ) ){\n return next;\n }\n }\n\n convert( next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) : Transactional {\n if( next == null || next instanceof this.type ) return next;\n\n // Convert type using implicitly created transactional object.\n const implicitObject = new ( this.type as any )( next, options, shareAndListen );\n\n // To prevent a leak, we need to take an ownership on it.\n aquire( record, implicitObject, this.name );\n\n return implicitObject;\n }\n\n // Refs are always valid.\n validate( model, value, name ){}\n\n // They are always created as null.\n create() : Transactional {\n return null;\n }\n\n // Listening to the change events\n _handleChange( next : Transactional, prev : Transactional, record : AttributesContainer, options ){\n if( prev ){\n // If there was an implicitly created object, remove an ownership.\n if( prev._owner === record ){\n free( record, prev );\n options.unset || prev.dispose();\n }\n else{\n off( prev, prev._changeEventName, this._onChange, record );\n }\n } \n \n if( next ){\n // No need to take an ownership for an implicit object - already done in convert or clone.\n if( next._owner !== record ){\n on( next, next._changeEventName, this._onChange, record );\n }\n } \n }\n\n dispose( record : AttributesContainer, value : Transactional ){\n if( value ){\n this.handleChange( void 0, value, record, {} );\n }\n }\n\n _onChange : ( child : Transactional, options : TransactionOptions, initiator : Transactional ) => void \n\n initialize( options ){\n // Create change event handler which knows current attribute name. \n const attribute = this;\n this._onChange = this.propagateChanges ? function( child, options, initiator ){\n this === initiator || this.forceAttributeChange( attribute.name, options );\n } : ignore;\n\n options.changeHandlers.unshift( this._handleChange );\n }\n}\n\nfunction ignore(){}","import { PrimitiveType, NumericType, ObjectType, ImmutableClassType, FunctionType, ArrayType } from './basic';\nimport { DateType } from './date';\nimport { AnyType, AttributeOptions } from './any';\n\nexport * from './any';\nexport * from './basic';\nexport * from './date';\nexport * from './owned';\nexport * from './shared';\n\n/**\n * Every record attribute type has the corresponding metatype controlling its behavior.\n * For built-in types, Type-R uses the predefined list to resolve metatype in order to avoid global objects modifications.\n * For user-defined types, static `_metatype` constructor member is used.\n */\n\nconst builtins : Function[] = [ String, Number, Boolean, Date, Object, Array, Function ],\n metatypes = [ PrimitiveType, NumericType, PrimitiveType, DateType, ObjectType, ArrayType, FunctionType ];\n\nexport function getMetatype( Ctor : Function ){\n return ( Ctor as any )._metatype || resolveBuiltins( Ctor );\n}\n\nAnyType.create = ( options : AttributeOptions, name : string ) => {\n const type = options.type,\n AttributeCtor = options._metatype || ( type ? getMetatype( type ): AnyType );\n\n return new AttributeCtor( name, options );\n}\n\nfunction resolveBuiltins( Ctor : Function ){\n const idx = builtins.indexOf( Ctor );\n return idx < 0 ? ImmutableClassType : metatypes[ idx ];\n}","/**\n * Type spec engine. Declare attributes using chainable syntax,\n * and returns object with spec.\n */\nimport { IOEndpoint } from '../io-tools';\nimport { definitionDecorator, EventMap, EventsDefinition, tools } from '../object-plus';\nimport { Transactional } from '../transactions';\nimport { AttributeOptions, AttributeToJSON, getMetatype, Parse, SharedType } from './metatypes';\nimport { AttributesContainer } from './updates';\n\nconst { assign } = tools;\n\nexport interface AttributeCheck {\n ( value : any, key : string ) : boolean\n error? : any\n}\n\n// Infer the proper TS type from a Type-R attribute spec.\nexport type Infer =\n A extends ChainableAttributeSpec ? TrueReturnType :\n A extends Function ? TrueReturnType :\n A;\n \n// Extract the proper TS return type for a function or constructor.\ntype TrueReturnType =\n F extends DateConstructor ? Date :\n F extends ( ...args : any[] ) => infer R ? R :\n F extends new ( ...args : any[] ) => infer R ? R :\n void;\n\nexport class ChainableAttributeSpec{\n options : AttributeOptions & { type? : F };\n\n constructor( options : AttributeOptions ) {\n // Shallow copy options, fill it with defaults.\n this.options = { getHooks : [], transforms : [], changeHandlers : []};\n if( options ) assign( this.options, options );\n }\n\n check( check : AttributeCheck, error? : any ) : this {\n function validate( model, value, name ){\n if( !check.call( model, value, name ) ){\n const msg = error || check.error || name + ' is not valid';\n return typeof msg === 'function' ? msg.call( model, name ) : msg;\n }\n }\n\n const prev = this.options.validate;\n\n return this.metadata({\n validate : prev ? (\n function( model, value, name ){\n return prev( model, value, name ) || validate( model, value, name );\n }\n ) : validate\n });\n }\n\n get as() : PropertyDecorator {\n return definitionDecorator( 'attributes', this );\n }\n\n get isRequired() : this {\n return this.required;\n }\n\n get required() : this {\n return this.metadata({ isRequired : true }); \n }\n\n endpoint( endpoint : IOEndpoint ) : this {\n return this.metadata({ endpoint });\n }\n\n watcher( ref : string | ( ( value : any, key : string ) => void ) ) : this {\n return this.metadata({ _onChange : ref });\n }\n\n // Attribute-specific parse transform\n parse( fun : Parse ) : this {\n return this.metadata({ parse : fun });\n }\n\n toJSON( fun : AttributeToJSON) : this {\n return this.metadata({\n toJSON : typeof fun === 'function' ? fun : ( fun ? ( x, k, o ) => x && x.toJSON( o ) : emptyFunction ) \n });\n }\n\n // Attribute get hook.\n get( fun ) : this {\n return this.metadata({\n getHooks : this.options.getHooks.concat( fun )\n });\n }\n\n // Attribute set hook.\n set( fun ) : this {\n function handleSetHook( next, prev, record : AttributesContainer, options ) {\n if( this.isChanged( next, prev ) ) {\n const changed = fun.call( record, next, this.name );\n return changed === void 0 ? prev : this.convert( changed, prev, record, options );\n }\n\n return prev;\n }\n\n return this.metadata({\n transforms : this.options.transforms.concat( handleSetHook )\n });\n }\n\n changeEvents( events : boolean ) : this {\n return this.metadata({ changeEvents : events });\n }\n\n // Subsribe to events from an attribute.\n events( map : EventsDefinition ) : this {\n const eventMap = new EventMap( map );\n\n function handleEventsSubscribtion( next, prev, record : AttributesContainer ){\n prev && prev.trigger && eventMap.unsubscribe( record, prev );\n\n next && next.trigger && eventMap.subscribe( record, next );\n }\n\n return this.metadata({\n changeHandlers : this.options.changeHandlers.concat( handleEventsSubscribtion )\n });\n }\n\n // Creates a copy of the spec.\n get has() : this {\n return this;\n }\n\n metadata( options : object ) : this {\n const cloned = new ChainableAttributeSpec( this.options );\n assign( cloned.options, options );\n return cloned as any;\n }\n\n value( x ) : this {\n return this.metadata({ value : x, hasCustomDefault : true });\n }\n\n static from( spec : any ) : ChainableAttributeSpec {\n // Pass metatype through untouched...\n if( spec && spec instanceof ChainableAttributeSpec ) {\n return spec;\n }\n\n return typeof spec === 'function' ? type( spec ) : value( spec );\n }\n}\n\nfunction emptyFunction(){}\n\nexport function type( this : void, Type : ChainableAttributeSpec | F, value? : any ) : ChainableAttributeSpec {\n if( Type instanceof ChainableAttributeSpec ) return Type;\n\n const attrDef = new ChainableAttributeSpec({ type : Type }),\n defaultValue = Type && value === void 0 ? getMetatype( Type ).defaultValue : value;\n\n return defaultValue === void 0 ? attrDef : attrDef.value( defaultValue );\n}\n\nexport function shared( this : void, Constructor : C ) : ChainableAttributeSpec {\n return new ChainableAttributeSpec({\n value : null,\n type : Constructor,\n _metatype : SharedType\n });\n}\n\n// Create attribute metatype inferring the type from the value.\nexport function value( this : void, x : any ) : ChainableAttributeSpec {\n const Type = inferType( x ),\n // Transactional types inferred from values must have shared type. \n AttrDef = Type && Type.prototype instanceof Transactional ? shared( Type ) :\n type( Type );\n\n return AttrDef.value( x );\n}\n\nfunction inferType( value : any ) : Function {\n switch( typeof value ) {\n case 'number' :\n return Number;\n case 'string' :\n return String;\n case 'boolean' :\n return Boolean;\n case 'function' :\n return Function;\n case 'undefined' :\n return void 0;\n case 'object' :\n return value ? value.constructor : void 0;\n }\n}","import { IOEndpoint } from '../io-tools';\nimport { eventsApi, tools as _ } from '../object-plus';\nimport { CompiledReference } from '../traversable';\nimport { ChainableAttributeSpec } from './attrDef';\nimport { AnyType } from './metatypes';\nimport { ConstructorsMixin, constructorsMixin } from './updates';\n\nexport interface RecordAttributesMixin extends ConstructorsMixin {\n // Attributes descriptors\n _attributes : AttributeDescriptors\n _attributesArray : AnyType[]\n \n // Attribute's property descriptors\n properties : PropertyDescriptorMap\n\n // Event map for record's local events.\n _localEvents? : eventsApi.EventMap,\n\n _endpoints : { [ name : string ] : IOEndpoint }\n}\n\nexport interface AttributeDescriptors {\n [ name : string ] : AnyType\n}\n\n// Create attribute from the type spec.\nexport function createAttribute( spec : any, name : string ) : AnyType {\n return AnyType.create( ChainableAttributeSpec.from( spec ).options, name );\n}\n\n// Create record mixin from the given record's attributes definition\nexport function createAttributesMixin( attributesDefinition : object, baseClassAttributes : AttributeDescriptors ) : RecordAttributesMixin {\n const myAttributes = _.transform( {} as AttributeDescriptors, attributesDefinition, createAttribute ),\n allAttributes = _.defaults( {} as AttributeDescriptors, myAttributes, baseClassAttributes );\n\n const ConstructorsMixin = constructorsMixin( allAttributes );\n\n return {\n ...ConstructorsMixin,\n _attributes : new ConstructorsMixin.AttributesCopy( allAttributes ),\n _attributesArray : Object.keys( allAttributes ).map( key => allAttributes[ key ] ),\n properties : _.transform( {}, myAttributes, x => x.createPropertyDescriptor() ),\n ...localEventsMixin( myAttributes ),\n _endpoints : _.transform( {}, allAttributes, attrDef => attrDef.options.endpoint )\n } \n}\n\ninterface LocalEventsMixin {\n _localEvents? : eventsApi.EventMap\n}\n\nfunction localEventsMixin( attrSpecs : AttributeDescriptors ) : LocalEventsMixin {\n let _localEvents : eventsApi.EventMap;\n\n for( var key in attrSpecs ){\n const attribute = attrSpecs[ key ],\n { _onChange } = attribute.options; \n\n if( _onChange ){\n _localEvents || ( _localEvents = new eventsApi.EventMap() );\n\n _localEvents.addEvent( 'change:' + key,\n typeof _onChange === 'string' ?\n createWatcherFromRef( _onChange, key ) : \n wrapWatcher( _onChange, key ) );\n }\n }\n\n return _localEvents ? { _localEvents } : {};\n}\n\nfunction wrapWatcher( watcher, key ){\n return function( record, value ){\n watcher.call( record, value, key );\n } \n}\n\nfunction createWatcherFromRef( ref : string, key : string ){\n const { local, resolve, tail } = new CompiledReference( ref, true );\n return local ?\n function( record, value ){\n record[ tail ]( value, key );\n } :\n function( record, value ){\n resolve( record )[ tail ]( value, key );\n }\n}","import { IOEndpoint, IONode, IOOptions, IOPromise, startIO } from '../io-tools';\nimport { TransactionOptions } from '../transactions';\n\nexport interface IORecord extends IONode {\n getEndpoint() : IOEndpoint\n save( options? : object ) : IOPromise\n fetch( options? : object ) : IOPromise\n destroy( options? : object ) : IOPromise\n toJSON( options? : object ) : any\n parse( data : any, options? : object ) : any\n isNew() : boolean\n id : string | number\n set( json : object, options : TransactionOptions ) : this\n}\n\nexport const IORecordMixin = {\n save( this : IORecord, options : IOOptions = {} ){\n const endpoint = this.getEndpoint(),\n json = this.toJSON({ ioMethod : 'save', ...options });\n\n return startIO(\n this,\n this.isNew() ?\n endpoint.create( json, options, this ) :\n endpoint.update( this.id, json, options, this ),\n options,\n\n update => {\n this.set( update, {\n parse : true,\n ioMethod : 'save',\n ...options\n } );\n }\n );\n },\n\n fetch( options : IOOptions = {} ){\n return startIO(\n this,\n this.getEndpoint().read( this.id, options, this ),\n options,\n\n json => this.set( json, { parse : true, ioMethod : 'fetch', ...options } )\n );\n },\n\n destroy( options : IOOptions = {} ){ \n return startIO(\n this,\n this.getEndpoint().destroy( this.id, options, this ),\n options,\n\n () => {\n const { collection } = this;\n if( collection ){\n collection.remove( this, options );\n }\n else{\n this.dispose();\n }\n\n return this;\n }\n )\n }\n}","/**\n * Record core implementing transactional updates.\n * The root of all definitions. \n */\n\nimport { CollectionConstructor } from '../collection';\nimport { IOEndpoint } from '../io-tools';\nimport { define, definitions, isProduction, Logger, logger, LogLevel, mixinRules, TheType, tools } from '../object-plus';\nimport { CloneOptions, Owner, Transaction, Transactional, TransactionalDefinition, TransactionOptions } from '../transactions';\nimport { ChildrenErrors } from '../validation';\nimport { Infer, type } from './attrDef';\nimport { IORecord, IORecordMixin } from './io-mixin';\nimport { AggregatedType, AnyType } from './metatypes';\nimport { AttributesConstructor, AttributesContainer, AttributesCopyConstructor, AttributesValues, setAttribute, shouldBeAnObject, unknownAttrsWarning, UpdateRecordMixin } from './updates';\n\n\nconst { assign, isEmpty } = tools;\n\n/*******************************************************\n * Record core implementation\n */\n\nexport interface ConstructorOptions extends TransactionOptions{\n clone? : boolean\n}\n\n// Client unique id counter\nlet _cidCounter : number = 0;\n\n/***************************************************************\n * Record Definition as accepted by Record.define( definition )\n */\nexport interface RecordDefinition extends TransactionalDefinition {\n idAttribute? : string\n attributes? : AttributesValues\n collection? : object\n Collection? : typeof Transactional\n}\n\nexport interface RecordConstructor extends TheType {\n new ( attrs? : Partial, options? : object ) : Record & A\n prototype : Record\n Collection : CollectionConstructor\n}\n\nexport type InferAttrs = {\n [K in keyof A]: Infer\n};\n\nexport type AttributesMixin = InferAttrs\n\n@define({\n // Default client id prefix \n cidPrefix : 'm',\n\n // Name of the change event\n _changeEventName : 'change',\n\n // Default id attribute name\n idAttribute : 'id'\n})\n@definitions({\n defaults : mixinRules.merge,\n attributes : mixinRules.merge,\n collection : mixinRules.merge,\n Collection : mixinRules.value,\n idAttribute : mixinRules.protoValue\n})\nexport class Record extends Transactional implements IORecord, AttributesContainer, Iterable {\n /** @internal */\n static _metatype = AggregatedType;\n\n // Hack\n static onDefine( definition, BaseClass ){}\n\n static Collection : CollectionConstructor;\n static DefaultCollection : CollectionConstructor;\n \n // Attribute type for the record id.\n static id = type( String ).value( null );\n \n // Lazy object reference, serializable as id.\n static get ref(){\n return type( this )\n .toJSON( x => x ? x.id : null )\n .parse( x => {\n return { [ this.prototype.idAttribute ] : x };\n });\n }\n\n static extendAttrs( this : T, attrs : A ) : RecordConstructor & InferAttrs> {\n return this.defaults( attrs ) as any;\n }\n\n static defaults( attrs : AttributesValues ) : typeof Record {\n return this.extend({ attributes : attrs }) as any;\n }\n \n static attributes : AttributesValues\n\n /********************\n * IO Methods\n */\n /** @internal */\n _endpoints : { [ name : string ] : IOEndpoint }\n\n /***********************************\n * Core Members\n */\n previousAttributes(){ return new this.AttributesCopy( this._previousAttributes ); } \n\n // Polymorphic accessor for aggregated attribute's canBeUpdated().\n /** @internal */\n get __inner_state__(){ return this.attributes; }\n\n get changed(){\n let changed = this._changedAttributes;\n\n if( !changed ){\n const prev = this._previousAttributes;\n changed = {};\n\n const { attributes } = this;\n\n for( let attr of this._attributesArray ){\n const key = attr.name,\n value = attributes[ key ];\n\n if( attr.isChanged( value, prev[ key ] ) ){\n changed[ key ] = value;\n }\n }\n\n this._changedAttributes = changed;\n }\n\n return changed; \n }\n\n changedAttributes( diff? : {} ) : boolean | {} {\n if( !diff ) return this.hasChanged() ? { ...this.changed } : false;\n\n var val, changed : {} | boolean = false,\n old = this._transaction ? this._previousAttributes : this.attributes,\n attrSpecs = this._attributes;\n\n for( var attr in diff ){\n if( !attrSpecs[ attr ].isChanged( old[ attr ], ( val = diff[ attr ] ) ) ) continue;\n (changed || (changed = {}))[ attr ] = val;\n }\n\n return changed; \n }\n\n hasChanged( key? : string ) : boolean {\n const { _previousAttributes } = this;\n if( !_previousAttributes ) return false;\n\n return key ?\n this._attributes[ key ].isChanged( this.attributes[ key ], _previousAttributes[ key ] ) :\n !isEmpty( this.changed );\n }\n\n previous( key : string ) : any {\n if( key ){\n const { _previousAttributes } = this;\n if( _previousAttributes ) return _previousAttributes[ key ];\n }\n \n return null;\n }\n\n isNew() : boolean {\n return this.id == null;\n }\n\n has( key : string ) : boolean {\n return this[ key ] != void 0;\n }\n\n // Return attribute value, setting an attribute to undefined.\n // TODO: If attribute was aggregated, don't dispose it.\n unset( key : string, options? ) : any {\n const value = this[ key ];\n this.set({ [ key ] : void 0 }, { unset : true, ...options });\n return value;\n }\n\n // Undocumented. Move to NestedTypes?\n clear( options? ) : this {\n const nullify = options && options.nullify;\n\n this.transaction( () =>{\n this.forEach( ( value, key ) => this[ key ] = nullify ? null : void 0 );\n }, options );\n\n return this;\n }\n\n // Returns Record owner skipping collections. TODO: Move out\n getOwner() : Owner {\n const owner : any = this._owner;\n\n // If there are no key, owner must be transactional object, and it's the collection.\n // We don't expect that collection can be the member of collection, so we're skipping just one level up. An optimization.\n return this._ownerKey ? owner : owner && owner._owner;\n }\n\n /***********************************\n * Identity managements\n */\n\n // Id attribute name ('id' by default)\n idAttribute : string;\n\n // Fixed 'id' property pointing to id attribute\n get id() : string { return this.attributes[ this.idAttribute ]; }\n set id( x : string ){ setAttribute( this, this.idAttribute, x ); }\n\n /***********************************\n * Dynamically compiled stuff\n */\n\n // Attributes specifications\n /** @internal */\n _attributes : { [ key : string ] : AnyType }\n\n /** @internal */\n _attributesArray : AnyType[]\n\n // Attributes object copy constructor\n Attributes : AttributesConstructor\n AttributesCopy : AttributesCopyConstructor\n\n // Create record default values, optionally augmenting given values.\n defaults( values = {} ){\n const defaults = {},\n { _attributesArray } = this;\n\n for( let attr of _attributesArray ){\n const key = attr.name,\n value = values[ key ];\n\n defaults[ key ] = value === void 0 ? attr.defaultValue() : value;\n }\n\n return defaults;\n }\n\n /***************************************************\n * Record construction\n */\n // Create record, optionally setting an owner\n constructor( a_values? : any, a_options? : ConstructorOptions ){\n super( _cidCounter++ );\n this.attributes = {};\n \n const options = a_options || {},\n values = ( options.parse ? this.parse( a_values, options ) : a_values ) || {};\n\n isProduction || typeCheck( this, values, options );\n\n this._previousAttributes = this.attributes = new this.Attributes( this, values, options );\n\n this.initialize( a_values, a_options );\n\n if( this._localEvents ) this._localEvents.subscribe( this, this );\n }\n\n // Initialization callback, to be overriden by the subclasses \n initialize( values? : Partial, options? ){}\n\n // Deeply clone record, optionally setting new owner.\n clone( options : CloneOptions = {} ) : this {\n const copy : this = new (this.constructor)( this.attributes, { clone : true } );\n \n if( options.pinStore ) copy._defaultStore = this.getStore();\n\n return copy;\n }\n\n /** @internal */\n _validateNested( errors : ChildrenErrors ) : number {\n var length = 0;\n\n const { attributes } = this;\n\n for( let attribute of this._attributesArray ){\n const { name } = attribute,\n error = attribute.validate( this, attributes[ name ], name );\n\n if( error ){\n errors[ name ] = error;\n length++;\n }\n }\n\n return length;\n }\n\n // Get attribute by key\n get( key : string ) : any {\n return this[ key ];\n }\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n set( values : any, options? : TransactionOptions ) : this {\n if( values ){ \n const transaction = this._createTransaction( values, options );\n transaction && transaction.commit();\n }\n\n return this;\n }\n\n /**\n * Serialization control\n */\n\n // Default record-level serializer, to be overriden by subclasses \n toJSON( options? : TransactionOptions ) : any {\n const json = {},\n { attributes } = this;\n\n for( let attribute of this._attributesArray ){\n const { name } = attribute,\n value = attributes[ name ];\n\n if( value !== void 0 ){\n // ...serialize it according to its spec.\n const asJson = attribute.toJSON.call( this, value, name, options );\n\n // ...skipping undefined values. Such an attributes are excluded.\n if( asJson !== void 0 ) json[ name ] = asJson; \n }\n }\n\n return json;\n }\n \n // Default record-level parser, to be overriden by the subclasses.\n parse( data, options? : TransactionOptions ){\n return data;\n }\n\n /**\n * Transactional control\n */\n deepSet( name : string, value : any, options? : any ){\n // Operation might involve series of nested object updates, thus it's wrapped in transaction.\n this.transaction( () => {\n const path = name.split( '.' ),\n l = path.length - 1,\n attr = path[ l ];\n\n let model = this;\n\n // Locate the model, traversing the path.\n for( let i = 0; i < l; i++ ){\n const key = path[ i ];\n\n // There might be collections in path, so use `get`.\n let next = model.get ? model.get( key ) : model[ key ];\n\n // Create models, if they are not exist.\n if( !next ){\n const attrSpecs = model._attributes;\n if( attrSpecs ){\n // If current object is model, create default attribute\n var newModel = attrSpecs[ key ].create();\n\n // If created object is model, nullify attributes when requested\n if( options && options.nullify && newModel._attributes ){\n newModel.clear( options );\n }\n\n model[ key ] = next = newModel;\n }\n // Silently fail in other case.\n else return;\n }\n \n model = next;\n }\n\n // Set model attribute.\n if( model.set ){\n model.set({ [ attr ] : value }, options );\n }\n else{\n model[ attr ] = value;\n }\n });\n\n return this;\n }\n \n // Returns owner without the key (usually it's collection)\n get collection() : any {\n return this._ownerKey ? null : this._owner;\n }\n\n // Dispose object and all childrens\n dispose(){\n if( this._disposed ) return;\n\n const { attributes } = this;\n\n for( let attr of this._attributesArray ){\n attr.dispose( this, attributes[ attr.name ] );\n }\n \n super.dispose();\n }\n\n /** @internal */\n _log( level : LogLevel, topic: string, text : string, props : object, a_logger? : Logger ) : void {\n ( a_logger || logger ).trigger( level, topic, this.getClassName() + ' ' + text, {\n ...props,\n 'Record' : this,\n 'Attributes definition' : this._attributes\n });\n }\n\n getClassName() : string {\n return super.getClassName() || 'Record';\n }\n\n /** @internal */\n _createTransaction( values : object, options : TransactionOptions ) : Transaction { return void 0; }\n // Simulate attribute change \n forceAttributeChange : ( key : string, options : TransactionOptions ) => void\n\n /** @internal */\n _onChildrenChange : ( child : Transactional, options : TransactionOptions ) => void\n\n\n /**\n * Map methods\n */\n\n forEach( iteratee : ( value? : any, key? : string ) => void, context? : any ){\n const fun = context !== void 0 ? ( v, k ) => iteratee.call( context, v, k ) : iteratee,\n { attributes } = this;\n\n for( const key in this.attributes ){\n const value = attributes[ key ];\n if( value !== void 0 ) fun( value, key );\n }\n }\n\n mapObject( a_fun : ( value, key ) => any, context? : any ) : object {\n const fun = context === void 0 ? a_fun : a_fun.bind( context );\n return tools.transform( {}, this.attributes, fun );\n }\n\n [ Symbol.iterator ](){\n return new RecordEntriesIterator( this );\n }\n\n entries(){\n return new RecordEntriesIterator( this );\n }\n\n // Get array of attribute keys (Record) or record ids (Collection) \n keys() : string[] {\n const keys : string[] = [];\n\n this.forEach( ( value, key ) => keys.push( key ) );\n\n return keys;\n }\n};\n\nexport interface Record extends IORecord {}\nexport interface Record extends AttributesContainer {}\n\n\nassign( Record.prototype, UpdateRecordMixin, IORecordMixin );\n\n/***********************************************\n * Helper functions\n */\n\nclass BaseRecordAttributes {\n id : string\n\n constructor( record : Record, x : AttributesValues, options : TransactionOptions ) {\n this.id = x.id;\n }\n}\n\nRecord.prototype.Attributes = BaseRecordAttributes;\n\nclass BaseRecordAttributesCopy {\n id : string\n\n constructor( x : AttributesValues ) {\n this.id = x.id;\n }\n}\n\nRecord.prototype.AttributesCopy = BaseRecordAttributesCopy;\n\nconst IdAttribute = AnyType.create({ value : void 0 }, 'id' );\nRecord.prototype._attributes = { id : IdAttribute };\nRecord.prototype._attributesArray = [ IdAttribute ];\n\nfunction typeCheck( record : Record, values : object, options ){\n if( shouldBeAnObject( record, values, options ) ){\n const { _attributes } = record;\n let unknown : string[];\n\n for( let name in values ){\n if( !_attributes[ name ] ){\n unknown || ( unknown = [] );\n unknown.push( `'${ name }'` );\n }\n }\n\n if( unknown ){\n unknownAttrsWarning( record, unknown, { values }, options );\n }\n }\n}\n\nexport class RecordEntriesIterator implements Iterator<[string, any]> {\n private idx = 0;\n \n constructor( private readonly record : Record){}\n\n next() : IteratorResult<[string, any]> {\n const { record } = this,\n metatype = record._attributesArray[ this.idx++ ];\n\n return {\n done : !metatype,\n value : metatype ? [ metatype.name, record[ metatype.name ] ] : void 0\n };\n }\n}","import { define, predefine, tools } from '../object-plus';\nimport { Transactional } from '../transactions';\nimport { type } from './attrDef';\nimport { createAttributesMixin } from './mixin';\nimport { InferAttrs, Record, RecordConstructor, RecordDefinition } from './record';\n\nexport * from './attrDef';\nexport * from './metatypes';\nexport { AttributesMixin, InferAttrs, RecordConstructor } from './record';\nexport { Record };\n\nconst { assign, defaults } = tools;\n\nexport function attributes( attrDefs : D ) : RecordConstructor> {\n @define class DefaultRecord extends Record {\n static attributes = attrDefs;\n }\n\n return DefaultRecord as any;\n}\n\nRecord.onExtend = function( this : typeof Record, BaseClass : typeof Record ){\n Transactional.onExtend.call( this, BaseClass );\n\n // Create the default collection\n const Class = this;\n\n @predefine class DefaultCollection extends BaseClass.Collection {\n static model = Class;\n }\n\n this.DefaultCollection = DefaultCollection;\n\n // If there are no collection defined in statics, use the default collection.\n // It will appear in onDefine's definition, overriding all other settings.\n if( Class.Collection === BaseClass.Collection ){\n this.Collection = DefaultCollection;\n }\n}\n\nRecord.onDefine = function( definition : RecordDefinition, BaseClass : typeof Record ){\n const baseProto : Record = BaseClass.prototype;\n\n // Compile attributes spec, creating definition mixin.\n const { properties, _localEvents, ...dynamicMixin } = createAttributesMixin( this.attributes = getAttributes( definition ), baseProto._attributes );\n assign( this.prototype, dynamicMixin );\n \n definition.properties = defaults( definition.properties || {}, properties );\n definition._localEvents = _localEvents;\n \n Transactional.onDefine.call( this, definition, BaseClass );\n\n // Finalize the definition of the default collection.\n this.DefaultCollection.define( definition.collection || {} );\n\n // assign collection from the definition.\n this.Collection = definition.Collection;\n this.Collection.prototype.model = this;\n\n if( definition.endpoint ) this.Collection.prototype._endpoint = definition.endpoint; \n}\n\nfunction getAttributes({ defaults, attributes, idAttribute } : RecordDefinition ) {\n const definition = attributes || defaults || {};\n \n // If there is an undeclared idAttribute, add its definition as untyped generic attribute.\n if( idAttribute && !( idAttribute in definition ) ){\n definition[ idAttribute ] = void 0;\n }\n\n return definition;\n}\n\ndeclare var Reflect;\n\nexport function auto( value : any ) : PropertyDecorator;\nexport function auto( proto : object, attrName : string ) : void;\nexport function auto( proto, attrName? : string ) : any {\n if( typeof Reflect !== 'undefined' && Reflect.getMetadata ){\n if( attrName ){\n type( Reflect.getMetadata( \"design:type\", proto, attrName ) ).as( proto, attrName );\n }\n else{\n const value = proto;\n return ( proto : object, attrName : string ) : void => {\n type( Reflect.getMetadata( \"design:type\", proto, attrName ) ).value( value ).as( proto, attrName );\n }\n } \n }\n else{\n proto._log( 'error', 'Type-R:MissingImport', 'Add import \"reflect-metadata\"; as the first line of your app.' );\n } \n}","import { eventsApi, Logger } from '../object-plus';\nimport { Record } from '../record';\nimport { ItemsBehavior, Owner, Transaction, Transactional, transactionApi, TransactionOptions } from '../transactions';\n\n\nconst { trigger2, trigger3, on, off } = eventsApi,\n { commit } = transactionApi,\n _aquire = transactionApi.aquire, _free = transactionApi.free;\n\n/** @private */\nexport interface CollectionCore extends Transactional, Owner {\n /** @internal */\n _byId : IdIndex\n\n models : Record[]\n model : typeof Record\n idAttribute : string // TODO: Refactor inconsistent idAttribute usage\n \n /** @internal */\n _comparator : Comparator\n \n get( objOrId : string | Record | Object ) : Record \n \n /** @internal */\n _itemEvents? : eventsApi.EventMap\n /** @internal */\n _shared : number\n /** @internal */\n _aggregationError : Record[]\n /** @internal */\n _log( level : string, topic : string, text : string, value : any, logger : Logger ) : void\n}\n\n// Collection's manipulation methods elements\nexport type Elements = ( Object | Record )[];\n\nexport interface CollectionOptions extends TransactionOptions {\n sort? : boolean\n}\n\nexport type Comparator = ( a : Record, b : Record ) => number; \n\n/** @private */\nexport function dispose( collection : CollectionCore ) : Record[]{\n const { models } = collection;\n\n collection.models = [];\n collection._byId = {};\n\n freeAll( collection, models );\n return models;\n}\n\n/** @private */\nexport function convertAndAquire( collection : CollectionCore, attrs : {} | Record, options : CollectionOptions ){\n const { model } = collection;\n \n let record : Record;\n\n if( collection._shared ){\n record = attrs instanceof model ? attrs : model.create( attrs, options );\n\n if( collection._shared & ItemsBehavior.listen ){\n on( record, record._changeEventName, collection._onChildrenChange, collection );\n }\n }\n else{\n record = attrs instanceof model ? ( options.merge ? attrs.clone() : attrs ) : model.create( attrs, options );\n\n if( record._owner ){\n if( record._owner !== collection ){\n _aquire( collection, record.clone() );\n const errors = collection._aggregationError || ( collection._aggregationError = [] );\n errors.push( record );\n }\n }\n else{\n _aquire( collection, record ); \n }\n } \n\n // Subscribe for events...\n const { _itemEvents } = collection;\n _itemEvents && _itemEvents.subscribe( collection, record );\n\n return record;\n}\n\n/** @private */\nexport function free( owner : CollectionCore, child : Record, unset? : boolean ) : void {\n if( owner._shared ){\n if( owner._shared & ItemsBehavior.listen ){\n off( child, child._changeEventName, owner._onChildrenChange, owner );\n }\n }\n else{\n _free( owner, child );\n unset || child.dispose();\n }\n\n const { _itemEvents } = owner;\n _itemEvents && _itemEvents.unsubscribe( owner, child );\n}\n\n/** @private */\nexport function freeAll( collection : CollectionCore, children : Record[] ) : Record[] {\n for( let child of children ){\n free( collection, child );\n }\n\n return children;\n}\n\n/**\n * Silently sort collection, if its required. Returns true if sort happened.\n * @private\n */ \nexport function sortElements( collection : CollectionCore, options : CollectionOptions ) : boolean {\n let { _comparator } = collection;\n if( _comparator && options.sort !== false ){\n collection.models.sort( _comparator );\n return true;\n }\n\n return false;\n}\n\n/**********************************\n * Collection Index\n * @private \n */\nexport interface IdIndex {\n [ id : string ] : Record\n}\n\n/** @private Add record */ \nexport function addIndex( index : IdIndex, model : Record ) : void {\n index[ model.cid ] = model;\n var id = model.id;\n \n if( id || ( id as any ) === 0 ){\n index[ id ] = model;\n }\n}\n\n/** @private Remove record */ \nexport function removeIndex( index : IdIndex, model : Record ) : void {\n delete index[ model.cid ];\n var id = model.id;\n if( id || ( id as any ) === 0 ){\n delete index[ id ];\n }\n}\n\nexport function updateIndex( index : IdIndex, model : Record ){\n delete index[ model.previous( model.idAttribute ) ];\n\n const { id } = model;\n id == null || ( index[ id ] = model );\n}\n\n/***\n * In Collections, transactions appears only when\n * add remove or change events might be emitted.\n * reset doesn't require transaction.\n * \n * Transaction holds information regarding events, and knows how to emit them.\n * \n * Two major optimization cases.\n * 1) Population of an empty collection\n * 2) Update of the collection (no or little changes) - it's crucial to reject empty transactions.\n */\n\n\n// Transaction class. Implements two-phase transactions on object's tree.\n/** @private */ \nexport class CollectionTransaction implements Transaction {\n // open transaction\n constructor( public object : CollectionCore,\n public isRoot : boolean,\n public added : Record[],\n public removed : Record[],\n public nested : Transaction[],\n public sorted : boolean ){}\n\n // commit transaction\n commit( initiator? : Transactional ){\n const { nested, object } = this,\n { _isDirty } = object;\n\n // Commit all nested transactions...\n for( let transaction of nested ){\n transaction.commit( object );\n }\n\n if( object._aggregationError ){\n logAggregationError( object, _isDirty );\n }\n\n // Just trigger 'change' on collection, it must be already triggered for models during nested commits.\n // ??? TODO: do it in nested transactions loop? This way appears to be more correct. \n for( let transaction of nested ){\n trigger2( object, 'change', transaction.object, _isDirty );\n }\n\n // Notify listeners on attribute changes...\n const { added, removed } = this;\n\n // Trigger `add` events for both model and collection.\n for( let record of added ){\n trigger3( record, 'add', record, object, _isDirty );\n trigger3( object, 'add', record, object, _isDirty );\n }\n\n // Trigger `remove` events for both model and collection.\n for( let record of removed ){\n trigger3( record, 'remove', record, object, _isDirty );\n trigger3( object, 'remove', record, object, _isDirty );\n }\n\n if( this.sorted ){\n trigger2( object, 'sort', object, _isDirty );\n }\n\n if( added.length || removed.length ){\n trigger2( object, 'update', object, _isDirty );\n }\n\n this.isRoot && commit( object, initiator );\n }\n}\n\nexport function logAggregationError( collection : CollectionCore, options : TransactionOptions ){\n collection._log( 'warn', 'Type-R:InvalidOwner', 'added records already have an owner and were cloned. Use explicit record.clone() to dismiss this warning.', collection._aggregationError, options.logger );\n collection._aggregationError = void 0;\n}","import { Record } from '../record';\nimport { Transaction, transactionApi } from '../transactions';\nimport { addIndex, CollectionCore, CollectionOptions, CollectionTransaction, convertAndAquire, logAggregationError, sortElements, updateIndex } from './commons';\n\nconst { begin, commit, markAsDirty } = transactionApi;\n\nexport interface AddOptions extends CollectionOptions {\n at? : number \n}\n\n/** @private */\nexport function addTransaction( collection : CollectionCore, items : any[], options : AddOptions, merge? : boolean ){\n const isRoot = begin( collection ),\n nested : Transaction[]= [];\n\n var added = appendElements( collection, items, nested, options, merge );\n\n if( added.length || nested.length ){\n let needSort = sortOrMoveElements( collection, added, options );\n if( markAsDirty( collection, options ) ){\n return new CollectionTransaction( collection, isRoot, added, [], nested, needSort );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n // No changes...\n isRoot && commit( collection );\n};\n\n// Handle sort or insert at options for add operation. Reurns true if sort happened.\n/** @private */ \nfunction sortOrMoveElements( collection : CollectionCore, added : Record[], options : AddOptions ) : boolean {\n let at = options.at;\n\n // if `at` option is given, it overrides sorting option...\n if( at != null ){\n // Take an original collection's length. \n const length = collection.models.length - added.length;\n\n // Crazy Backbone rules about `at` index. I don't know what that guys smoke.\n at = Number( at );\n if( at < 0 ) at += length + 1;\n if( at < 0 ) at = 0;\n if( at > length ) at = length;\n\n // Move added elements to desired position. In place.\n moveElements( collection.models, at, added );\n return false;\n }\n\n return sortElements( collection, options );\n}\n\n/** @private */\nfunction moveElements( source : any[], at : number, added : any[] ) : void {\n for( var j = source.length - 1, i = j - added.length; i >= at; i--, j-- ){\n source[ j ] = source[ i ];\n }\n\n for( i = 0, j = at; i < added.length; i++, j++ ){\n source[ j ] = added[ i ];\n }\n}\n\n// append data to model and index\n/** @private */\nfunction appendElements( collection : CollectionCore, a_items : any[], nested : Transaction[], a_options : AddOptions, forceMerge : boolean ){\n var { _byId, models } = collection,\n merge = ( forceMerge || a_options.merge ) && !collection._shared,\n parse = a_options.parse,\n idAttribute = collection.model.prototype.idAttribute,\n prevLength = models.length;\n\n for( const item of a_items ){\n let model = item ? _byId[ item[ idAttribute ] ] || _byId[ item.cid ] : null;\n\n if( model ){\n if( merge && item !== model ){\n var attrs = item.attributes || item;\n const transaction = model._createTransaction( attrs, a_options );\n transaction && nested.push( transaction );\n\n if( model.hasChanged( idAttribute ) ){\n updateIndex( _byId, model );\n }\n }\n }\n else{\n model = convertAndAquire( collection, item, a_options );\n models.push( model );\n addIndex( _byId, model );\n }\n }\n\n return models.slice( prevLength );\n}\n","/*************\n * Remove items from collections.\n * \n * Cannot be a part of two-phase transaction on object tree.\n * Can be executed in the scope of ad-hoc transaction or from the trigger, though.\n *\n * Implemented with low-level API. \n * Most frequent operation - single element remove. Thus, it have the fast-path.\n */\n\nimport { eventsApi } from '../object-plus';\nimport { Record } from '../record';\nimport { transactionApi, TransactionOptions } from '../transactions';\nimport { CollectionCore, CollectionTransaction, free, removeIndex } from './commons';\n\nconst { trigger2, trigger3 } = eventsApi,\n { markAsDirty, begin, commit } = transactionApi;\n\n/** @private */\nexport function removeOne( collection : CollectionCore, el : Record | {} | string, options : TransactionOptions ) : Record {\n var model : Record = collection.get( el );\n\n if( model ){\n const isRoot = begin( collection ),\n models = collection.models;\n\n // Remove model form the collection. \n models.splice( models.indexOf( model ), 1 );\n removeIndex( collection._byId, model );\n \n // Mark transaction as dirty. \n const notify = markAsDirty( collection, options );\n\n // Send out events.\n if( notify ){\n trigger3( model, 'remove', model, collection, options );\n trigger3( collection, 'remove', model, collection, options );\n } \n\n free( collection, model, options.unset );\n\n notify && trigger2( collection, 'update', collection, options );\n\n // Commit transaction.\n isRoot && commit( collection );\n\n return model;\n }\n};\n\n/** Optimized for removing many elements\n * 1. Remove elements from the index, checking for duplicates\n * 2. Create new models array matching index\n * 3. Send notifications and remove references\n */\n\n/** @private */\nexport function removeMany( collection : CollectionCore, toRemove : any[], options ){\n const removed = _removeFromIndex( collection, toRemove, options.unset );\n if( removed.length ){\n const isRoot = begin( collection );\n\n _reallocate( collection, removed.length );\n\n if( markAsDirty( collection, options ) ){\n const transaction = new CollectionTransaction( collection, isRoot, [], removed, [], false );\n transaction.commit();\n }\n else{\n // Commit transaction.\n isRoot && commit( collection );\n }\n }\n\n return removed;\n};\n\n// remove models from the index...\n/** @private */\nfunction _removeFromIndex( collection, toRemove, unset : boolean ){\n var removed = Array( toRemove.length ),\n _byId = collection._byId;\n\n for( var i = 0, j = 0; i < toRemove.length; i++ ){\n var model = collection.get( toRemove[ i ] );\n if( model ){\n removed[ j++ ] = model;\n removeIndex( _byId, model );\n free( collection, model, unset );\n }\n }\n\n removed.length = j;\n\n return removed;\n}\n\n// Allocate new models array removing models not present in the index.\n/** @private */\nfunction _reallocate( collection, removed ){\n var prev = collection.models,\n models = collection.models = Array( prev.length - removed ),\n _byId = collection._byId;\n\n for( var i = 0, j = 0; i < prev.length; i++ ){\n var model = prev[ i ];\n\n if( _byId[ model.cid ] ){\n models[ j++ ] = model;\n }\n }\n\n models.length = j;\n}","import { Record } from '../record';\nimport { Transaction, transactionApi } from '../transactions';\nimport { addIndex, CollectionCore, CollectionOptions, CollectionTransaction, convertAndAquire, Elements, free, freeAll, IdIndex, logAggregationError, sortElements } from './commons';\n\nconst { begin, commit, markAsDirty } = transactionApi;\n\n/** @private */\nconst silentOptions = { silent : true };\n\n/** @private */\nexport function emptySetTransaction( collection : CollectionCore, items : Elements, options : CollectionOptions, silent? : boolean ){\n const isRoot = begin( collection );\n\n const added = _reallocateEmpty( collection, items, options );\n\n if( added.length ){\n const needSort = sortElements( collection, options );\n\n if( markAsDirty( collection, silent ? silentOptions : options ) ){\n // 'added' is the reference to this.models. Need to copy it.\n return new CollectionTransaction( collection, isRoot, added.slice(), [], [], needSort );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n // No changes...\n isRoot && commit( collection );\n};\n\n/** @private */\nexport function setTransaction( collection, items, options ){\n const isRoot = begin( collection ),\n nested = [];\n\n var previous = collection.models,\n added = _reallocate( collection, items, nested, options );\n\n const reusedCount = collection.models.length - added.length,\n removed = reusedCount < previous.length ? (\n reusedCount ? _garbageCollect( collection, previous ) :\n freeAll( collection, previous )\n ) : []; \n \n const addedOrChanged = nested.length || added.length,\n // As we are reallocating models array, it needs to be sorted even if there are no changes.\n sorted = ( sortElements( collection, options ) && addedOrChanged ) || added.length || options.sorted;\n\n if( addedOrChanged || removed.length || sorted ){\n if( markAsDirty( collection, options ) ){ \n return new CollectionTransaction( collection, isRoot, added, removed, nested, sorted );\n }\n\n if( collection._aggregationError ) logAggregationError( collection, options );\n }\n\n isRoot && commit( collection );\n};\n\n// Remove references to all previous elements, which are not present in collection.\n// Returns an array with removed elements.\n/** @private */\nfunction _garbageCollect( collection : CollectionCore, previous : Record[] ) : Record[]{\n const { _byId } = collection,\n removed = [];\n\n // Filter out removed models and remove them from the index...\n for( let record of previous ){\n if( !_byId[ record.cid ] ){\n removed.push( record );\n free( collection, record );\n }\n }\n\n return removed;\n}\n\n// reallocate model and index\n/** @private */\nfunction _reallocate( collection : CollectionCore, source : any[], nested : Transaction[], options ){\n var models = Array( source.length ),\n _byId : IdIndex = {},\n merge = ( options.merge == null ? true : options.merge ) && !collection._shared,\n _prevById = collection._byId,\n prevModels = collection.models, \n idAttribute = collection.model.prototype.idAttribute,\n toAdd = [],\n orderKept = true;\n\n // for each item in source set...\n for( var i = 0, j = 0; i < source.length; i++ ){\n var item = source[ i ],\n model : Record = null;\n\n if( item ){\n var id = item[ idAttribute ],\n cid = item.cid;\n\n if( _byId[ id ] || _byId[ cid ] ) continue;\n\n model = _prevById[ id ] || _prevById[ cid ];\n }\n\n if( model ){\n if( merge && item !== model ){\n if( orderKept && prevModels[ j ] !== model ) orderKept = false;\n\n var attrs = item.attributes || item;\n const transaction = model._createTransaction( attrs, options );\n transaction && nested.push( transaction );\n }\n }\n else{\n model = convertAndAquire( collection, item, options );\n toAdd.push( model );\n }\n\n models[ j++ ] = model;\n addIndex( _byId, model );\n }\n\n models.length = j;\n collection.models = models;\n collection._byId = _byId;\n\n if( !orderKept ) options.sorted = true;\n\n return toAdd;\n}\n\n/** @private */\nfunction _reallocateEmpty( self, source, options ){\n var len = source ? source.length : 0,\n models = Array( len ),\n _byId : IdIndex = {},\n idAttribute = self.model.prototype.idAttribute;\n\n for( var i = 0, j = 0; i < len; i++ ){\n var src = source[ i ];\n\n if( src && ( _byId[ src[ idAttribute ] ] || _byId[ src.cid ] ) ){\n continue;\n }\n\n var model = convertAndAquire( self, src, options );\n models[ j++ ] = model;\n addIndex( _byId, model );\n }\n\n models.length = j;\n self._byId = _byId;\n\n return self.models = models;\n}","import { Record } from '../record'\n\nexport type Predicate = ( ( val : R, key? : number ) => boolean ) | Partial;\n\n/**\n * Optimized array methods.\n */\nexport abstract class ArrayMixin {\n models : R[]\n abstract get( modelOrId : string | Partial ) : R;\n\n /**\n * Map and optionally filter the collection.\n * @param mapFilter filter an element out if `undefined` is returned \n * @param context optional `this` for `mapFilter`\n */\n map( mapFilter : ( val : R, key? : number ) => T, context? : any ) : T[]{\n const { models } = this,\n { length } = models,\n res = Array( length ),\n fun = context ? mapFilter.bind( context ) : mapFilter;\n\n for( var i = 0, j = 0; i < length; i++ ){\n const val = fun( models[ i ], i );\n val === void 0 || ( res[ j++ ] = val );\n }\n\n if( i !== j ){\n res.length = j;\n }\n\n return res;\n }\n\n /**\n * Iterate through the collection.\n * @param context optional `this` for `iteratee`.\n */\n each( fun : ( val : R, key? : number ) => any, context? : any ) : void {\n const { models } = this,\n { length } = models,\n iteratee = context ? fun.bind( context ) : fun;\n\n for( let i = 0; i < length; i++ ){\n iteratee( models[ i ], i );\n }\n }\n\n /**\n * Iterate through collection optionally returning the value.\n * @param doWhile break the loop if anything but `undefined` is returned, and return this value.\n * @param context optional `this` for `doWhile`.\n */\n firstMatch( doWhile : ( val : R, key? : number ) => T ) : T\n firstMatch( doWhile : ( this : C, val : R, key? : number ) => T, context : C ) : T\n firstMatch( doWhile : ( val : R, key? : number ) => T, context? : any ) : T {\n const { models } = this,\n { length } = models,\n iteratee = context ? doWhile.bind( context ) : doWhile;\n\n for( let i = 0; i < length; i++ ){\n const res = iteratee( models[ i ], i );\n if( res !== void 0 ) return res;\n }\n }\n\n /**\n * Proxy for the `array.reduce()`\n * @param iteratee \n */\n reduce( iteratee : (previousValue: R, currentValue: R, currentIndex?: number ) => R ) : R\n reduce( iteratee : (previousValue: T, currentValue: R, currentIndex?: number ) => T, init? : any ) : T\n reduce( iteratee : (previousValue: any, currentValue: any, currentIndex?: number ) => any, init? : any ) : T | R {\n return init === void 0 ? this.models.reduce( iteratee ) : this.models.reduce( iteratee, init );\n }\n\n // Slice out a sub-array of models from the collection.\n slice( begin? : number, end? : number ) : R[] {\n return this.models.slice( begin, end );\n }\n \n indexOf( modelOrId : string | Partial ) : number {\n return this.models.indexOf( this.get( modelOrId ) );\n }\n\n includes( idOrObj : string | Partial ) : boolean {\n return Boolean( this.get( idOrObj ) );\n }\n\n filter( iteratee : Predicate, context? : any ) : R[] {\n const fun = toPredicateFunction( iteratee );\n return this.map( m => fun( m ) ? m : void 0, context );\n }\n\n find( iteratee : Predicate, context? : any ) : R {\n const fun = toPredicateFunction( iteratee );\n return this.firstMatch( m => fun( m ) ? m : void 0, context );\n }\n\n some( iteratee : Predicate, context? : any ) : boolean {\n return Boolean( this.find( iteratee, context ) );\n }\n\n forEach( iteratee : ( val : R, key? : number ) => void, context? : any ) : void {\n this.each( iteratee, context );\n }\n\n values() : IterableIterator {\n return this.models.values();\n }\n\n entries() : IterableIterator<[ number, R ]>{\n return this.models.entries();\n }\n\n every( iteratee : Predicate, context? : any ) : boolean {\n const fun = toPredicateFunction( iteratee );\n return this.firstMatch( m => fun( m ) ? void 0 : false, context ) === void 0;\n }\n\n pluck( key : K ) : R[K][] {\n return this.map( model => model[ key ] );\n }\n\n first() : R { return this.models[ 0 ]; }\n\n last() : R { return this.models[ this.models.length - 1 ]; }\n\n at( a_index : number ) : R {\n const index = a_index < 0 ? a_index + this.models.length : a_index; \n return this.models[ index ];\n }\n}\n\nconst noOp = x => x;\n\nfunction toPredicateFunction( iteratee : Predicate ){\n if( iteratee == null ) return noOp;\n\n switch( typeof iteratee ){\n case 'function' : return iteratee;\n case 'object' :\n const keys = Object.keys( iteratee );\n \n return x => {\n for( let key of keys ){\n if( iteratee[ key ] !== x[ key ] )\n return false;\n }\n\n return true;\n }\n default : throw new Error( 'Invalid iteratee' );\n }\n}","import { IOPromise, startIO } from '../io-tools';\nimport { define, definitions, EventMap, eventsApi, EventsDefinition, Logger, logger, LogLevel, Mixable, mixinRules, TheType, tools, mixins } from '../object-plus';\nimport { AggregatedType, Record, SharedType } from '../record';\nimport { CloneOptions, ItemsBehavior, Transactional, TransactionalDefinition, transactionApi, TransactionOptions } from '../transactions';\nimport { AddOptions, addTransaction } from './add';\nimport { CollectionCore, CollectionTransaction, Elements, free, sortElements, updateIndex } from './commons';\nimport { removeMany, removeOne } from './remove';\nimport { emptySetTransaction, setTransaction } from './set';\n\nconst { trigger2 } = eventsApi,\n { begin, commit, markAsDirty } = transactionApi;\n\nlet _count = 0;\n\nexport type GenericComparator = string | ( ( x : Record ) => number ) | ( ( a : Record, b : Record ) => number ); \n\nexport interface CollectionOptions extends TransactionOptions {\n comparator? : GenericComparator\n model? : typeof Record\n}\n\nexport interface CollectionDefinition extends TransactionalDefinition {\n model? : typeof Record,\n itemEvents? : EventsDefinition\n _itemEvents? : EventMap\n}\n\nclass CollectionRefsType extends SharedType {\n static defaultValue = [];\n}\n\nexport interface CollectionConstructor extends TheType {\n new ( records? : ElementsArg, options?: CollectionOptions ) : Collection\n prototype : Collection\n Refs : CollectionConstructor\n};\n\n@define({\n // Default client id prefix \n cidPrefix : 'c',\n model : Record,\n _changeEventName : 'changes',\n _aggregationError : null\n})\n@mixins( ArrayMixin )\n@definitions({\n comparator : mixinRules.value,\n model : mixinRules.protoValue,\n itemEvents : mixinRules.merge\n})\nexport class Collection< R extends Record = Record> extends Transactional implements CollectionCore, Iterable {\n /** @internal */\n _shared : number\n /** @internal */\n _aggregationError : R[]\n\n /**\n * EXPERIMENTAL notation to extract proper collection type from the model in TypeScript.\n * \n * attrName : Collection.of( User );\n * \n * const users = new ( Collection.of( User ) )\n */\n static of( Ctor : M ) : M['Collection'] extends CollectionConstructor> ? M['Collection'] : CollectionConstructor> {\n return Ctor.Collection as any;\n }\n\n /**\n * EXPERIMENTAL notation to extract proper collection type from the model in TypeScript.\n * \n * attrName : Collection.ofRefs( User );\n * \n * const users = new ( Collection.ofRefs( User ) )\n */\n static ofRefs( Ctor : M ) : M['Collection'] extends CollectionConstructor> ? M['Collection'] : CollectionConstructor> {\n return Ctor.Collection.Refs as any;\n }\n\n static Subset : typeof Collection\n static Refs : any\n\n /** @internal */\n static _SubsetOf : typeof Collection\n \n createSubset( models : ElementsArg, options? : CollectionOptions) : Collection{\n throw new ReferenceError( 'Failed dependency injection' )\n }\n\n static onExtend( BaseClass : typeof Transactional ){\n // Cached subset collection must not be inherited.\n const Ctor = this;\n this._SubsetOf = null;\n\n function RefsCollection( a, b, listen? ){\n Ctor.call( this, a, b, ItemsBehavior.share | ( listen ? ItemsBehavior.listen : 0 ) );\n }\n\n Mixable.mixins.populate( RefsCollection );\n \n RefsCollection.prototype = this.prototype;\n RefsCollection._metatype = CollectionRefsType;\n\n this.Refs = this.Subset = RefsCollection;\n\n Transactional.onExtend.call( this, BaseClass );\n }\n \n static onDefine( definition : CollectionDefinition, BaseClass : any ){\n if( definition.itemEvents ){\n const eventsMap = new EventMap( BaseClass.prototype._itemEvents );\n eventsMap.addEventsMap( definition.itemEvents );\n this.prototype._itemEvents = eventsMap;\n }\n\n if( definition.comparator !== void 0 ) this.prototype.comparator = definition.comparator;\n\n Transactional.onDefine.call( this, definition );\n }\n \n /** @internal */\n _itemEvents : EventMap\n\n /***********************************\n * Core Members\n */\n // Array of the records\n models : R[]\n\n // Polymorphic accessor for aggregated attribute's canBeUpdated().\n /** @internal */\n get __inner_state__(){ return this.models; }\n\n // Index by id and cid\n /** @internal */\n _byId : { [ id : string ] : R }\n\n set comparator( x : GenericComparator ){\n\n switch( typeof x ){\n case 'string' :\n this._comparator = ( a, b ) => {\n const aa = a[ x ], bb = b[ x ];\n if( aa === bb ) return 0;\n return aa < bb ? -1 : + 1;\n } \n break;\n case 'function' :\n if( x.length === 1 ){\n this._comparator = ( a, b ) => {\n const aa = (x).call( this, a ), bb = (x).call( this, b );\n if( aa === bb ) return 0;\n return aa < bb ? -1 : + 1;\n }\n }\n else{\n this._comparator = ( a, b ) => (x).call( this, a, b );\n }\n break;\n \n default :\n this._comparator = null;\n }\n }\n \n // TODO: Improve typing\n getStore() : Transactional {\n return this._store || ( this._store = this._owner ? this._owner.getStore() : this._defaultStore );\n }\n\n /** @internal */\n _store : Transactional\n\n get comparator(){ return this._comparator; }\n\n /** @internal */\n _comparator : ( a : R, b : R ) => number\n\n /** @internal */\n _onChildrenChange( record : R, options : TransactionOptions = {}, initiator? : Transactional ){\n // Ignore updates from nested transactions.\n if( initiator === this ) return;\n\n const { idAttribute } = this;\n\n if( record.hasChanged( idAttribute ) ){\n updateIndex( this._byId, record );\n }\n\n const isRoot = begin( this );\n\n if( markAsDirty( this, options ) ){\n // Forward change event from the record.\n trigger2( this, 'change', record, options )\n }\n\n isRoot && commit( this );\n }\n\n get( objOrId : string | { id? : string, cid? : string } ) : R {\n if( objOrId == null ) return;\n\n if( typeof objOrId === 'object' ){\n const id = objOrId[ this.idAttribute ];\n return ( id !== void 0 && this._byId[ id ] ) || this._byId[ objOrId.cid ];\n }\n else{\n return this._byId[ objOrId ];\n } \n }\n\n [ Symbol.iterator ]() : IterableIterator {\n return this.models[ Symbol.iterator ]();\n }\n\n // Loop through the members in the scope of transaction.\n // Transactional version of each()\n updateEach( iteratee : ( val : R, key? : number ) => void ){\n const isRoot = transactionApi.begin( this );\n this.each( iteratee );\n isRoot && transactionApi.commit( this );\n }\n\n /** @internal */\n _validateNested( errors : {} ) : number {\n // Don't validate if not aggregated.\n if( this._shared ) return 0;\n\n let count = 0;\n\n this.each( record => {\n const error = record.validationError;\n if( error ){\n errors[ record.cid ] = error;\n count++;\n }\n });\n\n return count;\n }\n\n model : typeof Record\n\n // idAttribute extracted from the model type.\n idAttribute : string\n\n constructor( records? : ElementsArg, options : CollectionOptions = {}, shared? : number ){\n super( _count++ );\n this.models = [];\n this._byId = {};\n \n this.comparator = this.comparator;\n\n if( options.comparator !== void 0 ){\n this.comparator = options.comparator;\n options.comparator = void 0;\n }\n \n this.model = this.model;\n \n if( options.model ){\n this.model = options.model;\n options.model = void 0;\n }\n\n this.idAttribute = this.model.prototype.idAttribute; //TODO: Remove?\n\n this._shared = shared || 0;\n\n if( records ){\n const elements = toElements( this, records, options );\n emptySetTransaction( this, elements, options, true );\n }\n\n this.initialize.apply( this, arguments );\n\n if( this._localEvents ) this._localEvents.subscribe( this, this );\n }\n\n initialize(){}\n\n // Deeply clone collection, optionally setting new owner.\n clone( options : CloneOptions = {} ) : this {\n const models = this._shared & ItemsBehavior.share ? this.models : this.map( model => model.clone() ),\n copy : this = new (this.constructor)( models, { model : this.model, comparator : this.comparator }, this._shared );\n \n if( options.pinStore ) copy._defaultStore = this.getStore();\n \n return copy;\n }\n\n toJSON( options? : object ) : any {\n return this.map( model => model.toJSON( options ) );\n }\n\n // Apply bulk in-place object update in scope of ad-hoc transaction \n set( elements : ElementsArg = [], options : TransactionOptions = {} ) : this {\n if( (options).add !== void 0 ){\n this._log( 'warn', \"Type-R:InvalidOption\", \"Collection.set doesn't support 'add' option, behaving as if options.add === true.\", options );\n }\n\n // Handle reset option here - no way it will be populated from the top as nested transaction.\n if( options.reset ){\n this.reset( elements, options )\n }\n else{\n const transaction = this._createTransaction( elements, options );\n transaction && transaction.commit();\n } \n\n return this; \n }\n\n /**\n * Enable or disable live updates.\n * \n * `true` enables full collection synchronization.\n * `false` cancel live updates.\n * `json => true | false` - filter updates\n */\n liveUpdates( enabled : LiveUpdatesOption ) : IOPromise {\n if( enabled ){\n this.liveUpdates( false );\n\n const filter = typeof enabled === 'function' ? enabled : () => true;\n\n this._liveUpdates = {\n updated : json => {\n filter( json ) && this.add( json, { parse : true, merge : true } );\n },\n\n removed : id => this.remove( id )\n };\n\n return this.getEndpoint().subscribe( this._liveUpdates, this ).then( () => this );\n }\n else{\n if( this._liveUpdates ){\n this.getEndpoint().unsubscribe( this._liveUpdates, this );\n this._liveUpdates = null;\n }\n\n // TODO: Return the resolved promise.\n }\n }\n\n /** @internal */\n _liveUpdates : object\n\n fetch( a_options : { liveUpdates? : LiveUpdatesOption } & TransactionOptions = {} ) : IOPromise {\n const options = { parse : true, ...a_options },\n endpoint = this.getEndpoint();\n\n return startIO(\n this,\n endpoint.list( options, this ),\n options,\n\n json => {\n let result : any = this.set( json, { parse : true, ioMethod : 'fetch', ...options } as TransactionOptions );\n \n if( options.liveUpdates ){\n result = this.liveUpdates( options.liveUpdates );\n }\n\n return result;\n }\n );\n }\n\n dispose() : void {\n if( this._disposed ) return;\n\n const aggregated = !this._shared;\n\n for( let record of this.models ){\n free( this, record );\n\n if( aggregated ) record.dispose();\n }\n\n this.liveUpdates( false );\n\n super.dispose();\n }\n\n reset( a_elements? : ElementsArg, options : TransactionOptions = {} ) : R[] {\n const isRoot = begin( this ),\n previousModels = this.models;\n\n // Make all changes required, but be silent.\n if( a_elements ){ \n emptySetTransaction( this, toElements( this, a_elements, options ), options, true );\n }\n else{\n this._byId = {};\n this.models = [];\n }\n\n markAsDirty( this, options );\n\n options.silent || trigger2( this, 'reset', this, { previousModels, ...options } );\n\n // Dispose models which are not in the updated collection.\n const { _byId } = this;\n \n for( let toDispose of previousModels ){\n _byId[ toDispose.cid ] || free( this, toDispose );\n }\n\n isRoot && commit( this );\n return this.models;\n }\n\n // Add elements to collection.\n add( a_elements : ElementsArg , options : AddOptions = {} ){\n const elements = toElements( this, a_elements, options ),\n transaction = this.models.length ?\n addTransaction( this, elements, options ) :\n emptySetTransaction( this, elements, options );\n\n if( transaction ){\n transaction.commit();\n return transaction.added;\n }\n }\n\n // Remove elements. \n remove( recordsOrIds : any, options : CollectionOptions = {} ) : R[] | R {\n if( recordsOrIds ){\n return Array.isArray( recordsOrIds ) ?\n removeMany( this, recordsOrIds, options ) as R[]:\n removeOne( this, recordsOrIds, options ) as R;\n }\n\n return [];\n }\n\n // Apply bulk object update without any notifications, and return open transaction.\n // Used internally to implement two-phase commit. \n /** @internal */\n _createTransaction( a_elements : ElementsArg, options : TransactionOptions = {} ) : CollectionTransaction | void {\n const elements = toElements( this, a_elements, options );\n\n if( this.models.length ){\n return options.remove === false ?\n addTransaction( this, elements, options, true ) :\n setTransaction( this, elements, options );\n }\n else{\n return emptySetTransaction( this, elements, options );\n }\n }\n\n /** @internal */\n static _metatype = AggregatedType;\n\n /***********************************\n * Collection manipulation methods\n */\n\n sort( options : TransactionOptions = {} ) : this {\n if( sortElements( this, options ) ){\n const isRoot = begin( this );\n \n if( markAsDirty( this, options ) ){\n trigger2( this, 'sort', this, options );\n }\n\n isRoot && commit( this );\n }\n\n return this;\n }\n\n // Remove and return given model.\n unset( modelOrId : R | string, options? ) : R {\n const value = this.get( modelOrId );\n this.remove( modelOrId, { unset : true, ...options } );\n return value;\n }\n\n modelId( attrs : {} ) : any {\n return attrs[ this.model.prototype.idAttribute ];\n }\n\n // Toggle model in collection.\n toggle( model : R, a_next? : boolean ) : boolean {\n var prev = Boolean( this.get( model ) ),\n next = a_next === void 0 ? !prev : Boolean( a_next );\n\n if( prev !== next ){\n if( prev ){\n this.remove( model );\n }\n else{\n this.add( model );\n }\n }\n\n return next;\n }\n\n /** @internal */\n _log( level : LogLevel, topic : string, text : string, value : object, a_logger? : Logger ) : void {\n ( a_logger || logger ).trigger( level, topic, `${ this.model.prototype.getClassName() }.${ this.getClassName() }: ` + text, {\n Argument : value,\n 'Attributes spec' : this.model.prototype._attributes\n });\n }\n\n getClassName() : string {\n return super.getClassName() || 'Collection';\n }\n\n /***********************************\n * Proxied Array methods\n */\n\n get length() : number { return this.models.length; }\n\n // Add a model to the end of the collection.\n push(model : ElementsArg, options? : CollectionOptions ) {\n return this.add(model, { at: this.length, ...options });\n }\n\n // Remove a model from the end of the collection.\n pop( options? : CollectionOptions ) : R {\n var model = this.at(this.length - 1);\n this.remove(model, { unset : true, ...options });\n return model;\n }\n\n // Add a model to the beginning of the collection.\n unshift(model : ElementsArg, options? : CollectionOptions ) {\n return this.add(model, { at: 0, ...options });\n }\n \n // Remove a model from the beginning of the collection.\n shift( options? : CollectionOptions ) : R {\n const model = this.at(0);\n this.remove( model, { unset : true, ...options } );\n return model;\n }\n}\n\nimport { ArrayMixin } from './arrayMethods'\n\nexport interface Collection extends ArrayMixin{}\n\nexport type LiveUpdatesOption = boolean | ( ( x : any ) => boolean );\n\nexport type ElementsArg = Partial | Partial[]\n\n// TODO: make is safe for parse to return null (?)\nfunction toElements( collection : Collection, elements : ElementsArg, options : CollectionOptions ) : Elements {\n const parsed = options.parse ? collection.parse( elements, options ) : elements; \n return Array.isArray( parsed ) ? parsed : [ parsed ];\n}\n\nRecord.Collection = Collection;","import { Collection } from '../collection';\nimport { Record } from '../record';\nimport { CompiledReference } from '../traversable';\n\nexport type CollectionReference = ( () => Collection ) | Collection | string; \n\n/** @private */\nexport function parseReference( collectionRef : CollectionReference ) : ( root : Record ) => Collection {\n switch( typeof collectionRef ){\n case 'function' :\n return root => (collectionRef).call( root );\n case 'object' :\n return () => collectionRef;\n case 'string' :\n const { resolve } = new CompiledReference( collectionRef );\n return resolve;\n }\n}","import { AnyType, ChainableAttributeSpec, Record } from '../record';\nimport { CollectionReference, parseReference } from './commons';\n\n\n/********\n * Reference to model by id.\n * \n * Untyped attribute. Holds model id, when unresolved. When resolved, is substituted\n * with a real model.\n * \n * No model changes are detected and counted as owner's change. That's intentional.\n */\n\n/** @private */\ntype RecordRefValue = Record | string;\n\n/** @private */\nclass RecordRefType extends AnyType {\n // It is always serialized as an id, whenever it's resolved or not. \n toJSON( value : RecordRefValue ){\n return value && typeof value === 'object' ? value.id : value;\n }\n\n // Wne \n clone( value : RecordRefValue ){\n return value && typeof value === 'object' ? value.id : value;\n }\n\n // Model refs by id are equal when their ids are equal.\n isChanged( a : RecordRefValue, b : RecordRefValue){\n var aId = a && ( (a).id == null ? a : (a).id ),\n bId = b && ( (b).id == null ? b : (b).id );\n\n return aId !== bId;\n }\n\n // Refs are always valid.\n validate( model, value, name ){}\n}\n\nexport function memberOf( this : void, masterCollection : CollectionReference, T? : R ) : ChainableAttributeSpec {\n const getMasterCollection = parseReference( masterCollection );\n\n const typeSpec = new ChainableAttributeSpec({\n value : null,\n _metatype : RecordRefType\n });\n \n return typeSpec\n .get( function( objOrId : RecordRefValue, name : string ) : Record {\n if( typeof objOrId === 'object' ) return objOrId;\n\n // So, we're dealing with an id reference. Resolve it.\n const collection = getMasterCollection( this );\n let record : Record = null;\n\n // If master collection exists and is not empty...\n if( collection && collection.length ){\n // Silently update attribute with record from this collection.\n record = collection.get( objOrId ) || null;\n this.attributes[ name ] = record;\n\n // Subscribe for events manually. delegateEvents won't be invoked.\n record && this._attributes[ name ].handleChange( record, null, this, {} );\n }\n\n return record;\n });\n}","import { Collection, CollectionConstructor } from '../collection';\nimport { define, tools } from '../object-plus';\nimport { AggregatedType, ChainableAttributeSpec, Record, type } from '../record';\nimport { ItemsBehavior, transactionApi } from '../transactions';\nimport { CollectionReference, parseReference } from './commons';\n\n\ntype RecordsIds = ( string | number )[];\n\nexport function subsetOf, R extends Record>( this : void, masterCollection : CollectionReference, T? : X ) : ChainableAttributeSpec{\n const CollectionClass = T || Collection,\n // Lazily define class for subset collection, if it's not defined already...\n SubsetOf = CollectionClass._SubsetOf || ( CollectionClass._SubsetOf = defineSubsetCollection( CollectionClass as any ) as any ),\n getMasterCollection = parseReference( masterCollection );\n\n return type( SubsetOf ).get(\n function( refs ){\n !refs || refs.resolvedWith || refs.resolve( getMasterCollection( this ) );\n return refs;\n }\n );\n}\n\nCollection.prototype.createSubset = function( models : any, options ) : Collection {\n const SubsetOf = subsetOf( this, this.constructor ).options.type,\n subset = new SubsetOf( models, options );\n \n subset.resolve( this );\n return subset;\n}\n\nconst subsetOfBehavior = ItemsBehavior.share | ItemsBehavior.persistent;\n\nfunction defineSubsetCollection( CollectionClass : typeof Collection ) {\n @define class SubsetOfCollection extends CollectionClass {\n refs : any[];\n resolvedWith : Collection = null;\n\n _metatype : AggregatedType\n\n get __inner_state__(){ return this.refs || this.models; }\n\n constructor( recordsOrIds?, options? ){\n super( [], options, subsetOfBehavior );\n this.refs = toArray( recordsOrIds );\n }\n\n // Remove should work fine as it already accepts ids. Add won't...\n add( a_elements, options = {} ){\n const { resolvedWith } = this,\n toAdd = toArray( a_elements );\n \n if( resolvedWith ){\n // If the collection is resolved already, everything is simple.\n return super.add( resolveRefs( resolvedWith, toAdd ), options );\n }\n else{\n // Collection is not resolved yet. So, we prepare the delayed computation.\n if( toAdd.length ){\n const isRoot = transactionApi.begin( this );\n\n // Save elements to resolve in future...\n this.refs = this.refs ? this.refs.concat( toAdd ) : toAdd.slice();\n\n transactionApi.markAsDirty( this, options );\n\n // And throw the 'changes' event.\n isRoot && transactionApi.commit( this );\n }\n }\n }\n\n reset( a_elements?, options = {} ){\n const { resolvedWith } = this,\n elements = toArray( a_elements );\n \n return resolvedWith ?\n // Collection is resolved, so parse ids and forward the call to set.\n super.reset( resolveRefs( resolvedWith, elements ), options ) :\n // Collection is not resolved yet. So, we prepare the delayed computation.\n delaySet( this, elements, options ) as any || [];\n }\n\n _createTransaction( a_elements, options? ){\n const { resolvedWith } = this,\n elements = toArray( a_elements );\n \n return resolvedWith ?\n // Collection is resolved, so parse ids and forward the call to set.\n super._createTransaction( resolveRefs( resolvedWith, elements ), options ) :\n // Collection is not resolved yet. So, we prepare the delayed computation.\n delaySet( this, elements, options );\n }\n\n // Serialized as an array of model ids.\n toJSON() : RecordsIds {\n return this.refs ?\n this.refs.map( objOrId => objOrId.id || objOrId ) :\n this.models.map( model => model.id );\n }\n\n // Subset is always valid.\n _validateNested(){ return 0; }\n\n get length() : number {\n return this.models.length || ( this.refs ? this.refs.length : 0 );\n }\n\n // Must be shallow copied on clone.\n clone( owner? ){\n var Ctor = (this).constructor,\n copy = new Ctor( [], {\n model : this.model,\n comparator : this.comparator\n });\n\n if( this.resolvedWith ){\n // TODO: bug here. \n copy.resolvedWith = this.resolvedWith;\n copy.refs = null;\n copy.reset( this.models, { silent : true } );\n }\n else{\n copy.refs = this.refs.slice();\n }\n\n return copy;\n }\n\n // Clean up the custom parse method possibly defined in the base class.\n parse( raw : any ) : Record[] {\n return raw;\n }\n\n resolve( collection : Collection ) : this {\n if( collection && collection.length ){\n this.resolvedWith = collection;\n\n if( this.refs ){\n this.reset( this.refs, { silent : true } );\n this.refs = null;\n }\n }\n\n return this;\n }\n\n getModelIds() : RecordsIds { return this.toJSON(); }\n\n toggle( modelOrId : any, val : boolean ) : boolean {\n return super.toggle( this.resolvedWith.get( modelOrId ), val );\n }\n\n addAll() : Record[] {\n if( this.resolvedWith ){\n this.set( this.resolvedWith.models );\n return this.models;\n }\n\n throw new Error( \"Cannot add elemens because the subset collection is not resolved yet.\" );\n }\n\n toggleAll() : Record[] {\n return this.length ? this.reset() : this.addAll();\n }\n }\n\n // Clean up all custom item events to prevent memory leaks.\n SubsetOfCollection.prototype._itemEvents = void 0;\n\n return SubsetOfCollection;\n}\n\nfunction resolveRefs( master, elements ){\n const records = [];\n \n for( let el of elements ){\n const record = master.get( el );\n if( record ) records.push( record );\n }\n\n return records;\n}\n\nfunction delaySet( collection, elements, options ) : void {\n if( tools.notEqual( collection.refs, elements ) ){\n const isRoot = transactionApi.begin( collection );\n\n // Save elements to resolve in future...\n collection.refs = elements.slice();\n\n transactionApi.markAsDirty( collection, options );\n \n // And throw the 'changes' event.\n isRoot && transactionApi.commit( collection );\n }\n}\n\nfunction toArray( elements ){\n return elements ? ( \n Array.isArray( elements ) ? elements : [ elements ]\n ) : [];\n}","import { Record } from '../record';\nimport { Transactional } from '../transactions';\n\nlet _store : Store = null;\n\nexport class Store extends Record {\n getStore() : Store { return this; }\n \n // delegate item lookup to owner, and to the global store if undefined\n get( name : string ) : any {\n // Lookup for resource in the current store. \n let local = this[ name ];\n\n // If something is found or it's the global store, return result.\n if( local || this === this._defaultStore ) return local;\n\n // Forward failed lookup to owner or global store.\n return this._owner ? this._owner.get( name ) : this._defaultStore.get( name ); \n }\n\n static get global(){ return _store; }\n static set global( store : Store ){\n if( _store ){\n _store.dispose();\n }\n\n Transactional.prototype._defaultStore = _store = store;\n }\n}\n\nStore.global = new Store();","// Dummy polyfill to prevent exception in IE.\nif( typeof Symbol === 'undefined' ){\n Object.defineProperty( window, 'Symbol', { value : { iterator : 'Symbol.iterator' }, configurable : true });\n}\n\nimport { Events, Mixable as Class } from './object-plus/';\n// Define synonims for NestedTypes backward compatibility.\nimport { Record as Model } from './record';\n\n/**\n * Export everything \n */\nexport * from './collection';\nexport * from './io-tools';\nexport * from './object-plus';\nexport * from './record';\nexport * from './relations';\nexport * from './transactions';\nexport { Model, Class };\n\n\nexport const { on, off, trigger, once, listenTo, stopListening, listenToOnce } = Events;\n\n/** Wrap model or collection method in transaction. */\nexport function transaction< F extends Function >( method : F ) : F {\n return function( ...args ){\n let result;\n \n this.transaction( () => {\n result = method.apply( this, args );\n });\n \n return result;\n }\n}"],"names":["defaults","dest","source","name","hasOwnProperty","arguments","length","i","other","isValidJSON","value","proto","Object","getPrototypeOf","prototype","Array","every","getBaseClass","Class","constructor","isEmpty","obj","key","some","fun","ArrayProto","arr","result","someArray","someObject","predicate","x","omit","discard","transform","assign","once","func","memo","first","apply","this","DateProto","Date","ObjectProto","notEqual","a","b","protoA","arraysNotEqual","keysA","keys","objectsNotEqual","HashProto","create","hashMap","hash","definition","_i","names","names_1","_a","name_1","prop","desc","getOwnPropertyDescriptor","o","map","EventMap","handlers","slice","addEventsMap","concat","addEvent","split","eventSplitter","getBubblingHandler","callback","name_2","push","EventDescriptor","target","event_1","on","event_2","off","handler","_bubblingHandlers","event","c","d","e","trigger5","trigger3","trigger2","context","next","listOff","_events","filteredHead","prev","head","ev","_callback","listSend3","call","EventHandler","once_1","_once","name_3","strings","api","events","test","self","queue","all","listSend2","listSend4","listSend5","f","listSend6","extendStatics","setPrototypeOf","__proto__","p","__extends","__","__assign","t","s","n","__rest","indexOf","getOwnPropertySymbols","__decorate","decorators","r","Reflect","decorate","defineProperty","Mixable","protoProps","staticProps","BaseClass","mixins","defineMixin","merge","mergeObject","getStaticDefinitions","onDefine","definitions","mergeInheritedMembers","spec","statics","TheSubclass","tslib_1.__extends","predefine","define","Constructor","__super__","MixinsState","get","populate","onExtend","ClassOrDefinition","Ctor","rules","definitionRules","definitionDecorator","definitionKey","mergeRules","appliedMixins","rule","mixins_1","mixin","isArray","sourceMixins","ctors","ctors_1","unshift","object","ignore","dontMix","getOwnPropertyNames","forEachOwnProp","sourceProp","_this","assignProperty","mixinRules","protoValue","baseProto","resolveRule","function","caller","list","destProp","configurable","pipe","classFirst","classLast","_idCount","uniqueId","cid","initialize","Messenger","localEvents","_localEvents","properties","eventsMap","defineProperties","toPropertyDescriptor","addReference","a_source","_listeningTo","removeAll","second","_disposed","stopListening","Events","listener","isProduction","process","env","NODE_ENV","logEvents","Logger","level","filter","topic","msg","props","args","toString","console","Error","counter","_super","window","something","body","join","JSON","stringify","logger","logEvents_1","logToConsole","throwingLogger","throwOn","log","trigger","bind","startIO","promise","options","thenDo","abortIO","_ioPromise","then","resp","triggerAndBubble","catch","err","abort","eventSource","collection","referenceMask","reference","splitTail","path","match","substr","tail","pop","local","resolve","Function","shift","resolveReference","root","action","skip","getStore","getOwner","ItemsBehavior","_validateNested","nested","error","validate","ValidationError","iteratee","each","eachError","cidPrefix","Transactional","endpoint","_endpoint","Transactional_1","_owner","_ownerKey","_changeEventName","listenTo","isRoot","transactionApi","begin","update","set","commit","transaction","__inner_state__","_changeToken","json","strict","validationError","eachValidationError","getClassName","data","_defaultStore","getOwnerEndpoint","_endpoints","_validationError","getValidationError","_transaction","markAsDirty","dirty","silent","_isDirty","initiator","originalOptions","_onChildrenChange","aquire","owner","child","ReferenceError","free","_begin","_markAsDirty","setAttribute","record","_attributes","doUpdate","attributes","_previousAttributes","AttributesCopy","_changedAttributes","UpdateRecordMixin","attribute","propagateChanges","forceAttributeChange","_createTransaction","a_values","unknown","changes","values","parse","shouldBeAnObject","unknownAttrsWarning","RecordTransaction","nested_1","_log","nested_2","changes_1","_b","emptyOptions","a_options","getHooks","transforms","changeHandlers","type","toJSON","changeEvents","hasCustomDefault","defaultValue","tools.isValidJSON","isRequired","convert","getHook_1","getHook","reduce","chainGetHooks","validate_1","chainTransforms","handleChange","chainChangeHandlers","doInit","AnyType","model","v","isChanged","code","text","New value","Prev. value","prevHook","nextHook","prevTransform","nextTransform","prevHandler","nextHandler","ImmutableClassType","PrimitiveType","NumericType","num","isFinite","ArrayType","ObjectType","doNothing","FunctionType","DateType","date","timestamp","getTime","toISOString","supportsDate","isNaN","struct","minutesOffset","isoDatePattern","exec","k","numericKeys","undefined","UTC","safeParseDate","AggregatedType","clone","canBeUpdated","nestedTransaction","_shared","persistent","_handleChange","unset","dispose","shareAndListen","listen","share","SharedType","implicitObject","_onChange","builtins","String","Number","Boolean","metatypes","getMetatype","_metatype","idx","ChainableAttributeSpec","check","metadata","required","ref","emptyFunction","changed","eventMap","unsubscribe","subscribe","cloned","Type","attrDef","shared","inferType","createAttribute","from","createAttributesMixin","attributesDefinition","baseClassAttributes","myAttributes","_.transform","allAttributes","_.defaults","ConstructorsMixin","attrDefs","attrs","attr","Attributes","constructorsMixin","_attributesArray","createPropertyDescriptor","attrSpecs","eventsApi.EventMap","createWatcherFromRef","wrapWatcher","localEventsMixin","watcher","IORecordMixin","save","getEndpoint","ioMethod","isNew","id","fetch","read","destroy","remove","_cidCounter","typeCheck","Record","idAttribute","extend","diff","hasChanged","val","old","nullify","forEach","_attributesArray_1","copy","pinStore","errors","asJson","l","newModel","clear","a_logger","Attributes definition","a_fun","tools.transform","Symbol","iterator","RecordEntriesIterator","Collection","BaseRecordAttributes","BaseRecordAttributesCopy","IdAttribute","metatype","done","DefaultCollection","dynamicMixin","_aquire","_free","convertAndAquire","_aggregationError","_itemEvents","sortElements","_comparator","sort","models","addIndex","index","removeIndex","updateIndex","previous","added","removed","sorted","CollectionTransaction","logAggregationError","added_1","_d","removed_1","_e","addTransaction","items","a_items","forceMerge","_byId","prevLength","a_items_1","item","appendElements","needSort","at","length_1","j","moveElements","sortOrMoveElements","removeMany","toRemove","_removeFromIndex","_reallocate","silentOptions","emptySetTransaction","len","src","_reallocateEmpty","setTransaction","_prevById","prevModels","toAdd","orderKept","reusedCount","previous_1","_garbageCollect","children","children_1","freeAll","addedOrChanged","ArrayMixin","mapFilter","res","doWhile","init","end","modelOrId","idOrObj","toPredicateFunction","m","firstMatch","find","entries","a_index","noOp","keys_1","keys_2","_count","CollectionRefsType","records","comparator","toElements","Refs","RefsCollection","_SubsetOf","Subset","itemEvents","aa","bb","_store","objOrId","count","elements","add","reset","enabled","liveUpdates","filter_1","_liveUpdates","updated","tslib_1.__assign","aggregated","a_elements","previousModels","previousModels_1","toDispose","recordsOrIds","el","splice","notify","removeOne","a_next","Argument","Attributes spec","parsed","parseReference","collectionRef","RecordRefType","subsetOf","masterCollection","T","CollectionClass","SubsetOf","subsetOfBehavior","refs","toArray","SubsetOfCollection","resolvedWith","resolveRefs","delaySet","raw","toggle","addAll","getMasterCollection","createSubset","subset","master","elements_1","tools.notEqual","Store","store","global","listenToOnce","method","reject","onAbort","fn","Promise","a_resolve","a_reject","listName","DefaultRecord","attrName","getMetadata","value_1","as"],"mappings":"4MAEgBA,EAAeC,EAAUC,GACrC,IAAK,IAAIC,KAAQD,EACTA,EAAOE,eAAgBD,KAAWF,EAAKG,eAAgBD,KACvDF,EAAME,GAASD,EAAQC,IAI/B,GAAuB,EAAnBE,UAAUC,OACV,IAAK,IAAIC,EAAI,EAAGA,EAAIF,UAAUC,OAAQC,IAAK,CACvC,IAAMC,EAAQH,UAAWE,GACzBC,GAASR,EAAUC,EAAMO,GAIjC,OAAOP,WAIKQ,EAAaC,GACzB,GAAc,OAAVA,EACA,OAAO,EAGX,cAAeA,GACf,IAAK,SACL,IAAK,SACL,IAAK,UACD,OAAO,EAEX,IAAK,SACD,IAAIC,EAAQC,OAAOC,eAAgBH,GAEnC,GAAIC,IAAUC,OAAOE,WAAaH,IAAUI,MAAMD,UAC9C,OAAOE,EAAON,EAAOD,GAI7B,OAAO,WAOKQ,EAAcC,GAC1B,OAAON,OAAOC,eAAgBK,EAAMJ,WAAYK,qBAWpCC,EAASC,GACrB,GAAIA,EACA,IAAK,IAAIC,KAAOD,EACZ,GAAIA,EAAIjB,eAAgBkB,GACpB,OAAO,EAKnB,OAAO,WA4BKC,EAAMF,EAAKG,GACvB,OAAIZ,OAAOC,eAAgBQ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,GACpG,IAAMa,EAAsBlB,GAAgBI,GAO5C,OALiB,IAAIxM,GAA0B,CAC3Crb,MAAQ,KACRmb,UAAYwM,KAIXne,IAAK,SAAUwc,EAA0BvmB,GACtC,GAAuB,iBAAZumB,EAAuB,OAAOA,EAGzC,IAAMjW,EAAa4Y,EAAqB5mB,MAClCyS,EAAkB,KAYxB,OATIzE,GAAcA,EAAWnQ,SAEzB4U,EAASzE,EAAWvG,IAAKwc,IAAa,MACtCjkB,KAAK4S,WAAYlV,GAAS+U,IAGhBzS,KAAK0S,YAAahV,GAAO2X,aAAc5C,EAAQ,KAAMzS,KAAM,KAGlEyS"} \ No newline at end of file diff --git a/docs/chapters/io.md b/docs/chapters/io.md index 548f6db6..6a601ef6 100644 --- a/docs/chapters/io.md +++ b/docs/chapters/io.md @@ -269,7 +269,7 @@ Record and Collection has a portion of common API related to the I/O and seriali ### obj.toJSON( options? ) -Serialize record or collection to JSON. Used internally by I/O methods. Can be overridden to customize serialization. +Serialize record or collection to JSON. Used internally by `save()` I/O method (`options.ioMethod === 'save'` when called from within `save()`). Can be overridden to customize serialization. Produces the JSON for the given record or collection and its aggregated members. Aggregation tree is serialized as nested JSON. Record corresponds to an object in JSON, while the collection is represented as an array of objects. @@ -314,9 +314,9 @@ const book = new Book(); book.set( bestSeller.toJSON(), { parse : true } ); ``` -### `callback` obj.parse( json ) +### `callback` obj.parse( json, options? ) -Optional hook called to transform the JSON when it's passes to the record or collection with `set( json, { parse : true })` call. Used internally by I/O methods. +Optional hook called to transform the JSON when it's passes to the record or collection with `set( json, { parse : true })` call. Used internally by I/O methods (`options.ioMethod` is either "save" or "fetch" when called from I/O method). If you override `toJSON()`, it usually means that you must override `parse()` as well, and vice versa. diff --git a/docs/index.html b/docs/index.html index 5016c343..d9df2fdb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -208,7 +208,7 @@

UI state and observable changes

@define UIState extends Record {
     static attributes = {
         users : User.Collection,
-        selectedUser : from( 'users' )
+        selectedUser : memberOf( 'users' )
     }
 }
 
@@ -225,7 +225,7 @@ 

UI state and observable changes

// For collections and more complex types attribute type must be provided explicitly @type( User.Collection ).as users : Collection<User> - @from( 'users' ).as selectedUser : User + @memberOf( 'users' ).as selectedUser : User } const uiState = new UIState(); @@ -1670,7 +1670,7 @@

createIOPromise( init )

Serialization

Record and Collection has a portion of common API related to the I/O and serialization.

obj.toJSON( options? )

-

Serialize record or collection to JSON. Used internally by I/O methods. Can be overridden to customize serialization.

+

Serialize record or collection to JSON. Used internally by save() I/O method (options.ioMethod === 'save' when called from within save()). Can be overridden to customize serialization.

Produces the JSON for the given record or collection and its aggregated members. Aggregation tree is serialized as nested JSON. Record corresponds to an object in JSON, while the collection is represented as an array of objects.

If you override toJSON(), it usually means that you must override parse() as well, and vice versa.

-

callback obj.parse( json )

-

Optional hook called to transform the JSON when it's passes to the record or collection with set( json, { parse : true }) call. Used internally by I/O methods.

+

callback obj.parse( json, options? )

+

Optional hook called to transform the JSON when it's passes to the record or collection with set( json, { parse : true }) call. Used internally by I/O methods (options.ioMethod is either "save" or "fetch" when called from I/O method).

If you override toJSON(), it usually means that you must override parse() as well, and vice versa.