@graphql-box/cache-manager 5.0.2 → 5.1.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.
Files changed (49) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs +1 -1
  4. package/dist/esm/index.mjs.map +1 -1
  5. package/dist/production.analysis.txt +125 -96
  6. package/dist/types/cjs/helpers/createEntityDataKey.d.cts +4 -0
  7. package/dist/types/cjs/helpers/createEntityDataKey.d.cts.map +1 -0
  8. package/dist/types/cjs/helpers/filterOutPropsWithEntityArgsOrDirectives.d.cts +5 -0
  9. package/dist/types/cjs/helpers/filterOutPropsWithEntityArgsOrDirectives.d.cts.map +1 -0
  10. package/dist/types/cjs/helpers/filterOutPropsWithEntityOrArgs.d.cts +6 -0
  11. package/dist/types/cjs/helpers/filterOutPropsWithEntityOrArgs.d.cts.map +1 -0
  12. package/dist/types/cjs/helpers/isFieldEntity.d.cts +3 -0
  13. package/dist/types/cjs/helpers/isFieldEntity.d.cts.map +1 -0
  14. package/dist/types/cjs/helpers/validTypeIdValue.d.cts +1 -1
  15. package/dist/types/cjs/helpers/validTypeIdValue.d.cts.map +1 -1
  16. package/dist/types/cjs/main.d.cts +3 -5
  17. package/dist/types/cjs/main.d.cts.map +1 -1
  18. package/dist/types/cjs/types.d.cts +5 -5
  19. package/dist/types/cjs/types.d.cts.map +1 -1
  20. package/dist/types/esm/helpers/createEntityDataKey.d.ts +4 -0
  21. package/dist/types/esm/helpers/createEntityDataKey.d.ts.map +1 -0
  22. package/dist/types/esm/helpers/filterOutPropsWithEntityArgsOrDirectives.d.ts +5 -0
  23. package/dist/types/esm/helpers/filterOutPropsWithEntityArgsOrDirectives.d.ts.map +1 -0
  24. package/dist/types/esm/helpers/filterOutPropsWithEntityOrArgs.d.ts +6 -0
  25. package/dist/types/esm/helpers/filterOutPropsWithEntityOrArgs.d.ts.map +1 -0
  26. package/dist/types/esm/helpers/isFieldEntity.d.ts +3 -0
  27. package/dist/types/esm/helpers/isFieldEntity.d.ts.map +1 -0
  28. package/dist/types/esm/helpers/validTypeIdValue.d.ts +1 -1
  29. package/dist/types/esm/helpers/validTypeIdValue.d.ts.map +1 -1
  30. package/dist/types/esm/main.d.ts +3 -5
  31. package/dist/types/esm/main.d.ts.map +1 -1
  32. package/dist/types/esm/types.d.ts +5 -5
  33. package/dist/types/esm/types.d.ts.map +1 -1
  34. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  35. package/package.json +5 -5
  36. package/src/__snapshots__/index.test.ts.snap +19450 -19450
  37. package/src/helpers/createEntityDataKey.ts +11 -0
  38. package/src/helpers/filterOutPropsWithEntityArgsOrDirectives.ts +45 -0
  39. package/src/helpers/filterOutPropsWithEntityOrArgs.ts +31 -0
  40. package/src/helpers/isFieldEntity.ts +24 -0
  41. package/src/helpers/validTypeIdValue.ts +3 -3
  42. package/src/index.test.ts +153 -127
  43. package/src/main.ts +122 -179
  44. package/src/types.ts +5 -5
  45. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts +0 -6
  46. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts.map +0 -1
  47. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts +0 -6
  48. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +0 -1
  49. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +0 -29
