UNPKG

joii

Version:

Javascript Object Inheritance Implementation

2 lines 38.4 kB
"use strict";!function(e){"function"==typeof define&&define.amd?define([],e):e("object"==typeof exports?exports:window)}(function(e){e="undefined"!=typeof e?e:{};var t="undefined"!=typeof e.JOII?e.JOII:{},i={};return t="undefined"!=typeof t?t:{},t.Config={constructors:["__construct","construct","->","=>"],callables:["__call","<>"],addConstructor:function(e){-1===t.Config.constructors.indexOf(e)&&t.Config.constructors.push(e)},removeConstructor:function(e){-1!==t.Config.constructors.indexOf(e)&&t.Config.constructors.splice(t.Config.constructors.indexOf(e),1)},addCallable:function(e){-1===t.Config.callables.indexOf(e)&&t.Config.callables.push(e)},removeCallable:function(e){-1!==t.Config.callables.indexOf(e)&&t.Config.callables.splice(t.Config.callables.indexOf(e),1)}},t="undefined"!=typeof t?t:{},t.Compat={},t.Compat.findJOIIName=function(e){var i,n;if("string"==typeof e||"number"==typeof e||"undefined"==typeof e||null===e)return!1;if("undefined"!=typeof e.__joii__)return e.__joii__.name;if("undefined"!=typeof e.prototype&&"undefined"!=typeof e.prototype.__joii__)return e.prototype.__joii__.name;if("undefined"!=typeof e.__proto__&&(n=t.Compat.findJOIIName(e.__proto__),"string"==typeof n))return n;"function"==typeof e&&(e=e.prototype);for(i in e)if(e.hasOwnProperty(i)!==!1&&("function"==typeof e[i]||"object"==typeof e[i])&&(n=t.Compat.findJOIIName(e[i]),"string"==typeof n))return n;return!1},t.Compat.indexOf=function(e,t){if("function"==typeof e.indexOf)return e.indexOf(t);var i=e.length>>>0,n=Number(arguments[1])||0;for(n=0>n?Math.ceil(n):Math.floor(n),n=0>n?n+i:n;i>n;n++)if(n in e&&e[n]===t)return n;return-1},t.Compat.extend=function(){var e,i,n,a,r=!1,o=arguments[0]||{},s=1,f=arguments.length,p=!1;for("boolean"==typeof o&&(p=o,o=arguments[s]||{},s++),"object"!=typeof o&&"function"!=typeof o&&(o={});f>s;s++)if(e=arguments[s],null!==e&&void 0!==arguments[s]){"undefined"!=typeof e.__joii__&&t.CreateProperty(o,"__joii__",e.__joii__);for(var _ in e)i=o[_],n=e[_],o!==n&&(p&&n&&(t.Compat.isPlainObject(n)||(r=t.Compat.isArray(n)))?(r?(r=!1,a=i&&t.Compat.isArray(i)?i:[]):a=i&&t.Compat.isPlainObject(i)?i:{},o[_]=t.Compat.extend(p,a,n)):void 0!==n&&(o[_]=n))}return o},t.Compat.isArray=function(e){var t=e.length,i=typeof e;return"function"===i||"undefined"!=typeof window&&e===window?!1:1===e.nodeType&&t?!0:"[object Array]"===Object.prototype.toString.call(e)},t.Compat.isPlainObject=function(e){var t={}.hasOwnProperty;return"object"!=typeof e||e.nodeType||"undefined"!=typeof window&&e===window?!1:!(e.constructor&&!t.call(e.constructor.prototype,"isPrototypeOf"))},t.Compat.CreateObject=function(e){if("function"==typeof Object.create)return Object.create(e);var t=function(){function e(){}return function(t){if(1!=arguments.length)throw new Error("JOII.Compat.CreateObject implementation only accepts one parameter.");return e.prototype=t,new e}}();return t(e)},t.Compat.Bind=function(e,t){if("function"!=typeof e)throw new TypeError("Function.prototype.bind - argument #1 must be a function.");return function(){return e.apply(t,arguments)}},t.Compat.GenerateUUID=function(){for(var e=[],t="0123456789abcdef",i=0;36>i;i++)e[i]=t.substr(Math.floor(16*Math.random()),1);return e[14]="4",e[19]=t.substr(3&e[19]|8,1),e[8]=e[13]=e[18]=e[23]="-",e.join("")},t.Compat.ParseArguments=function(e){var i={name:"",parameters:{},body:{}};switch(e.length){case 0:i.name=t.Compat.GenerateUUID();break;case 1:"string"==typeof e[0]&&(i.name=e[0]),"object"==typeof e[0]&&(i.name=t.Compat.GenerateUUID(),i.body=e[0]);break;case 2:"string"==typeof e[0]&&(i.name=e[0]),"object"==typeof e[0]&&(i.name=t.Compat.GenerateUUID(),i.parameters=e[0]),i.body=e[1];break;case 3:i.name=e[0],i.parameters=e[1],i.body=e[2];case 4:i.name=e[0],i.parameters=e[1],i.body=e[2],i.is_static_generated=e[3]}if("string"!=typeof i.name||"object"!=typeof i.parameters||"object"!=typeof i.body&&"function"!=typeof i.body)throw"Invalid parameter types given. Expected: ([[[string], object], <object|function>]).";return i},t.Compat.flexibleArgumentToArray=function(e,i){if("object"!=typeof e||t.Compat.isArray(e)||"undefined"!=typeof e[0]){if("function"==typeof e)return[i?t.Compat.extend(!0,{},e.prototype):e.prototype];if("object"==typeof e&&t.Compat.isArray(e)){var n=[];for(var a in e)n.push(t.Compat.flexibleArgumentToArray(e[a],!1)[0]);return n}throw"Unable to read "+typeof e+". Object, function or array expected."}return[i?t.Compat.extend(!0,{},e):e]},t.Compat.canTypeBeCastTo=function(e,i){if("undefined"!=typeof t.InterfaceRegistry[i]||"undefined"!=typeof t.ClassRegistry[i]){if(t.Compat.findJOIIName(e)!==i&&null!==e&&("function"!=typeof e.instanceOf||"object"==typeof e&&"function"==typeof e.instanceOf&&!e.instanceOf(i)))return!1}else if("undefined"!=typeof t.EnumRegistry[i]){var n=t.EnumRegistry[i];if(!n.contains(e))return!1}else if(typeof e!==i)return!1;return!0},t="undefined"!=typeof t?t:{},t.InternalPropertyNames=["__joii__","super","instanceOf","deserialize","serialize","getStatic","__api__"],t.InternalTypeNames=["undefined","object","boolean","number","string","symbol","function","const"],t.PrototypeBuilder=function(e,n,a,r,o){o=o===!0;var s={},f=t.Compat.extend(!0,{},a);if(t.CreateProperty(s,"__joii__",{name:e,parent:void 0,metadata:{},constants:{},implementations:[e],is_abstract:n["abstract"]===!0,is_final:n["final"]===!0,is_static:n["static"]===!0||o}),"undefined"!=typeof n.uses){var p=t.Compat.flexibleArgumentToArray(n.uses);for(var _ in p)f=t.Compat.extend(!0,f,p[_])}if(s.__joii__.is_abstract&&s.__joii__.is_final)throw"A class cannot be both abstract and final simultaniously.";for(var c in f)if(f.hasOwnProperty(c)!==!1){var l=t.ParseClassProperty(c,e);if(s.__joii__.is_static===!0||!l.is_static||r){if(s.__joii__.is_static&&!l.is_static){if(o)continue;throw"Member "+l.name+" is non-static. A static class cannot contain non-static members."}if("function"==typeof f[c]||l.parameters.length>0||l.name in s.__joii__.metadata&&"overloads"in s.__joii__.metadata[l.name]){if("function"!=typeof f[c])throw l.parameters.length>0?"Member "+l.name+" specifies parameters, but it's value isn't a function.":"Member "+l.name+" overloads an existing function, but it's value isn't a function.";if(l.name in s&&"function"!=typeof s[l.name])throw"Member "+l.name+" overloads an existing property, but the previous property isn't a function.";l.class_name=e,t.addFunctionToPrototype(s,l,f[c])}else l.is_constant?(s.__joii__.constants[l.name]=f[c],t.CreateProperty(s,l.name,f[c],!1),l.class_name=e,s.__joii__.metadata[l.name]=l):(s[l.name]=f[c],l.class_name=e,s.__joii__.metadata[l.name]=l)}}if("undefined"!=typeof n["abstract"]&&(s.__joii__.is_abstract=!0,r))throw"An interface cannot be declared abstract.";if(s.__joii__.is_static&&r)throw"An interface cannot be declared static.";for(var c in f)if(f.hasOwnProperty(c)!==!1){var l=t.ParseClassProperty(c,e);if(!("function"==typeof f[c]||l.parameters.length>0||"overloads"in l)&&(s.__joii__.is_static===!0||!l.is_static||r)){if(s.__joii__.is_static&&!l.is_static){if(o)continue;throw"Member "+l.name+"is non-static. A static class cannot contain non-static members."}if("private"!==l.visibility){var u=t.CreatePropertyGetterSetter(f,l,e);u.getter.meta.class_name=e,"undefined"!=typeof s.__joii__.metadata[u.getter.name]&&s.__joii__.metadata[u.getter.name].has_parameterless||t.addFunctionToPrototype(s,u.getter.meta,u.getter.fn,!0),"undefined"!=typeof u.setter.meta&&(u.setter.meta.class_name=e,"undefined"!=typeof s.__joii__.metadata[u.getter.name]&&s.__joii__.metadata[u.getter.name].has_parameterless||t.addFunctionToPrototype(s,u.setter.meta,u.setter.fn,!0))}}}if("undefined"!=typeof n["extends"]){var m=n["extends"];if("function"==typeof m&&(m=o?m.__joii__.prototype:m.prototype),"object"!=typeof m&&!o)throw(r?"An interface":"A class")+" may only extend on functions or object-types.";if(s.__joii__.parent=t.Compat.extend(!0,{},m),m.__joii__.is_final===!0)throw"Unable to extend on a final class.";for(var d=s.__joii__.parent;"undefined"!=typeof d;)s.__joii__.implementations.push(d.__joii__.name),d=d.__joii__.parent;s.__joii__.constants=t.Compat.extend(!0,s.__joii__.constants,m.__joii__.constants),t.CreateProperty(s.__joii__.parent,"__joii__",m.__joii__);for(c in s.__joii__.parent)if(s.__joii__.parent.hasOwnProperty(c)&&-1===t.Compat.indexOf(t.InternalPropertyNames,c)){var y=s.__joii__.parent[c],h=s.__joii__.parent.__joii__.metadata[c],b=s.__joii__.metadata[c];if(s.__joii__.is_static===!0||!h.is_static||r){if(s.__joii__.is_static&&!h.is_static){if(o)continue;throw"Member "+h.name+"is non-static. A static class cannot contain non-static members."}if("undefined"==typeof b&&(b=s.__joii__.metadata[c]=t.Compat.extend(!0,{},h),b.has_parameterless=!1,"overloads"in b&&delete b.overloads),"undefined"!=typeof s[c]&&"object"==typeof h&&"object"==typeof b){if(b.is_generated===!1){if(h.visibility!==b.visibility)throw'Member "'+c+'" must be '+h.visibility+" as defined in the parent "+(r?"interface":"class")+".";if("function"==typeof y||h.parameters.length>0||"overloads"in b||"overloads"in h);else{if(h.is_final===!0)throw'Final member "'+c+'" cannot be overwritten.';if(h.is_read_only!==b.is_read_only)throw'Member "'+c+'" must be read-only as defined in the parent '+(r?"interface":"class")+".";if(h.is_nullable!==b.is_nullable)throw'Member "'+c+'" must be nullable as defined in the parent '+(r?"interface":"class")+"."}}if(!("function"==typeof y||h.parameters.length>0||"overloads"in b||"overloads"in h))continue}if("function"==typeof y||h.parameters.length>0||"overloads"in b||"overloads"in h);else if("function"!=typeof y||r===!0){if(h.is_static||(s[c]=y),h.is_static){var u=t.CreatePropertyGetterSetter(s,h,e);u.getter.fn=Function(' var args = ["'+u.getter.name+"\"]; for (var i in arguments) { args.push(arguments[i]); } return this['super'].apply(this, args); "),u.setter.fn=Function(' var args = ["'+u.setter.name+"\"]; for (var i in arguments) { args.push(arguments[i]); } return this['super'].apply(this, args); "),"undefined"!=typeof u.getter.meta&&(u.getter.meta.is_generated=!0,u.getter.meta.is_inherited=!0,t.addFunctionToPrototype(s,u.getter.meta,u.getter.fn,!0)),"undefined"!=typeof u.setter.meta&&(u.setter.meta.is_generated=!0,u.setter.meta.is_inherited=!0,t.addFunctionToPrototype(s,u.setter.meta,u.setter.fn,!0))}continue}var g=null;g=h.is_static?function(e,t){return function(){return i[t][e].apply(i[t],arguments)}}(c,h.class_name):Function(' var args = ["'+c+"\"]; for (var i in arguments) { args.push(arguments[i]); } return this['super'].apply(this, args); ");var v=t.Compat.extend(!0,{},h);if(delete v.overloads,v.is_inherited=!0,v.has_parameterless=!1,b.has_parameterless){if(h.is_final)throw'Final member "'+h.name+"("+h.parameters.join(", ")+')" cannot be overwritten.'}else if("function"==typeof y||h.parameters.length>0||"overloads"in b||"overloads"in h)if("overloads"in h&&"object"==typeof h.overloads&&h.overloads.length>1)for(var j=0;j<h.overloads.length;j++)v.parameters=h.overloads[j].parameters,v.is_abstract=h.overloads[j].is_abstract,v.has_parameters=h.overloads[j].has_parameters,v.is_final=h.overloads[j].is_final,t.addFunctionToPrototype(s,v,g,!0);else t.addFunctionToPrototype(s,v,g,!0);else s[c]=g}}}return r!==!0&&(s["super"]=function(e){var t=Array.prototype.slice.call(arguments,1),i=this,n=this.__joii__,a=function(e,t,r){if("undefined"==typeof e)throw new Error('Parent method "'+t+'" does not exist.');if("undefined"!=typeof e.__joii__.parent&&"undefined"==typeof e.__joii__.parent[t])return a(e.__joii__.parent,t,r);var o=e.__joii__.parent;if("undefined"==typeof e.__joii__.parent){if("undefined"==typeof e.__api__.__joii__.parent)throw new Error('Method "'+t+"\" does not exist in the parent class. (called using 'super()')");o=e.__api__.__joii__.parent}var s=o[t];i.__joii__=o.__joii__;var f=s.apply(i,r);return i.__joii__=n,f};return a(this,e,t)},s.instanceOf=function(e){"function"==typeof e?e=e.prototype.__joii__.name:"object"==typeof e&&(e=e.__joii__.name);var i=this.__joii__.getInterfaces();for(var n in i)if(i.hasOwnProperty(n)!==!1){if(i[n].prototype.__joii__.name===e)return!0;if(-1!==t.Compat.indexOf(i[n].prototype.__joii__.implementations,e))return!0}if(this.__joii__.name!==e){if("undefined"!=typeof this.__joii__.parent){var a=this,r=this.__joii__.parent;t.Compat.Bind(r.instanceOf,r);var o=r.instanceOf(e);return t.Compat.Bind(r.instanceOf,a),o}return!1}return!0}),s},t.ParseClassProperty=function(e,i){var n=/\(.*\)/.exec(e.toString()),a=!1;null!==n&&(a=!0,n=n[0].match(/[^\(,\s\)]+/g)),("object"!=typeof n||null===n)&&(n=[]);var r,o=e.toString().replace(/\s?\(.*\)\s?|^\s+|\s+(?=\s)|\s+$/g,"").split(/\s/),s=o[o.length-1],f=t.InternalTypeNames,p=!1,_={name:s,type:null,visibility:"public",is_abstract:!1,is_final:!1,is_nullable:!1,is_read_only:!1,is_constant:!1,is_static:!1,is_enum:!1,is_generated:!1,is_inherited:!1,is_joii_object:!1,serializable:!1,has_parameters:a,parameters:n};for(var c in t.Config.callables)t.Config.callables[c]==s&&(_.is_static=!0);if(o.pop(),0===o.length)return _;var l=[];for(r in o)"undefined"==typeof t.InterfaceRegistry[o[r]]&&"undefined"==typeof t.ClassRegistry[o[r]]&&(l[r]=o[r].toString(),o[r]=l[r].toLowerCase());var u=function(e,i,n){"object"!=typeof e&&(e=[e]);for(var a in e)if(e.hasOwnProperty(a)!==!1&&-1!==t.Compat.indexOf(i,e[a]))throw n};for(r in o)switch(o[r]){case"public":u("protected",o,'Property "'+s+'" cannot be both public and protected at the same time.'),u("private",o,'Property "'+s+'" cannot be both public and private at the same time.'),_.visibility="public",p||(_.serializable=!0);break;case"protected":u("public",o,'Property "'+s+'" cannot be both protected and public at the same time.'),u("private",o,'Property "'+s+'" cannot be both protected and private at the same time.'),_.visibility="protected";break;case"private":u("public",o,'Property "'+s+'" cannot be both private and public at the same time.'),u("protected",o,'Property "'+s+'" cannot be both private and protected at the same time.'),_.visibility="private";break;case"abstract":u("final",o,'Property "'+s+'" cannot be both abstract and final at the same time.'),_.is_abstract=!0;break;case"final":u("abstract",o,'Property "'+s+'" cannot be both abstract and final at the same time.'),_.is_final=!0;break;case"nullable":_.is_nullable=!0;break;case"static":_.is_static=!0;break;case"read":case"immutable":_.is_read_only=!0;break;case"serializable":_.serializable=!0,p=!0;break;case"notserializable":_.serializable=!1,p=!0;break;case"const":u(["private","protected","public"],o,"A constant cannot have visibility modifiers."),u("final",o,"A constant cannot be final."),u("abstract",o,"A constant cannot be abstract."),u(["nullable","immutable","read"],o,"A constant cannot be nullable or immutable."),_.is_constant=!0;break;default:if(-1!==t.Compat.indexOf(f,o[r])){if(null!==_.type)throw'Property "'+s+'" has multiple type defintions.';_.type=o[r];break}if("undefined"!=typeof t.InterfaceRegistry[o[r]]){_.is_joii_object=!0,_.type=t.InterfaceRegistry[o[r]].definition.__interface__.name;break}if("undefined"!=typeof t.ClassRegistry[o[r]]){_.is_joii_object=!0,_.type=t.ClassRegistry[o[r]].prototype.__joii__.name;break}if("undefined"!=typeof t.EnumRegistry[o[r]]){_.is_enum=!0,_.type=o[r];break}if(i==l[r]){_.is_joii_object=!0,_.type=o[r];break}throw'Syntax error: unexpected "'+o[r]+'" in property declaration of "'+s+'".'}return _},t.CreatePropertyGetterSetter=function(e,n,a){var r,o,s;"boolean"===n.type?"Is"===t.CamelcaseName(n.name).substr(0,2)?(r=t.CamelcaseName(n.name),r=r.substring(0,1).toLowerCase()+r.substring(1)):r="is"+t.CamelcaseName(n.name):r="get"+t.CamelcaseName(n.name);var f,p,_="set"+t.CamelcaseName(n.name);if("undefined"==typeof e[r]&&(s=n.is_static?function(e,t){return function(){return i[e][t]}}(a,n.name):new Function('return this["'+n.name+'"];'),o=t.ParseClassProperty(n.visibility+" function "+r+"()",a),o.visibility=n.visibility,o.is_abstract=n.is_abstract,o.is_final=n.is_final,o.is_static=n.is_static,o.class_name=n.class_name),"undefined"==typeof e[_]&&n.is_read_only===!1){var c=n.is_nullable;p=null!==n.type?"undefined"!=typeof t.InterfaceRegistry[n.type]||"undefined"!=typeof t.ClassRegistry[n.type]?function(e,i,n,a,r){return function(e){if(null!==n)if(t.Compat.findJOIIName(e[0])===n);else if((null!==e[0]&&"function"!=typeof e[0].instanceOf||"object"==typeof e[0]&&null!==e[0]&&"function"==typeof e[0].instanceOf&&!e[0].instanceOf(n)||null===e[0])&&(a===!1||a===!0&&null!==e[0]&&"undefined"!=typeof e[0]))throw r+" expects an instance of "+n+", "+(null===e[0]?"null":typeof e[0])+" given.";return this[i]=e[0],this.__api__}}(a,n.name,n.type,c,_):function(e,i,n,a,r){return function(e){if(null!==n)if("undefined"!=typeof t.EnumRegistry[n]){var o=t.EnumRegistry[n];if(!o.contains(e[0]))throw r+": '"+e[0]+"' is not a member of enum "+o.getName()+"."}else if(typeof e[0]!==n&&(a===!1||a===!0&&null!==e[0]&&"undefined"!=typeof e[0]))throw r+" expects "+n+", "+typeof e[0]+" given.";return this[i]=e[0],this.__api__}}(a,n.name,n.type,c,_):function(e){return function(t){return this[e]=t[0],this.__api__}}(n.name),n.is_static&&(p="undefined"!=typeof t.InterfaceRegistry[n.type]||"undefined"!=typeof t.ClassRegistry[n.type]?function(e,n,a,r,o){return function(s){if(null!==a)if(t.Compat.findJOIIName(s[0])===a);else if((null!==s[0]&&"function"!=typeof s[0].instanceOf||"object"==typeof s[0]&&null!==s[0]&&"function"==typeof s[0].instanceOf&&!s[0].instanceOf(a)||null===s[0])&&(r===!1||r===!0&&null!==s[0]&&"undefined"!=typeof s[0]))throw o+" expects an instance of "+a+", "+(null===s[0]?"null":typeof s[0])+" given.";return i[e][n]=s[0],this.__api__}}(a,n.name,n.type,c,_):function(e,n,a,r,o){return function(s){if(null!==a)if("undefined"!=typeof t.EnumRegistry[a]){var f=t.EnumRegistry[a];if(!f.contains(s[0]))throw o+": '"+s[0]+"' is not a member of enum "+f.getName()+"."}else if(typeof s[0]!==a&&(r===!1||r===!0&&null!==s[0]&&"undefined"!=typeof s[0]))throw o+" expects "+a+", "+typeof s[0]+" given.";return i[e][n]=s[0],this.__api__}}(a,n.name,n.type,c,_)),f=t.ParseClassProperty(n.visibility+" function "+_+"(...)",a),f.visibility=n.visibility,f.is_abstract=n.is_abstract,f.is_final=n.is_final,f.is_static=n.is_static,f.class_name=n.class_name}return{getter:{name:r,fn:s,meta:o},setter:{name:_,fn:p,meta:f}}},t.CreateProperty=function(e,t,i,n){try{"undefined"!=typeof Object.defineProperty?Object.defineProperty(e,t,{value:i,enumerable:n===!1,configurable:n!==!1,writable:n!==!1}):e[t]=i}catch(a){e[t]=i}},t.addFunctionToPrototype=function(e,i,n,a){if(i.is_abstract&&i.is_final)throw'Member "'+i.name+"("+i.parameters.join(", ")+')" cannot be both abstract and final simultaniously.';"undefined"==typeof a&&(a=!1),"object"!=typeof e.__joii__.metadata[i.name]&&(e.__joii__.metadata[i.name]=t.Compat.extend(!0,{},i),e.__joii__.metadata[i.name].overloads=[]);var r=e.__joii__.metadata[i.name];if("object"!=typeof r.overloads&&(r.overloads=[]),r.visibility!==i.visibility)throw"Member "+i.name+": inconsistent visibility.";r.has_parameterless;r.is_abstract=!1,r.is_final=!1,r.has_parameterless=!1;for(var o=0;o<i.parameters.length-1;o++)if("..."==i.parameters[o])throw"Member "+i.name+": Variadic parameter (...) must be the last in the function parameter list.";for(var s=!i.is_final,f=0;f<r.overloads.length;f++){var p=r.overloads[f],_=!1;if(p.is_abstract&&(_=!0),p.has_parameters||(r.has_parameterless=!0),s=s||!p.is_final,p.parameters.length===i.parameters.length){for(var c=!1,l=0;l<p.parameters.length;l++)p.parameters[l]!=i.parameters[l]&&(c=!0);if(!c){if(!p.is_abstract){if(i.is_final)throw'Final member "'+i.name+"("+i.parameters.join(", ")+')" cannot be overwritten.';if(a)return!1;throw'Member "'+i.name+"("+i.parameters.join(", ")+')" is defined twice.'}r.overloads.splice(f,1),f--,_=!1}}_&&(r.is_abstract=!0)}var u={fn:n,parameters:i.parameters,is_abstract:i.is_abstract,is_final:i.is_final,is_inherited:i.is_inherited,has_parameters:i.has_parameters};return i.has_parameters||(r.has_parameterless=!0),e.__joii__.metadata[i.name].overloads.push(u),u.is_abstract&&(e.__joii__.metadata[i.name].is_abstract=!0),e.__joii__.metadata[i.name].is_final=!s,e[i.name]=t.createFunctionShim(i.name,e.__joii__.metadata[i.name].overloads),!0},t.createFunctionShim=function(e,i){return function(){if(1===i.length&&0===i[0].parameters.length)return i[0].fn.apply(this,arguments);for(var n=null,a=-1,r=null,o=0;o<i.length;o++){var s=i[o],f=s.parameters,p=!0;if(s.has_parameters||(r=s),f.length==arguments.length){for(var _=0;_<f.length;_++)if(!t.Compat.canTypeBeCastTo(arguments[_],f[_])){p=!1;break}if(p)return s.fn.apply(this,arguments)}if("..."==f[f.length-1]){p=null;for(var c=0,_=0;_<f.length;_++)if("..."===f[_])p=!0;else{if(!t.Compat.canTypeBeCastTo(arguments[_],f[_])){p=!1;break}c++}p&&c>a&&(n=s,a=c)}}if(null!=n){if(!s.is_inherited){for(var l=[],_=n.parameters.length-1;_<arguments.length;_++)l.push(arguments[_]);arguments.length=n.parameters.length,arguments[n.parameters.length-1]=l}return n.fn.apply(this,arguments)}if(null!=r)return r.fn.apply(this,arguments);for(var u=[],_=0;_<arguments.length;_++){var m=t.Compat.findJOIIName(arguments[_]);m||(m=typeof arguments[_]),u.push(null===m?typeof arguments[_]:m)}throw"Couldn't find a function handler to match: "+e+"("+u.join(", ")+")."}},t.CamelcaseName=function(e){return e=e.toLowerCase().replace(/_(.)/g,function(e,t){return t.toUpperCase()}),e.charAt(0).toUpperCase()+e.slice(1)},t="undefined"!=typeof t?t:{},t.ClassRegistry={},t.ClassBuilder=function(){function e(){return"undefined"==typeof this||"undefined"==typeof this.__joii__?n.apply(void 0,arguments):new n}function n(){var e=function(){};e.prototype=this;var t=new e,i=o(this,arguments,t,!1);if("undefined"==typeof this||"undefined"==typeof this.__joii__||"object"!=typeof i||"undefined"==typeof i.__joii__)return i;var n=s(this,i);return r(i,n),a(i,arguments),n}function a(e,i){for(var n in t.Config.constructors)if(t.Config.constructors.hasOwnProperty(n)){var a=t.Config.constructors[n];if("function"==typeof e[a]){e[a].apply(e,i);break}}1==i.length&&"object"==typeof i[0]&&"__joii_deserialize_object"in i[0]&&e.deserialize(i[0].data)}function r(e,t){if(e.__api__=t,"undefined"!=typeof e.__joii__.parent)for(var i=e.__joii__.parent;"undefined"!=typeof i;)i.__api__=t,i=i.__joii__.parent}function o(i,n,a,r){var o=a||{};if(r=r||!1,o=t.Compat.extend(!0,{},o),"undefined"!=typeof i&&t.CreateProperty(o,"__joii__",i.__joii__),"undefined"!=typeof i&&"object"==typeof o.__joii__){if(o.__joii__.is_abstract===!0)throw"An abstract class cannot be instantiated.";if(!r&&o.__joii__.is_static===!0)throw"A static class cannot be instantiated."}if("undefined"==typeof i||"undefined"==typeof i.__joii__){if("undefined"!=typeof e)for(var s in t.Config.callables)if(t.Config.callables.hasOwnProperty(s)&&"function"==typeof e[t.Config.callables[s]]){var f=e[t.Config.callables[s]].apply(m,n);if(f===m)throw t.Config.callables[s]+" cannot return itself.";return f}throw"This class cannot be called as a function because it's lacking the __call method."}if(i.__joii__.is_abstract)throw"Cannot instantiate abstract class "+i.__joii__.name;return o}function s(e,i,n){var a=n||{};if("undefined"!=typeof e&&"object"==typeof e.__joii__){if(t.CreateProperty(a,"__joii__",e.__joii__),a.__joii__.is_abstract===!0)throw"An abstract class cannot be instantiated.";for(var r in e){var o=i.__joii__.metadata[r];if(o&&"overloads"in o){for(var s in o.overloads)if(o.overloads[s]&&o.overloads[s].is_abstract===!0)throw"Missing abstract member implementation of "+r+"("+o.overloads[s].parameters.join(", ")+")"}else if(o&&o.is_abstract===!0)throw'Missing abstract member implementation of "'+r+'".'}}return f(i,a),a}function f(e,i){for(var n in e){var a=e.__joii__.metadata[n];"function"!=typeof e[n]||"undefined"!=typeof a&&"public"!==a.visibility||"__call"===n||(i[n]=t.Compat.Bind(e[n],e))}}function p(e){e.getInterfaces=t.Compat.Bind(function(){var e=[],i=t.Compat.Bind(function(e){if("function"==typeof e)return e;if("string"==typeof e){if("undefined"==typeof t.InterfaceRegistry[e])throw'Interface "'+e+'" does not exist.';return t.InterfaceRegistry[e]}},this);if("undefined"!=typeof this.parent&&"undefined"!=typeof this.parent.__joii__&&(e=this.parent.__joii__.getInterfaces()),"undefined"!=typeof this.interfaces)if("object"==typeof this.interfaces)for(var n in this.interfaces)this.interfaces.hasOwnProperty(n)&&e.push(i(this.interfaces[n]));else e.push(i(this.interfaces));return e},e)}function _(){var i=function(){};i.prototype=this;var f=new i;e.prototype=n;var p=o(this,[],f,!0);return e=t.Compat.extend(!0,e,p),n=s(e,e,n),r(e,n),a(e,[]),e}var c=t.Compat.ParseArguments(arguments),l=c.name,u=c.parameters,m=c.body,d=c.is_static_generated===!0;if("function"==typeof m&&(m=m(e)),"object"!=typeof m)throw"Invalid parameter types given. Expected: ([[[string], object], <object|function>]).";n.prototype=t.PrototypeBuilder(l,u,m,!1,d);for(var y in n.prototype.__joii__.constants)t.CreateProperty(n,y,n.prototype.__joii__.constants[y],!1);if("string"==typeof u["enum"]){var h=t.EnumBuilder(u["enum"],n);if(u.expose_enum===!0){var b="object"==typeof window?window:global;if("undefined"!=typeof b[u["enum"]])throw'Cannot expose Enum "'+u["enum"]+'" becase it already exists in the global scope.';b[u["enum"]]=h}}var g=arguments[0];if(n.toString=function(){return"string"==typeof g?"[class "+g+"]":"[class Class]"},n.prototype.__joii__.interfaces=u["implements"],p(n.prototype.__joii__),u["abstract"]!==!0){var v=n.prototype.__joii__.getInterfaces();for(var j in v)v.hasOwnProperty(j)&&"function"==typeof v[j]&&v[j](n)}if(u["static"]!==!0&&!d){if(!("serialize"in n.prototype.__joii__.metadata)||"overloads"in n.prototype.__joii__.metadata.serialize&&(n.prototype.__joii__.metadata.serialize.overloads[0].parameters.length>0||n.prototype.__joii__.metadata.serialize.overloads.length>1)){var C=function(e){var t={__joii_type:this.__joii__.name};for(var i in this.__joii__.metadata){var n=this.__joii__.metadata[i];n.serializable&&(n.is_joii_object&&!n.is_enum&&"object"==typeof this[n.name]&&null!=this[n.name]?t[n.name]=JSON.parse(this[n.name].serialize()):t[n.name]=this[n.name])}return JSON.stringify(t)},w=t.ParseClassProperty("public function serialize()");t.addFunctionToPrototype(n.prototype,w,C,!0)}if(!("deserialize"in n.prototype.__joii__.metadata)||"overloads"in n.prototype.__joii__.metadata.deserialize&&(n.prototype.__joii__.metadata.deserialize.overloads[0].parameters.length>0||n.prototype.__joii__.metadata.deserialize.overloads.length>1)){var C=function(e){this.deserialize(JSON.parse(e))},P=t.ParseClassProperty("public function deserialize(string)");t.addFunctionToPrototype(n.prototype,P,C,!0),C=function(e){for(var i in this.__joii__.metadata){var n=this.__joii__.metadata[i];if(n.serializable&&n.name in e&&"function"!=typeof e[n.name])if("object"==typeof e[n.name]&&null!=e[n.name]&&"__joii_type"in e[n.name]){var a=e[n.name].__joii_type;if("undefined"!=typeof t.InterfaceRegistry[a])throw"Cannot instantiate an interface.";if("undefined"==typeof t.ClassRegistry[a])throw"Class "+a+" not currently in scope!";this[n.name]=t.ClassRegistry[a].deserialize(e[n.name])}else this[n.name]=e[n.name]}},P=t.ParseClassProperty("public function deserialize(object)"),t.addFunctionToPrototype(n.prototype,P,C,!0)}}if(!d&&"string"!=typeof u["enum"]){var O=!1;if(O=!0,_.prototype=t.PrototypeBuilder(l,u,m,!1,!0),_.prototype.__joii__.interfaces=u["implements"],p(_.prototype.__joii__),u["abstract"]!==!0){var v=_.prototype.__joii__.getInterfaces();for(var j in v)v.hasOwnProperty(j)&&"function"==typeof v[j]&&v[j](_)}var C=function(e){return this.deserialize(JSON.parse(e))},P=t.ParseClassProperty("public static function deserialize(string)");t.addFunctionToPrototype(_.prototype,P,C,!0),C=function(e){var t={__joii_deserialize_object:!0,data:e};return new n(t)},P=t.ParseClassProperty("public static function deserialize(object)"),t.addFunctionToPrototype(_.prototype,P,C,!0),i[l]=new _,n.__joii__.prototype=_.prototype}if("undefined"!=typeof t.ClassRegistry[l])throw'Another class named "'+l+'" already exists.';return t.ClassRegistry[l]=n,n.prototype=t.Compat.extend(!0,{},n.prototype),n},t="undefined"!=typeof t?t:{},t.InterfaceRegistry={},t.InterfaceBuilder=function(){var e=t.Compat.ParseArguments(arguments),i=e.name,n=e.parameters,a=e.body,r=t.PrototypeBuilder(i,n,a,!0),o=function(e){var i,n,a,r=new t.Reflection.Class(e),o=this.reflector.getProperties(),s=this.reflector.getMethods();if(r.isAbstract())return!0;var f=function(e,t,i,n){if(t.getVisibility()!==i.getVisibility())throw n+" "+i.getName()+" cannot be "+i.getVisibility()+" because the interface declared it "+t.getVisibility()+".";if("Method"!=n){if(t.getType()!==i.getType())throw n+" "+i.getName()+" cannot be declared as "+i.getType()+" because the interface declared it as "+t.getType()+".";if(t.isNullable()!==i.isNullable())throw n+" "+i.getName()+" must be nullable as defined in the interface "+e.name+"."}return!0};for(i in o)if(o.hasOwnProperty(i)!==!1&&(n=o[i],(!n.isStatic()||r.isStatic())&&(n.isStatic()||!r.isStatic()))){if(!r.hasProperty(n.getName()))throw"Class must implement "+n.toString().split(":")[0]+" as defined in the interface "+this.name+".";a=r.getProperty(n.getName()),f(this,n,a,"Property")}for(i in s)if(s.hasOwnProperty(i)!==!1&&(n=s[i],(!n.isStatic()||r.isStatic())&&(n.isStatic()||!r.isStatic()))){if(!r.hasMethod(n.getName()))throw"Class must implement "+n.toString().split(":")[0]+" as defined in the interface "+this.name+".";a=r.getMethod(n.getName()),f(this,n,a,"Method");var p=n.getParameters(),_=a.getParameters();if(0==p.length||"object"!=typeof p[0]){if(p.length!==_.length)throw"Method "+n.getName()+" does not match the parameter count as defined in the interface "+this.name+"."}else for(var c=0;c<p.length;c++){for(var l=p[c],u=!0,m=0;m<_.length;m++){var d=_[m];if(l.length===d.length){u=!1;for(var y=0;y<l.length;y++)l[y].type!=d[y].type&&(u=!0);if(!u)break}}if(u)throw"Method "+n.getName()+" does not match the parameter types as defined in the interface "+this.name+"."}}};t.CreateProperty(o,"__interface__",{prototype:r,reflector:new t.Reflection.Class(r),name:i}),t.CreateProperty(o,"__joii__",r.__joii__);var s=t.Compat.Bind(o,o.__interface__);s.prototype=r;var f,p=o.__interface__.reflector.getProperties(),_=o.__interface__.reflector.getMethods(),c=function(e,t){if(e.isAbstract())throw"An interface may not contain abstract definitions. "+t+" "+e.getName()+" is abstract in interface "+o.__interface__.name+".";if(e.isFinal())throw"An interface may not contain final definitions. "+t+" "+e.getName()+" is final in interface "+o.__interface__.name+"."};for(f in p)p.hasOwnProperty(f)!==!1&&c(p[f],"Property");for(f in _)_.hasOwnProperty(f)!==!1&&c(_[f],"Method");if(t.CreateProperty(s,"definition",o),"undefined"!=typeof t.InterfaceRegistry[i])throw'Another interface with the name "'+i+'" already exists.';if(-1!==t.Compat.indexOf(t.InternalTypeNames,i))throw'An interface may not be named "'+i+'", becase that name is reserved.';var l={};for(f in r.__joii__.constants)r.__joii__.constants.hasOwnProperty(f)!==!1&&(t.CreateProperty(s,f,r.__joii__.constants[f],!1),l[f]=r.__joii__.constants[f]);if("string"==typeof n["enum"]){var u=t.EnumBuilder(n["enum"],l);if(n.expose_enum===!0){var m="object"==typeof window?window:global;if("undefined"!=typeof m[n["enum"]])throw'Cannot expose Enum "'+n["enum"]+'" becase it already exists in the global scope.';m[n["enum"]]=u}}return t.InterfaceRegistry[i]=s,s},t="undefined"!=typeof t?t:{},t.EnumRegistry={},t.EnumBuilder=t.ClassBuilder({"final":!0},{"public immutable string name":null,"public immutable object constants":{},__construct:function(e,t){ this.name=e,this.constants=t},contains:function(e){for(var t in this.constants)if(this.constants.hasOwnProperty(t)!==!1&&this.constants[t]===e)return!0;return!1},__call:function(e,i){if("string"!=typeof e)throw"Argument #1 of Enum must be a string, "+typeof e+" given.";if("function"==typeof i&&"undefined"!=typeof i.prototype.__joii__&&(i=i.prototype.__joii__.constants),"object"!=typeof i)throw"Argument #2 of Enum must be an object or definition, "+typeof i+" given.";if("undefined"!=typeof t.EnumRegistry[e.toLowerCase()])throw'Enumerator "'+e+'" already exists.';var n=new t.EnumBuilder(e,i);for(var a in i){if("function"==typeof i[a])throw'An enumerator cannot contain functions. "'+a+'" is a function.';if("object"==typeof i[a])throw'An enumerator cannot contain objects. "'+a+'" is an object.';t.CreateProperty(n,a,i[a],!1)}return t.EnumRegistry[e.toLowerCase()]=n,n}}),t="undefined"!=typeof t?t:{},t.Reflection={},t.Reflection.Class=t.ClassBuilder({},{"protected immutable object meta":null,"protected immutable object proto":null,"public immutable object parent":null,"protected __construct":function(e){if("function"==typeof e&&(e=e.prototype),"object"!=typeof e||"object"!=typeof e.__joii__)throw"Reflection.Class requires a JOII-created definition.";this.proto=e,this.meta=e.__joii__,"undefined"!=typeof this.meta.parent&&(this.parent=new t.Reflection.Class(this.meta.parent))},"public getName":function(){return this.meta.name},"public isAbstract":function(){return this.meta.is_abstract===!0},"public isStatic":function(){return this.meta.is_static},"public hasProperty":function(e){var t=this.getProperties();for(var i in t)if(t[i].getName()===e)return!0;return!1},"public hasParent":function(){return null!==this.parent},"public getParent":function(){return this.parent},"public getMethods":function(e){var i=[];for(var n in this.proto)"function"==typeof this.proto[n]&&-1===t.Compat.indexOf(t.InternalPropertyNames,n)&&i.push(new t.Reflection.Method(this,n));return i},"public hasMethod":function(e){var t=this.getMethods();for(var i in t)if(t[i].getName()===e)return!0;return!1},"public getMethod":function(e){var t=this.getMethods();for(var i in t)if(t[i].getName()===e)return t[i];throw'Method "'+e+'" does not exist.'},"public getProperties":function(e){var i=[];for(var n in this.proto)"function"!=typeof this.proto[n]&&-1===t.Compat.indexOf(t.InternalPropertyNames,n)&&i.push(new t.Reflection.Property(this,n));return i},"public getProperty":function(e){var t=this.getProperties();for(var i in t)if(t[i].getName()===e)return t[i];throw'Property "'+e+'" does not exist.'}}),t.Reflection.Property=t.ClassBuilder({},{"protected nullable object reflector":null,"protected nullable object meta":null,"public read string name":null,"protected __construct":function(e,t){this.reflector=e,this.name=t,this.meta=e.getMeta().metadata[t],"undefined"==typeof this.meta&&(this.meta={name:this.name,type:null,visibility:"public",is_nullable:!1,is_abstract:!1,is_read_only:!1,is_final:!1}),null===this.meta.type&&this.meta.is_nullable===!1&&(this.meta.type=typeof this.reflector.getProto()[this.meta.name])},"public getType":function(){return this.meta.type},"public isAbstract":function(){return this.meta.is_abstract},"public isStatic":function(){return this.meta.is_static},"public isNullable":function(){return this.meta.is_nullable},"public isFinal":function(){return this.meta.is_final},"public isPrivate":function(){return"private"===this.meta.visibility},"public isProtected":function(){return"protected"===this.meta.visibility},"public isPublic":function(){return"public"===this.meta.visibility},"public isImmutable":function(){return this.meta.is_read_only},"public isConstant":function(){return this.meta.is_constant},"public isType":function(e){return e===this.meta.type},"public getVisibility":function(){return this.meta.visibility},toString:function(){var e=[],t=this.reflector.getProto()[this.name],i="",n="";return this.meta.is_abstract&&e.push("abstract"),this.meta.is_final&&e.push("final"),e.push(this.meta.visibility),this.meta.is_static&&e.push("static"),this.meta.is_nullable&&e.push("nullable"),this.meta.is_read_only&&e.push("read"),null===this.meta.type?null===t?e.push("mixed"):e.push(typeof t):e.push(this.meta.type),e.push('"'+this.meta.name+'"'),i=e.join(" "),n="function"==typeof t?"[Function]":"object"==typeof t&&null!==t?"[Object ("+t.length+")]":"string"==typeof t?'"'+t+'"':t,i+": "+n}}),t.Reflection.Method=t.ClassBuilder({"extends":t.Reflection.Property},{"public getParameters":function(){var e=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,t=/,/,i=/^\s*(_?)(\S+?)\1\s*$/,n=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,a=function(a){var r,o,s=[];r=a.toString().replace(n,""),o=r.match(e);var f=o[1].split(t),p=function(e,t,i){s.push(i)};for(var _ in f){var c=f[_];c.replace(i,p)}return s},r=this.reflector.getProto(),o=r.__joii__.metadata[this.name].overloads;if(o&&0!==o.length){if(1===o.length&&0===o[0].parameters.length)return a(o[0].fn);for(var s=[],f=0;f<o.length;f++){for(var p=[],_=o[f],c=a(_.fn),l=0;l<_.parameters.length;l++){var u={name:c.length>l?c[l]:null,type:_.parameters[l]};p.push(u)}s.push(p)}return s}return a(this.reflector.getProto()[this.name])},"public getBodyAsString":function(e){var t=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,i=this.reflector.getProto()[this.name].toString().replace(t,"");return i.substr(i.indexOf("{")+1,i.lastIndexOf("}")-4).replace(/}([^}]*)$/,"$1")},"public usesVariadicArguments":function(){var e=this.reflector.getProto()[this.name].toString();return e.match(/[\(|\.|\ ](arguments)[\)|\.|\,|\ |]/g)},toString:function(){var e=this["super"]("toString").split(":")[0],t="[Function",i=this.getParameters(),n=this.usesVariadicArguments();if(i.length>0&&"object"==typeof i[0])for(var a=0;a<i.length;a++){var r=i[a];t+=" (";for(var o=!0,s=0;s<r.length;s++)o||(t+=", "),o=!1,t+=r[s].type,null!==r[s].name&&(t+=" "+r[s].name,n=!0);var f=this.reflector.getProto().__joii__.metadata[this.name].overloads[a].fn.toString();n=f.match(/[\(|\.|\ ](arguments)[\)|\.|\,|\ |]/g),n&&(t+=", ..."),t+=")\n"}else i.length>0?(t+=" ("+i.join(", "),n&&(t+=", ..."),t+=")"):0===i.length&&n&&(t+=" (...)");return t+="]",e+": "+t}}),e.JOII=t,e.Class=t.ClassBuilder,e.Interface=t.InterfaceBuilder,e.Enum=t.EnumBuilder,e.useGlobal=function(){var t="object"==typeof window?window:global;for(var i in e)e.hasOwnProperty(i)!==!1&&(t[i]=e[i])},e});