azure-functions-elasticizer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -74,4 +74,7 @@ import { Promise as Promise$1 } from 'bluebird'; | ||
Elasticizer.prototype.search = function (index, body, query, page, perPage, sortAsc) { | ||
var _this = this; | ||
var query$ = this.client.search({ | ||
index: "" + this.prefix + index, | ||
index: Array.isArray(index) | ||
? index.map(function (cur) { return "" + _this.prefix + cur; }) | ||
: "" + this.prefix + index, | ||
body: body, | ||
@@ -78,0 +81,0 @@ q: query, |
@@ -67,3 +67,5 @@ import { Promise as Promise$1 } from 'bluebird'; | ||
const query$ = this.client.search({ | ||
index: `${this.prefix}${index}`, | ||
index: Array.isArray(index) | ||
? index.map(cur => `${this.prefix}${cur}`) | ||
: `${this.prefix}${index}`, | ||
body, | ||
@@ -70,0 +72,0 @@ q: query, |
@@ -73,4 +73,7 @@ (function (global, factory) { | ||
Elasticizer.prototype.search = function (index, body, query, page, perPage, sortAsc) { | ||
var _this = this; | ||
var query$ = this.client.search({ | ||
index: "" + this.prefix + index, | ||
index: Array.isArray(index) | ||
? index.map(function (cur) { return "" + _this.prefix + cur; }) | ||
: "" + this.prefix + index, | ||
body: body, | ||
@@ -77,0 +80,0 @@ q: query, |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("bluebird"),require("lodash"),require("elasticsearch"),require("azure-functions-ts-essentials")):"function"==typeof define&&define.amd?define(["exports","bluebird","lodash","elasticsearch","azure-functions-ts-essentials"],t):t(e.azureFunctionsElasticizer=e.azureFunctionsElasticizer||{},e.bluebird,e._,e.elasticsearch,e._azureFunctionsTsEssentials)}(this,function(e,t,r,i,n){"use strict";var s=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o="wait_for",u=function(e){return new i.Client({host:e,defer:function(){return t.Promise.defer()}})},a=function(e){return Array.isArray(e)&&e.length>0?{status:n.HttpStatusCode.BadRequest,body:e.map(function(e){return{type:r.get(e,"type"),message:r.get(e,"reason"),index:r.get(e,"index"),uuid:r.get(e,"index_uuid")}})}:{status:e.status,body:{type:e.displayName,message:e.message}}},d=function(){function e(e,t,i){this.host=e,this.type=t,this.options=i,this.client=u(e),this.refresh=r.get(i,"refresh",o),this.prefix=r.get(i,"prefix","")}return e.prototype.getOne=function(e,t){return this.client.get({index:""+this.prefix+e,type:this.type,id:t}).then(function(e){return{status:n.HttpStatusCode.OK,body:s({_index:e._index,_id:e._id},e._source)}}).catch(a)},e.prototype.search=function(e,t,r,i,o,u){return this.client.search({index:""+this.prefix+e,body:t,q:r,from:Number(i)>=0&&Number(o)>0?Number(i)*Number(o):0,size:Number(o)>0?Number(o):2147483519,sort:"createdAtUtc:"+(u?"asc":"desc")}).then(function(e){return{status:n.HttpStatusCode.OK,body:{data:e.hits.hits.map(function(e){return s({_index:e._index,_id:e._id},e._source)}),hasMore:Number(i)>=0&&Number(o)>0&&e.hits.total>(Number(i)+1)*Number(o),totalCount:e.hits.total}}}).catch(a)},e.prototype.insertMany=function(e){var t=this,i=e.headers?e.headers["content-type"]:void 0;return i&&i.indexOf("application/json")>=0&&e.body&&Object.keys(e.body).length?this.client.bulk({type:this.type,refresh:this.refresh,body:e.body.reduce(function(e,r){var i={_index:""+t.prefix+r._index};return delete r._index,e.push({index:s({},i)},s({},r,{createdAtUtc:(new Date).toISOString()})),e},[])}).then(function(e){return r.get(e,"errors")?a(e.items.map(function(e){return e.index.error})):{status:n.HttpStatusCode.Created,body:{}}}).catch(a):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Invalid}})},e.prototype.updateOne=function(e,t,r){var i=t.headers?t.headers["content-type"]:void 0;return i&&i.indexOf("application/json")>=0&&t.body&&Object.keys(t.body).length&&r?(delete t.body._index,this.client.update({index:""+this.prefix+e,type:this.type,refresh:this.refresh,id:r,body:{doc:t.body}}).then(function(){return{status:n.HttpStatusCode.OK,body:{}}}).catch(a)):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Invalid}})},e.prototype.deleteOne=function(e,t){return t?this.client.delete({index:""+this.prefix+e,type:this.type,refresh:this.refresh,id:t}).then(function(){return{status:n.HttpStatusCode.OK,body:{}}}).catch(a):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Missing}})},e}();e.ELASTICSEARCH_REFRESH=o,e.ELASTICSEARCH_MAX_RESULTS=2147483519,e.getElasticClient=u,e.getStringDate=function(e){e||(e=new Date);var t=e.getUTCFullYear(),r=(e.getUTCMonth()+1).toString(),i=e.getUTCDate().toString();return r=(Number(r)<10?"0":"")+r,i=(Number(i)<10?"0":"")+i,t+"."+r+"."+i},e.Elasticizer=d,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("bluebird"),require("lodash"),require("elasticsearch"),require("azure-functions-ts-essentials")):"function"==typeof define&&define.amd?define(["exports","bluebird","lodash","elasticsearch","azure-functions-ts-essentials"],t):t(e.azureFunctionsElasticizer=e.azureFunctionsElasticizer||{},e.bluebird,e._,e.elasticsearch,e._azureFunctionsTsEssentials)}(this,function(e,t,r,i,n){"use strict";var s=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o="wait_for",u=function(e){return new i.Client({host:e,defer:function(){return t.Promise.defer()}})},a=function(e){return Array.isArray(e)&&e.length>0?{status:n.HttpStatusCode.BadRequest,body:e.map(function(e){return{type:r.get(e,"type"),message:r.get(e,"reason"),index:r.get(e,"index"),uuid:r.get(e,"index_uuid")}})}:{status:e.status,body:{type:e.displayName,message:e.message}}},d=function(){function e(e,t,i){this.host=e,this.type=t,this.options=i,this.client=u(e),this.refresh=r.get(i,"refresh",o),this.prefix=r.get(i,"prefix","")}return e.prototype.getOne=function(e,t){return this.client.get({index:""+this.prefix+e,type:this.type,id:t}).then(function(e){return{status:n.HttpStatusCode.OK,body:s({_index:e._index,_id:e._id},e._source)}}).catch(a)},e.prototype.search=function(e,t,r,i,o,u){var d=this;return this.client.search({index:Array.isArray(e)?e.map(function(e){return""+d.prefix+e}):""+this.prefix+e,body:t,q:r,from:Number(i)>=0&&Number(o)>0?Number(i)*Number(o):0,size:Number(o)>0?Number(o):2147483519,sort:"createdAtUtc:"+(u?"asc":"desc")}).then(function(e){return{status:n.HttpStatusCode.OK,body:{data:e.hits.hits.map(function(e){return s({_index:e._index,_id:e._id},e._source)}),hasMore:Number(i)>=0&&Number(o)>0&&e.hits.total>(Number(i)+1)*Number(o),totalCount:e.hits.total}}}).catch(a)},e.prototype.insertMany=function(e){var t=this,i=e.headers?e.headers["content-type"]:void 0;return i&&i.indexOf("application/json")>=0&&e.body&&Object.keys(e.body).length?this.client.bulk({type:this.type,refresh:this.refresh,body:e.body.reduce(function(e,r){var i={_index:""+t.prefix+r._index};return delete r._index,e.push({index:s({},i)},s({},r,{createdAtUtc:(new Date).toISOString()})),e},[])}).then(function(e){return r.get(e,"errors")?a(e.items.map(function(e){return e.index.error})):{status:n.HttpStatusCode.Created,body:{}}}).catch(a):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Invalid}})},e.prototype.updateOne=function(e,t,r){var i=t.headers?t.headers["content-type"]:void 0;return i&&i.indexOf("application/json")>=0&&t.body&&Object.keys(t.body).length&&r?(delete t.body._index,this.client.update({index:""+this.prefix+e,type:this.type,refresh:this.refresh,id:r,body:{doc:t.body}}).then(function(){return{status:n.HttpStatusCode.OK,body:{}}}).catch(a)):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Invalid}})},e.prototype.deleteOne=function(e,t){return t?this.client.delete({index:""+this.prefix+e,type:this.type,refresh:this.refresh,id:t}).then(function(){return{status:n.HttpStatusCode.OK,body:{}}}).catch(a):Promise.resolve({status:n.HttpStatusCode.BadRequest,body:{type:n.ErrorType.Missing}})},e}();e.ELASTICSEARCH_REFRESH=o,e.ELASTICSEARCH_MAX_RESULTS=2147483519,e.getElasticClient=u,e.getStringDate=function(e){e||(e=new Date);var t=e.getUTCFullYear(),r=(e.getUTCMonth()+1).toString(),i=e.getUTCDate().toString();return r=(Number(r)<10?"0":"")+r,i=(Number(i)<10?"0":"")+i,t+"."+r+"."+i},e.Elasticizer=d,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=azure-functions-elasticizer.umd.min.js.map |
import * as elasticsearch from 'elasticsearch'; | ||
import { HttpRequest } from 'azure-functions-ts-essentials'; | ||
import { NameList } from 'elasticsearch'; | ||
export declare const ELASTICSEARCH_REFRESH = "wait_for"; | ||
@@ -19,3 +20,3 @@ export declare const ELASTICSEARCH_MAX_RESULTS = 2147483519; | ||
getOne(index: string, id: any): Promise<any>; | ||
search(index: string, body?: any, query?: any, page?: number, perPage?: number, sortAsc?: boolean): Promise<any>; | ||
search(index: NameList, body?: any, query?: any, page?: number, perPage?: number, sortAsc?: boolean): Promise<any>; | ||
insertMany(req: HttpRequest): Promise<any>; | ||
@@ -22,0 +23,0 @@ updateOne(index: string, req: HttpRequest, id: any): Promise<any>; |
{ | ||
"name": "azure-functions-elasticizer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Elasticsearch-based RESTful API implementation on Azure Functions with TypeScript", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
86702
634