Skip to content

Commit

Permalink
ref #23 done
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesGrimont committed Nov 10, 2020
1 parent 5eefa5e commit c1776a2
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c8osdkjscore",
"version": "3.0.11-beta34",
"version": "3.0.11-beta35",
"description": "convertigo's sdk js core",
"main": "bundle/index.umd.js",
"module": "src/index.js",
Expand Down Expand Up @@ -41,15 +41,16 @@
"rxjs": "=> 5.5.11"
},
"dependencies": {
"@types/pouchdb": "6.4.0",
"pouchdb-browser": "7.2.2",
"pouchdb-checkpointer": "7.2.2",
"pouchdb-find": "7.2.2",
"pouchdb-extend": "0.1.2",
"pouchdb-generate-replication-id": "7.2.2",
"pouchdb-quick-search": "1.3.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@types/pouchdb": "6.4.0",
"@types/node": "12.12.6",
"rimraf": "2.6.1",
"@types/jasmine": "2.8.2",
Expand Down
19 changes: 19 additions & 0 deletions src/c8o/Exception/c8oExceptionMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ export class C8oExceptionMessage {
return "Unable to run the view query";
}

static couchRequestCreateIndex(): string {
return "Unable to create the index";
}
static couchRequestFind(): string {
return "Unable to run the query find";
}

static couchRequestExplain(): string {
return "Unable to run the query explain";
}

static couchRequestGetIndexes(): string {
return "Unable to run the query getIndexes";
}

static couchRequestDeleteIndex(): string {
return "Unable to run the query deleteIndex";
}

static couchRequestAllDocuments(): string {
return "Unable to run the all query";
}
Expand Down
53 changes: 53 additions & 0 deletions src/c8o/c8oFullSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,59 @@ export class C8oFullSyncCbl extends C8oFullSync {

}

public async handleCreateIndexRequest(databaseName: string, fields: any, parameters: Object): Promise<any> {
let fullSyncDatabase = await this.getOrCreateFullSyncDatabase(databaseName);
try {
parameters["fields"] = fields;
var result = await fullSyncDatabase.getdatabase.createIndex({index: parameters});
return result;
} catch (err) {
throw new C8oException(C8oExceptionMessage.couchRequestCreateIndex(), err)
}
}

public async handleGetFindRequest(databaseName: string,selector:any, parameters: Object): Promise<any> {
let fullSyncDatabase = await this.getOrCreateFullSyncDatabase(databaseName);
try {
parameters["selector"] = selector;
var result = await fullSyncDatabase.getdatabase.find(parameters);
return result;
} catch (err) {
throw new C8oException(C8oExceptionMessage.couchRequestFind(), err)
}
}

public async handleExplainRequest(databaseName: string,selector:any, parameters: Object): Promise<any> {
let fullSyncDatabase = await this.getOrCreateFullSyncDatabase(databaseName);
try {
parameters["selector"] = selector;
var result = await fullSyncDatabase.getdatabase.explain(parameters);
return result;
} catch (err) {
throw new C8oException(C8oExceptionMessage.couchRequestExplain(), err)
}
}

public async handleGetIndexesRequest(databaseName: string, parameters: Object): Promise<any> {
let fullSyncDatabase = await this.getOrCreateFullSyncDatabase(databaseName);
try {
var result = await fullSyncDatabase.getdatabase.getIndexes();
return result;
} catch (err) {
throw new C8oException(C8oExceptionMessage.couchRequestGetIndexes(), err)
}
}

public async handleDeleteIndexRequest(databaseName: string, parameters: Object): Promise<any> {
let fullSyncDatabase = await this.getOrCreateFullSyncDatabase(databaseName);
try {
var result = await fullSyncDatabase.getdatabase.deleteIndex(parameters);
return result;
} catch (err) {
throw new C8oException(C8oExceptionMessage.couchRequestDeleteIndex(), err)
}
}

/**
* Check network status before starting a replication
*/
Expand Down
2 changes: 2 additions & 0 deletions src/c8o/fullSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { C8oResponseListener, C8oResponseProgressListener } from "./c8oResponse"
import { FullSyncReplication } from "./fullSyncReplication";

import PouchDB from "pouchdb-browser";
import PouchDBFind from "pouchdb-find";

import {C8oLoad} from "./c8oload";

Expand Down Expand Up @@ -56,6 +57,7 @@ export class C8oFullSyncDatabase {
* @throws C8oException Failed to get the fullSync database.
*/
constructor(c8o: C8oCore, databaseName: string, fullSyncDatabases: string, localSuffix: string, localPrefix: string) {
PouchDB.plugin(PouchDBFind);
let c8oload: C8oLoad = new C8oLoad(c8o);
window["PouchDB"] =PouchDB;
this.c8o = c8o;
Expand Down
63 changes: 62 additions & 1 deletion src/c8o/fullSyncRequestable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {C8oUtilsCore} from "./c8oUtilsCore";
import {FullSyncAttachmentParameter} from "./fullSyncAttachmentParameter";
import {FullSyncGetDocumentParameter} from "./fullSyncGetDocumentParameter";
import {FullSyncGetViewParameter} from "./fullSyncGetViewParameter";
import {FullSyncGetIndexParameter} from "./fullSyncGetIndexParameter";
import {FullSyncGetFindParameter} from "./FullSyncGetFindParameter";
/**
* Created by charlesg on 10/01/2017.
*/
Expand Down Expand Up @@ -139,6 +141,65 @@ export class FullSyncRequestable {
});
});

