<commit_before>#include "resources.h"

namespace simpleServer {
Resource client_rpc_js = {
		"text/javascript",
		R"javascript(  //"

var RpcClient = (function(){
	"use strict";
	
	
	function RpcClient(url) {
		this.url = url;
		this.nextId = 1;
		this.context={};
	};
	
	function isObjEmpty(obj) {
		Object.keys(obj).length === 0; 
	}
	
	RpcClient.prototype.call2 = function(method,args,retryCnt) {
		if (!retryCnt) retryCnt = 0;

		function retryCallback(status, statusText, decision) {			
			if (decision) {
				return this.call2(method,args, retryCnt+1);
			} else {
				throw {code:status,message:statusText};
			}
		}
		

		var id = this.nextId++;
		var req = {
				jsonrpc: "2.0",
				id:this.nextId,
				method:method,
				params: args
		};
		if (Object.keys(this.context).length) {
			req.context = this.context;
		}
		return fetch(this.url, {
			method: "POST",
			headers: {
				"Content-Type":"application/json",
				"Accept":"application/json"
			},
			body: JSON.stringify(req)
		}).then(function(resp) {
			if (resp.status != 200) {
					return Promise.resolve(this.onConnectionError(
									[resp.status,resp.statusText],retryCnt))
							.then(retryCallback.bind(this,xhr.status,xhr.statusText));
			} else {
				return resp.json().then(function(jres) {
					if (jres.error) {
						return this.onError(jres.error).then(function(z) {
							if (z === undefined) return this.call2(method,args);
							else return z;
						}.bind(this));
					} else {
						if (jres.context) {
							this.updateContext(jres.context);
						}
						return jres.result;
					}
				}.bind(this),function(err){
					var msg = "Response parse error";
					return Promise.resolve(this.onConnectionError(
							[1,err],retryCnt)).then(retryCallback.bind(this,1,err));
				}.bind(this));
			}			
		}.bind(this), function(err) {
			return Promise.resolve(this.onConnectionError(
					[0,err],retryCnt)).then(retryCallback.bind(this,0,err));
		}.bind(this));		
	};
	
	RpcClient.prototype.updateContext = function(newCtx) {
		for (var i in newCtx) {
			if (newCtx[i] === null) delete this.context[i];
			else this.context[i] = newCtx[i];
		}<commit_msg>fix js error in rpc.js<commit_after>#include "resources.h"

namespace simpleServer {
Resource client_rpc_js = {
		"text/javascript",
		R"javascript(  //"

var RpcClient = (function(){
	"use strict";
	
	
	function RpcClient(url) {
		this.url = url;
		this.nextId = 1;
		this.context={};
	};
	
	function isObjEmpty(obj) {
		Object.keys(obj).length === 0; 
	}
	
	RpcClient.prototype.call2 = function(method,args,retryCnt) {
		if (!retryCnt) retryCnt = 0;

		function retryCallback(status, statusText, decision) {			
			if (decision) {
				return this.call2(method,args, retryCnt+1);
			} else {
				throw {code:status,message:statusText};
			}
		}
		

		var id = this.nextId++;
		var req = {
				jsonrpc: "2.0",
				id:this.nextId,
				method:method,
				params: args
		};
		if (Object.keys(this.context).length) {
			req.context = this.context;
		}
		return fetch(this.url, {
			method: "POST",
			headers: {
				"Content-Type":"application/json",
				"Accept":"application/json"
			},
			body: JSON.stringify(req)
		}).then(function(resp) {
			if (resp.status != 200) {
					return Promise.resolve(this.onConnectionError(
									[resp.status,resp.statusText],retryCnt))
							.then(retryCallback.bind(this,resp.status,resp.statusText));
			} else {
				return resp.json().then(function(jres) {
					if (jres.error) {
						return this.onError(jres.error).then(function(z) {
							if (z === undefined) return this.call2(method,args);
							else return z;
						}.bind(this));
					} else {
						if (jres.context) {
							this.updateContext(jres.context);
						}
						return jres.result;
					}
				}.bind(this),function(err){
					var msg = "Response parse error";
					return Promise.resolve(this.onConnectionError(
							[1,err],retryCnt)).then(retryCallback.bind(this,1,err));
				}.bind(this));
			}			
		}.bind(this), function(err) {
			return Promise.resolve(this.onConnectionError(
					[0,err],retryCnt)).then(retryCallback.bind(this,0,err));
		}.bind(this));		
	};
	
	RpcClient.prototype.updateContext = function(newCtx) {
		for (var i in newCtx) {
			if (newCtx[i] === null) delete this.context[i];
			else this.context[i] = newCtx[i];
		}
{'fraction_non_alphanumeric': 0.16198001394376016, 'fraction_numerical': 0.007436672089240065, 'mean_word_length': 3.16247582205029, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3349075', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1522, 'n_words': 258}