@graphql-tools/utils
Advanced tools
Comparing version 10.5.2 to 10.6.0-alpha-20240813170011-203a03313f5e89b402e0214cf11c8ae5ce1c33ca
@@ -63,1 +63,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./getDirectiveExtensions.js"), exports); | ||
tslib_1.__exportStar(require("./createDeferred.js"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.memoize2of5 = exports.memoize2of4 = exports.memoize5 = exports.memoize4 = exports.memoize3 = exports.memoize2 = exports.memoize1 = void 0; | ||
exports.memoize2of5 = exports.memoize2of4 = exports.memoize5 = exports.memoize4 = exports.memoize3of4 = exports.memoize3 = exports.memoize2 = exports.memoize1 = void 0; | ||
function memoize1(fn) { | ||
@@ -69,2 +69,33 @@ const memoize1cache = new WeakMap(); | ||
exports.memoize3 = memoize3; | ||
function memoize3of4(fn) { | ||
const memoize3Cache = new WeakMap(); | ||
return function memoized(a1, a2, a3, a4) { | ||
let cache2 = memoize3Cache.get(a1); | ||
if (!cache2) { | ||
cache2 = new WeakMap(); | ||
memoize3Cache.set(a1, cache2); | ||
const cache3 = new WeakMap(); | ||
cache2.set(a2, cache3); | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
let cache3 = cache2.get(a2); | ||
if (!cache3) { | ||
cache3 = new WeakMap(); | ||
cache2.set(a2, cache3); | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
const cachedValue = cache3.get(a3); | ||
if (cachedValue === undefined) { | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
return cachedValue; | ||
}; | ||
} | ||
exports.memoize3of4 = memoize3of4; | ||
function memoize4(fn) { | ||
@@ -71,0 +102,0 @@ const memoize4Cache = new WeakMap(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mergeIncrementalResult = void 0; | ||
const tslib_1 = require("tslib"); | ||
const dlv_1 = tslib_1.__importDefault(require("dlv")); | ||
const merge_1 = require("dset/merge"); | ||
const pathsMap = new WeakMap(); | ||
function mergeIncrementalResult({ incrementalResult, executionResult, }) { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
if (incrementalResult.items) { | ||
for (const item of incrementalResult.items) { | ||
(0, merge_1.dset)(executionResult, path, item); | ||
// Increment the last path segment (the array index) to merge the next item at the next index | ||
path[path.length - 1]++; | ||
let path = [ | ||
'data', | ||
...(incrementalResult.path ?? []), | ||
]; | ||
for (const result of [executionResult, incrementalResult]) { | ||
if (result.pending) { | ||
let paths = pathsMap.get(executionResult); | ||
if (paths === undefined) { | ||
paths = new Map(); | ||
pathsMap.set(executionResult, paths); | ||
} | ||
for (const { id, path } of result.pending) { | ||
paths.set(id, ['data', ...path]); | ||
} | ||
} | ||
} | ||
if (incrementalResult.data) { | ||
(0, merge_1.dset)(executionResult, path, incrementalResult.data); | ||
const items = incrementalResult.items; | ||
if (items) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const list = (0, dlv_1.default)(executionResult, path); | ||
list.push(...items); | ||
} | ||
else { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
for (const item of items) { | ||
(0, merge_1.dset)(executionResult, path, item); | ||
// Increment the last path segment (the array index) to merge the next item at the next index | ||
path[path.length - 1]++; | ||
} | ||
} | ||
} | ||
const data = incrementalResult.data; | ||
if (data) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const subPath = incrementalResult.subPath; | ||
if (subPath !== undefined) { | ||
path = [...path, ...subPath]; | ||
} | ||
} | ||
(0, merge_1.dset)(executionResult, path, data); | ||
} | ||
if (incrementalResult.errors) { | ||
@@ -32,3 +75,13 @@ executionResult.errors = executionResult.errors || []; | ||
} | ||
if (incrementalResult.completed) { | ||
// Remove tracking and add additional errors | ||
for (const { id, errors } of incrementalResult.completed) { | ||
pathsMap.get(executionResult)?.delete(id); | ||
if (errors) { | ||
executionResult.errors = executionResult.errors || []; | ||
executionResult.errors.push(...errors); | ||
} | ||
} | ||
} | ||
} | ||
exports.mergeIncrementalResult = mergeIncrementalResult; |
@@ -58,1 +58,2 @@ export * from './loaders.js'; | ||
export * from './getDirectiveExtensions.js'; | ||
export * from './createDeferred.js'; |
@@ -63,2 +63,32 @@ export function memoize1(fn) { | ||
} | ||
export function memoize3of4(fn) { | ||
const memoize3Cache = new WeakMap(); | ||
return function memoized(a1, a2, a3, a4) { | ||
let cache2 = memoize3Cache.get(a1); | ||
if (!cache2) { | ||
cache2 = new WeakMap(); | ||
memoize3Cache.set(a1, cache2); | ||
const cache3 = new WeakMap(); | ||
cache2.set(a2, cache3); | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
let cache3 = cache2.get(a2); | ||
if (!cache3) { | ||
cache3 = new WeakMap(); | ||
cache2.set(a2, cache3); | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
const cachedValue = cache3.get(a3); | ||
if (cachedValue === undefined) { | ||
const newValue = fn(a1, a2, a3, a4); | ||
cache3.set(a3, newValue); | ||
return newValue; | ||
} | ||
return cachedValue; | ||
}; | ||
} | ||
export function memoize4(fn) { | ||
@@ -65,0 +95,0 @@ const memoize4Cache = new WeakMap(); |
@@ -0,14 +1,56 @@ | ||
import delve from 'dlv'; | ||
import { dset } from 'dset/merge'; | ||
const pathsMap = new WeakMap(); | ||
export function mergeIncrementalResult({ incrementalResult, executionResult, }) { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
if (incrementalResult.items) { | ||
for (const item of incrementalResult.items) { | ||
dset(executionResult, path, item); | ||
// Increment the last path segment (the array index) to merge the next item at the next index | ||
path[path.length - 1]++; | ||
let path = [ | ||
'data', | ||
...(incrementalResult.path ?? []), | ||
]; | ||
for (const result of [executionResult, incrementalResult]) { | ||
if (result.pending) { | ||
let paths = pathsMap.get(executionResult); | ||
if (paths === undefined) { | ||
paths = new Map(); | ||
pathsMap.set(executionResult, paths); | ||
} | ||
for (const { id, path } of result.pending) { | ||
paths.set(id, ['data', ...path]); | ||
} | ||
} | ||
} | ||
if (incrementalResult.data) { | ||
dset(executionResult, path, incrementalResult.data); | ||
const items = incrementalResult.items; | ||
if (items) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const list = delve(executionResult, path); | ||
list.push(...items); | ||
} | ||
else { | ||
const path = ['data', ...(incrementalResult.path ?? [])]; | ||
for (const item of items) { | ||
dset(executionResult, path, item); | ||
// Increment the last path segment (the array index) to merge the next item at the next index | ||
path[path.length - 1]++; | ||
} | ||
} | ||
} | ||
const data = incrementalResult.data; | ||
if (data) { | ||
const id = incrementalResult.id; | ||
if (id) { | ||
path = pathsMap.get(executionResult)?.get(id); | ||
if (path === undefined) { | ||
throw new Error('Invalid incremental delivery format.'); | ||
} | ||
const subPath = incrementalResult.subPath; | ||
if (subPath !== undefined) { | ||
path = [...path, ...subPath]; | ||
} | ||
} | ||
dset(executionResult, path, data); | ||
} | ||
if (incrementalResult.errors) { | ||
@@ -29,2 +71,12 @@ executionResult.errors = executionResult.errors || []; | ||
} | ||
if (incrementalResult.completed) { | ||
// Remove tracking and add additional errors | ||
for (const { id, errors } of incrementalResult.completed) { | ||
pathsMap.get(executionResult)?.delete(id); | ||
if (errors) { | ||
executionResult.errors = executionResult.errors || []; | ||
executionResult.errors.push(...errors); | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "@graphql-tools/utils", | ||
"version": "10.5.2", | ||
"version": "10.6.0-alpha-20240813170011-203a03313f5e89b402e0214cf11c8ae5ce1c33ca", | ||
"description": "Common package containing utils and types for GraphQL tools", | ||
@@ -12,2 +12,3 @@ "sideEffects": false, | ||
"cross-inspect": "1.0.1", | ||
"dlv": "^1.1.3", | ||
"dset": "^3.1.2", | ||
@@ -14,0 +15,0 @@ "tslib": "^2.4.0" |
@@ -58,1 +58,2 @@ export * from './loaders.js'; | ||
export * from './getDirectiveExtensions.js'; | ||
export * from './createDeferred.js'; |
@@ -20,2 +20,12 @@ import { DefinitionNode, DocumentNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, FieldDefinitionNode, FieldNode, FragmentDefinitionNode, GraphQLArgument, GraphQLArgumentConfig, GraphQLDirective, GraphQLEnumType, GraphQLEnumValue, GraphQLEnumValueConfig, GraphQLError, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLIsTypeOfFn, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLScalarLiteralParser, GraphQLScalarSerializer, GraphQLScalarType, GraphQLScalarValueParser, GraphQLSchema, GraphQLType, GraphQLTypeResolver, GraphQLUnionType, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationTypeNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, SelectionNode, Source, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql'; | ||
items?: TData | null; | ||
id?: string; | ||
subPath?: ReadonlyArray<string | number>; | ||
pending?: ReadonlyArray<{ | ||
id: string; | ||
path: ReadonlyArray<string | number>; | ||
}>; | ||
completed?: ReadonlyArray<{ | ||
id: string; | ||
errors?: ReadonlyArray<GraphQLError>; | ||
}>; | ||
} | ||
@@ -22,0 +32,0 @@ export interface ExecutionRequest<TVariables extends Record<string, any> = any, TContext = any, TRootValue = any, TExtensions = Record<string, any>, TReturn = any> { |
export declare function memoize1<F extends (a1: any) => any>(fn: F): F; | ||
export declare function memoize2<F extends (a1: any, a2: any) => any>(fn: F): F; | ||
export declare function memoize3<F extends (a1: any, a2: any, a3: any) => any>(fn: F): F; | ||
export declare function memoize3of4<F extends (a1: any, a2: any, a3: any, a4: any) => any>(fn: F): F; | ||
export declare function memoize4<F extends (a1: any, a2: any, a3: any, a4: any) => any>(fn: F): F; | ||
@@ -5,0 +6,0 @@ export declare function memoize5<F extends (a1: any, a2: any, a3: any, a4: any, a5: any) => any>(fn: F): F; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
516133
250
11154
6
2
+ Addeddlv@^1.1.3
+ Addeddlv@1.1.3(transitive)