Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {} from './field_types'
import type {
PointFeature,
PointFeatureWithId,
Filter,
MediaArray
} from '../types'
const CACHE_SIZE = 5000
export const flattenFeature: (feature: PointFeature) => PointFeature = mem(
f => {
if (!f.properties) return f
return { ...f, properties: flatten(f.properties) }
},
{ cache: new QuickLRU({ maxSize: CACHE_SIZE }) }
)
export const addFeatureId: (
feature: PointFeature,
idx: number
// $FlowFixMe
) => PointFeatureWithId = mem(
(f, i) => {
if (f.id !== null && f.id !== undefined) return f
return { ...f, id: i }
},
{
cache: new QuickLRU({ maxSize: CACHE_SIZE })
}
)
// Constants
export const baseUrl = "https://api.jikan.moe/v3";
export const queue = new PQueue({ concurrency: 2 });
// Custom http client
const http = got.extend({
baseUrl,
headers: {
"User-Agent": `${pkg.name} / ${pkg.version} (${pkg.repository.url})`
},
json: true
});
// Memoized http client
export const api = PMemoize(http, { cache: new LRU({ maxSize: 1000 }) });
// Fast JSON logger
export const Logger = pino({
name: "jikants",
prettyPrint: true
});
sourceMaps = true,
...rest
}: any = {}) => ({
extensions,
plugins: [],
sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps,
...rest,
caller: {
name: "rollup-plugin-babel",
supportsStaticESM: true,
supportsDynamicImport: true,
...rest.caller
}
});
const lru = new QuickLRU<
string,
{ code: string; promise: Promise<{ code: string; map: any }> }
>({
maxSize: 1000
});
let hasher: (str: string) => string;
export let hasherPromise = initHasher().then(({ h64 }: any) => {
hasher = h64;
});
let rollupPluginBabel = (pluginOptions: any): Plugin => {
const { exclude, extensions, include, ...babelOptions } = unpackOptions(
pluginOptions
);
import { isEmpty, isEqual, values } from 'lodash';
import Cache from 'quick-lru';
import { unsafeGetProviderAndId } from './utils';
const VOTE_FACTOR = 1e12;
/**
* LRU cache used to speed up party creation date lookups over multiple function invocations.
*
* The cache is bounded at 1000 items to avoid excessive memory usage and will automatically
* drop the least-used items on overflow.
*
* Remark: This assumes the creation date of parties never change after initial setup.
*/
const partyCache = new Cache({ maxSize: 1000 });
/**
* Gets the creation date of the party with the given ID.
*
* Utilizes a LRU cache to speed up the process over multiple function invocations.
*
* @param partyId the ID of the party to get the creation date of.
*/
async function fetchPartyCreationDate(partyId: string): Promise {
const possiblyCached = partyCache.peek(partyId);
if (possiblyCached !== undefined) {
return possiblyCached;
}
const partySnap: firebase.database.DataSnapshot = await firebase.database()
.ref('/parties')
this.sodium = options.sodium;
this.channel = options.channel;
this.backend = options.backend;
if (!this.sodium) {
throw new Error('Missing required `sodium` option');
}
if (!this.channel) {
throw new Error('Missing required `channel` option');
}
if (!this.backend) {
throw new Error('Missing required `backend` option');
}
this.debugId = this.channel.id.toString('hex').slice(0, 8);
this.lru = new LRU({ maxSize: options.maxLRUSize });
this.lastCount = null;
this.leaves = null;
}
export function memo (fn) {
return pMemoize(fn, {
maxAge: MEMO_MAX_AGE,
cache: new QuickLRU({ maxSize: MEMO_MAX_SIZE })
})
}