pragmatismo-io-framework
Advanced tools
Comparing version 1.0.17 to 1.0.18
@@ -42,4 +42,10 @@ /*****************************************************************************\ | ||
deleteIndex(): Promise<{}>; | ||
deleteDataSource(name: string): Promise<{}>; | ||
/** | ||
* | ||
* @param dsType * 'azuresql', 'documentdb', 'azureblob', or 'azuretable' | ||
*/ | ||
createDataSource(name: string, description: string, tableName: string, dsType: string, connectionString: string): Promise<{}>; | ||
/** Creates an index in Azure search. */ | ||
createIndex(schema: any, dataSourceName: any): Promise<{}>; | ||
} |
@@ -64,3 +64,3 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
this.client.deleteIndex(this.searchIndex, (err) => { | ||
this.client.deleteIndex(this.searchIndex, err => { | ||
if (err) { | ||
@@ -70,3 +70,3 @@ reject(err); | ||
else { | ||
this.client.deleteIndexer(this.searchIndexer, (err) => { | ||
this.client.deleteIndexer(this.searchIndexer, err => { | ||
if (err) { | ||
@@ -83,2 +83,37 @@ reject(err); | ||
} | ||
deleteDataSource(name) { | ||
return new Promise((resolve, reject) => { | ||
this.client.deleteDataSource(name, err => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* | ||
* @param dsType * 'azuresql', 'documentdb', 'azureblob', or 'azuretable' | ||
*/ | ||
createDataSource(name, description, tableName, dsType, connectionString) { | ||
let ds = { | ||
name: name, | ||
description: description, | ||
type: dsType, | ||
credentials: { connectionString: connectionString }, | ||
container: { name: tableName } | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this.client.createDataSource(ds, err => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
/** Creates an index in Azure search. */ | ||
@@ -98,6 +133,6 @@ createIndex(schema, dataSourceName) { | ||
parameters: { | ||
'maxFailedItems': 10, | ||
'maxFailedItemsPerBatch': 5, | ||
'base64EncodeKeys': false, | ||
'batchSize': 500 | ||
maxFailedItems: 10, | ||
maxFailedItemsPerBatch: 5, | ||
base64EncodeKeys: false, | ||
batchSize: 500 | ||
} | ||
@@ -104,0 +139,0 @@ }; |
{ | ||
"name": "pragmatismo-io-framework", | ||
"version": "1.0.17", | ||
"description": "Anything reusable turned into classes.", | ||
"version": "1.0.18", | ||
"description": "Anything reusable turned into typed classes.", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "./dist/index.d.ts", |
@@ -35,97 +35,134 @@ /*****************************************************************************\ | ||
export class AzureSearch { | ||
client: any | ||
searchKey: string | ||
searchIndex: string | ||
searchIndexer: string | ||
client: any; | ||
searchKey: string; | ||
searchIndex: string; | ||
searchIndexer: string; | ||
constructor(searchKey: string, searchHost: string, searchIndex: string, searchIndexer: string) { | ||
this.searchKey = searchKey | ||
this.searchIndex = searchIndex | ||
this.searchIndexer = searchIndexer | ||
constructor( | ||
searchKey: string, | ||
searchHost: string, | ||
searchIndex: string, | ||
searchIndexer: string | ||
) { | ||
this.searchKey = searchKey; | ||
this.searchIndex = searchIndex; | ||
this.searchIndexer = searchIndexer; | ||
this.client = require("azure-search")({ | ||
url: "https://" + searchHost, | ||
key: searchKey | ||
}) | ||
}); | ||
} | ||
search(queryText: string, top = 1000) { | ||
return new Promise <any>( | ||
(resolve, reject) => { | ||
this.client.search( | ||
this.searchIndex, | ||
{ | ||
search: queryText, | ||
queryType: "simple", | ||
searchMode: "any" | ||
}, | ||
(err, results) => { | ||
return new Promise<any>((resolve, reject) => { | ||
this.client.search( | ||
this.searchIndex, | ||
{ | ||
search: queryText, | ||
queryType: "simple", | ||
searchMode: "any" | ||
}, | ||
(err, results) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(results); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
deleteIndex() { | ||
return new Promise((resolve, reject) => { | ||
this.client.deleteIndex(this.searchIndex, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
this.client.deleteIndexer(this.searchIndexer, err => { | ||
if (err) { | ||
reject(err) | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
else { | ||
resolve(results) | ||
} | ||
}) | ||
}) | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
deleteIndex() { | ||
return new Promise( | ||
(resolve, reject) => { | ||
this.client.deleteIndex(this.searchIndex, (err) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
else { | ||
this.client.deleteIndexer(this.searchIndexer, (err) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
else { | ||
resolve() | ||
} | ||
}) | ||
} | ||
}) | ||
}) | ||
deleteDataSource(name: string) { | ||
return new Promise((resolve, reject) => { | ||
this.client.deleteDataSource(name, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* | ||
* @param dsType * 'azuresql', 'documentdb', 'azureblob', or 'azuretable' | ||
*/ | ||
createDataSource( | ||
name: string, | ||
description: string, | ||
tableName: string, | ||
dsType: string, | ||
connectionString: string | ||
) { | ||
let ds = { | ||
name: name, | ||
description: description, | ||
type: dsType, | ||
credentials: { connectionString: connectionString }, | ||
container: { name: tableName } | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this.client.createDataSource(ds, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
/** Creates an index in Azure search. */ | ||
createIndex(schema, dataSourceName) { | ||
let _this_ = this | ||
return new Promise( | ||
(resolve, reject) => { | ||
this.client.createIndex(schema, (err, schemaReturned) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
else { | ||
let schemaIndexer = { | ||
name: _this_.searchIndexer, | ||
dataSourceName: dataSourceName, | ||
targetIndexName: this.searchIndex, | ||
parameters: { | ||
'maxFailedItems': 10, | ||
'maxFailedItemsPerBatch': 5, | ||
'base64EncodeKeys': false, | ||
'batchSize': 500 | ||
} | ||
let _this_ = this; | ||
return new Promise((resolve, reject) => { | ||
this.client.createIndex(schema, (err, schemaReturned) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
let schemaIndexer = { | ||
name: _this_.searchIndexer, | ||
dataSourceName: dataSourceName, | ||
targetIndexName: this.searchIndex, | ||
parameters: { | ||
maxFailedItems: 10, | ||
maxFailedItemsPerBatch: 5, | ||
base64EncodeKeys: false, | ||
batchSize: 500 | ||
} | ||
}; | ||
this.client.createIndexer(schemaIndexer, function (err, results) { | ||
if (err) { | ||
reject(err) | ||
} | ||
else { | ||
resolve(results) | ||
} | ||
}) | ||
} | ||
}) | ||
}) | ||
this.client.createIndexer(schemaIndexer, function(err, results) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(results); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
# History | ||
## Version 1.0.18 | ||
- NEW: Support for creation of datasources in Azure Search. | ||
## Version 1.0.17 | ||
@@ -4,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
452090
42
2371