@doclify/javascript
Advanced tools
Comparing version 2.0.6 to 2.0.7
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -203,4 +203,5 @@ * @license MIT | ||
this.q = []; | ||
this.withLazy = []; | ||
this.order = []; | ||
this.includeQuery = []; | ||
this.selectQuery = []; | ||
this.orderQuery = []; | ||
}; | ||
@@ -274,10 +275,21 @@ | ||
Documents.prototype.with = function with$1 (lazyField) { | ||
this.withLazy.push(lazyField); | ||
// deprecated | ||
Documents.prototype.with = function with$1 (field) { | ||
return this.include(field) | ||
}; | ||
Documents.prototype.include = function include (field) { | ||
this.includeQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.select = function select (field) { | ||
this.selectQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.orderBy = function orderBy (field, asc) { | ||
this.order.push([field, asc || 'asc']); | ||
this.orderQuery.push([field, asc || 'asc']); | ||
@@ -287,24 +299,33 @@ return this | ||
Documents.prototype.getParams = function getParams (params) { | ||
if ( params === void 0 ) params = {}; | ||
return Object.assign({ | ||
q: JSON.stringify(this.q), | ||
include: this.includeQuery.length ? JSON.stringify(this.includeQuery) : undefined, | ||
order: this.orderQuery.length ? JSON.stringify(this.orderQuery) : undefined, | ||
select: this.selectQuery.length ? JSON.stringify(this.selectQuery) : undefined, | ||
lang: this.lang | ||
}, params) | ||
}; | ||
Documents.prototype.fetch = function fetch (limit) { | ||
return this.client.cachedRequest('documents/search', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
limit: limit, | ||
lang: this.lang | ||
} | ||
params: this.getParams({ | ||
limit: limit | ||
}) | ||
}) | ||
}; | ||
// deprecated | ||
Documents.prototype.paginated = function paginated (page, perPage) { | ||
return this.paginate(page, perPage) | ||
}; | ||
Documents.prototype.paginate = function paginate (page, perPage) { | ||
return this.client.cachedRequest('documents/paginated', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
params: this.getParams({ | ||
perPage: perPage, | ||
page: page, | ||
lang: this.lang | ||
} | ||
}) | ||
}) | ||
@@ -315,8 +336,3 @@ }; | ||
return this.client.cachedRequest('documents/single', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
lang: this.lang | ||
} | ||
params: this.getParams() | ||
}) | ||
@@ -323,0 +339,0 @@ }; |
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -198,4 +198,5 @@ * @license MIT | ||
this.q = []; | ||
this.withLazy = []; | ||
this.order = []; | ||
this.includeQuery = []; | ||
this.selectQuery = []; | ||
this.orderQuery = []; | ||
} | ||
@@ -269,10 +270,21 @@ | ||
with (lazyField) { | ||
this.withLazy.push(lazyField); | ||
// deprecated | ||
with (field) { | ||
return this.include(field) | ||
} | ||
include(field) { | ||
this.includeQuery.push(field); | ||
return this | ||
} | ||
select (field) { | ||
this.selectQuery.push(field); | ||
return this | ||
} | ||
orderBy (field, asc) { | ||
this.order.push([field, asc || 'asc']); | ||
this.orderQuery.push([field, asc || 'asc']); | ||
@@ -282,24 +294,31 @@ return this | ||
getParams(params = {}) { | ||
return Object.assign({ | ||
q: JSON.stringify(this.q), | ||
include: this.includeQuery.length ? JSON.stringify(this.includeQuery) : undefined, | ||
order: this.orderQuery.length ? JSON.stringify(this.orderQuery) : undefined, | ||
select: this.selectQuery.length ? JSON.stringify(this.selectQuery) : undefined, | ||
lang: this.lang | ||
}, params) | ||
} | ||
fetch (limit) { | ||
return this.client.cachedRequest('documents/search', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
limit, | ||
lang: this.lang | ||
} | ||
params: this.getParams({ | ||
limit | ||
}) | ||
}) | ||
} | ||
// deprecated | ||
paginated (page, perPage) { | ||
return this.paginate(page, perPage) | ||
} | ||
paginate (page, perPage) { | ||
return this.client.cachedRequest('documents/paginated', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
params: this.getParams({ | ||
perPage, | ||
page, | ||
lang: this.lang | ||
} | ||
}) | ||
}) | ||
@@ -310,8 +329,3 @@ } | ||
return this.client.cachedRequest('documents/single', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
lang: this.lang | ||
} | ||
params: this.getParams() | ||
}) | ||
@@ -318,0 +332,0 @@ } |
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -7,6 +7,6 @@ * @license MIT | ||
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
* @license MIT | ||
*/ | ||
import e from"axios";class t{constructor(e){this.config=Object.assign({maxSize:1/0,maxLength:1/0,maxAge:0,getSize:()=>1},e||{}),this.entries=new Map,this.size=0,this.newest=this.oldest=void 0}reset(){this.entries.clear(),this.size=0,this.newest=this.oldest=void 0}get length(){return this.entries.size}has(e){return this.entries.has(e)}get(e){const t=this.entries.get(e);if(t){if(!(t.maxAge&&Date.now()-t.now>1e3*t.maxAge))return t.value;this.delete(t)}}set(e,t,i={}){const r=i.maxAge||this.config.maxAge;if(r&&"number"!=typeof r)throw new TypeError("maxAge must be a number");const n="number"==typeof i.size?i.size:this.config.getSize(t,e);if(n>this.config.maxSize)return this.has(e)&&this.delete(e),!1;let h=this.entries.get(e);return h?(this.size-=h.size,h.update(t,n,r),this.markEntryAsUsed(h)):(h=new s(e,t,n,r),this.entries.set(e,h),this.newest?(this.newest.newer=h,h.older=this.newest):this.oldest=h),this.size+=n,this.newest=h,this.cleanup(),!0}markEntryAsUsed(e){e!==this.newest&&(e.newer&&(e===this.oldest&&(this.oldest=e.newer),e.newer.older=e.older),e.older&&(e.older.newer=e.newer),e.newer=void 0,e.older=this.newest,this.newest&&(this.newest.newer=e),this.newest=e)}delete(e){const t=e instanceof s?e:this.entries.get(e);return!!t&&(this.size-=t.size,t.size=0,t.newer=t.older=void 0,this.entries.delete(t.key))}cleanup(){for(;(this.length>this.config.maxLength||this.size>this.config.maxSize)&&this.shift(););}shift(){const e=this.oldest;return!!e&&(this.oldest.newer?(this.oldest=this.oldest.newer,this.oldest.older=void 0):(this.oldest=void 0,this.newest=void 0),this.delete(e),!0)}}class s{constructor(e,t,s,i){this.key=e,this.newer=this.older=null,this.update(t,s,i)}update(e,t,s){this.value=e,this.size=t,this.maxAge=s,this.now=s?Date.now():null}}class i{constructor(e){this.client=e,this.lang=void 0,this.perPage=void 0,this.page=void 0,this.q=[],this.withLazy=[],this.order=[]}where(e,t,s){return void 0===s&&(s=t,t="eq"),this.q.push([e,t,s]),this}collection(e){return this.eq("sys.collection",e)}contentType(e){return this.eq("sys.contentType",e)}id(e){return this.eq("sys.id",e)}uid(e){return this.eq("sys.uid",e)}eq(e,t){return this.where(e,t)}not(e,t){return this.where(e,"not",t)}in(e,t){return this.where(e,"in",t)}nin(e,t){return this.where(e,"nin",t)}gt(e,t){return this.where(e,"gt",t)}gte(e,t){return this.where(e,"gte",t)}lt(e,t){return this.where(e,"lt",t)}lte(e,t){return this.where(e,"lte",t)}fulltext(e,t){return this.where(e,"fulltext",t)}match(e,t){return this.where(e,"match",t)}with(e){return this.withLazy.push(e),this}orderBy(e,t){return this.order.push([e,t||"asc"]),this}fetch(e){return this.client.cachedRequest("documents/search",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,limit:e,lang:this.lang}})}paginated(e,t){return this.client.cachedRequest("documents/paginated",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,perPage:t,page:e,lang:this.lang}})}first(){return this.client.cachedRequest("documents/single",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,lang:this.lang}})}}class r extends Error{constructor(e,t){super(e),Object.setPrototypeOf(this,new.target.prototype),this.info=t}get url(){return this.info.url}get method(){return this.info.method.toUpperCase()}get code(){return`${this.info.code||-1}`}get params(){return this.info.params||{}}get error(){return this.info.error||null}get data(){return this.info.data||{}}toString(){return["Doclify call failed:",`${this.method} ${this.url} ${JSON.stringify(this.params)} -`,this.message,`(code ${this.code})`].join(" ")}static fromError(e){const t={code:e.response?e.response.status:null,url:e.request.url,method:e.request.method,data:e.response?e.response.data:null};return new r(e.message,t)}}function n(e){return JSON.parse(JSON.stringify(e))}export default class{constructor(s){if(!s.repository&&!s.url)throw new TypeError("Repository or URL option is required");if(!s.key)throw new TypeError("API key is required");this.config=Object.assign({repository:null,key:null,cache:!1,timeout:1e4},s),this.http=e.create({baseURL:this.baseUrl,timeout:this.config.timeout,headers:{"x-api-key":this.config.key}}),this.http.interceptors.response.use(e=>e,(function(e){return Promise.reject(e)}));const i="object"==typeof this.config.cache&&this.config.cache?this.config.cache:{};this.cache=new t({maxAge:"number"==typeof i.maxAge?i.maxAge:30,maxSize:i.maxSize||3145728,maxLength:i.maxLength||1e3})}get baseUrl(){return this.config.url||`https://${this.config.repository}.cdn.doclify.io/api/v2`}request(e,t={},s=!1){return this.http.request(e,t).then(e=>s?e:e.data).catch(s=>{const i=s.response&&s.response.data?s.response.data:{},n={url:this.baseUrl+"/"+e,code:s.response?s.response.status:-1,params:t.params||{},method:t.method||"GET",error:i.error||null,data:i},h=i.error?i.error.message:s.message;return Promise.reject(new r(h,n))})}cachedRequest(e,t={}){if(!this.config.cache)return this.request(e,t);const s=`${e}:${JSON.stringify(t.params)}`,i=this.cache.get(s);if(i instanceof Promise)return i.then(e=>n(e.data));if(i instanceof Error)return Promise.reject(i);if(void 0!==i)return Promise.resolve(n(i));t.headers=t.headers||{},t.headers["x-cache"]="1";const r=this.request(e,t,!0);return this.cache.set(s,r,{size:1}),r.then(e=>{const t=Number(e.headers["content-length"])||0;return this.cache.set(s,e.data,{size:t}),n(e.data)}).catch(e=>{throw this.cache.set(s,e),e})}documents(){return new i(this)}} | ||
import e from"axios";class t{constructor(e){this.config=Object.assign({maxSize:1/0,maxLength:1/0,maxAge:0,getSize:()=>1},e||{}),this.entries=new Map,this.size=0,this.newest=this.oldest=void 0}reset(){this.entries.clear(),this.size=0,this.newest=this.oldest=void 0}get length(){return this.entries.size}has(e){return this.entries.has(e)}get(e){const t=this.entries.get(e);if(t){if(!(t.maxAge&&Date.now()-t.now>1e3*t.maxAge))return t.value;this.delete(t)}}set(e,t,r={}){const i=r.maxAge||this.config.maxAge;if(i&&"number"!=typeof i)throw new TypeError("maxAge must be a number");const n="number"==typeof r.size?r.size:this.config.getSize(t,e);if(n>this.config.maxSize)return this.has(e)&&this.delete(e),!1;let h=this.entries.get(e);return h?(this.size-=h.size,h.update(t,n,i),this.markEntryAsUsed(h)):(h=new s(e,t,n,i),this.entries.set(e,h),this.newest?(this.newest.newer=h,h.older=this.newest):this.oldest=h),this.size+=n,this.newest=h,this.cleanup(),!0}markEntryAsUsed(e){e!==this.newest&&(e.newer&&(e===this.oldest&&(this.oldest=e.newer),e.newer.older=e.older),e.older&&(e.older.newer=e.newer),e.newer=void 0,e.older=this.newest,this.newest&&(this.newest.newer=e),this.newest=e)}delete(e){const t=e instanceof s?e:this.entries.get(e);return!!t&&(this.size-=t.size,t.size=0,t.newer=t.older=void 0,this.entries.delete(t.key))}cleanup(){for(;(this.length>this.config.maxLength||this.size>this.config.maxSize)&&this.shift(););}shift(){const e=this.oldest;return!!e&&(this.oldest.newer?(this.oldest=this.oldest.newer,this.oldest.older=void 0):(this.oldest=void 0,this.newest=void 0),this.delete(e),!0)}}class s{constructor(e,t,s,r){this.key=e,this.newer=this.older=null,this.update(t,s,r)}update(e,t,s){this.value=e,this.size=t,this.maxAge=s,this.now=s?Date.now():null}}class r{constructor(e){this.client=e,this.lang=void 0,this.perPage=void 0,this.page=void 0,this.q=[],this.includeQuery=[],this.selectQuery=[],this.orderQuery=[]}where(e,t,s){return void 0===s&&(s=t,t="eq"),this.q.push([e,t,s]),this}collection(e){return this.eq("sys.collection",e)}contentType(e){return this.eq("sys.contentType",e)}id(e){return this.eq("sys.id",e)}uid(e){return this.eq("sys.uid",e)}eq(e,t){return this.where(e,t)}not(e,t){return this.where(e,"not",t)}in(e,t){return this.where(e,"in",t)}nin(e,t){return this.where(e,"nin",t)}gt(e,t){return this.where(e,"gt",t)}gte(e,t){return this.where(e,"gte",t)}lt(e,t){return this.where(e,"lt",t)}lte(e,t){return this.where(e,"lte",t)}fulltext(e,t){return this.where(e,"fulltext",t)}match(e,t){return this.where(e,"match",t)}with(e){return this.include(e)}include(e){return this.includeQuery.push(e),this}select(e){return this.selectQuery.push(e),this}orderBy(e,t){return this.orderQuery.push([e,t||"asc"]),this}getParams(e={}){return Object.assign({q:JSON.stringify(this.q),include:this.includeQuery.length?JSON.stringify(this.includeQuery):void 0,order:this.orderQuery.length?JSON.stringify(this.orderQuery):void 0,select:this.selectQuery.length?JSON.stringify(this.selectQuery):void 0,lang:this.lang},e)}fetch(e){return this.client.cachedRequest("documents/search",{params:this.getParams({limit:e})})}paginated(e,t){return this.paginate(e,t)}paginate(e,t){return this.client.cachedRequest("documents/paginated",{params:this.getParams({perPage:t,page:e})})}first(){return this.client.cachedRequest("documents/single",{params:this.getParams()})}}class i extends Error{constructor(e,t){super(e),Object.setPrototypeOf(this,new.target.prototype),this.info=t}get url(){return this.info.url}get method(){return this.info.method.toUpperCase()}get code(){return`${this.info.code||-1}`}get params(){return this.info.params||{}}get error(){return this.info.error||null}get data(){return this.info.data||{}}toString(){return["Doclify call failed:",`${this.method} ${this.url} ${JSON.stringify(this.params)} -`,this.message,`(code ${this.code})`].join(" ")}static fromError(e){const t={code:e.response?e.response.status:null,url:e.request.url,method:e.request.method,data:e.response?e.response.data:null};return new i(e.message,t)}}function n(e){return JSON.parse(JSON.stringify(e))}export default class{constructor(s){if(!s.repository&&!s.url)throw new TypeError("Repository or URL option is required");if(!s.key)throw new TypeError("API key is required");this.config=Object.assign({repository:null,key:null,cache:!1,timeout:1e4},s),this.http=e.create({baseURL:this.baseUrl,timeout:this.config.timeout,headers:{"x-api-key":this.config.key}}),this.http.interceptors.response.use(e=>e,(function(e){return Promise.reject(e)}));const r="object"==typeof this.config.cache&&this.config.cache?this.config.cache:{};this.cache=new t({maxAge:"number"==typeof r.maxAge?r.maxAge:30,maxSize:r.maxSize||3145728,maxLength:r.maxLength||1e3})}get baseUrl(){return this.config.url||`https://${this.config.repository}.cdn.doclify.io/api/v2`}request(e,t={},s=!1){return this.http.request(e,t).then(e=>s?e:e.data).catch(s=>{const r=s.response&&s.response.data?s.response.data:{},n={url:this.baseUrl+"/"+e,code:s.response?s.response.status:-1,params:t.params||{},method:t.method||"GET",error:r.error||null,data:r},h=r.error?r.error.message:s.message;return Promise.reject(new i(h,n))})}cachedRequest(e,t={}){if(!this.config.cache)return this.request(e,t);const s=`${e}:${JSON.stringify(t.params)}`,r=this.cache.get(s);if(r instanceof Promise)return r.then(e=>n(e.data));if(r instanceof Error)return Promise.reject(r);if(void 0!==r)return Promise.resolve(n(r));t.headers=t.headers||{},t.headers["x-cache"]="1";const i=this.request(e,t,!0);return this.cache.set(s,i,{size:1}),i.then(e=>{const t=Number(e.headers["content-length"])||0;return this.cache.set(s,e.data,{size:t}),n(e.data)}).catch(e=>{throw this.cache.set(s,e),e})}documents(){return new r(this)}} |
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -199,4 +199,5 @@ * @license MIT | ||
this.q = []; | ||
this.withLazy = []; | ||
this.order = []; | ||
this.includeQuery = []; | ||
this.selectQuery = []; | ||
this.orderQuery = []; | ||
}; | ||
@@ -270,10 +271,21 @@ | ||
Documents.prototype.with = function with$1 (lazyField) { | ||
this.withLazy.push(lazyField); | ||
// deprecated | ||
Documents.prototype.with = function with$1 (field) { | ||
return this.include(field) | ||
}; | ||
Documents.prototype.include = function include (field) { | ||
this.includeQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.select = function select (field) { | ||
this.selectQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.orderBy = function orderBy (field, asc) { | ||
this.order.push([field, asc || 'asc']); | ||
this.orderQuery.push([field, asc || 'asc']); | ||
@@ -283,24 +295,33 @@ return this | ||
Documents.prototype.getParams = function getParams (params) { | ||
if ( params === void 0 ) params = {}; | ||
return Object.assign({ | ||
q: JSON.stringify(this.q), | ||
include: this.includeQuery.length ? JSON.stringify(this.includeQuery) : undefined, | ||
order: this.orderQuery.length ? JSON.stringify(this.orderQuery) : undefined, | ||
select: this.selectQuery.length ? JSON.stringify(this.selectQuery) : undefined, | ||
lang: this.lang | ||
}, params) | ||
}; | ||
Documents.prototype.fetch = function fetch (limit) { | ||
return this.client.cachedRequest('documents/search', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
limit: limit, | ||
lang: this.lang | ||
} | ||
params: this.getParams({ | ||
limit: limit | ||
}) | ||
}) | ||
}; | ||
// deprecated | ||
Documents.prototype.paginated = function paginated (page, perPage) { | ||
return this.paginate(page, perPage) | ||
}; | ||
Documents.prototype.paginate = function paginate (page, perPage) { | ||
return this.client.cachedRequest('documents/paginated', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
params: this.getParams({ | ||
perPage: perPage, | ||
page: page, | ||
lang: this.lang | ||
} | ||
}) | ||
}) | ||
@@ -311,8 +332,3 @@ }; | ||
return this.client.cachedRequest('documents/single', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
lang: this.lang | ||
} | ||
params: this.getParams() | ||
}) | ||
@@ -319,0 +335,0 @@ }; |
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -205,4 +205,5 @@ * @license MIT | ||
this.q = []; | ||
this.withLazy = []; | ||
this.order = []; | ||
this.includeQuery = []; | ||
this.selectQuery = []; | ||
this.orderQuery = []; | ||
}; | ||
@@ -276,10 +277,21 @@ | ||
Documents.prototype.with = function with$1 (lazyField) { | ||
this.withLazy.push(lazyField); | ||
// deprecated | ||
Documents.prototype.with = function with$1 (field) { | ||
return this.include(field) | ||
}; | ||
Documents.prototype.include = function include (field) { | ||
this.includeQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.select = function select (field) { | ||
this.selectQuery.push(field); | ||
return this | ||
}; | ||
Documents.prototype.orderBy = function orderBy (field, asc) { | ||
this.order.push([field, asc || 'asc']); | ||
this.orderQuery.push([field, asc || 'asc']); | ||
@@ -289,24 +301,33 @@ return this | ||
Documents.prototype.getParams = function getParams (params) { | ||
if ( params === void 0 ) params = {}; | ||
return Object.assign({ | ||
q: JSON.stringify(this.q), | ||
include: this.includeQuery.length ? JSON.stringify(this.includeQuery) : undefined, | ||
order: this.orderQuery.length ? JSON.stringify(this.orderQuery) : undefined, | ||
select: this.selectQuery.length ? JSON.stringify(this.selectQuery) : undefined, | ||
lang: this.lang | ||
}, params) | ||
}; | ||
Documents.prototype.fetch = function fetch (limit) { | ||
return this.client.cachedRequest('documents/search', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
limit: limit, | ||
lang: this.lang | ||
} | ||
params: this.getParams({ | ||
limit: limit | ||
}) | ||
}) | ||
}; | ||
// deprecated | ||
Documents.prototype.paginated = function paginated (page, perPage) { | ||
return this.paginate(page, perPage) | ||
}; | ||
Documents.prototype.paginate = function paginate (page, perPage) { | ||
return this.client.cachedRequest('documents/paginated', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
params: this.getParams({ | ||
perPage: perPage, | ||
page: page, | ||
lang: this.lang | ||
} | ||
}) | ||
}) | ||
@@ -317,8 +338,3 @@ }; | ||
return this.client.cachedRequest('documents/single', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
lang: this.lang | ||
} | ||
params: this.getParams() | ||
}) | ||
@@ -325,0 +341,0 @@ }; |
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
@@ -7,6 +7,6 @@ * @license MIT | ||
/*! | ||
* @doclify/javascript v2.0.6 | ||
* @doclify/javascript v2.0.7 | ||
* (c) 2020 Doclify | ||
* @license MIT | ||
*/ | ||
var t,e;t=this,e=function(t){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var e=function(t){this.config=Object.assign({maxSize:1/0,maxLength:1/0,maxAge:0,getSize:function(){return 1}},t||{}),this.entries=new Map,this.size=0,this.newest=this.oldest=void 0},r={length:{configurable:!0}};e.prototype.reset=function(){this.entries.clear(),this.size=0,this.newest=this.oldest=void 0},r.length.get=function(){return this.entries.size},e.prototype.has=function(t){return this.entries.has(t)},e.prototype.get=function(t){var e=this.entries.get(t);if(e){if(!(e.maxAge&&Date.now()-e.now>1e3*e.maxAge))return e.value;this.delete(e)}},e.prototype.set=function(t,e,r){void 0===r&&(r={});var n=r.maxAge||this.config.maxAge;if(n&&"number"!=typeof n)throw new TypeError("maxAge must be a number");var o="number"==typeof r.size?r.size:this.config.getSize(e,t);if(o>this.config.maxSize)return this.has(t)&&this.delete(t),!1;var s=this.entries.get(t);return s?(this.size-=s.size,s.update(e,o,n),this.markEntryAsUsed(s)):(s=new i(t,e,o,n),this.entries.set(t,s),this.newest?(this.newest.newer=s,s.older=this.newest):this.oldest=s),this.size+=o,this.newest=s,this.cleanup(),!0},e.prototype.markEntryAsUsed=function(t){t!==this.newest&&(t.newer&&(t===this.oldest&&(this.oldest=t.newer),t.newer.older=t.older),t.older&&(t.older.newer=t.newer),t.newer=void 0,t.older=this.newest,this.newest&&(this.newest.newer=t),this.newest=t)},e.prototype.delete=function(t){var e=t instanceof i?t:this.entries.get(t);return!!e&&(this.size-=e.size,e.size=0,e.newer=e.older=void 0,this.entries.delete(e.key))},e.prototype.cleanup=function(){for(;(this.length>this.config.maxLength||this.size>this.config.maxSize)&&this.shift(););},e.prototype.shift=function(){var t=this.oldest;return!!t&&(this.oldest.newer?(this.oldest=this.oldest.newer,this.oldest.older=void 0):(this.oldest=void 0,this.newest=void 0),this.delete(t),!0)},Object.defineProperties(e.prototype,r);var i=function(t,e,r,i){this.key=t,this.newer=this.older=null,this.update(e,r,i)};i.prototype.update=function(t,e,r){this.value=t,this.size=e,this.maxAge=r,this.now=r?Date.now():null};var n=function(t){this.client=t,this.lang=void 0,this.perPage=void 0,this.page=void 0,this.q=[],this.withLazy=[],this.order=[]};n.prototype.where=function(t,e,r){return void 0===r&&(r=e,e="eq"),this.q.push([t,e,r]),this},n.prototype.collection=function(t){return this.eq("sys.collection",t)},n.prototype.contentType=function(t){return this.eq("sys.contentType",t)},n.prototype.id=function(t){return this.eq("sys.id",t)},n.prototype.uid=function(t){return this.eq("sys.uid",t)},n.prototype.eq=function(t,e){return this.where(t,e)},n.prototype.not=function(t,e){return this.where(t,"not",e)},n.prototype.in=function(t,e){return this.where(t,"in",e)},n.prototype.nin=function(t,e){return this.where(t,"nin",e)},n.prototype.gt=function(t,e){return this.where(t,"gt",e)},n.prototype.gte=function(t,e){return this.where(t,"gte",e)},n.prototype.lt=function(t,e){return this.where(t,"lt",e)},n.prototype.lte=function(t,e){return this.where(t,"lte",e)},n.prototype.fulltext=function(t,e){return this.where(t,"fulltext",e)},n.prototype.match=function(t,e){return this.where(t,"match",e)},n.prototype.with=function(t){return this.withLazy.push(t),this},n.prototype.orderBy=function(t,e){return this.order.push([t,e||"asc"]),this},n.prototype.fetch=function(t){return this.client.cachedRequest("documents/search",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,limit:t,lang:this.lang}})},n.prototype.paginated=function(t,e){return this.client.cachedRequest("documents/paginated",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,perPage:e,page:t,lang:this.lang}})},n.prototype.first=function(){return this.client.cachedRequest("documents/single",{params:{q:JSON.stringify(this.q),with:this.withLazy.length?JSON.stringify(this.withLazy):void 0,order:this.order.length?JSON.stringify(this.order):void 0,lang:this.lang}})};var o=function(t){function e(e,r){t.call(this,e),Object.setPrototypeOf(this,new.target.prototype),this.info=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={url:{configurable:!0},method:{configurable:!0},code:{configurable:!0},params:{configurable:!0},error:{configurable:!0},data:{configurable:!0}};return r.url.get=function(){return this.info.url},r.method.get=function(){return this.info.method.toUpperCase()},r.code.get=function(){return""+(this.info.code||-1)},r.params.get=function(){return this.info.params||{}},r.error.get=function(){return this.info.error||null},r.data.get=function(){return this.info.data||{}},e.prototype.toString=function(){return["Doclify call failed:",this.method+" "+this.url+" "+JSON.stringify(this.params)+" -",this.message,"(code "+this.code+")"].join(" ")},e.fromError=function(t){var r={code:t.response?t.response.status:null,url:t.request.url,method:t.request.method,data:t.response?t.response.data:null};return new e(t.message,r)},Object.defineProperties(e.prototype,r),e}(Error);function s(t){return JSON.parse(JSON.stringify(t))}var h=function(r){if(!r.repository&&!r.url)throw new TypeError("Repository or URL option is required");if(!r.key)throw new TypeError("API key is required");this.config=Object.assign({repository:null,key:null,cache:!1,timeout:1e4},r),this.http=t.create({baseURL:this.baseUrl,timeout:this.config.timeout,headers:{"x-api-key":this.config.key}}),this.http.interceptors.response.use((function(t){return t}),(function(t){return Promise.reject(t)}));var i="object"==typeof this.config.cache&&this.config.cache?this.config.cache:{};this.cache=new e({maxAge:"number"==typeof i.maxAge?i.maxAge:30,maxSize:i.maxSize||3145728,maxLength:i.maxLength||1e3})},a={baseUrl:{configurable:!0}};return a.baseUrl.get=function(){return this.config.url||"https://"+this.config.repository+".cdn.doclify.io/api/v2"},h.prototype.request=function(t,e,r){var i=this;return void 0===e&&(e={}),void 0===r&&(r=!1),this.http.request(t,e).then((function(t){return r?t:t.data})).catch((function(r){var n=r.response&&r.response.data?r.response.data:{},s={url:i.baseUrl+"/"+t,code:r.response?r.response.status:-1,params:e.params||{},method:e.method||"GET",error:n.error||null,data:n},h=n.error?n.error.message:r.message;return Promise.reject(new o(h,s))}))},h.prototype.cachedRequest=function(t,e){var r=this;if(void 0===e&&(e={}),!this.config.cache)return this.request(t,e);var i=t+":"+JSON.stringify(e.params),n=this.cache.get(i);if(n instanceof Promise)return n.then((function(t){return s(t.data)}));if(n instanceof Error)return Promise.reject(n);if(void 0!==n)return Promise.resolve(s(n));e.headers=e.headers||{},e.headers["x-cache"]="1";var o=this.request(t,e,!0);return this.cache.set(i,o,{size:1}),o.then((function(t){var e=Number(t.headers["content-length"])||0;return r.cache.set(i,t.data,{size:e}),s(t.data)})).catch((function(t){throw r.cache.set(i,t),t}))},h.prototype.documents=function(){return new n(this)},Object.defineProperties(h.prototype,a),h},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):(t=t||self).DoclifyJS=e(t.axios); | ||
var e,t;e=this,t=function(e){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var t=function(e){this.config=Object.assign({maxSize:1/0,maxLength:1/0,maxAge:0,getSize:function(){return 1}},e||{}),this.entries=new Map,this.size=0,this.newest=this.oldest=void 0},r={length:{configurable:!0}};t.prototype.reset=function(){this.entries.clear(),this.size=0,this.newest=this.oldest=void 0},r.length.get=function(){return this.entries.size},t.prototype.has=function(e){return this.entries.has(e)},t.prototype.get=function(e){var t=this.entries.get(e);if(t){if(!(t.maxAge&&Date.now()-t.now>1e3*t.maxAge))return t.value;this.delete(t)}},t.prototype.set=function(e,t,r){void 0===r&&(r={});var n=r.maxAge||this.config.maxAge;if(n&&"number"!=typeof n)throw new TypeError("maxAge must be a number");var o="number"==typeof r.size?r.size:this.config.getSize(t,e);if(o>this.config.maxSize)return this.has(e)&&this.delete(e),!1;var s=this.entries.get(e);return s?(this.size-=s.size,s.update(t,o,n),this.markEntryAsUsed(s)):(s=new i(e,t,o,n),this.entries.set(e,s),this.newest?(this.newest.newer=s,s.older=this.newest):this.oldest=s),this.size+=o,this.newest=s,this.cleanup(),!0},t.prototype.markEntryAsUsed=function(e){e!==this.newest&&(e.newer&&(e===this.oldest&&(this.oldest=e.newer),e.newer.older=e.older),e.older&&(e.older.newer=e.newer),e.newer=void 0,e.older=this.newest,this.newest&&(this.newest.newer=e),this.newest=e)},t.prototype.delete=function(e){var t=e instanceof i?e:this.entries.get(e);return!!t&&(this.size-=t.size,t.size=0,t.newer=t.older=void 0,this.entries.delete(t.key))},t.prototype.cleanup=function(){for(;(this.length>this.config.maxLength||this.size>this.config.maxSize)&&this.shift(););},t.prototype.shift=function(){var e=this.oldest;return!!e&&(this.oldest.newer?(this.oldest=this.oldest.newer,this.oldest.older=void 0):(this.oldest=void 0,this.newest=void 0),this.delete(e),!0)},Object.defineProperties(t.prototype,r);var i=function(e,t,r,i){this.key=e,this.newer=this.older=null,this.update(t,r,i)};i.prototype.update=function(e,t,r){this.value=e,this.size=t,this.maxAge=r,this.now=r?Date.now():null};var n=function(e){this.client=e,this.lang=void 0,this.perPage=void 0,this.page=void 0,this.q=[],this.includeQuery=[],this.selectQuery=[],this.orderQuery=[]};n.prototype.where=function(e,t,r){return void 0===r&&(r=t,t="eq"),this.q.push([e,t,r]),this},n.prototype.collection=function(e){return this.eq("sys.collection",e)},n.prototype.contentType=function(e){return this.eq("sys.contentType",e)},n.prototype.id=function(e){return this.eq("sys.id",e)},n.prototype.uid=function(e){return this.eq("sys.uid",e)},n.prototype.eq=function(e,t){return this.where(e,t)},n.prototype.not=function(e,t){return this.where(e,"not",t)},n.prototype.in=function(e,t){return this.where(e,"in",t)},n.prototype.nin=function(e,t){return this.where(e,"nin",t)},n.prototype.gt=function(e,t){return this.where(e,"gt",t)},n.prototype.gte=function(e,t){return this.where(e,"gte",t)},n.prototype.lt=function(e,t){return this.where(e,"lt",t)},n.prototype.lte=function(e,t){return this.where(e,"lte",t)},n.prototype.fulltext=function(e,t){return this.where(e,"fulltext",t)},n.prototype.match=function(e,t){return this.where(e,"match",t)},n.prototype.with=function(e){return this.include(e)},n.prototype.include=function(e){return this.includeQuery.push(e),this},n.prototype.select=function(e){return this.selectQuery.push(e),this},n.prototype.orderBy=function(e,t){return this.orderQuery.push([e,t||"asc"]),this},n.prototype.getParams=function(e){return void 0===e&&(e={}),Object.assign({q:JSON.stringify(this.q),include:this.includeQuery.length?JSON.stringify(this.includeQuery):void 0,order:this.orderQuery.length?JSON.stringify(this.orderQuery):void 0,select:this.selectQuery.length?JSON.stringify(this.selectQuery):void 0,lang:this.lang},e)},n.prototype.fetch=function(e){return this.client.cachedRequest("documents/search",{params:this.getParams({limit:e})})},n.prototype.paginated=function(e,t){return this.paginate(e,t)},n.prototype.paginate=function(e,t){return this.client.cachedRequest("documents/paginated",{params:this.getParams({perPage:t,page:e})})},n.prototype.first=function(){return this.client.cachedRequest("documents/single",{params:this.getParams()})};var o=function(e){function t(t,r){e.call(this,t),Object.setPrototypeOf(this,new.target.prototype),this.info=r}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var r={url:{configurable:!0},method:{configurable:!0},code:{configurable:!0},params:{configurable:!0},error:{configurable:!0},data:{configurable:!0}};return r.url.get=function(){return this.info.url},r.method.get=function(){return this.info.method.toUpperCase()},r.code.get=function(){return""+(this.info.code||-1)},r.params.get=function(){return this.info.params||{}},r.error.get=function(){return this.info.error||null},r.data.get=function(){return this.info.data||{}},t.prototype.toString=function(){return["Doclify call failed:",this.method+" "+this.url+" "+JSON.stringify(this.params)+" -",this.message,"(code "+this.code+")"].join(" ")},t.fromError=function(e){var r={code:e.response?e.response.status:null,url:e.request.url,method:e.request.method,data:e.response?e.response.data:null};return new t(e.message,r)},Object.defineProperties(t.prototype,r),t}(Error);function s(e){return JSON.parse(JSON.stringify(e))}var h=function(r){if(!r.repository&&!r.url)throw new TypeError("Repository or URL option is required");if(!r.key)throw new TypeError("API key is required");this.config=Object.assign({repository:null,key:null,cache:!1,timeout:1e4},r),this.http=e.create({baseURL:this.baseUrl,timeout:this.config.timeout,headers:{"x-api-key":this.config.key}}),this.http.interceptors.response.use((function(e){return e}),(function(e){return Promise.reject(e)}));var i="object"==typeof this.config.cache&&this.config.cache?this.config.cache:{};this.cache=new t({maxAge:"number"==typeof i.maxAge?i.maxAge:30,maxSize:i.maxSize||3145728,maxLength:i.maxLength||1e3})},u={baseUrl:{configurable:!0}};return u.baseUrl.get=function(){return this.config.url||"https://"+this.config.repository+".cdn.doclify.io/api/v2"},h.prototype.request=function(e,t,r){var i=this;return void 0===t&&(t={}),void 0===r&&(r=!1),this.http.request(e,t).then((function(e){return r?e:e.data})).catch((function(r){var n=r.response&&r.response.data?r.response.data:{},s={url:i.baseUrl+"/"+e,code:r.response?r.response.status:-1,params:t.params||{},method:t.method||"GET",error:n.error||null,data:n},h=n.error?n.error.message:r.message;return Promise.reject(new o(h,s))}))},h.prototype.cachedRequest=function(e,t){var r=this;if(void 0===t&&(t={}),!this.config.cache)return this.request(e,t);var i=e+":"+JSON.stringify(t.params),n=this.cache.get(i);if(n instanceof Promise)return n.then((function(e){return s(e.data)}));if(n instanceof Error)return Promise.reject(n);if(void 0!==n)return Promise.resolve(s(n));t.headers=t.headers||{},t.headers["x-cache"]="1";var o=this.request(e,t,!0);return this.cache.set(i,o,{size:1}),o.then((function(e){var t=Number(e.headers["content-length"])||0;return r.cache.set(i,e.data,{size:t}),s(e.data)})).catch((function(e){throw r.cache.set(i,e),e}))},h.prototype.documents=function(){return new n(this)},Object.defineProperties(h.prototype,u),h},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):(e=e||self).DoclifyJS=t(e.axios); |
{ | ||
"name": "@doclify/javascript", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Official JavaScript SDK for Doclify", | ||
@@ -5,0 +5,0 @@ "main": "dist/doclify-javascript.common.js", |
@@ -9,4 +9,5 @@ export default class Documents { | ||
this.q = [] | ||
this.withLazy = [] | ||
this.order = [] | ||
this.includeQuery = [] | ||
this.selectQuery = [] | ||
this.orderQuery = [] | ||
} | ||
@@ -80,10 +81,21 @@ | ||
with (lazyField) { | ||
this.withLazy.push(lazyField) | ||
// deprecated | ||
with (field) { | ||
return this.include(field) | ||
} | ||
include(field) { | ||
this.includeQuery.push(field) | ||
return this | ||
} | ||
select (field) { | ||
this.selectQuery.push(field) | ||
return this | ||
} | ||
orderBy (field, asc) { | ||
this.order.push([field, asc || 'asc']) | ||
this.orderQuery.push([field, asc || 'asc']) | ||
@@ -93,24 +105,31 @@ return this | ||
getParams(params = {}) { | ||
return Object.assign({ | ||
q: JSON.stringify(this.q), | ||
include: this.includeQuery.length ? JSON.stringify(this.includeQuery) : undefined, | ||
order: this.orderQuery.length ? JSON.stringify(this.orderQuery) : undefined, | ||
select: this.selectQuery.length ? JSON.stringify(this.selectQuery) : undefined, | ||
lang: this.lang | ||
}, params) | ||
} | ||
fetch (limit) { | ||
return this.client.cachedRequest('documents/search', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
limit, | ||
lang: this.lang | ||
} | ||
params: this.getParams({ | ||
limit | ||
}) | ||
}) | ||
} | ||
// deprecated | ||
paginated (page, perPage) { | ||
return this.paginate(page, perPage) | ||
} | ||
paginate (page, perPage) { | ||
return this.client.cachedRequest('documents/paginated', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
params: this.getParams({ | ||
perPage, | ||
page, | ||
lang: this.lang | ||
} | ||
}) | ||
}) | ||
@@ -121,10 +140,5 @@ } | ||
return this.client.cachedRequest('documents/single', { | ||
params: { | ||
q: JSON.stringify(this.q), | ||
with: this.withLazy.length ? JSON.stringify(this.withLazy) : undefined, | ||
order: this.order.length ? JSON.stringify(this.order) : undefined, | ||
lang: this.lang | ||
} | ||
params: this.getParams() | ||
}) | ||
} | ||
} |
77507
2034