-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
3,139 additions
and
1,256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import _ from 'lodash' | ||
import { uid } from 'quasar' | ||
|
||
export function removeServerSideParameters(context) { | ||
const params = context.params | ||
_.unset(params, 'query.$locale') | ||
_.unset(params, 'query.$collation') | ||
_.unset(params, 'query.populate') | ||
if (_.has(params, 'query.upsert')) { | ||
_.set(params, 'upsert', _.get(params, 'query.upsert')) | ||
_.unset(params, 'query.upsert') | ||
} | ||
} | ||
|
||
export function generateId(context) { | ||
const params = context.params | ||
// Generate ID only when not doing a snapshot because it should keep data as it is on the server side | ||
// Typically some services like the catalog deliver objects without any IDs (as directly coming from the configuration not the database) | ||
// and this property is used to make some difference in the way the GUI interpret this objects | ||
if (params.snapshot) return | ||
const data = (Array.isArray(context.data) ? context.data : [context.data]) | ||
// Update only items without any ID | ||
data.filter(item => !item._id).forEach(item => { | ||
item._id = uid().toString() | ||
}) | ||
} | ||
|
||
export function ensureSerializable(context) { | ||
// Serialization in localforage will raise error with structures that are not raw JSON: | ||
// JS proxy objects, function properties, etc. | ||
if (context.data) context.data = _.cloneDeep(context.data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './hooks.logger.js' | ||
export * from './hooks.events.js' | ||
export * from './hooks.offline.js' | ||
export * from './hooks.users.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logger from 'loglevel' | ||
import _ from 'lodash' | ||
import { LocalForage } from '@kalisio/feathers-localforage' | ||
|
||
export const LocalCache = { | ||
initialize () { | ||
logger.debug('[KDK] initializing local cache') | ||
LocalForage.config({ | ||
name: 'offline_cache', | ||
storeName: 'cache_entries' | ||
}) | ||
}, | ||
async createCache (cacheName) { | ||
const cache = await caches.open(cacheName) | ||
return cache | ||
}, | ||
async getCache (cacheName) { | ||
const cache = await caches.open(cacheName) | ||
return cache | ||
}, | ||
async removeCache (cacheName) { | ||
await caches.delete(cacheName) | ||
}, | ||
async has (key) { | ||
return !_.isNil(this.getCount(key)) | ||
}, | ||
async getCount (key) { | ||
return await LocalForage.getItem(key) | ||
}, | ||
async setCount (key, count) { | ||
await LocalForage.setItem(key, count) | ||
}, | ||
async set (cacheName, key, url, fetchOptions = {}) { | ||
const count = await this.getCount(key) | ||
if (!_.isNil(count)) { | ||
await this.setCount(key, count + 1) | ||
} else { | ||
const cache = await this.getCache(cacheName) | ||
let response = await fetch(url, fetchOptions) | ||
// Convert response from 206 -> 200 to make it cacheable | ||
if (response.status === 206) response = new Response(response.body, { status: 200, headers: response.headers }) | ||
await cache.put(key, response) | ||
await LocalForage.setItem(key, 1) | ||
} | ||
}, | ||
async unset (cacheName, key) { | ||
const cache = await this.getCache(cacheName) | ||
const count = await this.getCount(key) | ||
if (_.isNil(count)) return | ||
if (count <= 1) { | ||
cache.delete(key) | ||
await LocalForage.removeItem(key) | ||
} else { | ||
await this.setCount(key, count - 1) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.