@kitql/client
Advanced tools
Comparing version 0.2.5 to 0.3.0
18
index.js
@@ -304,13 +304,13 @@ 'use strict'; | ||
constructor(options) { | ||
var _a, _b, _c; | ||
const { url, defaultCache, credentials, headers, defaultPolicy } = options !== null && options !== void 0 ? options : {}; | ||
this.defaultPolicy = defaultPolicy !== null && defaultPolicy !== void 0 ? defaultPolicy : 'cache-first'; | ||
var _a, _b; | ||
const { url, cacheMs, credentials, headers, policy, headersContentType } = options !== null && options !== void 0 ? options : {}; | ||
this.url = url; | ||
this.policy = policy !== null && policy !== void 0 ? policy : 'cache-first'; | ||
this.headers = headers !== null && headers !== void 0 ? headers : {}; | ||
this.defaultCache = defaultCache !== null && defaultCache !== void 0 ? defaultCache : 1000 * 60 * 3; | ||
this.cacheMs = cacheMs !== null && cacheMs !== void 0 ? cacheMs : 1000 * 60 * 3; | ||
this.credentials = credentials; | ||
this.headersContentType = (_a = options.headersContentType) !== null && _a !== void 0 ? _a : 'application/graphql+json'; | ||
this.logType = (_b = options.logType) !== null && _b !== void 0 ? _b : []; | ||
this.headersContentType = headersContentType !== null && headersContentType !== void 0 ? headersContentType : 'application/graphql+json'; | ||
this.logType = (_a = options.logType) !== null && _a !== void 0 ? _a : []; | ||
this.cacheData = (_b = options.cacheImplementation) !== null && _b !== void 0 ? _b : new InMemoryCache(); | ||
this.log = new helper.Log('KitQL Client'); | ||
this.cacheData = (_c = options.cacheImplementation) !== null && _c !== void 0 ? _c : new InMemoryCache(); | ||
} | ||
@@ -333,3 +333,3 @@ logOperation(from, operation, variables = null) { | ||
} | ||
requestCache({ variables, cacheKey, cache, browser }) { | ||
requestCache({ variables, cacheKey, cacheMs, browser }) { | ||
const logStatements = this.getLogsStatements(browser); | ||
@@ -342,3 +342,3 @@ // No caching in the server for now! (Need to have a session identification to not mix things up) | ||
// cache time of the query or of the default config | ||
if (xMs < (cache !== null && cache !== void 0 ? cache : this.defaultCache)) { | ||
if (xMs < (cacheMs !== null && cacheMs !== void 0 ? cacheMs : this.cacheMs)) { | ||
if (logStatements.logOpVar) { | ||
@@ -345,0 +345,0 @@ this.logOperation(exports.RequestFrom.CACHE, cacheKey, helper.stry(variables, 0)); |
@@ -5,2 +5,2 @@ export { InMemoryCache, LocalStorageCache } from './cache'; | ||
export { defaultStoreValue, KitQLClient, RequestFrom, RequestStatus } from './kitQLClient'; | ||
export type { RequestParameters, RequestResult } from './kitQLClient'; | ||
export type { Credential, HeaderContentType, LogType, Policy, RequestParameters, RequestQueryParameters, RequestResult } from './kitQLClient'; |
@@ -8,4 +8,4 @@ import type { ICacheData } from './cache/ICacheData'; | ||
/** | ||
* Headers of your requests to graphql endpoint | ||
* @name headers | ||
* @description Headers of your requests to graphql endpoint | ||
* @default {} | ||
@@ -15,21 +15,23 @@ */ | ||
/** | ||
* @default 3_Minutes Default Cache in miliseconds (can be overwritten at Query level, so `cache:0` force a network call) | ||
* Default Cache in miliseconds | ||
* @default 3 Minutes (1000 * 60 * 3) | ||
*/ | ||
defaultCache?: number; | ||
cacheMs?: number; | ||
/** | ||
* @default cache-first | ||
*/ | ||
defaultPolicy?: 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only'; | ||
policy?: Policy; | ||
/** | ||
* @Default omit Secure by default. More info there: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials | ||
* More info there: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials | ||
* @Default omit Secure by default. | ||
*/ | ||
credentials?: 'omit' | 'same-origin' | 'include'; | ||
credentials?: Credential; | ||
/** | ||
* @Default to `/graphql+json`. But if your server is a bit legacy, you can go back to `/json` | ||
*/ | ||
headersContentType?: 'application/graphql+json' | 'application/json'; | ||
headersContentType?: HeaderContentType; | ||
/** | ||
* @Default [] That means no logs!. | ||
*/ | ||
logType?: ('server' | 'client' | 'operation' | 'operationAndvariables' | 'rawResult')[]; | ||
logType?: LogType[]; | ||
/** | ||
@@ -45,11 +47,17 @@ * @Default InMemory that mean a cache in a variable | ||
*/ | ||
cache?: number; | ||
cacheMs?: number; | ||
/** | ||
* overwrite the default cache policy | ||
*/ | ||
policy?: 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only'; | ||
policy?: Policy; | ||
}; | ||
export declare type Policy = 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only'; | ||
export declare type Credential = 'omit' | 'same-origin' | 'include'; | ||
export declare type HeaderContentType = 'application/graphql+json' | 'application/json'; | ||
export declare type LogType = 'server' | 'client' | 'operation' | 'operationAndvariables' | 'rawResult'; | ||
export declare type RequestParameters<V> = { | ||
fetch?: typeof fetch; | ||
variables?: V; | ||
}; | ||
export declare type RequestQueryParameters<V> = RequestParameters<V> & { | ||
settings?: RequestSettings; | ||
@@ -91,6 +99,6 @@ }; | ||
export declare class KitQLClient { | ||
defaultPolicy: 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only'; | ||
private url; | ||
policy: Policy; | ||
private headers; | ||
private defaultCache; | ||
private cacheMs; | ||
private credentials; | ||
@@ -104,6 +112,6 @@ private headersContentType; | ||
private getLogsStatements; | ||
requestCache<D, V>({ variables, cacheKey, cache, browser }: { | ||
requestCache<D, V>({ variables, cacheKey, cacheMs, browser }: { | ||
variables: any; | ||
cacheKey: string; | ||
cache: number | null; | ||
cacheMs: number | null; | ||
browser: boolean; | ||
@@ -110,0 +118,0 @@ }): ResponseResult<D, V> | null; |
{ | ||
"name": "@kitql/client", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "@kitql/helper": "0.1.6" |
Sorry, the diff of this file is not supported yet
45806
1069