export default class RemoteObject{static fromLocalObject(value){return new LocalJSONObject(value);} static type(remoteObject){if(remoteObject===null){return'null';} const type=typeof remoteObject;if(type!=='object'&&type!=='function'){return type;} return remoteObject.type;} static arrayNameFromDescription(description){return description.replace(_descriptionLengthParenRegex,'').replace(_descriptionLengthSquareRegex,'');} static arrayLength(object){if(object.subtype!=='array'&&object.subtype!=='typedarray'){return 0;} const parenMatches=object.description.match(_descriptionLengthParenRegex);const squareMatches=object.description.match(_descriptionLengthSquareRegex);return parenMatches?parseInt(parenMatches[1],10):(squareMatches?parseInt(squareMatches[1],10):0);} static unserializableDescription(object){const type=typeof object;if(type==='number'){const description=String(object);if(object===0&&1/object<0){return UnserializableNumber.Negative0;} if(description===UnserializableNumber.NaN||description===UnserializableNumber.Infinity||description===UnserializableNumber.NegativeInfinity){return description;}} if(type==='bigint'){return object+'n';} return null;} static toCallArgument(object){const type=typeof object;if(type==='undefined'){return{};} const unserializableDescription=RemoteObject.unserializableDescription(object);if(type==='number'){if(unserializableDescription!==null){return{unserializableValue:unserializableDescription};} return{value:object};} if(type==='bigint'){return{unserializableValue:(unserializableDescription)};} if(type==='string'||type==='boolean'){return{value:object};} if(!object){return{value:null};} if(object instanceof RemoteObject){const unserializableValue=object.unserializableValue();if(unserializableValue!==undefined){return{unserializableValue:unserializableValue};}}else if(object.unserializableValue!==undefined){return{unserializableValue:object.unserializableValue};} if(typeof object.objectId!=='undefined'){return{objectId:object.objectId};} return{value:object.value};} static async loadFromObjectPerProto(object,generatePreview){const result=await Promise.all([object.getAllProperties(true,generatePreview),object.getOwnProperties(generatePreview)]);const accessorProperties=result[0].properties;const ownProperties=result[1].properties;const internalProperties=result[1].internalProperties;if(!ownProperties||!accessorProperties){return({properties:null,internalProperties:null});} const propertiesMap=new Map();const propertySymbols=[];for(let i=0;ipreviewChars){buffer+=',\u2026';break;} if(i){buffer+=', ';} buffer+=itemDescription;} buffer+=suffix;return buffer;} get type(){return typeof this._value;} get subtype(){if(this._value===null){return'null';} if(Array.isArray(this._value)){return'array';} if(this._value instanceof Date){return'date';} return undefined;} get hasChildren(){if((typeof this._value!=='object')||(this._value===null)){return false;} return!!Object.keys((this._value)).length;} getOwnProperties(generatePreview){return Promise.resolve(({properties:this._children(),internalProperties:null}));} getAllProperties(accessorPropertiesOnly,generatePreview){if(accessorPropertiesOnly){return Promise.resolve(({properties:[],internalProperties:null}));}else{return Promise.resolve(({properties:this._children(),internalProperties:null}));}} _children(){if(!this.hasChildren){return[];} const value=(this._value);function buildProperty(propName){let propValue=value[propName];if(!(propValue instanceof RemoteObject)){propValue=RemoteObject.fromLocalObject(propValue);} return new RemoteObjectProperty(propName,propValue);} if(!this._cachedChildren){this._cachedChildren=Object.keys(value).map(buildProperty);} return this._cachedChildren;} arrayLength(){return Array.isArray(this._value)?this._value.length:0;} callFunction(functionDeclaration,args){const target=(this._value);const rawArgs=args?args.map(arg=>arg.value):[];let result;let wasThrown=false;try{result=functionDeclaration.apply(target,rawArgs);}catch(e){wasThrown=true;} const object=RemoteObject.fromLocalObject(result);return Promise.resolve(({object,wasThrown}));} callFunctionJSON(functionDeclaration,args){const target=(this._value);const rawArgs=args?args.map(arg=>arg.value):[];let result;try{result=functionDeclaration.apply(target,rawArgs);}catch(e){result=null;} return Promise.resolve(result);}} export class RemoteArray{constructor(object){this._object=object;} static objectAsArray(object){if(!object||object.type!=='object'||(object.subtype!=='array'&&object.subtype!=='typedarray')){throw new Error('Object is empty or not an array');} return new RemoteArray(object);} static createFromRemoteObjects(objects){if(!objects.length){throw new Error('Input array is empty');} const objectArguments=[];for(let i=0;i1){return new Array(arguments);} return[arguments[0]];} function returnRemoteArray(result){if(result.wasThrown||!result.object){throw new Error('Call function throws exceptions or returns empty value');} return RemoteArray.objectAsArray(result.object);}} at(index){if(index<0||index>this._object.arrayLength()){throw new Error('Out of range');} return this._object.callFunction(at,[RemoteObject.toCallArgument(index)]).then(assertCallFunctionResult);function at(index){return this[index];} function assertCallFunctionResult(result){if(result.wasThrown||!result.object){throw new Error('Exception in callFunction or result value is empty');} return result.object;}} length(){return this._object.arrayLength();} map(func){const promises=[];for(let i=0;i