//noinspection JSUnusedLocalSymbols
public static CREATEINDEX: FullSyncRequestable = new FullSyncRequestable("createIndex", async (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
try{
const fields: string = C8oUtilsCore.peekParameterObjectValue(parameters, FullSyncGetIndexParameter.FIELDS.name, false);
let result = await c8oFullSync.handleCreateIndexRequest(databaseName, fields, parameters);
return result;
}
catch(e){
return e;
}
});

//noinspection JSUnusedLocalSymbols
public static FIND: FullSyncRequestable = new FullSyncRequestable("find", async (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
try{
const selector: string = C8oUtilsCore.peekParameterObjectValue(parameters, FullSyncGetFindParameter.SELECTOR.name, false);
let result = await c8oFullSync.handleGetFindRequest(databaseName, selector, parameters);
return result;
}
catch(e){
return e;
}
});

//noinspection JSUnusedLocalSymbols
public static EXPLAIN: FullSyncRequestable = new FullSyncRequestable("explain", async (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
try{
const selector: string = C8oUtilsCore.peekParameterObjectValue(parameters, FullSyncGetFindParameter.SELECTOR.name, false);
let result = await c8oFullSync.handleExplainRequest(databaseName, selector, parameters);
return result;
}
catch(e){
return e;
}
});

//noinspection JSUnusedLocalSymbols
public static GETINDEXES: FullSyncRequestable = new FullSyncRequestable("getIndexes", async (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
try{
let result = await c8oFullSync.handleGetIndexesRequest(databaseName, parameters);
return result;
}
catch(e){
return e;
}
});

//noinspection JSUnusedLocalSymbols
public static DELETEINDEX: FullSyncRequestable = new FullSyncRequestable("deleteIndex", async (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
try{
let result = await c8oFullSync.handleDeleteIndexRequest(databaseName, parameters);
return result;
}
catch(e){
return e;
}
});


public static SYNC: FullSyncRequestable = new FullSyncRequestable("sync", (c8oFullSync: C8oFullSyncCbl, databaseName: string, parameters: Object, c8oResponseListener: C8oResponseListener) => {
let pullFinish: boolean = false;
let pushFinish: boolean = false;
Expand Down Expand Up @@ -303,7 +364,7 @@ export class FullSyncRequestable {
}

public static values(): FullSyncRequestable[] {
return [this.GET, this.DELETE, this.POST, this.ALL, this.ALL_LOCAL, this.VIEW, this.SYNC, this.REPLICATE_PULL, this.REPLICATE_PUSH, this.RESET, this.CREATE, this.DESTROY, this.PUT_ATTACHMENT, this.GET_ATTACHMENT,this.DELETE_ATTACHMENT, this.BULK, this.INFO];
return [this.GET, this.DELETE, this.POST, this.ALL, this.ALL_LOCAL, this.VIEW, this.SYNC, this.REPLICATE_PULL, this.REPLICATE_PUSH, this.RESET, this.CREATE, this.DESTROY, this.PUT_ATTACHMENT, this.GET_ATTACHMENT,this.DELETE_ATTACHMENT, this.BULK, this.INFO, this.CREATEINDEX, this.FIND, this.DELETEINDEX, this.GETINDEXES, this.EXPLAIN];

}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit c1776a2

Please sign in to comment.