@envelop/core 2.3.1 → 2.4.0-alpha-3936561.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +44 -0
- package/index.mjs +44 -1
- package/package.json +1 -1
- package/utils.d.ts +9 -0
package/index.js
CHANGED
|
@@ -299,6 +299,49 @@ function errorAsyncIterator(source, onError) {
|
|
|
299
299
|
};
|
|
300
300
|
return stream;
|
|
301
301
|
}
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
303
|
+
function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
|
|
304
|
+
let storage = {};
|
|
305
|
+
let keys = [];
|
|
306
|
+
return {
|
|
307
|
+
get(key) {
|
|
308
|
+
return storage[key];
|
|
309
|
+
},
|
|
310
|
+
set(key, value) {
|
|
311
|
+
queueMicrotask(() => {
|
|
312
|
+
if (storage[key] != null) {
|
|
313
|
+
if (keys.indexOf(key)) {
|
|
314
|
+
keys.splice(keys.indexOf(key), 1);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
keys.push(key);
|
|
318
|
+
storage[key] = value;
|
|
319
|
+
while (keys.length > max) {
|
|
320
|
+
const key = keys.shift();
|
|
321
|
+
if (key != null) {
|
|
322
|
+
onDelete(key, storage[key]);
|
|
323
|
+
delete storage[key];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
delete(key) {
|
|
329
|
+
queueMicrotask(() => {
|
|
330
|
+
if (storage[key] != null) {
|
|
331
|
+
keys.splice(keys.indexOf(key), 1);
|
|
332
|
+
onDelete(key, storage[key]);
|
|
333
|
+
delete storage[key];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
clear() {
|
|
338
|
+
queueMicrotask(() => {
|
|
339
|
+
storage = {};
|
|
340
|
+
keys = [];
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
302
345
|
|
|
303
346
|
function createEnvelopOrchestrator(plugins) {
|
|
304
347
|
let schema = null;
|
|
@@ -1289,6 +1332,7 @@ exports.envelopIsIntrospectionSymbol = envelopIsIntrospectionSymbol;
|
|
|
1289
1332
|
exports.errorAsyncIterator = errorAsyncIterator;
|
|
1290
1333
|
exports.finalAsyncIterator = finalAsyncIterator;
|
|
1291
1334
|
exports.formatError = formatError;
|
|
1335
|
+
exports.getInMemoryLRUCache = getInMemoryLRUCache;
|
|
1292
1336
|
exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult;
|
|
1293
1337
|
exports.isAsyncIterable = isAsyncIterable;
|
|
1294
1338
|
exports.isIntrospectionDocument = isIntrospectionDocument;
|
package/index.mjs
CHANGED
|
@@ -295,6 +295,49 @@ function errorAsyncIterator(source, onError) {
|
|
|
295
295
|
};
|
|
296
296
|
return stream;
|
|
297
297
|
}
|
|
298
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
299
|
+
function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
|
|
300
|
+
let storage = {};
|
|
301
|
+
let keys = [];
|
|
302
|
+
return {
|
|
303
|
+
get(key) {
|
|
304
|
+
return storage[key];
|
|
305
|
+
},
|
|
306
|
+
set(key, value) {
|
|
307
|
+
queueMicrotask(() => {
|
|
308
|
+
if (storage[key] != null) {
|
|
309
|
+
if (keys.indexOf(key)) {
|
|
310
|
+
keys.splice(keys.indexOf(key), 1);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
keys.push(key);
|
|
314
|
+
storage[key] = value;
|
|
315
|
+
while (keys.length > max) {
|
|
316
|
+
const key = keys.shift();
|
|
317
|
+
if (key != null) {
|
|
318
|
+
onDelete(key, storage[key]);
|
|
319
|
+
delete storage[key];
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
delete(key) {
|
|
325
|
+
queueMicrotask(() => {
|
|
326
|
+
if (storage[key] != null) {
|
|
327
|
+
keys.splice(keys.indexOf(key), 1);
|
|
328
|
+
onDelete(key, storage[key]);
|
|
329
|
+
delete storage[key];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
clear() {
|
|
334
|
+
queueMicrotask(() => {
|
|
335
|
+
storage = {};
|
|
336
|
+
keys = [];
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
}
|
|
298
341
|
|
|
299
342
|
function createEnvelopOrchestrator(plugins) {
|
|
300
343
|
let schema = null;
|
|
@@ -1269,4 +1312,4 @@ const useImmediateIntrospection = () => {
|
|
|
1269
1312
|
};
|
|
1270
1313
|
};
|
|
1271
1314
|
|
|
1272
|
-
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
|
|
1315
|
+
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, getInMemoryLRUCache, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
|
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -31,3 +31,12 @@ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): may
|
|
|
31
31
|
export declare function handleStreamOrSingleExecutionResult<ContextType = DefaultContext>(payload: OnExecuteDoneEventPayload<ContextType>, fn: OnExecuteDoneHookResultOnNextHook<ContextType>): void | OnExecuteDoneHookResult<ContextType>;
|
|
32
32
|
export declare function finalAsyncIterator<TInput>(source: AsyncIterable<TInput>, onFinal: () => void): AsyncGenerator<TInput>;
|
|
33
33
|
export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>;
|
|
34
|
+
export declare function getInMemoryLRUCache<V>({ max, onDelete, }?: {
|
|
35
|
+
max?: number;
|
|
36
|
+
onDelete?: (key: string, value: V) => void;
|
|
37
|
+
}): {
|
|
38
|
+
get(key: string): V | undefined;
|
|
39
|
+
set(key: string, value: V): void;
|
|
40
|
+
delete(key: string): void;
|
|
41
|
+
clear(): void;
|
|
42
|
+
};
|