@envelop/core 2.3.0 → 2.4.0-alpha-0969daf.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 +50 -1
- package/index.mjs +50 -2
- package/package.json +1 -1
- package/utils.d.ts +12 -0
package/index.js
CHANGED
|
@@ -299,6 +299,48 @@ 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
|
+
}
|
|
302
344
|
|
|
303
345
|
function createEnvelopOrchestrator(plugins) {
|
|
304
346
|
let schema = null;
|
|
@@ -1229,9 +1271,15 @@ const useMaskedErrors = (opts) => {
|
|
|
1229
1271
|
|
|
1230
1272
|
const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
|
|
1231
1273
|
const rootQueryType = ctx.getSchema().getQueryType();
|
|
1274
|
+
const rootMutationType = ctx.getSchema().getMutationType();
|
|
1275
|
+
const rootSubscriptionType = ctx.getSchema().getSubscriptionType();
|
|
1232
1276
|
return {
|
|
1233
1277
|
Field(field) {
|
|
1234
|
-
|
|
1278
|
+
const parentType = ctx.getParentType();
|
|
1279
|
+
const isQuery = parentType === rootQueryType;
|
|
1280
|
+
const isMutation = parentType === rootMutationType;
|
|
1281
|
+
const isSubscription = parentType === rootSubscriptionType;
|
|
1282
|
+
if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
|
|
1235
1283
|
onNonIntrospectionField();
|
|
1236
1284
|
return graphql.BREAK;
|
|
1237
1285
|
}
|
|
@@ -1283,6 +1331,7 @@ exports.envelopIsIntrospectionSymbol = envelopIsIntrospectionSymbol;
|
|
|
1283
1331
|
exports.errorAsyncIterator = errorAsyncIterator;
|
|
1284
1332
|
exports.finalAsyncIterator = finalAsyncIterator;
|
|
1285
1333
|
exports.formatError = formatError;
|
|
1334
|
+
exports.getInMemoryLRUCache = getInMemoryLRUCache;
|
|
1286
1335
|
exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult;
|
|
1287
1336
|
exports.isAsyncIterable = isAsyncIterable;
|
|
1288
1337
|
exports.isIntrospectionDocument = isIntrospectionDocument;
|
package/index.mjs
CHANGED
|
@@ -295,6 +295,48 @@ 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
|
+
}
|
|
298
340
|
|
|
299
341
|
function createEnvelopOrchestrator(plugins) {
|
|
300
342
|
let schema = null;
|
|
@@ -1225,9 +1267,15 @@ const useMaskedErrors = (opts) => {
|
|
|
1225
1267
|
|
|
1226
1268
|
const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
|
|
1227
1269
|
const rootQueryType = ctx.getSchema().getQueryType();
|
|
1270
|
+
const rootMutationType = ctx.getSchema().getMutationType();
|
|
1271
|
+
const rootSubscriptionType = ctx.getSchema().getSubscriptionType();
|
|
1228
1272
|
return {
|
|
1229
1273
|
Field(field) {
|
|
1230
|
-
|
|
1274
|
+
const parentType = ctx.getParentType();
|
|
1275
|
+
const isQuery = parentType === rootQueryType;
|
|
1276
|
+
const isMutation = parentType === rootMutationType;
|
|
1277
|
+
const isSubscription = parentType === rootSubscriptionType;
|
|
1278
|
+
if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
|
|
1231
1279
|
onNonIntrospectionField();
|
|
1232
1280
|
return BREAK;
|
|
1233
1281
|
}
|
|
@@ -1263,4 +1311,4 @@ const useImmediateIntrospection = () => {
|
|
|
1263
1311
|
};
|
|
1264
1312
|
};
|
|
1265
1313
|
|
|
1266
|
-
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 };
|
|
1314
|
+
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,15 @@ 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
|
+
};
|