@kitql/client
Advanced tools
Comparing version 0.0.23 to 0.0.24
40
index.js
@@ -38,2 +38,11 @@ 'use strict'; | ||
} | ||
logOperation(browser, from, operation, variables = null) { | ||
this.log.info(`${helper.logCyan('Mode:')} ` + | ||
`${helper.logGreen(browser ? 'browser' : 'ssr')}, ` + | ||
`${helper.logCyan('From:')} ${helper.logGreen(from)}, ` + | ||
`${helper.logCyan('Operation:')} ${helper.logGreen(operation)}` + | ||
variables | ||
? `${helper.logCyan('Variables:')} ${helper.logGreen(variables)}` | ||
: ``); | ||
} | ||
async request({ skFetch, document, variables, cacheKey, cacheMs, browser }) { | ||
@@ -44,4 +53,5 @@ //Cache key... Relys on the order of the variables :s | ||
const serverAndWantLog = !browser && this.logType.includes('server'); | ||
const wantLogInfo = this.logType.includes('info') && (browserAndWantLog || serverAndWantLog); | ||
const wantLogDebug = this.logType.includes('debug') && (browserAndWantLog || serverAndWantLog); | ||
const logOp = this.logType.includes('operation') && (browserAndWantLog || serverAndWantLog); | ||
const logOpVar = this.logType.includes('operationAndvariables') && (browserAndWantLog || serverAndWantLog); | ||
const logRawResult = this.logType.includes('rawResult') && (browserAndWantLog || serverAndWantLog); | ||
// No caching in the server for now! (Need to have a session identification to not mix things up) | ||
@@ -54,8 +64,8 @@ if (browser) { | ||
if (xMs < (cacheMs || this.cacheMs)) { | ||
if (wantLogInfo) { | ||
this.log.info(`${helper.logCyan('Mode:')} ` + | ||
`${helper.logGreen(browser ? 'browser' : 'ssr')}, ` + | ||
`${helper.logCyan('From:')} ${helper.logGreen('CACHE')}, ` + | ||
`${helper.logCyan('Operation:')} ${helper.logGreen(cacheKey)}`); | ||
if (logOp) { | ||
this.logOperation(browser, exports.RequestFrom.CACHE, cacheKey); | ||
} | ||
else if (logOpVar) { | ||
this.logOperation(browser, exports.RequestFrom.CACHE, cacheKey, JSON.stringify(variables, null, 2)); | ||
} | ||
return { ...this.cache[key], from: exports.RequestFrom.CACHE }; | ||
@@ -76,5 +86,2 @@ } | ||
const fetchToUse = skFetch ? skFetch : fetch; | ||
if (wantLogDebug) { | ||
this.log.info(`${helper.logCyan('fetchToUse:')} ` + `${skFetch ? 'SvelteKit Fetch' : 'fetch'}`); | ||
} | ||
let dateToReturn = { | ||
@@ -98,10 +105,11 @@ date: new Date().getTime(), | ||
if (res.url === '') { | ||
// In the browser we see a flickering from NETWORK to SSR, because it's the Real SSR coming with a from network... Replaced by the SSR side! | ||
dateToReturn.from = exports.RequestFrom.SSR; | ||
} | ||
if (wantLogInfo) { | ||
this.log.info(`${helper.logCyan('Mode:')} ` + | ||
`${helper.logGreen(browser ? 'browser' : 'ssr')}, ` + | ||
`${helper.logCyan('From:')} ${helper.logGreen(dateToReturn.from)}, ` + | ||
`${helper.logCyan('Operation:')} ${helper.logGreen(cacheKey)}`); | ||
if (logOp) { | ||
this.logOperation(browser, dateToReturn.from, cacheKey); | ||
} | ||
else if (logOpVar) { | ||
this.logOperation(browser, dateToReturn.from, cacheKey, JSON.stringify(variables, null, 2)); | ||
} | ||
if (res.status !== 200) { | ||
@@ -117,3 +125,3 @@ if (res.statusText === '') { | ||
let dataJson = await res.json(); | ||
if (wantLogDebug) { | ||
if (logRawResult) { | ||
this.log.info(`${helper.logCyan('dataJson:')} ` + `${JSON.stringify(dataJson, null, 2)}`); | ||
@@ -120,0 +128,0 @@ } |
@@ -19,5 +19,5 @@ export declare type ClientSettings = { | ||
/** | ||
* Default to `[]` no logs!. | ||
* Default to `[]` => no logs!. | ||
*/ | ||
logType?: ('server' | 'client' | 'info' | 'debug')[]; | ||
logType?: ('server' | 'client' | 'operation' | 'operationAndvariables' | 'rawResult')[]; | ||
}; | ||
@@ -73,2 +73,3 @@ export declare type RequestSettings = { | ||
constructor(options: ClientSettings); | ||
private logOperation; | ||
request<D, V>({ skFetch, document, variables, cacheKey, cacheMs, browser }: { | ||
@@ -75,0 +76,0 @@ skFetch: any; |
{ | ||
"name": "@kitql/client", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "@kitql/helper": "0.0.3", |
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
18293
462