c8osdkjscore
Advanced tools
Comparing version 0.0.0-beta12 to 0.0.0-beta13
{ | ||
"name": "c8osdkjscore", | ||
"version": "0.0.0-beta12", | ||
"version": "0.0.0-beta13", | ||
"description": "convertigo's sdk js core", | ||
@@ -5,0 +5,0 @@ "main": "bundle/index.umd.js", |
@@ -160,2 +160,2 @@ import {C8oLogLevel} from "./c8oLogLevel"; | ||
} | ||
} | ||
} |
@@ -39,10 +39,10 @@ "use strict"; | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oFullSync_1 = require("./c8oFullSync"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oLocalCache_1 = require("./c8oLocalCache"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oLocalCacheResponse_1 = require("./c8oLocalCacheResponse"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oTranslator_1 = require("./c8oTranslator"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oHttpRequestException_1 = require("./Exception/c8oHttpRequestException"); | ||
@@ -194,3 +194,3 @@ var c8oUnavailableLocalCacheException_1 = require("./Exception/c8oUnavailableLocalCacheException"); | ||
case 2: | ||
if (error["status"] === 0) { | ||
if (error.status === 0) { | ||
reject(new c8oHttpRequestException_1.C8oHttpRequestException("ERR_INTERNET_DISCONNECTED", error)); | ||
@@ -197,0 +197,0 @@ } |
import {C8oCore} from "./c8oCore"; | ||
import {C8oResponseListener, C8oResponseJsonListener} from "./c8oResponse"; | ||
import {C8oExceptionListener} from "./Exception/c8oExceptionListener"; | ||
import {C8oFullSync, C8oFullSyncCbl} from "./c8oFullSync"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {C8oLocalCache} from "./c8oLocalCache"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oLocalCacheResponse} from "./c8oLocalCacheResponse"; | ||
import {C8oResponseJsonListener, C8oResponseListener} from "./c8oResponse"; | ||
import {C8oTranslator} from "./c8oTranslator"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oExceptionListener} from "./Exception/c8oExceptionListener"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {C8oHttpRequestException} from "./Exception/c8oHttpRequestException"; | ||
import {C8oUnavailableLocalCacheException} from "./Exception/c8oUnavailableLocalCacheException" | ||
import {C8oUnavailableLocalCacheException} from "./Exception/c8oUnavailableLocalCacheException"; | ||
@@ -46,4 +46,3 @@ export class C8oCallTask { | ||
}); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
this.c8oExceptionListener.onException(error, this.parameters); | ||
@@ -59,8 +58,6 @@ } | ||
async handleRequest(): Promise<any> { | ||
public async handleRequest(): Promise<any> { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
let isFullSyncRequest: boolean = C8oFullSync.isFullSyncRequest(this.parameters); | ||
const isFullSyncRequest: boolean = C8oFullSync.isFullSyncRequest(this.parameters); | ||
if (isFullSyncRequest) { | ||
@@ -70,5 +67,5 @@ this.c8o.log._debug("Is FullSync request"); | ||
// FS_LIVE | ||
let liveid = C8oUtilsCore.getParameterStringValue(this.parameters, C8oCore.FS_LIVE, false); | ||
const liveid = C8oUtilsCore.getParameterStringValue(this.parameters, C8oCore.FS_LIVE, false); | ||
if (liveid !== null) { | ||
let dbName: string = (C8oUtilsCore.getParameterStringValue(this.parameters, C8oCore.ENGINE_PARAMETER_PROJECT, true) as string).substring(C8oFullSync.FULL_SYNC_PROJECT.length); | ||
const dbName: string = (C8oUtilsCore.getParameterStringValue(this.parameters, C8oCore.ENGINE_PARAMETER_PROJECT, true) as string).substring(C8oFullSync.FULL_SYNC_PROJECT.length); | ||
this.c8o.addLive(liveid, dbName, this); | ||
@@ -85,9 +82,7 @@ } | ||
reject(error); | ||
} | ||
else { | ||
} else { | ||
reject(new C8oException(C8oExceptionMessage.handleFullSyncRequest(), error)); | ||
} | ||
}); | ||
} | ||
else { | ||
} else { | ||
let responseType: string = ""; | ||
@@ -101,3 +96,3 @@ if (this.c8oResponseListener instanceof C8oResponseJsonListener) { | ||
let c8oCallRequestIdentifier: string = null; | ||
let localCache: C8oLocalCache = C8oUtilsCore.getParameterObjectValue(this.parameters, C8oLocalCache.PARAM, false); | ||
const localCache: C8oLocalCache = C8oUtilsCore.getParameterObjectValue(this.parameters, C8oLocalCache.PARAM, false); | ||
let localCacheEnabled: boolean = false; | ||
@@ -112,4 +107,3 @@ | ||
c8oCallRequestIdentifier = C8oUtilsCore.identifyC8oCallRequest(this.parameters, responseType); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(new C8oException(C8oExceptionMessage.serializeC8oCallRequest(), error)); | ||
@@ -119,10 +113,9 @@ } | ||
// if connection is not available this will generates an exception that will be caught | ||
if(localCache.priority.isAvailable) { | ||
if (localCache.priority.isAvailable) { | ||
try { | ||
let result = await (this.c8o.c8oFullSync as C8oFullSyncCbl).getResponseFromLocalCache(c8oCallRequestIdentifier); | ||
const result = await (this.c8o.c8oFullSync as C8oFullSyncCbl).getResponseFromLocalCache(c8oCallRequestIdentifier); | ||
if (result instanceof C8oUnavailableLocalCacheException) { | ||
// no entry | ||
} | ||
else { | ||
let localCacheResponse: C8oLocalCacheResponse = (result as C8oLocalCacheResponse); | ||
} else { | ||
const localCacheResponse: C8oLocalCacheResponse = (result as C8oLocalCacheResponse); | ||
@@ -136,8 +129,6 @@ if (!localCacheResponse.isExpired()) { | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
if (error instanceof C8oUnavailableLocalCacheException) { | ||
// no entry | ||
} | ||
else { | ||
} else { | ||
reject(error); | ||
@@ -153,9 +144,9 @@ } | ||
this.c8oCallUrl = this.c8o.endpoint + "/." + responseType; | ||
let params : Object = new Object(); | ||
params= Object.assign(params, this.parameters) | ||
await this.c8o.httpInterface.handleRequest(this.c8oCallUrl, params, this.c8oResponseListener | ||
let params: Object = new Object(); | ||
params = Object.assign(params, this.parameters); | ||
await this.c8o.httpInterface.handleRequest(this.c8oCallUrl, params, this.c8oResponseListener, | ||
).catch( | ||
async (error) => { | ||
if (localCacheEnabled) { | ||
await (this.c8o.c8oFullSync as C8oFullSyncCbl).getResponseFromLocalCache(c8oCallRequestIdentifier | ||
await (this.c8o.c8oFullSync as C8oFullSyncCbl).getResponseFromLocalCache(c8oCallRequestIdentifier, | ||
).then( | ||
@@ -169,4 +160,3 @@ (localCacheResponse: C8oLocalCacheResponse) => { | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
// no entry | ||
@@ -176,6 +166,5 @@ } | ||
} | ||
if (error["status"] === 0) { | ||
if (error.status === 0) { | ||
reject(new C8oHttpRequestException("ERR_INTERNET_DISCONNECTED", error)); | ||
} | ||
else { | ||
} else { | ||
reject(new C8oException(C8oExceptionMessage.handleC8oCallRequest(), error, true)); | ||
@@ -192,13 +181,10 @@ } | ||
responseString = result; | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(new C8oException(C8oExceptionMessage.parseInputStreamToString(), error)); | ||
} | ||
response = result; | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(error); | ||
} | ||
} | ||
else { | ||
} else { | ||
reject(new C8oException(C8oExceptionMessage.wrongListener(this.c8oResponseListener))); | ||
@@ -212,4 +198,4 @@ } | ||
} | ||
let localCacheResponse: C8oLocalCacheResponse = new C8oLocalCacheResponse(responseString, responseType, expirationDate); | ||
let p1 = await (this.c8o.c8oFullSync as C8oFullSyncCbl).saveResponseToLocalCache(c8oCallRequestIdentifier, localCacheResponse); | ||
const localCacheResponse: C8oLocalCacheResponse = new C8oLocalCacheResponse(responseString, responseType, expirationDate); | ||
const p1 = await (this.c8o.c8oFullSync as C8oFullSyncCbl).saveResponseToLocalCache(c8oCallRequestIdentifier, localCacheResponse); | ||
Promise.all([p1]) | ||
@@ -219,4 +205,3 @@ .then(() => { | ||
}); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(new C8oException(C8oExceptionMessage.saveResponseToLocalCache())); | ||
@@ -229,4 +214,3 @@ } | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(error); | ||
@@ -236,3 +220,2 @@ } | ||
} | ||
@@ -244,18 +227,14 @@ | ||
return; | ||
} | ||
else if (result instanceof Error || result instanceof C8oException) { | ||
} else if (result instanceof Error || result instanceof C8oException) { | ||
this.c8o.handleCallException(this.c8oExceptionListener, this.parameters, result); | ||
} | ||
else if (result instanceof Object) { | ||
} else if (result instanceof Object) { | ||
this.c8o.log.logC8oCallJSONResponse(result, this.c8oCallUrl, this.parameters); | ||
(this.c8oResponseListener as C8oResponseJsonListener).onJsonResponse(result, this.parameters); | ||
} | ||
else { | ||
} else { | ||
this.c8o.handleCallException(this.c8oExceptionListener, this.parameters, new C8oException(C8oExceptionMessage.wrongResult(result))); | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
this.c8o.handleCallException(this.c8oExceptionListener, this.parameters, error); | ||
} | ||
} | ||
} | ||
} |
@@ -8,6 +8,6 @@ import { C8oBase } from "./c8oBase"; | ||
import { C8oResponseListener } from "./c8oResponse"; | ||
import { C8oCallTask } from "./c8oCallTask"; | ||
import { C8oFullSyncChangeListener } from "./c8oFullSyncChangeListener"; | ||
import { C8oPromise } from "./c8oPromise"; | ||
import { C8oCallTask } from "./c8oCallTask"; | ||
import { C8oExceptionListener } from "./Exception/c8oExceptionListener"; | ||
import { C8oFullSyncChangeListener } from "./c8oFullSyncChangeListener"; | ||
export declare abstract class C8oCore extends C8oBase { | ||
@@ -48,4 +48,4 @@ protected static RE_REQUESTABLE: RegExp; | ||
c8oFullSync: C8oFullSync; | ||
lives: Array<C8oCallTask>; | ||
livesDb: Array<string>; | ||
lives: C8oCallTask[]; | ||
livesDb: string[]; | ||
protected data: any; | ||
@@ -52,0 +52,0 @@ protected _http: any; |
@@ -14,13 +14,13 @@ "use strict"; | ||
var c8oBase_1 = require("./c8oBase"); | ||
var c8oLogger_1 = require("./c8oLogger"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oLogger_1 = require("./c8oLogger"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oFullSync_1 = require("./c8oFullSync"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oCallTask_1 = require("./c8oCallTask"); | ||
var c8oFullSyncChangeListener_1 = require("./c8oFullSyncChangeListener"); | ||
var c8oPromise_1 = require("./c8oPromise"); | ||
var c8oCallTask_1 = require("./c8oCallTask"); | ||
var c8oCouchBaseLiteException_1 = require("./Exception/c8oCouchBaseLiteException"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oExceptionListener_1 = require("./Exception/c8oExceptionListener"); | ||
var c8oFullSyncChangeListener_1 = require("./c8oFullSyncChangeListener"); | ||
var c8oCouchBaseLiteException_1 = require("./Exception/c8oCouchBaseLiteException"); | ||
var C8oCore = (function (_super) { | ||
@@ -27,0 +27,0 @@ __extends(C8oCore, _super); |
import {C8oBase} from "./c8oBase"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oHttpInterfaceCore} from "./c8oHttpInterfaceCore"; | ||
@@ -7,13 +6,14 @@ import {C8oLogger} from "./c8oLogger"; | ||
import {C8oSettings} from "./c8oSettings"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oFullSync, C8oFullSyncCbl} from "./c8oFullSync"; | ||
import {C8oResponseJsonListener, C8oResponseListener} from "./c8oResponse"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {C8oFullSync, C8oFullSyncCbl} from "./c8oFullSync"; | ||
import {C8oResponseListener, C8oResponseJsonListener} from "./c8oResponse"; | ||
import {C8oCallTask} from "./c8oCallTask"; | ||
import {C8oFullSyncChangeListener} from "./c8oFullSyncChangeListener"; | ||
import {C8oPromise} from "./c8oPromise"; | ||
import {C8oCallTask} from "./c8oCallTask"; | ||
import {C8oCouchBaseLiteException} from "./Exception/c8oCouchBaseLiteException"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oExceptionListener} from "./Exception/c8oExceptionListener"; | ||
import {C8oFullSyncChangeListener} from "./c8oFullSyncChangeListener"; | ||
import {C8oCouchBaseLiteException} from "./Exception/c8oCouchBaseLiteException"; | ||
@@ -43,3 +43,2 @@ declare var require: any; | ||
/** | ||
@@ -53,10 +52,10 @@ * The regex used to get the part of the endpoint before '/projects/...' | ||
*/ | ||
static ENGINE_PARAMETER_PROJECT: string = "__project"; | ||
static ENGINE_PARAMETER_SEQUENCE: string = "__sequence"; | ||
static ENGINE_PARAMETER_CONNECTOR: string = "__connector"; | ||
static ENGINE_PARAMETER_TRANSACTION: string = "__transaction"; | ||
static ENGINE_PARAMETER_ENCODED: string = "__encoded"; | ||
static ENGINE_PARAMETER_DEVICE_UUID: string = "__uuid"; | ||
static ENGINE_PARAMETER_PROGRESS: string = "__progress"; | ||
static ENGINE_PARAMETER_FROM_LIVE: string = "__fromLive"; | ||
public static ENGINE_PARAMETER_PROJECT: string = "__project"; | ||
public static ENGINE_PARAMETER_SEQUENCE: string = "__sequence"; | ||
public static ENGINE_PARAMETER_CONNECTOR: string = "__connector"; | ||
public static ENGINE_PARAMETER_TRANSACTION: string = "__transaction"; | ||
public static ENGINE_PARAMETER_ENCODED: string = "__encoded"; | ||
public static ENGINE_PARAMETER_DEVICE_UUID: string = "__uuid"; | ||
public static ENGINE_PARAMETER_PROGRESS: string = "__progress"; | ||
public static ENGINE_PARAMETER_FROM_LIVE: string = "__fromLive"; | ||
@@ -77,3 +76,3 @@ /** | ||
*/ | ||
static FS_POLICY: string = "_use_policy"; | ||
public static FS_POLICY: string = "_use_policy"; | ||
/** | ||
@@ -84,3 +83,3 @@ Use it with "fs://.post" and C8o.FS_POLICY. | ||
*/ | ||
static FS_POLICY_NONE: string = "none"; | ||
public static FS_POLICY_NONE: string = "none"; | ||
/** | ||
@@ -91,3 +90,3 @@ Use it with "fs://.post" and C8o.FS_POLICY. | ||
*/ | ||
static FS_POLICY_CREATE: string = "create"; | ||
public static FS_POLICY_CREATE: string = "create"; | ||
/** | ||
@@ -98,3 +97,3 @@ Use it with "fs://.post" and C8o.FS_POLICY. | ||
*/ | ||
static FS_POLICY_OVERRIDE: string = "override"; | ||
public static FS_POLICY_OVERRIDE: string = "override"; | ||
/** | ||
@@ -105,3 +104,3 @@ Use it with "fs://.post" and C8o.FS_POLICY. | ||
*/ | ||
static FS_POLICY_MERGE: string = "merge"; | ||
public static FS_POLICY_MERGE: string = "merge"; | ||
/** | ||
@@ -112,3 +111,3 @@ Use it with "fs://.post". Default value is ".". | ||
*/ | ||
static FS_SUBKEY_SEPARATOR: string = "_use_subkey_separator"; | ||
public static FS_SUBKEY_SEPARATOR: string = "_use_subkey_separator"; | ||
@@ -121,17 +120,17 @@ /** | ||
*/ | ||
public static FS_LIVE: string = "__live"; | ||
public static FS_LIVE: string = "__live"; | ||
/** Local cache keys **/ | ||
static LOCAL_CACHE_DOCUMENT_KEY_RESPONSE: string = "response"; | ||
static LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE: string = "responseType"; | ||
static LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE: string = "expirationDate"; | ||
public static LOCAL_CACHE_DOCUMENT_KEY_RESPONSE: string = "response"; | ||
public static LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE: string = "responseType"; | ||
public static LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE: string = "expirationDate"; | ||
static LOCAL_CACHE_DATABASE_NAME: string = "c8olocalcache"; | ||
public static LOCAL_CACHE_DATABASE_NAME: string = "c8olocalcache"; | ||
/** Response type **/ | ||
static RESPONSE_TYPE_XML: string = "pxml"; | ||
static RESPONSE_TYPE_JSON: string = "json"; | ||
public static RESPONSE_TYPE_XML: string = "pxml"; | ||
public static RESPONSE_TYPE_JSON: string = "json"; | ||
/* Static configuration */ | ||
static deviceUUID: string = C8oUtilsCore.getNewGUIDString(); | ||
public static deviceUUID: string = C8oUtilsCore.getNewGUIDString(); | ||
@@ -154,3 +153,3 @@ /** Network **/ | ||
*/ | ||
httpInterface: C8oHttpInterfaceCore; | ||
public httpInterface: C8oHttpInterfaceCore; | ||
@@ -160,3 +159,3 @@ /** | ||
*/ | ||
c8oLogger: C8oLogger; | ||
public c8oLogger: C8oLogger; | ||
@@ -166,6 +165,6 @@ /** | ||
*/ | ||
c8oFullSync: C8oFullSync; | ||
public c8oFullSync: C8oFullSync; | ||
lives: Array<C8oCallTask> = []; | ||
livesDb: Array<string> = []; | ||
public lives: C8oCallTask[] = []; | ||
public livesDb: string[] = []; | ||
@@ -179,3 +178,2 @@ protected data: any; | ||
public get couchUrl(): string { | ||
@@ -310,3 +308,3 @@ return this._couchUrl; | ||
*/ | ||
public abstract init(c8oSettings?: C8oSettings):Promise<any>; | ||
public abstract init(c8oSettings?: C8oSettings): Promise<any>; | ||
@@ -317,4 +315,4 @@ /** | ||
*/ | ||
public finalizeInit(): Promise<any>{ | ||
this.promiseFinInit = new Promise((resolve)=>{ | ||
public finalizeInit(): Promise<any> { | ||
this.promiseFinInit = new Promise((resolve) => { | ||
Promise.all([this.promiseInit]).then(() => { | ||
@@ -336,4 +334,3 @@ /** | ||
resolve(); | ||
} | ||
else{ | ||
} else { | ||
url = url.replace(new RegExp("/$"), ""); | ||
@@ -344,4 +341,3 @@ this.couchUrl = url; | ||
}); | ||
} | ||
else { | ||
} else { | ||
resolve(); | ||
@@ -358,3 +354,3 @@ } | ||
} | ||
let matches = C8oCore.RE_ENDPOINT.exec(this.endpoint.toString()); | ||
const matches = C8oCore.RE_ENDPOINT.exec(this.endpoint.toString()); | ||
if (matches === null) { | ||
@@ -387,8 +383,7 @@ throw new C8oException(C8oExceptionMessage.illegalArgumentInvalidEndpoint(this.endpoint.toString())); | ||
parameters = {}; | ||
} | ||
else { | ||
} else { | ||
//parameters = (JSON.parse(JSON.stringify(parameters))); | ||
} | ||
let regex = C8oCore.RE_REQUESTABLE.exec(requestable); | ||
const regex = C8oCore.RE_REQUESTABLE.exec(requestable); | ||
if (regex[0] === null || regex === undefined) { | ||
@@ -403,4 +398,3 @@ //noinspection ExceptionCaughtLocallyJS | ||
parameters[C8oCore.ENGINE_PARAMETER_SEQUENCE.toString()] = regex[2]; | ||
} | ||
else { | ||
} else { | ||
parameters[C8oCore.ENGINE_PARAMETER_CONNECTOR.toString()] = regex[3]; | ||
@@ -410,8 +404,6 @@ parameters[C8oCore.ENGINE_PARAMETER_TRANSACTION.toString()] = regex[4]; | ||
return this._call(parameters, c8oResponseListener, c8oExceptionListener); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
this.handleCallException(c8oExceptionListener, parameters, error); | ||
} finally { | ||
} | ||
finally { | ||
} | ||
} | ||
@@ -434,13 +426,10 @@ | ||
parameters = {}; | ||
} | ||
else { | ||
} else { | ||
//parameters = (JSON.parse(JSON.stringify(parameters))); | ||
} | ||
let task: C8oCallTask = new C8oCallTask(this, parameters, c8oResponseListener, c8oExceptionListener); | ||
const task: C8oCallTask = new C8oCallTask(this, parameters, c8oResponseListener, c8oExceptionListener); | ||
task.run(); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
this.handleCallException(c8oExceptionListener, parameters, error); | ||
} | ||
finally { | ||
} finally { | ||
@@ -464,8 +453,7 @@ } | ||
public callJsonObject(requestable: string, parameters: Object): C8oPromise<JSON> { | ||
let promise: C8oPromise<JSON> = new C8oPromise<JSON>(this); | ||
const promise: C8oPromise<JSON> = new C8oPromise<JSON>(this); | ||
this.call(requestable, parameters, new C8oResponseJsonListener((response: any, requestParameters: Object) => { | ||
if (response == null && requestParameters[C8oCore.ENGINE_PARAMETER_PROGRESS]) { | ||
promise.onProgress(requestParameters[C8oCore.ENGINE_PARAMETER_PROGRESS]); | ||
} | ||
else { | ||
} else { | ||
promise.onResponse(response, requestParameters); | ||
@@ -502,3 +490,3 @@ } | ||
public static toParameters(parameters: any): Object { | ||
let newParameters: Object = {}; | ||
const newParameters: Object = {}; | ||
if (0 !== parameters.length % 2) { | ||
@@ -520,3 +508,3 @@ throw new C8oException("Incorrect number of parameters"); | ||
*/ | ||
handleCallException(c8oExceptionListener: C8oExceptionListener, requestParameters: Object, exception: Error) { | ||
public handleCallException(c8oExceptionListener: C8oExceptionListener, requestParameters: Object, exception: Error) { | ||
this.c8oLogger.warn("Handle a call exception", exception); | ||
@@ -538,11 +526,11 @@ if (c8oExceptionListener != null) { | ||
return new Promise((resolve, reject) => { | ||
if(database_name == null){ | ||
if (database_name == null) { | ||
database_name = this.defaultDatabaseName; | ||
} | ||
if((this.c8oFullSync as C8oFullSyncCbl) != undefined){ | ||
let fullsyncdb = (this.c8oFullSync as C8oFullSyncCbl).getOrCreateFullSyncDatabase(database_name); | ||
if ((this.c8oFullSync as C8oFullSyncCbl) != undefined) { | ||
const fullsyncdb = (this.c8oFullSync as C8oFullSyncCbl).getOrCreateFullSyncDatabase(database_name); | ||
fullsyncdb.getdatabase.getAttachment(id, attachment_name).then((buffer) => { | ||
resolve(buffer); | ||
}).catch((err) => { | ||
reject(err) | ||
reject(err); | ||
}); | ||
@@ -559,3 +547,3 @@ } | ||
*/ | ||
public addFullSyncChangeListener (db: string, listener: C8oFullSyncChangeListener) { | ||
public addFullSyncChangeListener(db: string, listener: C8oFullSyncChangeListener) { | ||
(this.c8oFullSync as C8oFullSyncCbl).addFullSyncChangeListener(db, listener); | ||
@@ -570,7 +558,7 @@ } | ||
*/ | ||
public removeFullSyncChangeListener (db: string, listener: C8oFullSyncChangeListener) { | ||
public removeFullSyncChangeListener(db: string, listener: C8oFullSyncChangeListener) { | ||
(this.c8oFullSync as C8oFullSyncCbl).removeFullSyncChangeListener(db, listener); | ||
} | ||
addLive(liveid: string, db: string, task: C8oCallTask) { | ||
public addLive(liveid: string, db: string, task: C8oCallTask) { | ||
this.cancelLive(liveid); | ||
@@ -599,3 +587,3 @@ this.lives[liveid] = task; | ||
(changes: Object) => { | ||
for (let task in this.lives) { | ||
for (const task in this.lives) { | ||
(this.lives[task] as C8oCallTask).executeFromLive(); | ||
@@ -622,3 +610,2 @@ } | ||
public static CREATE: FullSyncPolicy = new FullSyncPolicy(C8oCore.FS_POLICY_CREATE, (database: any, newProperties: Object) => { | ||
@@ -633,4 +620,3 @@ try { | ||
}); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
throw new C8oCouchBaseLiteException(C8oExceptionMessage.fullSyncPutProperties(newProperties), error); | ||
@@ -642,3 +628,3 @@ } | ||
try { | ||
let documentId: string = C8oUtilsCore.getParameterStringValue(newProperties, C8oFullSync.FULL_SYNC__ID, false); | ||
const documentId: string = C8oUtilsCore.getParameterStringValue(newProperties, C8oFullSync.FULL_SYNC__ID, false); | ||
delete newProperties[C8oFullSync.FULL_SYNC__ID]; | ||
@@ -653,4 +639,3 @@ delete newProperties[C8oFullSync.FULL_SYNC__REV]; | ||
}); | ||
} | ||
else { | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
@@ -667,7 +652,6 @@ database.get(documentId).then((doc) => { | ||
return database.post(newProperties); | ||
} | ||
else { | ||
} else { | ||
reject(error); | ||
} | ||
} | ||
}, | ||
).then((createdDocument) => { | ||
@@ -678,4 +662,3 @@ resolve(createdDocument); | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
throw new C8oCouchBaseLiteException(C8oExceptionMessage.fullSyncPutProperties(newProperties), error); | ||
@@ -687,3 +670,3 @@ } | ||
try { | ||
let documentId: string = C8oUtilsCore.getParameterStringValue(newProperties, C8oFullSync.FULL_SYNC__ID, false); | ||
const documentId: string = C8oUtilsCore.getParameterStringValue(newProperties, C8oFullSync.FULL_SYNC__ID, false); | ||
// delete newProperties[C8oFullSync.FULL_SYNC__ID]; | ||
@@ -701,4 +684,3 @@ delete newProperties[C8oFullSync.FULL_SYNC__REV]; | ||
}); | ||
} | ||
else { | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
@@ -721,4 +703,3 @@ database.get(documentId).then((doc) => { | ||
}); | ||
} | ||
else { | ||
} else { | ||
reject(new C8oCouchBaseLiteException(C8oExceptionMessage.fullSyncPutProperties(newProperties), error)); | ||
@@ -729,4 +710,3 @@ } | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
throw new C8oCouchBaseLiteException(C8oExceptionMessage.fullSyncPutProperties(newProperties), error); | ||
@@ -750,4 +730,4 @@ } | ||
if (value != null) { | ||
let fullSyncPolicyValues: FullSyncPolicy[] = FullSyncPolicy.values(); | ||
for (let fullSyncPolicy of fullSyncPolicyValues) { | ||
const fullSyncPolicyValues: FullSyncPolicy[] = FullSyncPolicy.values(); | ||
for (const fullSyncPolicy of fullSyncPolicyValues) { | ||
if (fullSyncPolicy.value === value) { | ||
@@ -773,3 +753,3 @@ return fullSyncPolicy as FullSyncPolicy; | ||
public static values(): FullSyncPostDocumentParameter[] { | ||
let array: FullSyncPostDocumentParameter[] = []; | ||
const array: FullSyncPostDocumentParameter[] = []; | ||
array.push(this.POLICY, this.SUBKEY_SEPARATOR); | ||
@@ -779,2 +759,2 @@ return array; | ||
} | ||
} |
@@ -0,7 +1,7 @@ | ||
import { C8oCore, FullSyncPolicy } from "./c8oCore"; | ||
import { C8oFullSyncChangeListener } from "./c8oFullSyncChangeListener"; | ||
import { C8oLocalCacheResponse } from "./c8oLocalCacheResponse"; | ||
import { C8oResponseListener } from "./c8oResponse"; | ||
import { C8oFullSyncDatabase } from "./fullSyncDatabase"; | ||
import { C8oResponseListener } from "./c8oResponse"; | ||
import { FullSyncDefaultResponse, FullSyncDocumentOperationResponse } from "./fullSyncResponse"; | ||
import { C8oLocalCacheResponse } from "./c8oLocalCacheResponse"; | ||
import { C8oFullSyncChangeListener } from "./c8oFullSyncChangeListener"; | ||
import { C8oCore, FullSyncPolicy } from "./c8oCore"; | ||
export declare class C8oFullSync { | ||
@@ -8,0 +8,0 @@ private static FULL_SYNC_URL_PATH; |
@@ -48,16 +48,16 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fullSyncRequestable_1 = require("./fullSyncRequestable"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oFullSyncTranslator_1 = require("./c8oFullSyncTranslator"); | ||
var c8oLocalCacheResponse_1 = require("./c8oLocalCacheResponse"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oCouchBaseLiteException_1 = require("./Exception/c8oCouchBaseLiteException"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oRessourceNotFoundException_1 = require("./Exception/c8oRessourceNotFoundException"); | ||
var c8oUnavailableLocalCacheException_1 = require("./Exception/c8oUnavailableLocalCacheException"); | ||
var fullSyncDatabase_1 = require("./fullSyncDatabase"); | ||
var fullSyncDeleteDocumentParameter_1 = require("./fullSyncDeleteDocumentParameter"); | ||
var c8oUnavailableLocalCacheException_1 = require("./Exception/c8oUnavailableLocalCacheException"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oCouchBaseLiteException_1 = require("./Exception/c8oCouchBaseLiteException"); | ||
var c8oFullSyncTranslator_1 = require("./c8oFullSyncTranslator"); | ||
var c8oRessourceNotFoundException_1 = require("./Exception/c8oRessourceNotFoundException"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var fullSyncRequestable_1 = require("./fullSyncRequestable"); | ||
var fullSyncResponse_1 = require("./fullSyncResponse"); | ||
var c8oLocalCacheResponse_1 = require("./c8oLocalCacheResponse"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var C8oFullSync = (function () { | ||
@@ -88,4 +88,5 @@ function C8oFullSync(c8o) { | ||
fullSyncRequestableValue = c8oUtilsCore_1.C8oUtilsCore.peekParameterStringValue(parameters, c8oCore_1.C8oCore.ENGINE_PARAMETER_SEQUENCE, true); | ||
if (fullSyncRequestableValue.indexOf("#") !== -1) | ||
if (fullSyncRequestableValue.indexOf("#") !== -1) { | ||
fullSyncRequestableValue = fullSyncRequestableValue.substring(0, fullSyncRequestableValue.indexOf("#")); | ||
} | ||
fullSyncRequestable = fullSyncRequestable_1.FullSyncRequestable.getFullSyncRequestable(fullSyncRequestableValue); | ||
@@ -187,3 +188,3 @@ if (fullSyncRequestable === null) { | ||
var param; | ||
param = parameters["attachments"] ? { "attachments": true } : {}; | ||
param = parameters["attachments"] ? { attachments: true } : {}; | ||
parameters["binary"] ? param["binary"] = true : {}; | ||
@@ -199,3 +200,3 @@ fullSyncDatabase = this.getOrCreateFullSyncDatabase(fullSyncDatabaseName); | ||
var attachmentName = attachments_1[_i]; | ||
var url = attachments["url"]; | ||
var url = attachments.url; | ||
var attachmentDesc = attachments[attachmentName]; | ||
@@ -367,5 +368,5 @@ attachmentDesc[C8oFullSyncCbl.ATTACHMENT_PROPERTY_KEY_CONTENT_URL] = url.toString(); | ||
_this.handleGetDocumentRequest(databaseName, resp.id, { | ||
"attachments": true, | ||
"binary": true, | ||
"include_docs": true | ||
attachments: true, | ||
binary: true, | ||
include_docs: true, | ||
}).then(function (getResult) { | ||
@@ -611,3 +612,3 @@ array_1.push(getResult); | ||
live: true, | ||
include_docs: true | ||
include_docs: true, | ||
}).on("change", function (change) { | ||
@@ -617,4 +618,4 @@ var changes = {}; | ||
var doc = {}; | ||
doc["id"] = change["doc"]["_id"]; | ||
doc["rev"] = change["doc"]["_rev"]; | ||
doc["id"] = change.doc._id; | ||
doc["rev"] = change.doc._rev; | ||
doc["isConflict"] = change.doc._conflicts; | ||
@@ -621,0 +622,0 @@ if (change.source != null) { |
@@ -1,17 +0,17 @@ | ||
import {FullSyncRequestable} from "./fullSyncRequestable"; | ||
import {C8oBase} from "./c8oBase"; | ||
import {C8oCore, FullSyncPolicy} from "./c8oCore"; | ||
import {C8oFullSyncChangeListener} from "./c8oFullSyncChangeListener"; | ||
import {C8oFullSyncTranslator} from "./c8oFullSyncTranslator"; | ||
import {C8oLocalCacheResponse} from "./c8oLocalCacheResponse"; | ||
import {C8oResponseJsonListener, C8oResponseListener} from "./c8oResponse"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oCouchBaseLiteException} from "./Exception/c8oCouchBaseLiteException"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {C8oRessourceNotFoundException} from "./Exception/c8oRessourceNotFoundException"; | ||
import {C8oUnavailableLocalCacheException} from "./Exception/c8oUnavailableLocalCacheException"; | ||
import {C8oFullSyncDatabase} from "./fullSyncDatabase"; | ||
import {FullSyncDeleteDocumentParameter} from "./fullSyncDeleteDocumentParameter"; | ||
import {C8oUnavailableLocalCacheException} from "./Exception/c8oUnavailableLocalCacheException"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oCouchBaseLiteException} from "./Exception/c8oCouchBaseLiteException"; | ||
import {C8oFullSyncTranslator} from "./c8oFullSyncTranslator"; | ||
import {C8oRessourceNotFoundException} from "./Exception/c8oRessourceNotFoundException"; | ||
import {C8oResponseJsonListener, C8oResponseListener} from "./c8oResponse"; | ||
import {FullSyncRequestable} from "./fullSyncRequestable"; | ||
import {FullSyncDefaultResponse, FullSyncDocumentOperationResponse} from "./fullSyncResponse"; | ||
import {C8oLocalCacheResponse} from "./c8oLocalCacheResponse"; | ||
import {C8oFullSyncChangeListener} from "./c8oFullSyncChangeListener"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {C8oBase} from "./c8oBase"; | ||
import {C8oCore, FullSyncPolicy} from "./c8oCore"; | ||
@@ -28,3 +28,3 @@ export class C8oFullSync { | ||
c8o: C8oCore; | ||
public c8o: C8oCore; | ||
protected fullSyncDatabaseUrlBase: string; | ||
@@ -49,13 +49,12 @@ protected localSuffix: string; | ||
public async handleFullSyncRequest(_parameters: Object, listener: C8oResponseListener): Promise<any> { | ||
let parameters = {}; | ||
for(let val in _parameters){ | ||
if(_parameters[val] instanceof Blob != true){ | ||
const parameters = {}; | ||
for (const val in _parameters) { | ||
if (_parameters[val] instanceof Blob != true) { | ||
//if it's not a blob then stringify and parse the value to make some values like true case insensitive ( from string to boolean) | ||
parameters[val] = JSON.parse(JSON.stringify(_parameters[val])); | ||
} | ||
else{ | ||
} else { | ||
parameters[val] = _parameters[val]; | ||
} | ||
} | ||
let projectParameterValue: string = C8oUtilsCore.peekParameterStringValue(parameters, C8oCore.ENGINE_PARAMETER_PROJECT, true); | ||
const projectParameterValue: string = C8oUtilsCore.peekParameterStringValue(parameters, C8oCore.ENGINE_PARAMETER_PROJECT, true); | ||
if (!projectParameterValue.startsWith(C8oFullSync.FULL_SYNC_PROJECT)) { | ||
@@ -67,6 +66,7 @@ throw new C8oException(C8oExceptionMessage.invalidParameterValue(projectParameterValue, "its don't start with" + C8oFullSync.FULL_SYNC_PROJECT)); | ||
// get rid of the optional trailing #RouteHint present in the sequence | ||
if (fullSyncRequestableValue.indexOf("#") !== -1) | ||
if (fullSyncRequestableValue.indexOf("#") !== -1) { | ||
fullSyncRequestableValue = fullSyncRequestableValue.substring(0, fullSyncRequestableValue.indexOf("#")); | ||
} | ||
let fullSyncRequestable: FullSyncRequestable = FullSyncRequestable.getFullSyncRequestable(fullSyncRequestableValue); | ||
const fullSyncRequestable: FullSyncRequestable = FullSyncRequestable.getFullSyncRequestable(fullSyncRequestableValue); | ||
if (fullSyncRequestable === null) { | ||
@@ -94,4 +94,3 @@ throw new C8oException(C8oExceptionMessage.invalidParameterValue(C8oCore.ENGINE_PARAMETER_PROJECT, C8oExceptionMessage.unknownValue("fullSync requestable", fullSyncRequestableValue))); | ||
reject(error); | ||
} | ||
else { | ||
} else { | ||
reject(new C8oException(C8oExceptionMessage.FullSyncRequestFail(), error)); | ||
@@ -111,3 +110,3 @@ } | ||
*/ | ||
handleFullSyncResponse(response: any, listener: C8oResponseListener): any { | ||
public handleFullSyncResponse(response: any, listener: C8oResponseListener): any { | ||
return response; | ||
@@ -119,7 +118,6 @@ } | ||
*/ | ||
static isFullSyncRequest(requestParameter: Object): boolean { | ||
public static isFullSyncRequest(requestParameter: Object): boolean { | ||
if (C8oUtilsCore.getParameterStringValue(requestParameter, C8oCore.ENGINE_PARAMETER_PROJECT, false) !== null) { | ||
return C8oUtilsCore.getParameterStringValue(requestParameter, C8oCore.ENGINE_PARAMETER_PROJECT, false).startsWith(C8oFullSync.FULL_SYNC_PROJECT); | ||
} | ||
else { | ||
} else { | ||
return false; | ||
@@ -134,4 +132,4 @@ } | ||
private fullSyncDatabases: Object; | ||
private fullSyncChangeListeners: Array<Array<C8oFullSyncChangeListener>> = []; | ||
private cblChangeListeners: Array<any> = []; | ||
private fullSyncChangeListeners: C8oFullSyncChangeListener[][] = []; | ||
private cblChangeListeners: any[] = []; | ||
@@ -152,3 +150,3 @@ constructor(c8o: C8oCore) { | ||
public getOrCreateFullSyncDatabase(databaseName: string): C8oFullSyncDatabase { | ||
let localDatabaseName: string = databaseName + this.localSuffix; | ||
const localDatabaseName: string = databaseName + this.localSuffix; | ||
@@ -161,4 +159,3 @@ if (this.fullSyncDatabases[localDatabaseName] == null) { | ||
handleFullSyncResponse(response: any, listener: C8oResponseListener): any { | ||
public handleFullSyncResponse(response: any, listener: C8oResponseListener): any { | ||
response = super.handleFullSyncResponse(response, listener); | ||
@@ -168,11 +165,7 @@ if (listener instanceof C8oResponseJsonListener) { | ||
return C8oFullSyncTranslator.fullSyncDocumentOperationResponseToJson(response as FullSyncDocumentOperationResponse); | ||
} | ||
else if (response instanceof FullSyncDefaultResponse) { | ||
} else if (response instanceof FullSyncDefaultResponse) { | ||
return C8oFullSyncTranslator.fullSyncDefaultResponseToJson(response as FullSyncDefaultResponse); | ||
} | ||
else if (response instanceof Object) { | ||
} else if (response instanceof Object) { | ||
return response as JSON; | ||
} | ||
else { | ||
} else { | ||
throw new C8oException(C8oExceptionMessage.illegalArgumentIncompatibleListener(listener.toString(), typeof response)); | ||
@@ -183,6 +176,6 @@ } | ||
handleGetAttachmentUrlRequest(fullSyncDatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
public handleGetAttachmentUrlRequest(fullSyncDatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = null; | ||
fullSyncDatabase = this.getOrCreateFullSyncDatabase(fullSyncDatabaseName); | ||
let attachmentName = C8oUtilsCore.getParameterStringValue(parameters, "attachment_name", false); | ||
const attachmentName = C8oUtilsCore.getParameterStringValue(parameters, "attachment_name", false); | ||
return new Promise((resolve) => { | ||
@@ -195,10 +188,9 @@ fullSyncDatabase.getdatabase.getAttachment(docid, attachmentName).then((buffer) => { | ||
handleGetDocumentRequest(fullSyncDatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
public handleGetDocumentRequest(fullSyncDatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = null; | ||
let dictDoc: Object = {}; | ||
let param: Object; | ||
param = parameters["attachments"] ? {"attachments": true} : {}; | ||
param = parameters["attachments"] ? {attachments: true} : {}; | ||
parameters["binary"] ? param["binary"] = true : {}; | ||
fullSyncDatabase = this.getOrCreateFullSyncDatabase(fullSyncDatabaseName); | ||
@@ -209,9 +201,9 @@ return new Promise((resolve, reject) => { | ||
dictDoc = document; | ||
let attachments = document[C8oFullSync.FULL_SYNC__ATTACHMENTS]; | ||
const attachments = document[C8oFullSync.FULL_SYNC__ATTACHMENTS]; | ||
if (attachments != null) { | ||
for (let attachmentName of attachments) { | ||
let url = attachments["url"]; | ||
let attachmentDesc: Object = attachments[attachmentName]; | ||
for (const attachmentName of attachments) { | ||
const url = attachments.url; | ||
const attachmentDesc: Object = attachments[attachmentName]; | ||
attachmentDesc[C8oFullSyncCbl.ATTACHMENT_PROPERTY_KEY_CONTENT_URL] = url.toString(); | ||
let dictAny: Object = {}; | ||
const dictAny: Object = {}; | ||
dictAny[attachmentName] = attachmentDesc; | ||
@@ -221,4 +213,3 @@ dictDoc[C8oFullSyncCbl.FULL_SYNC__ATTACHMENTS] = dictAny; | ||
} | ||
} | ||
else { | ||
} else { | ||
throw new C8oRessourceNotFoundException((C8oExceptionMessage.ressourceNotFound("requested document \"" + docid + "\""))); | ||
@@ -238,7 +229,7 @@ } | ||
handleDeleteDocumentRequest(DatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
public handleDeleteDocumentRequest(DatabaseName: string, docid: string, parameters: Object): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = null; | ||
fullSyncDatabase = this.getOrCreateFullSyncDatabase(DatabaseName); | ||
let revParameterValue: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncDeleteDocumentParameter.REV.name, false); | ||
const revParameterValue: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncDeleteDocumentParameter.REV.name, false); | ||
let documentRevision: string; | ||
@@ -259,4 +250,3 @@ if (revParameterValue === null) { | ||
}); | ||
} | ||
else { | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
@@ -274,3 +264,3 @@ fullSyncDatabase.getdatabase.remove(docid, revParameterValue) | ||
handlePostDocumentRequest(databaseName: string, fullSyncPolicy: FullSyncPolicy, parameters: Object): Promise<FullSyncDocumentOperationResponse> { | ||
public handlePostDocumentRequest(databaseName: string, fullSyncPolicy: FullSyncPolicy, parameters: Object): Promise<FullSyncDocumentOperationResponse> { | ||
let fullSyncDatabase: C8oFullSyncDatabase; | ||
@@ -282,3 +272,3 @@ fullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
} | ||
let newProperties = {}; | ||
const newProperties = {}; | ||
for (let i = 0; i < Object.keys(parameters).length; i++) { | ||
@@ -288,3 +278,3 @@ let parameterName: string = Object.keys(parameters)[i]; | ||
let objectParameterValue: any = parameters[Object.keys(parameters)[i]]; | ||
let paths: Array<string> = parameterName.split(subkeySeparatorParameterValue); | ||
const paths: string[] = parameterName.split(subkeySeparatorParameterValue); | ||
if (paths.length > 1) { | ||
@@ -294,3 +284,3 @@ parameterName = paths[0]; | ||
while (count > 0) { | ||
let tmpObject: Object = {}; | ||
const tmpObject: Object = {}; | ||
tmpObject[paths[count]] = objectParameterValue; | ||
@@ -300,3 +290,3 @@ objectParameterValue = tmpObject; | ||
} | ||
let existProperty = newProperties[parameterName]; | ||
const existProperty = newProperties[parameterName]; | ||
if (existProperty != null) { | ||
@@ -309,8 +299,7 @@ C8oFullSyncCbl.mergeProperties(objectParameterValue, existProperty); | ||
} | ||
let db = fullSyncDatabase.getdatabase; | ||
const db = fullSyncDatabase.getdatabase; | ||
return new Promise((resolve, reject) => { | ||
fullSyncPolicy.action(db, newProperties).then((createdDocument) => { | ||
let fsDocOpeResp: FullSyncDocumentOperationResponse = new FullSyncDocumentOperationResponse(createdDocument.id, createdDocument.rev, createdDocument.ok); | ||
const fsDocOpeResp: FullSyncDocumentOperationResponse = new FullSyncDocumentOperationResponse(createdDocument.id, createdDocument.rev, createdDocument.ok); | ||
resolve(fsDocOpeResp); | ||
@@ -323,5 +312,5 @@ }).catch((error) => { | ||
handlePutAttachmentRequest(databaseName: string, docid: string, attachmentName: string, attachmentType: string, attachmentContent: any): Promise<any> { | ||
public handlePutAttachmentRequest(databaseName: string, docid: string, attachmentName: string, attachmentType: string, attachmentContent: any): Promise<any> { | ||
let document: any = null; | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
@@ -333,3 +322,3 @@ return new Promise((resolve) => { | ||
if (document !== null) { | ||
fullSyncDatabase.getdatabase.putAttachment(docid, attachmentName,result._rev, attachmentContent, attachmentType) | ||
fullSyncDatabase.getdatabase.putAttachment(docid, attachmentName, result._rev, attachmentContent, attachmentType) | ||
.then((result) => { | ||
@@ -348,8 +337,7 @@ // handle result | ||
} | ||
handleDeleteAttachmentRequest(databaseName: string, docid: string, attachmentName: string): Promise<any> { | ||
public handleDeleteAttachmentRequest(databaseName: string, docid: string, attachmentName: string): Promise<any> { | ||
let document: any = null; | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
@@ -364,4 +352,3 @@ return new Promise((resolve) => { | ||
}); | ||
} | ||
else { | ||
} else { | ||
throw new C8oRessourceNotFoundException(C8oExceptionMessage.toDo()); | ||
@@ -390,3 +377,3 @@ } | ||
handleGetViewRequest(databaseName: string, ddocName: string, viewName: string, parameters: Object): Promise<any> { | ||
public handleGetViewRequest(databaseName: string, ddocName: string, viewName: string, parameters: Object): Promise<any> { | ||
let fullSyncDatabase = null; | ||
@@ -403,3 +390,2 @@ fullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
return new Promise((resolve, reject) => { | ||
@@ -409,9 +395,9 @@ fullSyncDatabase.getdatabase.query(ddocName + "/" + viewName, parameters) | ||
if (attachments) { | ||
let array: Array<Object> = []; | ||
const array: Object[] = []; | ||
let len = 0; | ||
for (let resp of result.rows) { | ||
for (const resp of result.rows) { | ||
this.handleGetDocumentRequest(databaseName, resp.id, { | ||
"attachments": true, | ||
"binary": true, | ||
"include_docs": true | ||
attachments: true, | ||
binary: true, | ||
include_docs: true, | ||
}).then((getResult) => { | ||
@@ -426,4 +412,3 @@ array.push(getResult); | ||
} | ||
} | ||
else { | ||
} else { | ||
resolve(result); | ||
@@ -439,18 +424,18 @@ } | ||
handleSyncRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
public handleSyncRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
return fullSyncDatabase.startAllReplications(parameters, c8oResponseListener); | ||
} | ||
handleReplicatePullRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
public handleReplicatePullRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
return fullSyncDatabase.startPullReplication(parameters, c8oResponseListener); | ||
} | ||
handleReplicatePushRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
public handleReplicatePushRequest(databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
return fullSyncDatabase.startPushReplication(parameters, c8oResponseListener); | ||
} | ||
handleResetDatabaseRequest(databaseName: string): Promise<FullSyncDefaultResponse> { | ||
public handleResetDatabaseRequest(databaseName: string): Promise<FullSyncDefaultResponse> { | ||
return new Promise((resolve) => { | ||
@@ -462,6 +447,5 @@ this.handleDestroyDatabaseRequest(databaseName).then(() => { | ||
} | ||
handleCreateDatabaseRequest(databaseName: string): FullSyncDefaultResponse { | ||
public handleCreateDatabaseRequest(databaseName: string): FullSyncDefaultResponse { | ||
this.getOrCreateFullSyncDatabase(databaseName); | ||
@@ -471,5 +455,5 @@ return new FullSyncDefaultResponse(true); | ||
handleDestroyDatabaseRequest(databaseName: string): Promise<FullSyncDefaultResponse> { | ||
public handleDestroyDatabaseRequest(databaseName: string): Promise<FullSyncDefaultResponse> { | ||
return new Promise((resolve, reject) => { | ||
let localDatabaseName = databaseName + this.localSuffix; | ||
const localDatabaseName = databaseName + this.localSuffix; | ||
this.getOrCreateFullSyncDatabase(databaseName).deleteDB().then((response) => { | ||
@@ -486,21 +470,18 @@ if (this.fullSyncDatabases[localDatabaseName] !== null) { | ||
static mergeProperties(newProperties: Object, oldProperties: Object) { | ||
public static mergeProperties(newProperties: Object, oldProperties: Object) { | ||
for (let i = 0; i < Object.keys(oldProperties).length; i++) { | ||
let oldPropertyKey = Object.keys(oldProperties)[i]; | ||
let oldPropertyValue = oldProperties[Object.keys(oldProperties)[i]]; | ||
const oldPropertyKey = Object.keys(oldProperties)[i]; | ||
const oldPropertyValue = oldProperties[Object.keys(oldProperties)[i]]; | ||
// Checks if the new document contains the same key | ||
if (newProperties[oldPropertyKey] !== null && newProperties[oldPropertyKey] !== undefined) { | ||
let newDocumentValue = newProperties[oldPropertyKey]; | ||
const newDocumentValue = newProperties[oldPropertyKey]; | ||
if (Object.prototype.toString.call( newDocumentValue ) === "[object Array]" && Object.prototype.toString.call( oldPropertyValue ) === "[object Array]") { | ||
C8oFullSyncCbl.mergeArrayProperties(newDocumentValue, oldPropertyValue); | ||
} | ||
else if (typeof(newDocumentValue) === "object" && typeof(oldPropertyValue) === "object") { | ||
} else if (typeof(newDocumentValue) === "object" && typeof(oldPropertyValue) === "object") { | ||
C8oFullSyncCbl.mergeProperties(newDocumentValue, oldPropertyValue); | ||
} | ||
else { | ||
} else { | ||
// If the new document has the same key but its value is not the same type than the old one or if their type are "simple" | ||
// Does nothing cause the right value is the new one | ||
} | ||
} | ||
else { | ||
} else { | ||
// If the new document does not contain the key then adds it | ||
@@ -512,5 +493,5 @@ newProperties[oldPropertyKey] = oldPropertyValue; | ||
static mergeArrayProperties(newArray: any, oldArray: any) { | ||
let newArraySize = newArray.length; | ||
let oldArraySize = oldArray.length; | ||
public static mergeArrayProperties(newArray: any, oldArray: any) { | ||
const newArraySize = newArray.length; | ||
const oldArraySize = oldArray.length; | ||
for (let i = 0; i < oldArraySize; i++) { | ||
@@ -521,3 +502,3 @@ let newArrayValue: any = null; | ||
} | ||
let oldArrayValue = oldArray[i]; | ||
const oldArrayValue = oldArray[i]; | ||
@@ -527,12 +508,9 @@ if (newArrayValue !== null) { | ||
C8oFullSyncCbl.mergeArrayProperties(newArrayValue, oldArrayValue); | ||
} | ||
else if (typeof(newArrayValue) === "object" && typeof(oldArrayValue) === "object") { | ||
} else if (typeof(newArrayValue) === "object" && typeof(oldArrayValue) === "object") { | ||
C8oFullSyncCbl.mergeProperties(newArrayValue, oldArrayValue); | ||
} | ||
else { | ||
} else { | ||
// If the new array value is not the same type than the old one or if their type are "simple" | ||
// Does nothing cause the right value is the new one | ||
} | ||
} | ||
else { | ||
} else { | ||
// If the new array value is null then it means that it size is reach so we can add objects at its end | ||
@@ -545,8 +523,7 @@ newArray.push(oldArrayValue); | ||
//noinspection JSUnusedLocalSymbols | ||
getDocucmentFromDatabase(c8o: C8oCore, databaseName: string, documentId: string): Promise<any> { | ||
public getDocucmentFromDatabase(c8o: C8oCore, databaseName: string, documentId: string): Promise<any> { | ||
let c8oFullSyncDatabase: C8oFullSyncDatabase; | ||
try { | ||
c8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
} | ||
catch (err) { | ||
} catch (err) { | ||
throw new C8oException(C8oExceptionMessage.fullSyncGetOrCreateDatabase(databaseName)); | ||
@@ -562,3 +539,3 @@ } | ||
overrideDocument(document: any, properties: Object, databaseName) { | ||
public overrideDocument(document: any, properties: Object, databaseName) { | ||
properties[C8oFullSync.FULL_SYNC__REV] = document._rev; | ||
@@ -568,8 +545,6 @@ let c8oFullSyncDatabase: C8oFullSyncDatabase; | ||
c8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(databaseName); | ||
} | ||
catch (err) { | ||
} catch (err) { | ||
throw new C8oException(C8oExceptionMessage.fullSyncGetOrCreateDatabase(databaseName)); | ||
} | ||
c8oFullSyncDatabase.getdatabase().put(properties).catch(() => { | ||
@@ -581,4 +556,4 @@ throw new C8oException("TODO"); | ||
async getResponseFromLocalCache(c8oCallRequestIdentifier: string): Promise<any> { | ||
let fullSyncDatabase = this.getOrCreateFullSyncDatabase(C8oCore.LOCAL_CACHE_DATABASE_NAME); | ||
public async getResponseFromLocalCache(c8oCallRequestIdentifier: string): Promise<any> { | ||
const fullSyncDatabase = this.getOrCreateFullSyncDatabase(C8oCore.LOCAL_CACHE_DATABASE_NAME); | ||
let localCacheDocument = null; | ||
@@ -589,5 +564,5 @@ return new Promise((resolve, reject) => { | ||
let response = JSON.stringify(localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE]); | ||
let responseType = localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE]; | ||
let expirationDate = localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE]; | ||
const response = JSON.stringify(localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE]); | ||
const responseType = localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE]; | ||
const expirationDate = localCacheDocument[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE]; | ||
@@ -601,4 +576,3 @@ let responseString: string = null; | ||
responseString = response; | ||
} | ||
else { | ||
} else { | ||
throw new C8oException(C8oExceptionMessage.InvalidLocalCacheResponseInformation()); | ||
@@ -610,4 +584,3 @@ } | ||
responseTypeString = responseType; | ||
} | ||
else { | ||
} else { | ||
throw new C8oException(C8oExceptionMessage.InvalidLocalCacheResponseInformation()); | ||
@@ -619,8 +592,7 @@ } | ||
expirationDateNumber = expirationDate; | ||
let currentTime = new Date().getTime(); | ||
const currentTime = new Date().getTime(); | ||
if (expirationDateNumber < currentTime) { | ||
throw new C8oUnavailableLocalCacheException(C8oExceptionMessage.timeToLiveExpired()); | ||
} | ||
} | ||
else { | ||
} else { | ||
throw new C8oException(C8oExceptionMessage.InvalidLocalCacheResponseInformation()); | ||
@@ -633,4 +605,3 @@ } | ||
resolve(new C8oUnavailableLocalCacheException(C8oExceptionMessage.localCacheDocumentJustCreated())); | ||
} | ||
else { | ||
} else { | ||
reject(err); | ||
@@ -641,10 +612,9 @@ } | ||
} | ||
async saveResponseToLocalCache(c8oCallRequestIdentifier: string, localCacheResponse: C8oLocalCacheResponse): Promise<any> { | ||
let fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(C8oCore.LOCAL_CACHE_DATABASE_NAME); | ||
public async saveResponseToLocalCache(c8oCallRequestIdentifier: string, localCacheResponse: C8oLocalCacheResponse): Promise<any> { | ||
const fullSyncDatabase: C8oFullSyncDatabase = this.getOrCreateFullSyncDatabase(C8oCore.LOCAL_CACHE_DATABASE_NAME); | ||
return new Promise((resolve) => { | ||
fullSyncDatabase.getdatabase.get(c8oCallRequestIdentifier).then((localCacheDocument) => { | ||
let properties = {}; | ||
const properties = {}; | ||
properties[C8oFullSync.FULL_SYNC__ID] = c8oCallRequestIdentifier; | ||
@@ -656,3 +626,3 @@ properties[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE] = localCacheResponse.getResponse(); | ||
} | ||
let currentRevision = localCacheDocument._rev; | ||
const currentRevision = localCacheDocument._rev; | ||
if (currentRevision !== null) { | ||
@@ -666,3 +636,3 @@ properties[C8oFullSyncCbl.FULL_SYNC__REV] = currentRevision; | ||
if (error.status === 404) { | ||
let properties = {}; | ||
const properties = {}; | ||
properties[C8oFullSync.FULL_SYNC__ID] = c8oCallRequestIdentifier; | ||
@@ -677,4 +647,3 @@ properties[C8oCore.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE] = localCacheResponse.getResponse(); | ||
}); | ||
} | ||
else { | ||
} else { | ||
resolve(error); | ||
@@ -691,22 +660,21 @@ } | ||
let listeners: Array<Array<C8oFullSyncChangeListener>> = []; | ||
const listeners: C8oFullSyncChangeListener[][] = []; | ||
if (this.fullSyncChangeListeners[db] != null) { | ||
listeners[0] = this.fullSyncChangeListeners[db]; | ||
} | ||
else { | ||
} else { | ||
listeners[0] = []; | ||
this.fullSyncChangeListeners[db] = listeners[0]; | ||
//noinspection UnnecessaryLocalVariableJS | ||
let evtHandler = this.getOrCreateFullSyncDatabase(db).getdatabase | ||
const evtHandler = this.getOrCreateFullSyncDatabase(db).getdatabase | ||
.changes({ | ||
since: "now", | ||
live: true, | ||
include_docs: true | ||
}).on("change", function (change) { | ||
let changes: Object = {}; | ||
let docs: Array<Object> = []; | ||
include_docs: true, | ||
}).on("change", function(change) { | ||
const changes: Object = {}; | ||
const docs: Object[] = []; | ||
// docs["isExternal"] = false; | ||
let doc: Object = {}; | ||
doc["id"] = change["doc"]["_id"]; | ||
doc["rev"] = change["doc"]["_rev"]; | ||
const doc: Object = {}; | ||
doc["id"] = change.doc._id; | ||
doc["rev"] = change.doc._rev; | ||
doc["isConflict"] = change.doc._conflicts; | ||
@@ -718,3 +686,3 @@ if (change.source != null) { | ||
changes["changes"] = docs; | ||
for (let handler of listeners[0]) { | ||
for (const handler of listeners[0]) { | ||
if (handler !== undefined) { | ||
@@ -736,4 +704,4 @@ handler.onChange(changes); | ||
if (this.fullSyncChangeListeners[db] != null) { | ||
let listeners: Array<C8oFullSyncChangeListener> = this.fullSyncChangeListeners[db]; | ||
for (let list in listeners) { | ||
const listeners: C8oFullSyncChangeListener[] = this.fullSyncChangeListeners[db]; | ||
for (const list in listeners) { | ||
if (listeners[list] === listener) { | ||
@@ -751,2 +719,2 @@ delete listeners[list]; | ||
} | ||
} | ||
} |
@@ -9,2 +9,2 @@ export class C8oFullSyncChangeListener { | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { FullSyncDefaultResponse, FullSyncAbstractResponse } from "./fullSyncResponse"; | ||
import { FullSyncAbstractResponse, FullSyncDefaultResponse } from "./fullSyncResponse"; | ||
export declare class C8oFullSyncTranslator { | ||
@@ -3,0 +3,0 @@ static FULL_SYNC_RESPONSE_KEY_COUNT: string; |
@@ -1,26 +0,25 @@ | ||
import {FullSyncDefaultResponse, FullSyncAbstractResponse} from "./fullSyncResponse"; | ||
import {FullSyncAbstractResponse, FullSyncDefaultResponse} from "./fullSyncResponse"; | ||
export class C8oFullSyncTranslator { | ||
static FULL_SYNC_RESPONSE_KEY_COUNT: string = "count"; | ||
static FULL_SYNC_RESPONSE_KEY_ROWS: string = "rows"; | ||
static FULL_SYNC_RESPONSE_KEY_CURRENT: string = "current"; | ||
static FULL_SYNC_RESPONSE_KEY_DIRECTION: string = "direction"; | ||
static FULL_SYNC_RESPONSE_KEY_TOTAL: string = "total"; | ||
static FULL_SYNC_RESPONSE_KEY_OK: string = "ok"; | ||
static FULL_SYNC_RESPONSE_KEY_STATUS: string = "status"; | ||
public static FULL_SYNC_RESPONSE_KEY_COUNT: string = "count"; | ||
public static FULL_SYNC_RESPONSE_KEY_ROWS: string = "rows"; | ||
public static FULL_SYNC_RESPONSE_KEY_CURRENT: string = "current"; | ||
public static FULL_SYNC_RESPONSE_KEY_DIRECTION: string = "direction"; | ||
public static FULL_SYNC_RESPONSE_KEY_TOTAL: string = "total"; | ||
public static FULL_SYNC_RESPONSE_KEY_OK: string = "ok"; | ||
public static FULL_SYNC_RESPONSE_KEY_STATUS: string = "status"; | ||
static FULL_SYNC_RESPONSE_VALUE_DIRECTION_PUSH: string = "push"; | ||
static FULL_SYNC_RESPONSE_VALUE_DIRECTION_PULL: string = "pull"; | ||
public static FULL_SYNC_RESPONSE_VALUE_DIRECTION_PUSH: string = "push"; | ||
public static FULL_SYNC_RESPONSE_VALUE_DIRECTION_PULL: string = "pull"; | ||
static XML_KEY_DOCUMENT: string = "document"; | ||
static XML_KEY_COUCHDB_OUTPUT: string = "couchdb_output"; | ||
public static XML_KEY_DOCUMENT: string = "document"; | ||
public static XML_KEY_COUCHDB_OUTPUT: string = "couchdb_output"; | ||
static fullSyncDocumentOperationResponseToJson(fullSyncDocumentOperationResponse: FullSyncAbstractResponse): JSON { | ||
public static fullSyncDocumentOperationResponseToJson(fullSyncDocumentOperationResponse: FullSyncAbstractResponse): JSON { | ||
return fullSyncDocumentOperationResponse.getProperties() as JSON; | ||
} | ||
static fullSyncDefaultResponseToJson(fullSyncDefaultResponse: FullSyncDefaultResponse): JSON { | ||
public static fullSyncDefaultResponseToJson(fullSyncDefaultResponse: FullSyncDefaultResponse): JSON { | ||
return fullSyncDefaultResponse.getProperties() as JSON; | ||
} | ||
} | ||
} |
@@ -0,5 +1,5 @@ | ||
import "rxjs/add/operator/retry"; | ||
import { C8oCore } from "./c8oCore"; | ||
import 'rxjs/add/operator/retry'; | ||
import { C8oProgress } from "./c8oProgress"; | ||
import { C8oResponseListener } from "./c8oResponse"; | ||
import { C8oProgress } from "./c8oProgress"; | ||
export declare abstract class C8oHttpInterfaceCore { | ||
@@ -6,0 +6,0 @@ c8o: C8oCore; |
@@ -0,11 +1,11 @@ | ||
import "rxjs/add/operator/retry"; | ||
import {C8oCore} from "./c8oCore"; | ||
import 'rxjs/add/operator/retry'; | ||
import {C8oProgress} from "./c8oProgress"; | ||
import { C8oResponseListener} from "./c8oResponse"; | ||
import {C8oProgress} from "./c8oProgress"; | ||
export abstract class C8oHttpInterfaceCore { | ||
c8o: C8oCore; | ||
timeout: number; | ||
firstCall: boolean = true; | ||
p1: Promise<Object>; | ||
public c8o: C8oCore; | ||
public timeout: number; | ||
public firstCall: boolean = true; | ||
public p1: Promise<Object>; | ||
protected _isCordova = null; | ||
@@ -26,3 +26,3 @@ | ||
*/ | ||
abstract checkFile(parameters: Object): number; | ||
public abstract checkFile(parameters: Object): number; | ||
@@ -34,3 +34,3 @@ /** | ||
*/ | ||
abstract transformRequest(parameters: Object): string; | ||
public abstract transformRequest(parameters: Object): string; | ||
@@ -42,5 +42,4 @@ /** | ||
*/ | ||
abstract transformRequestformdata(parameters: Object): FormData ; | ||
public abstract transformRequestformdata(parameters: Object): FormData ; | ||
/** | ||
@@ -51,5 +50,4 @@ * Extract file from parameters and return and array containing a file and params | ||
*/ | ||
abstract transformRequestfileNative(parameters: Object): any; | ||
public abstract transformRequestfileNative(parameters: Object): any; | ||
/** | ||
@@ -62,3 +60,3 @@ * Handle the request | ||
*/ | ||
abstract async handleRequest(url: string, parameters: Object, c8oResponseListener?: C8oResponseListener): Promise<any>; | ||
public abstract async handleRequest(url: string, parameters: Object, c8oResponseListener?: C8oResponseListener): Promise<any>; | ||
@@ -72,3 +70,3 @@ /** | ||
*/ | ||
abstract uploadFilePluginNative(url: string, parameters: Object, c8oResponseListener: C8oResponseListener):Promise<any>; | ||
public abstract uploadFilePluginNative(url: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
@@ -81,3 +79,3 @@ /** | ||
*/ | ||
abstract httpPost(url: string, parameters: Object): Promise<any>; | ||
public abstract httpPost(url: string, parameters: Object): Promise<any>; | ||
@@ -92,3 +90,3 @@ /** | ||
*/ | ||
abstract uploadFileHttp(url: string, form: FormData, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
public abstract uploadFileHttp(url: string, form: FormData, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
@@ -103,3 +101,3 @@ /** | ||
*/ | ||
abstract handleProgress(event: any, progress: C8oProgress, parameters: any, c8oResponseListener: C8oResponseListener, varNull: JSON): void; | ||
} | ||
public abstract handleProgress(event: any, progress: C8oProgress, parameters: any, c8oResponseListener: C8oResponseListener, varNull: JSON): void; | ||
} |
@@ -0,9 +1,9 @@ | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {Priority} from "./priority.service"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
export class C8oLocalCache { | ||
static PARAM: string = "__localCache"; | ||
public static PARAM: string = "__localCache"; | ||
public priority: Priority; | ||
ttl: number; | ||
enabled: boolean; | ||
public ttl: number; | ||
public enabled: boolean; | ||
@@ -19,2 +19,2 @@ constructor(priority: Priority, ttl: number = -1, enabled: boolean = true) { | ||
} | ||
} |
@@ -15,5 +15,4 @@ export class C8oLocalCacheResponse { | ||
return false; | ||
} | ||
else { | ||
let currentDate = new Date().getTime(); | ||
} else { | ||
const currentDate = new Date().getTime(); | ||
return this.expirationDate < currentDate; | ||
@@ -34,2 +33,2 @@ } | ||
} | ||
} | ||
} |
@@ -0,3 +1,3 @@ | ||
import { C8oCore } from "./c8oCore"; | ||
import { C8oLogLevel } from "./c8oLogLevel"; | ||
import { C8oCore } from "./c8oCore"; | ||
export declare class C8oLogger { | ||
@@ -4,0 +4,0 @@ private static LOG_INTERNAL_PREFIX; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oLogLevel_1 = require("./c8oLogLevel"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oException_1 = require("./Exception/c8oException"); | ||
var c8oExceptionMessage_1 = require("./Exception/c8oExceptionMessage"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var C8oLogger = (function () { | ||
@@ -198,6 +198,6 @@ function C8oLogger(c8o, first) { | ||
if (response !== undefined) { | ||
if (response["error"] !== undefined) { | ||
if (response.error !== undefined) { | ||
_this.c8o.logRemote = false; | ||
if (_this.c8o.logOnFail != null) { | ||
_this.c8o.logOnFail(new c8oException_1.C8oException(c8oExceptionMessage_1.C8oExceptionMessage.RemoteLogFail(), response["error"]), null); | ||
_this.c8o.logOnFail(new c8oException_1.C8oException(c8oExceptionMessage_1.C8oExceptionMessage.RemoteLogFail(), response.error), null); | ||
} | ||
@@ -246,6 +246,6 @@ } | ||
if (response !== undefined) { | ||
if (response["error"] !== undefined) { | ||
if (response.error !== undefined) { | ||
_this.c8o.logRemote = false; | ||
if (_this.c8o.logOnFail != null) { | ||
_this.c8o.logOnFail(new c8oException_1.C8oException(c8oExceptionMessage_1.C8oExceptionMessage.RemoteLogFail(), response["error"]), null); | ||
_this.c8o.logOnFail(new c8oException_1.C8oException(c8oExceptionMessage_1.C8oExceptionMessage.RemoteLogFail(), response.error), null); | ||
} | ||
@@ -252,0 +252,0 @@ } |
@@ -0,6 +1,6 @@ | ||
import {C8oCore} from "./c8oCore"; | ||
import {C8oLogLevel} from "./c8oLogLevel"; | ||
import {C8oCore} from "./c8oCore"; | ||
import {Queue} from "./c8oUtilsCore"; | ||
import {C8oException} from "./Exception/c8oException"; | ||
import {C8oExceptionMessage} from "./Exception/c8oExceptionMessage"; | ||
import {Queue} from "./c8oUtilsCore"; | ||
@@ -13,3 +13,3 @@ export class C8oLogger { | ||
static REMOTE_LOG_LIMIT: number = 100; | ||
public static REMOTE_LOG_LIMIT: number = 100; | ||
@@ -43,6 +43,6 @@ private static JSON_KEY_REMOTE_LOG_LEVEL: string = "remoteLogLevel"; | ||
} | ||
public affect_val(c8o: C8oCore, first:boolean){ | ||
if(first){ | ||
public affect_val(c8o: C8oCore, first: boolean) { | ||
if (first) { | ||
this.c8o = c8o; | ||
this.remoteLogUrl= ""; | ||
this.remoteLogUrl = ""; | ||
this.remoteLogs = new Queue<JSON>(); | ||
@@ -56,9 +56,8 @@ this.pending_remoteLogsLevel = new Queue<C8oLogLevel>(); | ||
this.uidRemoteLogs = Math.round((new Date().getTime() * Math.random())).toString(36); | ||
let obj = {}; | ||
const obj = {}; | ||
obj["uid"] = this.uidRemoteLogs.toUpperCase(); | ||
obj["uuid"] = C8oCore.deviceUUID.toUpperCase(); | ||
obj["project"] = "" | ||
obj["project"] = ""; | ||
this.env = JSON.stringify(obj); | ||
} | ||
else{ | ||
} else { | ||
this.c8o = c8o; | ||
@@ -74,3 +73,3 @@ | ||
this.uidRemoteLogs = Math.round((new Date().getTime() * Math.random())).toString(36); | ||
let obj = {}; | ||
const obj = {}; | ||
obj["uid"] = this.uidRemoteLogs.toUpperCase(); | ||
@@ -125,4 +124,4 @@ obj["uuid"] = C8oCore.deviceUUID.toUpperCase(); | ||
private log(logLevel: C8oLogLevel, message: string, exception: Error) { | ||
let isLogConsole: boolean = this.isLoggableConsole(logLevel); | ||
let isLogRemote: boolean = this.isLoggableRemote(logLevel); | ||
const isLogConsole: boolean = this.isLoggableConsole(logLevel); | ||
const isLogRemote: boolean = this.isLoggableRemote(logLevel); | ||
@@ -134,19 +133,18 @@ if (isLogConsole || isLogRemote) { | ||
let time: string = (((new Date().getTime().valueOf()) - (this.startTimeRemoteLog)) / 1000).toString(); | ||
if(!this.initDone){ | ||
let obj = {}; | ||
const time: string = (((new Date().getTime().valueOf()) - (this.startTimeRemoteLog)) / 1000).toString(); | ||
if (!this.initDone) { | ||
const obj = {}; | ||
obj[(C8oLogger.JSON_KEY_TIME.valueOf())] = time; | ||
obj[(C8oLogger.JSON_KEY_LEVEL.valueOf())] = logLevel.name; | ||
obj[(C8oLogger.JSON_KEY_MESSAGE.valueOf())] = message.toString(); | ||
let objJson: JSON = <JSON>obj; | ||
const objJson: JSON = obj as JSON; | ||
this.pending_remoteLogs.push(objJson); | ||
this.pending_remoteLogsLevel.push(logLevel) | ||
} | ||
else{ | ||
this.pending_remoteLogsLevel.push(logLevel); | ||
} else { | ||
if (isLogRemote) { | ||
let obj = {}; | ||
const obj = {}; | ||
obj[(C8oLogger.JSON_KEY_TIME.valueOf())] = time; | ||
obj[(C8oLogger.JSON_KEY_LEVEL.valueOf())] = logLevel.name; | ||
obj[(C8oLogger.JSON_KEY_MESSAGE.valueOf())] = message.toString(); | ||
let objJson: JSON = <JSON>obj; | ||
const objJson: JSON = obj as JSON; | ||
this.remoteLogs.push(objJson); | ||
@@ -160,3 +158,2 @@ this.logRemote(); | ||
} | ||
@@ -211,3 +208,3 @@ } | ||
_debug(message: string, exceptions: Error = null) { | ||
public _debug(message: string, exceptions: Error = null) { | ||
this._log(C8oLogLevel.DEBUG, message, exceptions); | ||
@@ -220,17 +217,17 @@ } | ||
logRemoteInit(){ | ||
public logRemoteInit() { | ||
this.initDone = true; | ||
let count: number = 0; | ||
let listSize: number = this.pending_remoteLogs.count(); | ||
let logsArray = new Array<any>(); | ||
const listSize: number = this.pending_remoteLogs.count(); | ||
const logsArray = new Array<any>(); | ||
while (count < listSize && count < C8oLogger.REMOTE_LOG_LIMIT) { | ||
let logLvl = this.pending_remoteLogsLevel.pop(); | ||
let mvar = this.pending_remoteLogs.pop(); | ||
const logLvl = this.pending_remoteLogsLevel.pop(); | ||
const mvar = this.pending_remoteLogs.pop(); | ||
if(this.isLoggableConsole(logLvl)){ | ||
if (this.isLoggableConsole(logLvl)) { | ||
console.log("(" + mvar["time"] + ") [" + logLvl.name + "] " + mvar["msg"]); | ||
} | ||
if(this.isLoggableRemote(logLvl)){ | ||
if (this.isLoggableRemote(logLvl)) { | ||
logsArray.push(mvar); | ||
@@ -247,3 +244,3 @@ count += 1; | ||
} | ||
let parameters: Object = {}; | ||
const parameters: Object = {}; | ||
parameters[C8oLogger.JSON_KEY_LOGS.valueOf()] = JSON.stringify(logsArray); | ||
@@ -256,13 +253,13 @@ parameters[C8oCore.ENGINE_PARAMETER_DEVICE_UUID] = this.c8o.deviceUUID; | ||
if (response !== undefined) { | ||
if (response["error"] !== undefined) { | ||
if (response.error !== undefined) { | ||
this.c8o.logRemote = false; | ||
if (this.c8o.logOnFail != null) { | ||
this.c8o.logOnFail(new C8oException(C8oExceptionMessage.RemoteLogFail(), response["error"]), null); | ||
this.c8o.logOnFail(new C8oException(C8oExceptionMessage.RemoteLogFail(), response.error), null); | ||
} | ||
} | ||
} | ||
let logLevelResponse = response[C8oLogger.JSON_KEY_REMOTE_LOG_LEVEL.toString()]; | ||
const logLevelResponse = response[C8oLogger.JSON_KEY_REMOTE_LOG_LEVEL.toString()]; | ||
if (logLevelResponse != null) { | ||
let logLevelResponseStr: string = logLevelResponse.toString(); | ||
let c8oLogLevel = C8oLogLevel.getC8oLogLevel(logLevelResponseStr); | ||
const logLevelResponseStr: string = logLevelResponse.toString(); | ||
const c8oLogLevel = C8oLogLevel.getC8oLogLevel(logLevelResponseStr); | ||
if (c8oLogLevel != null) { | ||
@@ -283,3 +280,3 @@ this.remoteLogLevel = c8oLogLevel; | ||
logRemote() { | ||
public logRemote() { | ||
@@ -299,4 +296,4 @@ //noinspection JSUnusedAssignment | ||
let count: number = 0; | ||
let listSize: number = <number>this.remoteLogs.count(); | ||
let logsArray = []; | ||
const listSize: number = this.remoteLogs.count() as number; | ||
const logsArray = []; | ||
while (count < listSize && count < C8oLogger.REMOTE_LOG_LIMIT) { | ||
@@ -306,3 +303,3 @@ logsArray.push(this.remoteLogs.pop()); | ||
} | ||
let parameters: Object = {}; | ||
const parameters: Object = {}; | ||
parameters[C8oLogger.JSON_KEY_LOGS.valueOf()] = JSON.stringify(logsArray); | ||
@@ -315,13 +312,13 @@ parameters[C8oCore.ENGINE_PARAMETER_DEVICE_UUID] = this.c8o.deviceUUID; | ||
if (response !== undefined) { | ||
if (response["error"] !== undefined) { | ||
if (response.error !== undefined) { | ||
this.c8o.logRemote = false; | ||
if (this.c8o.logOnFail != null) { | ||
this.c8o.logOnFail(new C8oException(C8oExceptionMessage.RemoteLogFail(), response["error"]), null); | ||
this.c8o.logOnFail(new C8oException(C8oExceptionMessage.RemoteLogFail(), response.error), null); | ||
} | ||
} | ||
} | ||
let logLevelResponse = response[C8oLogger.JSON_KEY_REMOTE_LOG_LEVEL.toString()]; | ||
const logLevelResponse = response[C8oLogger.JSON_KEY_REMOTE_LOG_LEVEL.toString()]; | ||
if (logLevelResponse != null) { | ||
let logLevelResponseStr: string = logLevelResponse.toString(); | ||
let c8oLogLevel = C8oLogLevel.getC8oLogLevel(logLevelResponseStr); | ||
const logLevelResponseStr: string = logLevelResponse.toString(); | ||
const c8oLogLevel = C8oLogLevel.getC8oLogLevel(logLevelResponseStr); | ||
if (c8oLogLevel != null) { | ||
@@ -342,3 +339,3 @@ this.remoteLogLevel = c8oLogLevel; | ||
} | ||
logMethodCall(methodName: string, ...parameters: any[]) { | ||
public logMethodCall(methodName: string, ...parameters: any[]) { | ||
if (this.c8o.logC8o && this.isDebug) { | ||
@@ -351,3 +348,3 @@ let methodCallLogMessage: string = "Method call: " + methodName; | ||
methodCallLogMessage += ", Parameters: ["; | ||
for (let param of parameters) { | ||
for (const param of parameters) { | ||
let paramStr = "null"; | ||
@@ -363,4 +360,3 @@ if (parameters != null) { | ||
this._trace(methodCallLogMessage); | ||
} | ||
else { | ||
} else { | ||
this._debug(methodCallLogMessage); | ||
@@ -371,3 +367,3 @@ } | ||
logC8oCall(url: string, parameters: any) { | ||
public logC8oCall(url: string, parameters: any) { | ||
if (this.c8o.logC8o && this.isDebug) { | ||
@@ -382,12 +378,11 @@ let c8oCallLogMessage: string = "C8o call: " + url; | ||
logC8oCallJSONResponse(response: JSON, url: string, parameters: any) { | ||
public logC8oCallJSONResponse(response: JSON, url: string, parameters: any) { | ||
this.logC8oCallResponse(JSON.stringify(response), "JSON", url, parameters); | ||
} | ||
logC8oCallXMLResponse(response: Document, url: string, parameters: Object) { | ||
public logC8oCallXMLResponse(response: Document, url: string, parameters: Object) { | ||
this.logC8oCallResponse(response.toString(), "XML", url, parameters); | ||
} | ||
logC8oCallResponse(responseStr: string, responseType: string, url: string, parameters: any) { | ||
public logC8oCallResponse(responseStr: string, responseType: string, url: string, parameters: any) { | ||
if (this.c8o.logC8o && this.isTrace) { | ||
@@ -408,2 +403,2 @@ let c8oCallResponseLogMessage: string; | ||
} | ||
} | ||
} |
@@ -13,3 +13,3 @@ export class C8oLogLevel { | ||
static C8O_LOG_LEVELS = [C8oLogLevel.NULL, C8oLogLevel.NONE, C8oLogLevel.TRACE, C8oLogLevel.DEBUG, C8oLogLevel.INFO, C8oLogLevel.WARN, C8oLogLevel.ERROR, C8oLogLevel.FATAL]; | ||
public static C8O_LOG_LEVELS = [C8oLogLevel.NULL, C8oLogLevel.NONE, C8oLogLevel.TRACE, C8oLogLevel.DEBUG, C8oLogLevel.INFO, C8oLogLevel.WARN, C8oLogLevel.ERROR, C8oLogLevel.FATAL]; | ||
@@ -24,3 +24,3 @@ public name: string; | ||
static getC8oLogLevel(name: string): C8oLogLevel { | ||
public static getC8oLogLevel(name: string): C8oLogLevel { | ||
for (let i = 0; i <= C8oLogLevel.C8O_LOG_LEVELS.length; i++) { | ||
@@ -32,2 +32,2 @@ if (C8oLogLevel.C8O_LOG_LEVELS[i].name === name) { | ||
} | ||
} | ||
} |
@@ -28,8 +28,6 @@ import {C8oFullSyncTranslator} from "./c8oFullSyncTranslator"; | ||
this._raw = progress._raw; | ||
} | ||
else { | ||
} else { | ||
if (progress === undefined) { | ||
this._raw = null; | ||
} | ||
else { | ||
} else { | ||
throw new Error(`Expected C8oProgress or empty constructor, got '${progress}'.`); | ||
@@ -137,2 +135,2 @@ } | ||
} | ||
} | ||
} |
@@ -0,5 +1,5 @@ | ||
import "rxjs/add/observable/fromPromise"; | ||
import { Observable } from "rxjs/Observable"; | ||
import { C8oCore } from "./c8oCore"; | ||
import { C8oProgress } from "./c8oProgress"; | ||
import { C8oCore } from "./c8oCore"; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/observable/fromPromise'; | ||
export declare class C8oPromise<T> { | ||
@@ -6,0 +6,0 @@ private c8o; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("rxjs/add/observable/fromPromise"); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var Observable_1 = require("rxjs/Observable"); | ||
require("rxjs/add/observable/fromPromise"); | ||
var C8oPromise = (function () { | ||
@@ -7,0 +7,0 @@ function C8oPromise(c8o) { |
@@ -0,5 +1,5 @@ | ||
import "rxjs/add/observable/fromPromise"; | ||
import { Observable } from "rxjs/Observable"; | ||
import {C8oCore} from "./c8oCore"; | ||
import {C8oProgress} from "./c8oProgress"; | ||
import {C8oCore} from "./c8oCore"; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/observable/fromPromise'; | ||
@@ -21,4 +21,4 @@ export class C8oPromise<T> { | ||
async(): Promise<any> { | ||
return new Promise((resolve, reject)=>{ | ||
public async(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
this.then((response, parameters) => { | ||
@@ -33,11 +33,10 @@ resolve(response); | ||
toObservable() : Observable<any> { | ||
public toObservable(): Observable<any> { | ||
return Observable.fromPromise(this.async()); | ||
} | ||
then(c8oOnResponse: (response: T, parameters: Object) => C8oPromise<T>) { | ||
public then(c8oOnResponse: (response: T, parameters: Object) => C8oPromise<T>) { | ||
if (this.nextPromise != null) { | ||
return this.nextPromise.then(c8oOnResponse); | ||
} | ||
else { | ||
} else { | ||
this.c8oResponse = c8oOnResponse; | ||
@@ -58,7 +57,6 @@ this.nextPromise = new C8oPromise<T>(this.c8o); | ||
progress(c8oOnProgress: (C8oProgress: C8oProgress) => C8oPromise<T>) { | ||
public progress(c8oOnProgress: (C8oProgress: C8oProgress) => C8oPromise<T>) { | ||
if (this.nextPromise != null) { | ||
return this.nextPromise.progress(c8oOnProgress); | ||
} | ||
else { | ||
} else { | ||
this.c8oProgress = c8oOnProgress; | ||
@@ -70,7 +68,6 @@ this.nextPromise = new C8oPromise<T>(this.c8o); | ||
fail(c8oOnFail: (error: Error, parameters: Object) => C8oPromise<T>) { | ||
public fail(c8oOnFail: (error: Error, parameters: Object) => C8oPromise<T>) { | ||
if (this.nextPromise != null) { | ||
return this.nextPromise.fail(c8oOnFail); | ||
} | ||
else { | ||
} else { | ||
this.c8oFail = c8oOnFail; | ||
@@ -85,7 +82,6 @@ this.nextPromise = new C8oPromise<T>(this.c8o); | ||
private _onResponse() { | ||
try { | ||
if (this.c8oResponse != null) { | ||
let promise: C8oPromise<T>[] = new Array<C8oPromise<T>>(0); | ||
const promise: Array<C8oPromise<T>> = new Array<C8oPromise<T>>(0); | ||
promise.push(this.c8oResponse(this.lastResponse, this.lastParameters)); | ||
@@ -101,15 +97,11 @@ if (promise[0] != null) { | ||
this.nextPromise = promise[0]; | ||
} | ||
else if (this.nextPromise != null) { | ||
} else if (this.nextPromise != null) { | ||
this.nextPromise.onResponse(this.lastResponse, this.lastParameters); | ||
} | ||
} | ||
else if (this.nextPromise != null) { | ||
} else if (this.nextPromise != null) { | ||
this.nextPromise.onResponse(this.lastResponse, this.lastParameters); | ||
} | ||
else { | ||
} else { | ||
// Response received and no handler | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
this.onFailure(error, this.lastParameters); | ||
@@ -119,3 +111,3 @@ } | ||
onResponse(response: T, parameters: Object) { | ||
public onResponse(response: T, parameters: Object) { | ||
if ((this.lastResponse != null || this.lastResponse !== undefined) && parameters[C8oCore.ENGINE_PARAMETER_FROM_LIVE] === undefined) { | ||
@@ -125,4 +117,3 @@ if (this.nextPromise != null || this.nextPromise !== undefined) { | ||
} | ||
} | ||
else { | ||
} else { | ||
this.lastResponse = response; | ||
@@ -134,7 +125,6 @@ this.lastParameters = parameters; | ||
onProgress(progress: C8oProgress) { | ||
public onProgress(progress: C8oProgress) { | ||
if (this.c8oProgress != null) { | ||
this.c8oProgress(progress); | ||
} | ||
else if (this.nextPromise != null) { | ||
} else if (this.nextPromise != null) { | ||
this.nextPromise.onProgress(progress); | ||
@@ -144,3 +134,3 @@ } | ||
onFailure(error: Error, parameters: Object) { | ||
public onFailure(error: Error, parameters: Object) { | ||
@@ -157,2 +147,2 @@ this.lastFailure = error; | ||
} | ||
} | ||
} |
@@ -21,8 +21,7 @@ /** | ||
export class C8oResponseProgressListener implements C8oResponseListener { | ||
onProgressResponse: (C8oProgress, Object) => void; | ||
public onProgressResponse: (C8oProgress, Object) => void; | ||
constructor(onProgressResponse: (C8oProgress, Object) => void) { | ||
this.onProgressResponse = onProgressResponse; | ||
} | ||
} | ||
} |
@@ -39,3 +39,2 @@ import {C8oBase} from "./c8oBase"; | ||
/** | ||
@@ -93,4 +92,3 @@ * Sets the connection timeout to Convertigo in milliseconds. A value of zero means the timeout is not used.<br/> | ||
this._clientCertificateFiles[anyCertificate] = password; | ||
} | ||
else if (typeof anyCertificate === "number") { | ||
} else if (typeof anyCertificate === "number") { | ||
if (this._clientCertificateBinaries == null) { | ||
@@ -118,3 +116,2 @@ this._clientCertificateBinaries = {}; | ||
/** | ||
@@ -234,2 +231,2 @@ * Sets a value indicating if logs are sent to the Convertigo server.<br/> | ||
} | ||
} | ||
} |
export class C8oTranslator { | ||
static stringToJSON(jsonValueString): JSON { | ||
public static stringToJSON(jsonValueString): JSON { | ||
return JSON.parse(jsonValueString); | ||
} | ||
} | ||
} |
@@ -6,3 +6,3 @@ | ||
private static USE_PARAMETER_IDENTIFIER: string = "_use_"; | ||
data: JSON; | ||
public data: JSON; | ||
@@ -18,7 +18,6 @@ public constructor() { | ||
*/ | ||
static getObjectClassName(object: any) { | ||
public static getObjectClassName(object: any) { | ||
return typeof object; | ||
} | ||
public static isValidUrl(url: string): boolean { | ||
@@ -28,3 +27,2 @@ return /^(http|https):\/\/[^ "]+$/.test(url.toString()); | ||
public static getNewGUIDString(): string { | ||
@@ -36,3 +34,3 @@ let d = new Date().getTime(); | ||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { | ||
let r = (d + Math.random() * 16) % 16 | 0; | ||
const r = (d + Math.random() * 16) % 16 | 0; | ||
d = Math.floor(d / 16); | ||
@@ -47,5 +45,5 @@ return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16); | ||
for (let _i = 0; _i < Object.keys(parameters).length; _i++) { | ||
let parameterName = Object.keys(parameters)[_i]; | ||
const parameterName = Object.keys(parameters)[_i]; | ||
if ((name === parameterName) || (useName && name === this.USE_PARAMETER_IDENTIFIER + parameterName)) { | ||
let obj = {}; | ||
const obj = {}; | ||
obj[Object.keys(parameters)[_i]] = parameters[Object.keys(parameters)[_i]]; | ||
@@ -68,3 +66,3 @@ return obj; | ||
public static getParameterStringValue(parameters: Object, name: string, useName: boolean): string { | ||
let parameter = C8oUtilsCore.getParameter(parameters, name, useName); | ||
const parameter = C8oUtilsCore.getParameter(parameters, name, useName); | ||
if (parameter != null) { | ||
@@ -78,8 +76,7 @@ return "" + parameter[name]; | ||
//noinspection UnnecessaryLocalVariableJS | ||
let parameters2 = parameters; | ||
let parameter = C8oUtilsCore.getParameter(parameters2, name, useName); | ||
const parameters2 = parameters; | ||
const parameter = C8oUtilsCore.getParameter(parameters2, name, useName); | ||
if (parameter != null) { | ||
return parameter[name]; | ||
} | ||
else { | ||
} else { | ||
return null; | ||
@@ -92,4 +89,4 @@ } | ||
//noinspection UnnecessaryLocalVariableJS | ||
let parameters2 = parameters; | ||
let value: string = this.getParameterStringValue(parameters2, name, false); | ||
const parameters2 = parameters; | ||
const value: string = this.getParameterStringValue(parameters2, name, false); | ||
if (value == null) { | ||
@@ -99,4 +96,3 @@ if (exceptionIfMissing) { | ||
} | ||
} | ||
else { | ||
} else { | ||
delete parameters[name]; | ||
@@ -108,4 +104,4 @@ } | ||
public static peekParameterObjectValue(parameters: Object, name: string, exceptionIfMissing: boolean): string { | ||
let parameters2 = parameters; | ||
let value: string = this.getParameterObjectValue(parameters2, name, false); | ||
const parameters2 = parameters; | ||
const value: string = this.getParameterObjectValue(parameters2, name, false); | ||
if (value == null) { | ||
@@ -115,4 +111,3 @@ if (exceptionIfMissing) { | ||
} | ||
} | ||
else { | ||
} else { | ||
delete parameters2[name]; | ||
@@ -131,3 +126,3 @@ } | ||
*/ | ||
static identifyC8oCallRequest(parameters: Object, responseType: string): string { | ||
public static identifyC8oCallRequest(parameters: Object, responseType: string): string { | ||
return responseType + JSON.stringify(parameters); | ||
@@ -138,16 +133,15 @@ } | ||
export class Queue<T> { | ||
_store: T[] = []; | ||
public _store: T[] = []; | ||
push(val: T) { | ||
public push(val: T) { | ||
this._store.push(val); | ||
} | ||
pop(): T { | ||
public pop(): T { | ||
return this._store.shift(); | ||
} | ||
count(): number { | ||
public count(): number { | ||
return this._store.length; | ||
} | ||
} | ||
@@ -12,2 +12,2 @@ export class FullSyncAttachmentParameter { | ||
} | ||
} | ||
} |
@@ -0,3 +1,3 @@ | ||
import { C8oCore } from "./c8oCore"; | ||
import { C8oResponseListener } from "./c8oResponse"; | ||
import { C8oCore } from "./c8oCore"; | ||
export declare class C8oFullSyncDatabase { | ||
@@ -4,0 +4,0 @@ private c8o; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oProgress_1 = require("./c8oProgress"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var fullSyncReplication_1 = require("./fullSyncReplication"); | ||
@@ -16,3 +16,3 @@ var pouchdb_browser_1 = require("pouchdb-browser"); | ||
var header = { | ||
'x-convertigo-sdk': this.c8o.sdkVersion | ||
"x-convertigo-sdk": this.c8o.sdkVersion, | ||
}; | ||
@@ -22,4 +22,4 @@ Object.assign(header, this.c8o.headers); | ||
ajax: { | ||
headers: header | ||
} | ||
headers: header, | ||
}, | ||
}; | ||
@@ -26,0 +26,0 @@ this.c8oFullSyncDatabaseUrl = fullSyncDatabases + databaseName; |
@@ -1,7 +0,7 @@ | ||
import {C8oResponseProgressListener, C8oResponseListener} from "./c8oResponse"; | ||
import {C8oCore} from "./c8oCore"; | ||
import {C8oProgress} from "./c8oProgress"; | ||
import {C8oResponseListener, C8oResponseProgressListener} from "./c8oResponse"; | ||
import {FullSyncReplication} from "./fullSyncReplication"; | ||
import PouchDB from 'pouchdb-browser' | ||
import PouchDB from "pouchdb-browser"; | ||
/** | ||
@@ -54,4 +54,4 @@ * Created by charlesg on 10/01/2017. | ||
this.c8o = c8o; | ||
let header = { | ||
'x-convertigo-sdk': this.c8o.sdkVersion | ||
const header = { | ||
"x-convertigo-sdk": this.c8o.sdkVersion, | ||
}; | ||
@@ -61,4 +61,4 @@ Object.assign(header, this.c8o.headers); | ||
ajax: { | ||
headers: header | ||
} | ||
headers: header, | ||
}, | ||
}; | ||
@@ -75,4 +75,3 @@ this.c8oFullSyncDatabaseUrl = fullSyncDatabases + databaseName; | ||
} | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
throw error; | ||
@@ -109,6 +108,6 @@ } | ||
let cancel: boolean = false; | ||
let parametersObj: Object = {}; | ||
const parametersObj: Object = {}; | ||
//stop replication if exists | ||
if(fullSyncReplication.replication != null){ | ||
if (fullSyncReplication.replication != null) { | ||
fullSyncReplication.replication.cancel(); | ||
@@ -121,4 +120,3 @@ } | ||
continuous = true; | ||
} | ||
else { | ||
} else { | ||
continuous = false; | ||
@@ -132,4 +130,3 @@ } | ||
cancel = true; | ||
} | ||
else { | ||
} else { | ||
cancel = false; | ||
@@ -170,3 +167,3 @@ } | ||
if (parameters["back_off_function"] != null) { | ||
parametersObj["back_off_function"] = parameters["back_off_function"]; | ||
parametersObj["back_off_function"] = parameters["back_off_function"]; | ||
} | ||
@@ -180,6 +177,6 @@ if (parameters["checkpoint"] != null) { | ||
let remoteDB = new PouchDB(this.c8oFullSyncDatabaseUrl, this.remotePouchHeader); | ||
const remoteDB = new PouchDB(this.c8oFullSyncDatabaseUrl, this.remotePouchHeader); | ||
let rep = fullSyncReplication.replication = this.database.sync(remoteDB, parametersObj); | ||
let param = parameters; | ||
let progress: C8oProgress = new C8oProgress(); | ||
const param = parameters; | ||
const progress: C8oProgress = new C8oProgress(); | ||
progress.raw = rep; | ||
@@ -195,4 +192,3 @@ progress.continuous = false; | ||
progress.finished = rep.pull.state !== "active"; | ||
} | ||
else if (info.direction === "push") { | ||
} else if (info.direction === "push") { | ||
progress.pull = false; | ||
@@ -242,4 +238,3 @@ progress.status = rep.push.state; | ||
progress.status = rep.pull.state; | ||
} | ||
else if (info.direction === "push") { | ||
} else if (info.direction === "push") { | ||
progress.pull = false; | ||
@@ -253,3 +248,3 @@ progress.status = rep.push.state; | ||
}) | ||
.on("paused", function () { | ||
.on("paused", function() { | ||
progress.finished = true; | ||
@@ -269,15 +264,12 @@ (c8oResponseListener as C8oResponseProgressListener).onProgressResponse(progress, param); | ||
rep.cancel(); | ||
if(err.code === "ETIMEDOUT" && err.status === 0){ | ||
if(parameters["force_retry"] == true){ | ||
if (err.code === "ETIMEDOUT" && err.status === 0) { | ||
if (parameters["force_retry"] == true) { | ||
this.c8o.log.warn("C80=>FullSyncDatabase: Timeout handle during fullsync replication (fs://.sync) \n Forcing Restarting replication"); | ||
this.database.sync(remoteDB, {timeout: 600000, retry: true}); | ||
} | ||
else{ | ||
} else { | ||
this.c8o.log.warn("C80=>FullSyncDatabase: Timeout handle during fullsync replication (fs://.sync) \n Restarting automatically replication"); | ||
} | ||
} | ||
else if(err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with "){ | ||
} else if (err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with ") { | ||
reject("NO_NETWORK"); | ||
} | ||
else{ | ||
} else { | ||
reject(err); | ||
@@ -297,16 +289,12 @@ } | ||
} | ||
else if(err.code === "ETIMEDOUT" && err.status === 0){ | ||
if(parameters["force_retry"] == true){ | ||
} else if (err.code === "ETIMEDOUT" && err.status === 0) { | ||
if (parameters["force_retry"] == true) { | ||
this.c8o.log.warn("C80=>FullSyncDatabase: Timeout handle during fullsync replication (fs://.sync) \n Forcing Restarting replication"); | ||
this.database.sync(remoteDB, {timeout: 600000, retry: true}); | ||
} | ||
else{ | ||
} else { | ||
this.c8o.log.warn("C80=>FullSyncDatabase: Timeout handle during fullsync replication (fs://.sync) \n Restarting automatically replication"); | ||
} | ||
} | ||
else if(err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with "){ | ||
} else if (err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with ") { | ||
reject("NO_NETWORK"); | ||
} | ||
else{ | ||
} else { | ||
reject(err); | ||
@@ -341,5 +329,5 @@ } | ||
let cancel: boolean = false; | ||
let parametersObj: Object = {}; | ||
const parametersObj: Object = {}; | ||
//stop replication if exists | ||
if(fullSyncReplication.replication != null){ | ||
if (fullSyncReplication.replication != null) { | ||
fullSyncReplication.replication.cancel(); | ||
@@ -351,4 +339,3 @@ } | ||
continuous = true; | ||
} | ||
else { | ||
} else { | ||
continuous = false; | ||
@@ -362,4 +349,3 @@ } | ||
cancel = true; | ||
} | ||
else { | ||
} else { | ||
cancel = false; | ||
@@ -369,2 +355,3 @@ } | ||
//check parameters to throw to pouchDB | ||
//check parameters to throw to pouchDB | ||
if (parameters["retry"] != null) { | ||
@@ -401,3 +388,3 @@ parametersObj["retry"] = parameters["retry"]; | ||
if (parameters["back_off_function"] != null) { | ||
parametersObj["back_off_function"] = parameters["back_off_function"]; | ||
parametersObj["back_off_function"] = parameters["back_off_function"]; | ||
} | ||
@@ -411,6 +398,6 @@ if (parameters["checkpoint"] != null) { | ||
let remoteDB = new PouchDB(this.c8oFullSyncDatabaseUrl, this.remotePouchHeader); | ||
const remoteDB = new PouchDB(this.c8oFullSyncDatabaseUrl, this.remotePouchHeader); | ||
let rep = fullSyncReplication.replication = fullSyncReplication.pull ? this.database.replicate.from(remoteDB, parametersObj) : this.database.replicate.to(remoteDB, parametersObj); | ||
let progress: C8oProgress = new C8oProgress(); | ||
const progress: C8oProgress = new C8oProgress(); | ||
progress.raw = rep; | ||
@@ -455,12 +442,9 @@ progress.pull = fullSyncReplication.pull; | ||
} else { | ||
rep.cancel(); | ||
if(err.code === "ETIMEDOUT" && err.status === 0){ | ||
if (err.code === "ETIMEDOUT" && err.status === 0) { | ||
reject("TIMEOUT"); | ||
} | ||
else if(err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with "){ | ||
} else if (err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with ") { | ||
reject("NO_NETWORK"); | ||
} | ||
else{ | ||
} else { | ||
reject(err); | ||
@@ -478,10 +462,7 @@ } | ||
rep.cancel(); | ||
} | ||
else if(err.code === "ETIMEDOUT" && err.status === 0){ | ||
} else if (err.code === "ETIMEDOUT" && err.status === 0) { | ||
reject("TIMEOUT"); | ||
} | ||
else if(err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with "){ | ||
} else if (err.name === "unknown" && err.status === 0 && err.message === "getCheckpoint rejected with ") { | ||
reject("NO_NETWORK"); | ||
} | ||
else{ | ||
} else { | ||
reject(err); | ||
@@ -507,3 +488,2 @@ } | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -518,3 +498,3 @@ public get getdatabseName(): string { | ||
deleteDB(): Promise<any> { | ||
public deleteDB(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
@@ -521,0 +501,0 @@ if (this.database != null) { |
@@ -10,2 +10,2 @@ export class FullSyncDeleteDocumentParameter { | ||
} | ||
} | ||
} |
@@ -10,2 +10,2 @@ export class FullSyncGetDocumentParameter { | ||
} | ||
} |
@@ -10,2 +10,2 @@ export class FullSyncGetViewParameter { | ||
} | ||
} | ||
} |
@@ -14,3 +14,3 @@ import {C8oCore} from "./c8oCore"; | ||
public static values(): FullSyncPostDocumentParameter[] { | ||
let array: FullSyncPostDocumentParameter[] = []; | ||
const array: FullSyncPostDocumentParameter[] = []; | ||
array.push(this.POLICY, this.SUBKEY_SEPARATOR); | ||
@@ -20,2 +20,2 @@ return array; | ||
} | ||
} |
export class FullSyncReplication { | ||
pull: boolean; | ||
sync: boolean; | ||
replication: any; | ||
public pull: boolean; | ||
public sync: boolean; | ||
public replication: any; | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -9,9 +9,8 @@ public changeListener: Event; | ||
constructor(pull: boolean = null) { | ||
if(pull != null){ | ||
if (pull != null) { | ||
this.pull = pull; | ||
} | ||
else{ | ||
} else { | ||
this.sync = true; | ||
} | ||
} | ||
} | ||
} |
@@ -22,3 +22,3 @@ import { C8oFullSync, C8oFullSyncCbl } from "./c8oFullSync"; | ||
static getFullSyncRequestable(value: string): FullSyncRequestable; | ||
static values(): Array<FullSyncRequestable>; | ||
static values(): FullSyncRequestable[]; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var c8oResponse_1 = require("./c8oResponse"); | ||
var c8oUtilsCore_1 = require("./c8oUtilsCore"); | ||
var c8oCore_1 = require("./c8oCore"); | ||
var fullSyncAttachmentParameter_1 = require("./fullSyncAttachmentParameter"); | ||
var fullSyncGetDocumentParameter_1 = require("./fullSyncGetDocumentParameter"); | ||
var fullSyncAttachmentParameter_1 = require("./fullSyncAttachmentParameter"); | ||
var fullSyncGetViewParameter_1 = require("./fullSyncGetViewParameter"); | ||
@@ -131,3 +131,3 @@ var FullSyncRequestable = (function () { | ||
if (pullFinish || pushFinish) { | ||
resolve({ "ok": true }); | ||
resolve({ ok: true }); | ||
} | ||
@@ -146,3 +146,3 @@ })).catch(function (error) { | ||
if (progress.finished) { | ||
resolve({ "ok": true }); | ||
resolve({ ok: true }); | ||
} | ||
@@ -165,3 +165,3 @@ if (c8oResponseListener instanceof c8oResponse_1.C8oResponseJsonListener) { | ||
if (progress.finished) { | ||
resolve({ "ok": true }); | ||
resolve({ ok: true }); | ||
} | ||
@@ -168,0 +168,0 @@ if (c8oResponseListener instanceof c8oResponse_1.C8oResponseJsonListener) { |
@@ -0,11 +1,11 @@ | ||
import {FullSyncPolicy, FullSyncPostDocumentParameter} from "./c8oCore"; | ||
import {C8oFullSync, C8oFullSyncCbl} from "./c8oFullSync"; | ||
import { | ||
C8oResponseJsonListener, | ||
C8oResponseListener, | ||
C8oResponseProgressListener, | ||
C8oResponseJsonListener | ||
} from "./c8oResponse"; | ||
import {C8oUtilsCore} from "./c8oUtilsCore"; | ||
import {FullSyncPolicy, FullSyncPostDocumentParameter} from "./c8oCore"; | ||
import {FullSyncAttachmentParameter} from "./fullSyncAttachmentParameter"; | ||
import {FullSyncGetDocumentParameter} from "./fullSyncGetDocumentParameter"; | ||
import {FullSyncAttachmentParameter} from "./fullSyncAttachmentParameter"; | ||
import {FullSyncGetViewParameter} from "./fullSyncGetViewParameter"; | ||
@@ -18,5 +18,5 @@ /** | ||
//noinspection JSUnusedLocalSymbols | ||
static GET: FullSyncRequestable = new FullSyncRequestable("get", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static GET: FullSyncRequestable = new FullSyncRequestable("get", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve) => { | ||
let docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, true); | ||
const docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, true); | ||
resolve(c8oFullSync.handleGetDocumentRequest(databaseName, docid, parameters)); | ||
@@ -29,5 +29,5 @@ }).catch((error) => { | ||
//noinspection JSUnusedLocalSymbols | ||
static DELETE: FullSyncRequestable = new FullSyncRequestable("delete", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static DELETE: FullSyncRequestable = new FullSyncRequestable("delete", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
let docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, true); | ||
const docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, true); | ||
c8oFullSync.handleDeleteDocumentRequest(databaseName, docid, parameters).then((result) => { | ||
@@ -45,10 +45,9 @@ resolve(result); | ||
//noinspection JSUnusedLocalSymbols | ||
static POST: FullSyncRequestable = new FullSyncRequestable("post", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static POST: FullSyncRequestable = new FullSyncRequestable("post", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
let fullSyncPolicyParameter: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncPostDocumentParameter.POLICY.name, false); | ||
let fullSyncPolicy: FullSyncPolicy = FullSyncPolicy.getFullSyncPolicy(fullSyncPolicyParameter); | ||
const fullSyncPolicyParameter: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncPostDocumentParameter.POLICY.name, false); | ||
const fullSyncPolicy: FullSyncPolicy = FullSyncPolicy.getFullSyncPolicy(fullSyncPolicyParameter); | ||
resolve(c8oFullSync.handlePostDocumentRequest(databaseName, fullSyncPolicy, parameters)); | ||
} | ||
catch (error) { | ||
} catch (error) { | ||
reject(error); | ||
@@ -64,8 +63,8 @@ } | ||
//noinspection JSUnusedLocalSymbols | ||
static PUT_ATTACHMENT: FullSyncRequestable = new FullSyncRequestable("put_attachment", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static PUT_ATTACHMENT: FullSyncRequestable = new FullSyncRequestable("put_attachment", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve) => { | ||
let docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, false); | ||
let name: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.NAME.name, false); | ||
let contentType: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.CONTENT_TYPE.name, false); | ||
let content = C8oUtilsCore.getParameterObjectValue(parameters, FullSyncAttachmentParameter.CONTENT.name, false); | ||
const docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, false); | ||
const name: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.NAME.name, false); | ||
const contentType: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.CONTENT_TYPE.name, false); | ||
const content = C8oUtilsCore.getParameterObjectValue(parameters, FullSyncAttachmentParameter.CONTENT.name, false); | ||
resolve(c8oFullSync.handlePutAttachmentRequest(databaseName, docid, name, contentType, content)); | ||
@@ -78,6 +77,6 @@ }).catch((error) => { | ||
//noinspection JSUnusedLocalSymbols | ||
static DELETE_ATTACHMENT: FullSyncRequestable = new FullSyncRequestable("delete_attachment", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static DELETE_ATTACHMENT: FullSyncRequestable = new FullSyncRequestable("delete_attachment", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve) => { | ||
let docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, false); | ||
let name: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.NAME.name, false); | ||
const docid: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetDocumentParameter.DOCID.name, false); | ||
const name: string = C8oUtilsCore.getParameterStringValue(parameters, FullSyncAttachmentParameter.NAME.name, false); | ||
resolve(c8oFullSync.handleDeleteAttachmentRequest(databaseName, docid, name)); | ||
@@ -90,3 +89,3 @@ }).catch((error) => { | ||
//noinspection JSUnusedLocalSymbols | ||
static ALL: FullSyncRequestable = new FullSyncRequestable("all", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static ALL: FullSyncRequestable = new FullSyncRequestable("all", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve) => { | ||
@@ -102,6 +101,6 @@ c8oFullSync.handleAllDocumentsRequest(databaseName, parameters).then((result) => { | ||
//noinspection JSUnusedLocalSymbols | ||
static VIEW: FullSyncRequestable = new FullSyncRequestable("view", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static VIEW: FullSyncRequestable = new FullSyncRequestable("view", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
let ddoc: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetViewParameter.DDOC.name, false); | ||
let view: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetViewParameter.VIEW.name, false); | ||
const ddoc: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetViewParameter.DDOC.name, false); | ||
const view: string = C8oUtilsCore.peekParameterStringValue(parameters, FullSyncGetViewParameter.VIEW.name, false); | ||
c8oFullSync.handleGetViewRequest(databaseName, ddoc, view, parameters).then((result) => { | ||
@@ -117,4 +116,3 @@ resolve(result); | ||
static SYNC: FullSyncRequestable = new FullSyncRequestable("sync", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static SYNC: FullSyncRequestable = new FullSyncRequestable("sync", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
let pullFinish: boolean = false; | ||
@@ -134,7 +132,7 @@ let pushFinish: boolean = false; | ||
c8oFullSync.c8o.log._debug("handleFullSyncRequest onJsonResponse: " + progress.toString()); | ||
let varNull: JSON = null; | ||
const varNull: JSON = null; | ||
(c8oResponseListener as C8oResponseJsonListener).onJsonResponse(varNull, parameters); | ||
} | ||
if (pullFinish || pushFinish) { | ||
resolve({"ok": true}); | ||
resolve({ok: true}); | ||
} | ||
@@ -150,11 +148,10 @@ })).catch((error) => { | ||
static REPLICATE_PULL: FullSyncRequestable = new FullSyncRequestable("replicate_pull", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static REPLICATE_PULL: FullSyncRequestable = new FullSyncRequestable("replicate_pull", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
c8oFullSync.handleReplicatePullRequest(databaseName, parameters, new C8oResponseProgressListener((progress, param) => { | ||
if (progress.finished) { | ||
resolve({"ok": true}); | ||
resolve({ok: true}); | ||
} | ||
if (c8oResponseListener instanceof C8oResponseJsonListener) { | ||
let varNull: JSON = null; | ||
const varNull: JSON = null; | ||
(c8oResponseListener as C8oResponseJsonListener).onJsonResponse(varNull, param); | ||
@@ -171,11 +168,10 @@ } | ||
static REPLICATE_PUSH: FullSyncRequestable = new FullSyncRequestable("replicate_push", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static REPLICATE_PUSH: FullSyncRequestable = new FullSyncRequestable("replicate_push", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
c8oFullSync.handleReplicatePushRequest(databaseName, parameters, new C8oResponseProgressListener((progress, param) => { | ||
if (progress.finished) { | ||
resolve({"ok": true}); | ||
resolve({ok: true}); | ||
} | ||
if (c8oResponseListener instanceof C8oResponseJsonListener) { | ||
let varNull: JSON = null; | ||
const varNull: JSON = null; | ||
(c8oResponseListener as C8oResponseJsonListener).onJsonResponse(varNull, param); | ||
@@ -193,3 +189,3 @@ } | ||
//noinspection JSUnusedLocalSymbols,JSUnusedLocalSymbols | ||
static RESET: FullSyncRequestable = new FullSyncRequestable("reset", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static RESET: FullSyncRequestable = new FullSyncRequestable("reset", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -207,3 +203,3 @@ c8oFullSync.handleResetDatabaseRequest(databaseName).then((response) => { | ||
//noinspection JSUnusedLocalSymbols,JSUnusedLocalSymbols | ||
static CREATE: FullSyncRequestable = new FullSyncRequestable("create", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static CREATE: FullSyncRequestable = new FullSyncRequestable("create", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve) => { | ||
@@ -217,3 +213,3 @@ resolve(c8oFullSync.handleCreateDatabaseRequest(databaseName)); | ||
//noinspection JSUnusedLocalSymbols,JSUnusedLocalSymbols | ||
static DESTROY: FullSyncRequestable = new FullSyncRequestable("destroy", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
public static DESTROY: FullSyncRequestable = new FullSyncRequestable("destroy", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -231,3 +227,2 @@ c8oFullSync.handleDestroyDatabaseRequest(databaseName).then((response) => { | ||
private value: string; | ||
@@ -241,3 +236,3 @@ private handleFullSyncRequestOp: (c8oFullSyncCbl: C8oFullSync, str: string, dictionary: Object, c8oResponseListener: C8oResponseListener) => any; | ||
handleFullSyncRequest(c8oFullSync: C8oFullSync, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
public handleFullSyncRequest(c8oFullSync: C8oFullSync, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
@@ -251,7 +246,6 @@ this.handleFullSyncRequestOp(c8oFullSync, databaseName, parameters, c8oResponseListener).then((result) => { | ||
} | ||
static getFullSyncRequestable(value: string): FullSyncRequestable { | ||
let fullSyncRequestableValues: Array<FullSyncRequestable> = FullSyncRequestable.values(); | ||
public static getFullSyncRequestable(value: string): FullSyncRequestable { | ||
const fullSyncRequestableValues: FullSyncRequestable[] = FullSyncRequestable.values(); | ||
for (let i = 0; i < fullSyncRequestableValues.length; i++) { | ||
@@ -264,6 +258,6 @@ if (fullSyncRequestableValues[i].value === value) { | ||
static values(): Array<FullSyncRequestable> { | ||
public static values(): FullSyncRequestable[] { | ||
return [this.GET, this.DELETE, this.POST, this.ALL, this.VIEW, this.SYNC, this.REPLICATE_PULL, this.REPLICATE_PUSH, this.RESET, this.CREATE, this.DESTROY, this.PUT_ATTACHMENT, this.DELETE_ATTACHMENT]; | ||
} | ||
} | ||
} |
@@ -9,11 +9,10 @@ export class FullSyncRequestParameter { | ||
} | ||
public get type(){ | ||
public get type() { | ||
return this._type; | ||
} | ||
public get name(){ | ||
public get name() { | ||
return this._name; | ||
} | ||
public static DESCENDING: FullSyncRequestParameter = new FullSyncRequestParameter("descending", "boolean"); | ||
@@ -35,4 +34,3 @@ public static ENDKEY: FullSyncRequestParameter = new FullSyncRequestParameter("endkey", "Object"); | ||
public static values(): Array<FullSyncRequestParameter> { | ||
public static values(): FullSyncRequestParameter[] { | ||
return [FullSyncRequestParameter.DESCENDING, FullSyncRequestParameter.ENDKEY, FullSyncRequestParameter.ENDKEY_DOCID, FullSyncRequestParameter.GROUP_LEVEL, FullSyncRequestParameter.INCLUDE_DELETED, FullSyncRequestParameter.INDEX_UPDATE_MODE, FullSyncRequestParameter.KEY, FullSyncRequestParameter.KEYS, FullSyncRequestParameter.LIMIT, FullSyncRequestParameter.REDUCE, FullSyncRequestParameter.GROUP, FullSyncRequestParameter.SKIP, FullSyncRequestParameter.STARTKEY, FullSyncRequestParameter.STARTKEY_DOCID, FullSyncRequestParameter.INCLUDE_DOCS]; | ||
@@ -44,3 +42,3 @@ } | ||
if (name != null) { | ||
for (let fullSyncRequestParameter of FullSyncRequestParameter.values()){ | ||
for (const fullSyncRequestParameter of FullSyncRequestParameter.values()) { | ||
if (name === fullSyncRequestParameter.name) { | ||
@@ -52,2 +50,2 @@ return fullSyncRequestParameter as FullSyncRequestParameter; | ||
} | ||
} | ||
} |
@@ -6,11 +6,11 @@ export class FullSyncResponse { | ||
*/ | ||
static RESPONSE_KEY_OK: string = "ok"; | ||
public static RESPONSE_KEY_OK: string = "ok"; | ||
/** | ||
* The response key indicating the document ID. | ||
*/ | ||
static RESPONSE_KEY_DOCUMENT_ID: string = "id"; | ||
public static RESPONSE_KEY_DOCUMENT_ID: string = "id"; | ||
/** | ||
* The response key indicating the document revision. | ||
*/ | ||
static RESPONSE_KEY_DOCUMENT_REVISION: string = "rev"; | ||
public static RESPONSE_KEY_DOCUMENT_REVISION: string = "rev"; | ||
} | ||
@@ -28,4 +28,4 @@ | ||
getProperties(): any { | ||
let properties: Object = {}; | ||
public getProperties(): any { | ||
const properties: Object = {}; | ||
properties[FullSyncResponse.RESPONSE_KEY_OK] = this.operationStatus; | ||
@@ -49,4 +49,4 @@ return properties; | ||
export class FullSyncDocumentOperationResponse extends FullSyncAbstractResponse { | ||
documentId: string; | ||
documentRevision: string; | ||
public documentId: string; | ||
public documentRevision: string; | ||
@@ -59,4 +59,4 @@ constructor(documentId: string, documentRevision: string, operationStatus: boolean) { | ||
getProperties(): Object { | ||
let properties: Object = super.getProperties(); | ||
public getProperties(): Object { | ||
const properties: Object = super.getProperties(); | ||
properties[FullSyncResponse.RESPONSE_KEY_DOCUMENT_ID] = this.documentId; | ||
@@ -67,2 +67,2 @@ properties[FullSyncResponse.RESPONSE_KEY_DOCUMENT_REVISION] = this.documentRevision; | ||
} | ||
} |
@@ -6,3 +6,3 @@ /** | ||
export class Priority { | ||
isAvailable: boolean; | ||
public isAvailable: boolean; | ||
@@ -19,2 +19,2 @@ //noinspection JSUnusedLocalSymbols | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
543225
8732