@@ -0,0 +1,11 @@
1
+ import type { EntityData, FieldTypeInfo } from '@graphql-box/core';
2
+ import type { CacheManagerContext } from '../types.ts';
3
+
4
+ export const createEntityDataKey = (
5
+ fieldData: EntityData,
6
+ fieldTypeInfo: FieldTypeInfo,
7
+ context: CacheManagerContext
8
+ ) => {
9
+ const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
10
+ return `${fieldTypeName}::${String(fieldData[context.typeIDKey!])}`;
11
+ };
@@ -0,0 +1,45 @@
1
+ import { type PlainObject } from '@graphql-box/core';
2
+ import {
3
+ type KeysAndPaths,
4
+ buildFieldKeysAndPaths,
5
+ getName,
6
+ isPlainObject,
7
+ resolveFragments,
8
+ } from '@graphql-box/helpers';
9
+ import { type FieldNode } from 'graphql';
10
+ import { keys } from 'lodash-es';
11
+ import { type CacheManagerContext } from '../types.ts';
12
+ import { isFieldEntity } from './isFieldEntity.ts';
13
+
14
+ export const filterOutPropsWithEntityArgsOrDirectives = (
15
+ fieldData: unknown,
16
+ field: FieldNode,
17
+ ancestorKeysAndPaths: KeysAndPaths,
18
+ context: CacheManagerContext
19
+ ) => {
20
+ if (!isPlainObject(fieldData)) {
21
+ return fieldData;
22
+ }
23
+
24
+ const fieldAndTypeName = resolveFragments(field.selectionSet?.selections, context.fragmentDefinitions);
25
+
26
+ return keys(fieldData).reduce<PlainObject>((acc, key) => {
27
+ const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
28
+
29
+ if (match) {
30
+ const keysAndPaths = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
31
+ const fieldTypeInfo = context.fieldTypeMap.get(keysAndPaths.requestFieldPath);
32
+
33
+ if (
34
+ isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) ||
35
+ fieldTypeInfo?.hasArguments ||
36
+ fieldTypeInfo?.hasDirectives
37
+ ) {
38
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
39
+ delete fieldData[key];
40
+ }
41
+ }
42
+
43
+ return acc;
44
+ }, fieldData);
45
+ };
@@ -0,0 +1,31 @@
1
+ import { type EntityData } from '@graphql-box/core';
2
+ import { type KeysAndPaths, buildFieldKeysAndPaths, getName, resolveFragments } from '@graphql-box/helpers';
3
+ import { type FieldNode } from 'graphql';
4
+ import { keys } from 'lodash-es';
5
+ import { type CacheManagerContext } from '../types.ts';
6
+ import { isFieldEntity } from './isFieldEntity.ts';
7
+
8
+ export const filterOutPropsWithEntityOrArgs = (
9
+ fieldData: EntityData,
10
+ field: FieldNode,
11
+ ancestorKeysAndPaths: KeysAndPaths,
12
+ context: CacheManagerContext
13
+ ) => {
14
+ const fieldAndTypeName = resolveFragments(field.selectionSet?.selections, context.fragmentDefinitions);
15
+
16
+ return keys(fieldData).reduce<Partial<EntityData>>((acc, key) => {
17
+ const match = fieldAndTypeName.find(({ fieldNode }) => getName(fieldNode) === key);
18
+
19
+ if (match) {
20
+ const { requestFieldPath } = buildFieldKeysAndPaths(match.fieldNode, ancestorKeysAndPaths, context);
21
+ const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
22
+
23
+ if (isFieldEntity(fieldData[key], fieldTypeInfo, context.typeIDKey!) || fieldTypeInfo?.hasArguments) {
24
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
25
+ delete fieldData[key];
26
+ }
27
+ }
28
+
29
+ return acc;
30
+ }, fieldData) as EntityData;
31
+ };
@@ -0,0 +1,24 @@
1
+ import type { EntityData, FieldTypeInfo } from '@graphql-box/core';
2
+ import { isPlainObject } from '@graphql-box/helpers';
3
+
4
+ export const isFieldEntity = (
5
+ fieldData: unknown,
6
+ fieldTypeInfo: FieldTypeInfo | undefined,
7
+ typeIDKey: string
8
+ ): fieldData is EntityData => {
9
+ if (!isPlainObject(fieldData) || !(typeIDKey in fieldData)) {
10
+ return false;
11
+ }
12
+
13
+ const { isEntity = false, possibleTypes = [] } = fieldTypeInfo ?? {};
14
+
15
+ if (isEntity) {
16
+ return true;
17
+ }
18
+
19
+ if (possibleTypes.length === 0) {
20
+ return false;
21
+ }
22
+
23
+ return possibleTypes.some(type => type.typeName === fieldData.__typename);
24
+ };
@@ -3,11 +3,11 @@ import { isPlainObject } from '@graphql-box/helpers';
3
3
 
4
4
  export const getValidTypeIdValue = (
5
5
  requestFieldPathData: unknown,
6
- { typeIDValue }: FieldTypeInfo,
6
+ fieldTypeInfo: FieldTypeInfo | undefined,
7
7
  typeIDKey: string
8
8
  ): string | number | undefined => {
9
- if (typeIDValue) {
10
- return typeIDValue;
9
+ if (fieldTypeInfo?.typeIDValue) {
10
+ return fieldTypeInfo.typeIDValue;
11
11
  }
12
12
 
13
13
  if (isPlainObject(requestFieldPathData)) {