@elastic.io/oih-standard-library
Advanced tools
Comparing version 1.0.1-dev.1 to 1.0.1-dev.2
@@ -17,8 +17,17 @@ interface GetInMetadataPropertiesParams { | ||
* @param cfg | ||
* @returns all objects that meet the criteria | ||
*/ | ||
abstract getObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any): Promise<any>; | ||
/** | ||
* | ||
* @param objectType | ||
* @param criteria | ||
* @param msg | ||
* @param cfg | ||
* @param pageSize | ||
* @param start pageSize * pageNumber | ||
* @param orderBy how to order search results | ||
* @returns all objects that meet the criteria | ||
* @returns page of objects that meet the criteria | ||
*/ | ||
abstract getObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any, pageSize?: number, start?: number, orderBy?: any): Promise<any>; | ||
abstract getPageOfObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any, pageSize?: number, start?: number, orderBy?: any): Promise<any>; | ||
/** | ||
@@ -56,3 +65,3 @@ * Can use or override the `getInMetadata` function defined below | ||
*/ | ||
getCriteria(cfg: any, msg: any): any; | ||
getCriteria(msg: any, cfg: any): object; | ||
/** | ||
@@ -59,0 +68,0 @@ * Default implementation expects type to be present inside input configuration `objectType` param. If you need other behaviour override this method. |
@@ -29,8 +29,6 @@ "use strict"; | ||
this.logger.trace('Search criteria: %j', criteria); | ||
const result = await this.lookupObjects(objectType, criteria, msg, cfg); | ||
this.logger.trace('Message results: %j', result); | ||
await this.lookupObjects(objectType, criteria, msg, cfg); | ||
this.logger.info('Finished processing call to lookupObjects action'); | ||
} | ||
catch (e) { | ||
constants_1.NUM_SEARCH_TERMS; | ||
this.logger.error('Unexpected error while processing lookupObjectById call for message: %j, cfg: %j', msg, cfg, e); | ||
@@ -53,3 +51,3 @@ throw e; | ||
this.logger.trace('Max result size: %j', maxResultSize); | ||
const results = await this.getObjectsByCriteria(objectType, criteria); | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -63,3 +61,3 @@ if (results.length > maxResultSize) { | ||
case constants_1.EMIT_INDIVIDUALLY: { | ||
const results = await this.getObjectsByCriteria(objectType, criteria); | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -78,3 +76,3 @@ for (const result of results) { | ||
this.logger.trace('Order by: %j', orderByTerms); | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg, pageSize, pageSize * pageNumber, orderByTerms); | ||
const results = await this.getPageOfObjectsByCriteria(objectType, criteria, msg, cfg, pageSize, pageSize * pageNumber, orderByTerms); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -98,10 +96,8 @@ for (const result of results) { | ||
*/ | ||
getCriteria(cfg, msg) { | ||
const numSearchTerms = cfg[constants_1.NUM_SEARCH_TERMS]; | ||
const criteria = []; | ||
if (numSearchTerms === undefined) | ||
throw new Error('You must have at least one search term'); | ||
getCriteria(msg, cfg) { | ||
const numSearchTerms = cfg[constants_1.NUM_SEARCH_TERMS] || 0; | ||
const criteria = {}; | ||
for (let i = 0; i < numSearchTerms; i++) { | ||
const searchTerm = `searchTerm${i}`; | ||
criteria.push(msg.body[searchTerm]); | ||
criteria[searchTerm] = msg.body[searchTerm]; | ||
} | ||
@@ -206,13 +202,7 @@ return criteria; | ||
*/ | ||
getInMetadata(cfg, properties = { | ||
conditions: CONDITIONS_LIST, | ||
fields: [], | ||
includeOrder: false, | ||
}) { | ||
const conditionsEnum = properties.conditions || CONDITIONS_LIST; | ||
const fieldsEnum = properties.fields || []; | ||
const includeOrder = properties.includeOrder || false; | ||
const numSearchTerms = cfg[constants_1.NUM_SEARCH_TERMS]; | ||
if (numSearchTerms === undefined) | ||
throw new Error('You must have at least one search term'); | ||
getInMetadata(cfg, properties) { | ||
const conditionsEnum = (properties && properties.conditions !== undefined) ? properties.conditions : CONDITIONS_LIST; | ||
const fieldsEnum = (properties && properties.fields !== undefined) ? properties.fields : []; | ||
const includeOrder = (properties && properties.includeOrder !== undefined) ? properties.includeOrder : true; | ||
const numSearchTerms = cfg[constants_1.NUM_SEARCH_TERMS] || 0; | ||
const inMetadata = { | ||
@@ -219,0 +209,0 @@ type: 'object', |
@@ -29,2 +29,3 @@ import { | ||
interface SearchTerm { | ||
@@ -57,8 +58,18 @@ title: string; | ||
* @param cfg | ||
* @returns all objects that meet the criteria | ||
*/ | ||
public abstract async getObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any): Promise<any>; | ||
/** | ||
* | ||
* @param objectType | ||
* @param criteria | ||
* @param msg | ||
* @param cfg | ||
* @param pageSize | ||
* @param start pageSize * pageNumber | ||
* @param orderBy how to order search results | ||
* @returns all objects that meet the criteria | ||
* @returns page of objects that meet the criteria | ||
*/ | ||
public abstract async getObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any, pageSize?: number, start?: number, orderBy?: any): Promise<any>; | ||
public abstract async getPageOfObjectsByCriteria(objectType: any, criteria: any, msg?: any, cfg?: any, pageSize?: number, start?: number, orderBy?: any): Promise<any>; | ||
@@ -91,7 +102,5 @@ /** | ||
this.logger.trace('Search criteria: %j', criteria); | ||
const result = await this.lookupObjects(objectType, criteria, msg, cfg); | ||
this.logger.trace('Message results: %j', result); | ||
await this.lookupObjects(objectType, criteria, msg, cfg); | ||
this.logger.info('Finished processing call to lookupObjects action'); | ||
} catch (e) {NUM_SEARCH_TERMS | ||
} catch (e) { | ||
this.logger.error('Unexpected error while processing lookupObjectById call for message: %j, cfg: %j', msg, cfg, e); | ||
@@ -116,3 +125,3 @@ throw e; | ||
const results = await this.getObjectsByCriteria(objectType, criteria); | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -127,3 +136,3 @@ | ||
case EMIT_INDIVIDUALLY: { | ||
const results = await this.getObjectsByCriteria(objectType, criteria); | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -145,3 +154,3 @@ for (const result of results) { | ||
const results = await this.getObjectsByCriteria(objectType, criteria, msg, cfg, pageSize, pageSize * pageNumber, orderByTerms); | ||
const results = await this.getPageOfObjectsByCriteria(objectType, criteria, msg, cfg, pageSize, pageSize * pageNumber, orderByTerms); | ||
this.logger.trace('Results from lookup: %j', results); | ||
@@ -167,9 +176,8 @@ | ||
*/ | ||
public getCriteria(cfg: any, msg: any): any { | ||
const numSearchTerms = cfg[NUM_SEARCH_TERMS]; | ||
const criteria: Array<object> = []; | ||
if (numSearchTerms === undefined) throw new Error('You must have at least one search term'); | ||
public getCriteria(msg: any, cfg: any): object { | ||
const numSearchTerms = cfg[NUM_SEARCH_TERMS] || 0; | ||
const criteria: object = {}; | ||
for (let i = 0; i < numSearchTerms; i++) { | ||
const searchTerm = `searchTerm${i}`; | ||
criteria.push(msg.body[searchTerm]); | ||
criteria[searchTerm] = msg.body[searchTerm]; | ||
} | ||
@@ -276,13 +284,8 @@ return criteria; | ||
*/ | ||
public getInMetadata(cfg: any, properties: GetInMetadataPropertiesParams = { | ||
conditions: CONDITIONS_LIST, | ||
fields: [], | ||
includeOrder: false, | ||
}): object { | ||
const conditionsEnum = properties.conditions || CONDITIONS_LIST; | ||
const fieldsEnum = properties.fields || []; | ||
const includeOrder = properties.includeOrder || false; | ||
public getInMetadata(cfg: any, properties?: GetInMetadataPropertiesParams): object { | ||
const conditionsEnum = (properties && properties.conditions !== undefined) ? properties.conditions : CONDITIONS_LIST; | ||
const fieldsEnum = (properties && properties.fields !== undefined) ? properties.fields : []; | ||
const includeOrder = (properties && properties.includeOrder !== undefined) ? properties.includeOrder : true; | ||
const numSearchTerms = cfg[NUM_SEARCH_TERMS]; | ||
if (numSearchTerms === undefined) throw new Error('You must have at least one search term'); | ||
const numSearchTerms = cfg[NUM_SEARCH_TERMS] || 0; | ||
const inMetadata: InputMetadata = { | ||
@@ -289,0 +292,0 @@ type: 'object', |
{ | ||
"name": "@elastic.io/oih-standard-library", | ||
"version": "1.0.1-dev.1", | ||
"version": "1.0.1-dev.2", | ||
"description": "Library for OIH standards implementation", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
196840
2961