@envelop/core 2.3.1 → 2.4.0-alpha-35741fe.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 +48 -0
- package/index.mjs +47 -1
- package/package.json +1 -1
- package/utils.d.ts +13 -0
package/index.js
CHANGED
|
@@ -299,6 +299,52 @@ function errorAsyncIterator(source, onError) {
|
|
|
299
299
|
};
|
|
300
300
|
return stream;
|
|
301
301
|
}
|
|
302
|
+
function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
|
|
303
|
+
let storage = {};
|
|
304
|
+
let keys = [];
|
|
305
|
+
return {
|
|
306
|
+
get(key) {
|
|
307
|
+
return storage[key];
|
|
308
|
+
},
|
|
309
|
+
set(key, value) {
|
|
310
|
+
queueMicrotask(() => {
|
|
311
|
+
if (storage[key] != null) {
|
|
312
|
+
if (keys.indexOf(key)) {
|
|
313
|
+
keys.splice(keys.indexOf(key), 1);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
keys.push(key);
|
|
317
|
+
storage[key] = value;
|
|
318
|
+
while (keys.length > max) {
|
|
319
|
+
const key = keys.shift();
|
|
320
|
+
if (key != null) {
|
|
321
|
+
onDelete(key, storage[key]);
|
|
322
|
+
delete storage[key];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
delete(key) {
|
|
328
|
+
queueMicrotask(() => {
|
|
329
|
+
if (storage[key] != null) {
|
|
330
|
+
keys.splice(keys.indexOf(key), 1);
|
|
331
|
+
onDelete(key, storage[key]);
|
|
332
|
+
delete storage[key];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
clear() {
|
|
337
|
+
queueMicrotask(() => {
|
|
338
|
+
storage = {};
|
|
339
|
+
keys = [];
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
345
|
+
function isSourceObject(maybeSource) {
|
|
346
|
+
return maybeSource != null && maybeSource.body != null;
|
|
347
|
+
}
|
|
302
348
|
|
|
303
349
|
function createEnvelopOrchestrator(plugins) {
|
|
304
350
|
let schema = null;
|
|
@@ -1289,6 +1335,7 @@ exports.envelopIsIntrospectionSymbol = envelopIsIntrospectionSymbol;
|
|
|
1289
1335
|
exports.errorAsyncIterator = errorAsyncIterator;
|
|
1290
1336
|
exports.finalAsyncIterator = finalAsyncIterator;
|
|
1291
1337
|
exports.formatError = formatError;
|
|
1338
|
+
exports.getInMemoryLRUCache = getInMemoryLRUCache;
|
|
1292
1339
|
exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult;
|
|
1293
1340
|
exports.isAsyncIterable = isAsyncIterable;
|
|
1294
1341
|
exports.isIntrospectionDocument = isIntrospectionDocument;
|
|
@@ -1296,6 +1343,7 @@ exports.isIntrospectionOperation = isIntrospectionOperation;
|
|
|
1296
1343
|
exports.isIntrospectionOperationString = isIntrospectionOperationString;
|
|
1297
1344
|
exports.isOperationDefinition = isOperationDefinition;
|
|
1298
1345
|
exports.isPluginEnabled = isPluginEnabled;
|
|
1346
|
+
exports.isSourceObject = isSourceObject;
|
|
1299
1347
|
exports.makeExecute = makeExecute;
|
|
1300
1348
|
exports.makeSubscribe = makeSubscribe;
|
|
1301
1349
|
exports.mapAsyncIterator = mapAsyncIterator;
|
package/index.mjs
CHANGED
|
@@ -295,6 +295,52 @@ function errorAsyncIterator(source, onError) {
|
|
|
295
295
|
};
|
|
296
296
|
return stream;
|
|
297
297
|
}
|
|
298
|
+
function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
|
|
299
|
+
let storage = {};
|
|
300
|
+
let keys = [];
|
|
301
|
+
return {
|
|
302
|
+
get(key) {
|
|
303
|
+
return storage[key];
|
|
304
|
+
},
|
|
305
|
+
set(key, value) {
|
|
306
|
+
queueMicrotask(() => {
|
|
307
|
+
if (storage[key] != null) {
|
|
308
|
+
if (keys.indexOf(key)) {
|
|
309
|
+
keys.splice(keys.indexOf(key), 1);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
keys.push(key);
|
|
313
|
+
storage[key] = value;
|
|
314
|
+
while (keys.length > max) {
|
|
315
|
+
const key = keys.shift();
|
|
316
|
+
if (key != null) {
|
|
317
|
+
onDelete(key, storage[key]);
|
|
318
|
+
delete storage[key];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
delete(key) {
|
|
324
|
+
queueMicrotask(() => {
|
|
325
|
+
if (storage[key] != null) {
|
|
326
|
+
keys.splice(keys.indexOf(key), 1);
|
|
327
|
+
onDelete(key, storage[key]);
|
|
328
|
+
delete storage[key];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
clear() {
|
|
333
|
+
queueMicrotask(() => {
|
|
334
|
+
storage = {};
|
|
335
|
+
keys = [];
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
341
|
+
function isSourceObject(maybeSource) {
|
|
342
|
+
return maybeSource != null && maybeSource.body != null;
|
|
343
|
+
}
|
|
298
344
|
|
|
299
345
|
function createEnvelopOrchestrator(plugins) {
|
|
300
346
|
let schema = null;
|
|
@@ -1269,4 +1315,4 @@ const useImmediateIntrospection = () => {
|
|
|
1269
1315
|
};
|
|
1270
1316
|
};
|
|
1271
1317
|
|
|
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 };
|
|
1318
|
+
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, getInMemoryLRUCache, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, isSourceObject, 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,16 @@ 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 interface BasicCache<V> {
|
|
35
|
+
get(key: string): V | undefined;
|
|
36
|
+
set(key: string, value: V): void;
|
|
37
|
+
delete(key: string): void;
|
|
38
|
+
clear?: () => void;
|
|
39
|
+
}
|
|
40
|
+
export declare function getInMemoryLRUCache<V>({ max, onDelete, }?: {
|
|
41
|
+
max?: number;
|
|
42
|
+
onDelete?: (key: string, value: V) => void;
|
|
43
|
+
}): BasicCache<V> & {
|
|
44
|
+
clear(): void;
|
|
45
|
+
};
|
|
46
|
+
export declare function isSourceObject(maybeSource: any): maybeSource is Source;
|