@baeta/extension-complexity 0.0.1 → 0.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @baeta/extension-complexity
2
2
 
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c8dea0c`](https://github.com/andreisergiu98/baeta/commit/c8dea0c6a7824039cf4de13a8d2c0b1682ea3d02) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - maintain order of prepended middlewares
8
+
9
+ - Updated dependencies [[`c8dea0c`](https://github.com/andreisergiu98/baeta/commit/c8dea0c6a7824039cf4de13a8d2c0b1682ea3d02)]:
10
+ - @baeta/core@0.1.3
11
+
3
12
  ## 0.0.1
4
13
 
5
14
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -308,12 +308,12 @@ var ComplexityExtension = (_class = class extends _sdk.Extension {
308
308
  }
309
309
  if (type !== "Subscription") {
310
310
  for (const field of mapper.getTypeFields(type)) {
311
- mapper.addMiddleware(type, field, this.createComplexityMiddleware());
311
+ mapper.prependMiddleware(type, field, this.createComplexityMiddleware());
312
312
  }
313
313
  continue;
314
314
  }
315
315
  for (const field of mapper.getTypeFields(type)) {
316
- mapper.addMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());
316
+ mapper.prependMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());
317
317
  }
318
318
  }
319
319
  }}
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/baeta/baeta/packages/extension-complexity/dist/index.cjs","../lib/complexity-extension.ts","../lib/complexity-calculator.ts","../utils/graphlq.ts","../utils/string.ts","../lib/field-settings.ts","../lib/complexity-errors.ts","../lib/complexity-options.ts","../lib/store.ts","../lib/store-loader.ts","../index.ts"],"names":["ComplexityErrorKind"],"mappings":"AAAA;ACAA;AACC;AAAA,sCAIM;ADDP;AACA;AELA,uCAAgC;AAChC;AAMC;AAGA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;AACD,IAAA;AACA,EAAA;AACF;ATmNqE;AACA;AClOb;AACtC,EAAA;AAE0C,EAAA;AACpD,IAAA;AACiC,IAAA;AACxC,EAAA;AAE8C,iBAAA;AAKM,kBAAA;AAC5C,IAAA;AACe,MAAA;AAC4B,QAAA;AACjD,MAAA;AACD,IAAA;AACD,EAAA;AAMsE,kBAAA;AAC9D,IAAA;AACe,MAAA;AAC8B,QAAA;AACnD,MAAA;AACD,IAAA;AACD,EAAA;AAKkE,kBAAA;AAC1D,IAAA;AACe,MAAA;AACwC,QAAA;AAC7D,MAAA;AACD,IAAA;AACD,EAAA;AAOE,EAAA;AACiD,IAAA;AAC2B,MAAA;AAElC,MAAA;AAErB,MAAA;AAEuB,MAAA;AACoC,QAAA;AACrD,UAAA;AACA,UAAA;AACzB,QAAA;AACD,MAAA;AAEiC,MAAA;AACd,QAAA;AACpB,MAAA;AAEsC,MAAA;AAClB,QAAA;AAAA,UAAA;AAEX,UAAA;AACC,UAAA;AACT,QAAA;AACD,MAAA;AAE4C,MAAA;AACxB,QAAA;AAAA,UAAA;AAEX,UAAA;AACC,UAAA;AACT,QAAA;AACD,MAAA;AAEiC,MAAA;AAClC,IAAA;AACD,EAAA;AAE4D,kBAAA;AACrB,IAAA;AACmB,MAAA;AACvD,QAAA;AACD,MAAA;AAE6B,MAAA;AACoB,QAAA;AACR,UAAA;AACxC,QAAA;AACA,QAAA;AACD,MAAA;AAEgD,MAAA;AACO,QAAA;AACvD,MAAA;AACD,IAAA;AACD,EAAA;AACD;ADqMqE;AACA;AUxTe;AACvC,EAAA;AAC7C;AV0TqE;AACA;AACA;AACA","file":"/home/runner/work/baeta/baeta/packages/extension-complexity/dist/index.cjs","sourcesContent":[null,"import {\n\tExtension,\n\ttype ModuleBuilder,\n\ttype NativeMiddleware,\n\ttype ResolverMapper,\n} from '@baeta/core/sdk';\nimport { calculateComplexity } from './complexity-calculator.ts';\nimport { ComplexityErrorKind } from './complexity-errors.ts';\nimport {\n\ttype ComplexityExtensionOptions,\n\tdefaultLimits,\n\tnormalizeOptions,\n} from './complexity-options.ts';\nimport { type FieldSettingsMap, registerFieldSettingsSetter } from './field-settings.ts';\nimport { loadComplexityStore } from './store-loader.ts';\nimport { getComplexityStore } from './store.ts';\n\nexport class ComplexityExtension<Ctx> extends Extension {\n\tprivate readonly options: Required<ComplexityExtensionOptions<Ctx>>;\n\n\tconstructor(options: ComplexityExtensionOptions<Ctx> = {}) {\n\t\tsuper();\n\t\tthis.options = normalizeOptions(options);\n\t}\n\n\tprivate fieldSettingsMap: FieldSettingsMap = {};\n\n\tgetTypeExtensions = <Root, Context>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t): BaetaExtensions.TypeExtensions<Root, Context> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, '*', fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetResolverExtensions = <Result, Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t\tfield: string,\n\t): BaetaExtensions.ResolverExtensions<Result, Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetSubscriptionExtensions = <Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\tfield: string,\n\t): BaetaExtensions.SubscriptionExtensions<Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter('Subscription', field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tcreateComplexityMiddleware<Result, Root, Context, Args>(): NativeMiddleware<\n\t\tResult,\n\t\tRoot,\n\t\tContext,\n\t\tArgs\n\t> {\n\t\treturn (next) => async (root, args, ctx, info) => {\n\t\t\tloadComplexityStore(ctx as unknown as Ctx, this.options.limit, defaultLimits);\n\n\t\t\tconst store = await getComplexityStore(ctx);\n\n\t\t\tconst limits = store.limits;\n\n\t\t\tconst results = store.cacheComplexity(() => {\n\t\t\t\treturn calculateComplexity(ctx as unknown as Ctx, info, this.fieldSettingsMap, {\n\t\t\t\t\tcomplexity: this.options.defaultComplexity,\n\t\t\t\t\tmultiplier: this.options.defaultListMultiplier,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (results.depth > limits.depth) {\n\t\t\t\tthrow this.options.complexityError(ComplexityErrorKind.Depth, limits.depth, results.depth);\n\t\t\t}\n\n\t\t\tif (results.breadth > limits.breadth) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Breadth,\n\t\t\t\t\tlimits.breadth,\n\t\t\t\t\tresults.breadth,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (results.complexity > limits.complexity) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Complexity,\n\t\t\t\t\tlimits.complexity,\n\t\t\t\t\tresults.complexity,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn next(root, args, ctx, info);\n\t\t};\n\t}\n\n\tbuild = (_module: ModuleBuilder, mapper: ResolverMapper) => {\n\t\tfor (const type of mapper.getTypes()) {\n\t\t\tif (type !== 'Query' && type !== 'Mutation' && type !== 'Subscription') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (type !== 'Subscription') {\n\t\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\t\tmapper.addMiddleware(type, field, this.createComplexityMiddleware());\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\tmapper.addMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());\n\t\t\t}\n\t\t}\n\t};\n}\n","import { ValidationError } from '@baeta/errors';\nimport {\n\ttype FieldNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\ttype InlineFragmentNode,\n\tKind,\n\ttype SelectionNode,\n\ttype SelectionSetNode,\n\tgetNamedType,\n\tisInterfaceType,\n\tisObjectType,\n\tisOutputType,\n} from 'graphql';\nimport { isListOrNullableList } from '../utils/graphlq.ts';\nimport { capitalize } from '../utils/string.ts';\nimport { type FieldSettingsMap, getFieldComplexitySettings } from './field-settings.ts';\n\ninterface ComplexityDefaults {\n\tcomplexity: number;\n\tmultiplier: number;\n}\n\nexport function calculateComplexity<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst operationName = capitalize(info.operation.operation);\n\tconst operationType = info.schema.getType(operationName);\n\n\tif (!operationType || !isOutputType(operationType)) {\n\t\tthrow new ValidationError(`Unsupported operation ${operationName}`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\toperationType,\n\t\tinfo.operation.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromSelectionSet<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselectionSet: SelectionSetNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst result = {\n\t\tdepth: 0,\n\t\tbreadth: 0,\n\t\tcomplexity: 0,\n\t};\n\n\tfor (const selection of selectionSet.selections) {\n\t\tconst selectionResult = complexityFromSelection(\n\t\t\tctx,\n\t\t\tinfo,\n\t\t\ttype,\n\t\t\tselection,\n\t\t\tfieldSettingsMap,\n\t\t\tdefaults,\n\t\t);\n\t\tresult.complexity += selectionResult.complexity;\n\t\tresult.breadth += selectionResult.breadth;\n\t\tresult.depth = Math.max(result.depth, selectionResult.depth);\n\t}\n\n\treturn result;\n}\n\nfunction complexityFromSelection<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: SelectionNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tif (selection.kind === Kind.FIELD) {\n\t\treturn complexityFromField(ctx, info, type, selection, fieldSettingsMap, defaults);\n\t}\n\n\tif (selection.kind === Kind.FRAGMENT_SPREAD) {\n\t\tconst fragment = info.fragments[selection.name.value];\n\n\t\tif (!fragment) {\n\t\t\tthrow new ValidationError(`Fragment ${selection.name.value} not found`);\n\t\t}\n\n\t\treturn complexityFromFragment(ctx, info, type, fragment, fieldSettingsMap, defaults);\n\t}\n\n\treturn complexityFromFragment(ctx, info, type, selection, fieldSettingsMap, defaults);\n}\n\nfunction complexityFromFragment<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfragment: FragmentDefinitionNode | InlineFragmentNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fragmentType = fragment.typeCondition\n\t\t? info.schema.getType(fragment.typeCondition.name.value)\n\t\t: type;\n\n\tif (!isOutputType(fragmentType)) {\n\t\tthrow new ValidationError(`Unsupported fragment type ${fragmentType}`);\n\t}\n\n\tif (!fragmentType) {\n\t\tthrow new ValidationError(`Fragment type ${fragmentType} not found`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tfragmentType,\n\t\tfragment.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromField<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: FieldNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fieldName = selection.name.value;\n\n\tconst field =\n\t\tisObjectType(type) || isInterfaceType(type) ? type.getFields()[fieldName] : undefined;\n\n\tif (!field && !fieldName.startsWith('__')) {\n\t\tthrow new ValidationError(`Field ${fieldName} not found on type ${type.name}`);\n\t}\n\n\tif (!field) {\n\t\treturn {\n\t\t\tdepth: 1,\n\t\t\tbreadth: 1,\n\t\t\tcomplexity: 1,\n\t\t};\n\t}\n\n\tconst fieldComplexitySettings = getFieldComplexitySettings(\n\t\tctx,\n\t\tinfo,\n\t\ttype,\n\t\tfield,\n\t\tselection,\n\t\tfieldName,\n\t\tfieldSettingsMap,\n\t);\n\n\tif (fieldComplexitySettings === false) {\n\t\treturn {\n\t\t\tdepth: 0,\n\t\t\tbreadth: 0,\n\t\t\tcomplexity: 0,\n\t\t};\n\t}\n\n\tlet depth = 1;\n\tlet breadth = 1;\n\tlet complexity = 0;\n\n\tconst listMultiplier = fieldComplexitySettings?.multiplier ?? defaults.multiplier;\n\tconst multiplier = field && isListOrNullableList(field.type) ? listMultiplier : 1;\n\n\tcomplexity += (fieldComplexitySettings?.complexity ?? defaults.complexity) * multiplier;\n\n\tif (!field || !selection.selectionSet) {\n\t\treturn {\n\t\t\tdepth,\n\t\t\tbreadth,\n\t\t\tcomplexity,\n\t\t};\n\t}\n\n\tconst subSelection = complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tgetNamedType(field.type),\n\t\tselection.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n\n\tdepth += subSelection.depth;\n\tbreadth += subSelection.breadth;\n\tcomplexity += subSelection.complexity * Math.max(multiplier, 1);\n\n\treturn {\n\t\tdepth,\n\t\tbreadth,\n\t\tcomplexity,\n\t};\n}\n","import { GraphQLList, GraphQLNonNull, type GraphQLOutputType } from 'graphql';\n\nexport function isListOrNullableList(type: GraphQLOutputType): boolean {\n\tif (type instanceof GraphQLList) {\n\t\treturn true;\n\t}\n\n\tif (type instanceof GraphQLNonNull) {\n\t\treturn isListOrNullableList(type.ofType);\n\t}\n\n\treturn false;\n}\n","export function capitalize(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import {\n\ttype FieldNode,\n\ttype GraphQLField,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\tgetArgumentValues,\n} from 'graphql';\n\nexport type FieldSettingsMap = Record<\n\tstring,\n\t// biome-ignore lint/suspicious/noExplicitAny: Match any type from the original code\n\tRecord<string, GetFieldSettings<any, any> | undefined> | undefined\n>;\n\nexport type FieldSettings = {\n\tcomplexity?: number;\n\tmultiplier?: number;\n};\n\nexport type GetFieldSettingsArgs<Context, Args> = {\n\targs: Args;\n\tctx: Context;\n};\n\nexport type GetFieldSettings<Context, Args> = (\n\tparams: GetFieldSettingsArgs<Context, Args>,\n) => FieldSettings | false;\n\nexport function getFieldComplexitySettings<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfield: GraphQLField<unknown, unknown>,\n\tselection: FieldNode,\n\tfieldName: string,\n\tfieldSettingsMap: FieldSettingsMap,\n) {\n\tconst args = getArgumentValues(field, selection, info.variableValues);\n\tconst customComplexity = fieldSettingsMap[type.name]?.[fieldName];\n\n\tif (customComplexity) {\n\t\treturn customComplexity({ args, ctx });\n\t}\n\n\tconst wildCardComplexity = fieldSettingsMap[type.name]?.['*'];\n\n\tif (wildCardComplexity) {\n\t\treturn wildCardComplexity({ args, ctx });\n\t}\n}\n\nexport function registerFieldSettingsSetter<Context, Args>(\n\ttype: string,\n\tfield: string,\n\tfn: GetFieldSettings<Context, Args>,\n\tmap: FieldSettingsMap,\n) {\n\tmap[type] ??= {};\n\tmap[type][field] = fn;\n}\n","import { ValidationError } from '@baeta/errors';\nimport type { GraphQLError } from 'graphql';\n\nexport enum ComplexityErrorKind {\n\tDepth = 'DepthExceeded',\n\tBreadth = 'BreadthExceeded',\n\tComplexity = 'ComplexityExceeded',\n}\n\nexport type GetComplexityError = (\n\tkind: ComplexityErrorKind,\n\tlimits: number,\n\tresults: number,\n) => GraphQLError;\n\nexport function getDefaultComplexityError(\n\tkind: ComplexityErrorKind,\n\tlimit: number,\n\tresult: number,\n): GraphQLError {\n\tif (kind === ComplexityErrorKind.Depth) {\n\t\treturn new ValidationError(`Depth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Breadth) {\n\t\treturn new ValidationError(`Breadth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Complexity) {\n\t\treturn new ValidationError(`Complexity limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tthrow new Error('Unknown complexity error kind');\n}\n","import { type GetComplexityError, getDefaultComplexityError } from './complexity-errors.ts';\nimport type { GetComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityExtensionOptions<Context> {\n\tlimit?: GetComplexityLimit<Context>;\n\tdefaultComplexity?: number;\n\tdefaultListMultiplier?: number;\n\tcomplexityError?: GetComplexityError;\n}\n\nexport const defaultLimits = {\n\tdepth: 10,\n\tbreadth: 50,\n\tcomplexity: 1000,\n};\n\nexport type NormalizedOptions<Context> = Required<ComplexityExtensionOptions<Context>>;\n\nexport function normalizeOptions<Context>(\n\toptions: ComplexityExtensionOptions<Context>,\n): NormalizedOptions<Context> {\n\treturn {\n\t\tlimit: options.limit ?? defaultLimits,\n\t\tdefaultComplexity: options.defaultComplexity ?? 1,\n\t\tdefaultListMultiplier: options.defaultListMultiplier ?? 10,\n\t\tcomplexityError: options.complexityError ?? getDefaultComplexityError,\n\t};\n}\n","import { createContextStore } from '@baeta/core';\nimport type { ComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityStore {\n\tlimits: Required<ComplexityLimit>;\n\tcacheComplexity: (fn: () => Required<ComplexityLimit>) => Required<ComplexityLimit>;\n}\n\nexport const complexityStoreKey = Symbol('complexity-extension');\n\nexport const [getComplexityStore, setComplexityStoreLoader] =\n\tcreateContextStore<ComplexityStore>(complexityStoreKey);\n","import type { ComplexityLimit } from './complexity-limits.ts';\nimport { setComplexityStoreLoader } from './store.ts';\n\nexport function loadComplexityStore<T>(\n\tctx: T,\n\tgetLimits: ComplexityLimit | ((ctx: T) => ComplexityLimit | Promise<ComplexityLimit>) | undefined,\n\tdefaultLimits: Required<ComplexityLimit>,\n) {\n\tsetComplexityStoreLoader(ctx, async () => {\n\t\tconst limits = typeof getLimits === 'function' ? await getLimits(ctx) : getLimits;\n\n\t\tlet cache: Required<ComplexityLimit> | undefined = undefined;\n\n\t\tconst cacheComplexity = (fn: () => Required<ComplexityLimit>) => {\n\t\t\tif (cache) {\n\t\t\t\treturn cache;\n\t\t\t}\n\n\t\t\tcache = fn();\n\t\t\treturn cache;\n\t\t};\n\n\t\treturn {\n\t\t\tlimits: {\n\t\t\t\tdepth: limits?.depth ?? defaultLimits.depth,\n\t\t\t\tbreadth: limits?.breadth ?? defaultLimits.breadth,\n\t\t\t\tcomplexity: limits?.complexity ?? defaultLimits.complexity,\n\t\t\t},\n\t\t\tcacheComplexity,\n\t\t};\n\t});\n}\n","import './lib/global-types.ts';\n\nimport { ComplexityExtension } from './lib/complexity-extension.ts';\nimport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport { ComplexityErrorKind, type GetComplexityError } from './lib/complexity-errors.ts';\nexport type { ComplexityLimit, GetComplexityLimit } from './lib/complexity-limits.ts';\nexport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport function complexityExtension<Ctx>(options?: ComplexityExtensionOptions<Ctx>) {\n\treturn () => new ComplexityExtension(options);\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/baeta/baeta/packages/extension-complexity/dist/index.cjs","../lib/complexity-extension.ts","../lib/complexity-calculator.ts","../utils/graphlq.ts","../utils/string.ts","../lib/field-settings.ts","../lib/complexity-errors.ts","../lib/complexity-options.ts","../lib/store.ts","../lib/store-loader.ts","../index.ts"],"names":["ComplexityErrorKind"],"mappings":"AAAA;ACAA;AACC;AAAA,sCAIM;ADDP;AACA;AELA,uCAAgC;AAChC;AAMC;AAGA;AACA;AACA;AACA;AAAA,kCACM;AFAP;AACA;AGfA;AAEO,SAAS,oBAAA,CAAqB,IAAA,EAAkC;AACtE,EAAA,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AACxC,EAAA;AAE8C,iBAAA;AAKM,kBAAA;AAC5C,IAAA;AACe,MAAA;AAC4B,QAAA;AACjD,MAAA;AACD,IAAA;AACD,EAAA;AAMsE,kBAAA;AAC9D,IAAA;AACe,MAAA;AAC8B,QAAA;AACnD,MAAA;AACD,IAAA;AACD,EAAA;AAKkE,kBAAA;AAC1D,IAAA;AACe,MAAA;AACwC,QAAA;AAC7D,MAAA;AACD,IAAA;AACD,EAAA;AAOE,EAAA;AACiD,IAAA;AAC2B,MAAA;AAElC,MAAA;AAErB,MAAA;AAEuB,MAAA;AACoC,QAAA;AACrD,UAAA;AACA,UAAA;AACzB,QAAA;AACD,MAAA;AAEiC,MAAA;AACd,QAAA;AACpB,MAAA;AAEsC,MAAA;AAClB,QAAA;AAAA,UAAA;AAEX,UAAA;AACC,UAAA;AACT,QAAA;AACD,MAAA;AAE4C,MAAA;AACxB,QAAA;AAAA,UAAA;AAEX,UAAA;AACC,UAAA;AACT,QAAA;AACD,MAAA;AAEiC,MAAA;AAClC,IAAA;AACD,EAAA;AAE4D,kBAAA;AACrB,IAAA;AACmB,MAAA;AACvD,QAAA;AACD,MAAA;AAE6B,MAAA;AACoB,QAAA;AACJ,UAAA;AAC5C,QAAA;AACA,QAAA;AACD,MAAA;AAEgD,MAAA;AACW,QAAA;AAC3D,MAAA;AACD,IAAA;AACD,EAAA;AACD;ADqMqE;AACA;AUxTe;AACvC,EAAA;AAC7C;AV0TqE;AACA;AACA;AACA","file":"/home/runner/work/baeta/baeta/packages/extension-complexity/dist/index.cjs","sourcesContent":[null,"import {\n\tExtension,\n\ttype ModuleBuilder,\n\ttype NativeMiddleware,\n\ttype ResolverMapper,\n} from '@baeta/core/sdk';\nimport { calculateComplexity } from './complexity-calculator.ts';\nimport { ComplexityErrorKind } from './complexity-errors.ts';\nimport {\n\ttype ComplexityExtensionOptions,\n\tdefaultLimits,\n\tnormalizeOptions,\n} from './complexity-options.ts';\nimport { type FieldSettingsMap, registerFieldSettingsSetter } from './field-settings.ts';\nimport { loadComplexityStore } from './store-loader.ts';\nimport { getComplexityStore } from './store.ts';\n\nexport class ComplexityExtension<Ctx> extends Extension {\n\tprivate readonly options: Required<ComplexityExtensionOptions<Ctx>>;\n\n\tconstructor(options: ComplexityExtensionOptions<Ctx> = {}) {\n\t\tsuper();\n\t\tthis.options = normalizeOptions(options);\n\t}\n\n\tprivate fieldSettingsMap: FieldSettingsMap = {};\n\n\tgetTypeExtensions = <Root, Context>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t): BaetaExtensions.TypeExtensions<Root, Context> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, '*', fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetResolverExtensions = <Result, Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t\tfield: string,\n\t): BaetaExtensions.ResolverExtensions<Result, Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetSubscriptionExtensions = <Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\tfield: string,\n\t): BaetaExtensions.SubscriptionExtensions<Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter('Subscription', field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tcreateComplexityMiddleware<Result, Root, Context, Args>(): NativeMiddleware<\n\t\tResult,\n\t\tRoot,\n\t\tContext,\n\t\tArgs\n\t> {\n\t\treturn (next) => async (root, args, ctx, info) => {\n\t\t\tloadComplexityStore(ctx as unknown as Ctx, this.options.limit, defaultLimits);\n\n\t\t\tconst store = await getComplexityStore(ctx);\n\n\t\t\tconst limits = store.limits;\n\n\t\t\tconst results = store.cacheComplexity(() => {\n\t\t\t\treturn calculateComplexity(ctx as unknown as Ctx, info, this.fieldSettingsMap, {\n\t\t\t\t\tcomplexity: this.options.defaultComplexity,\n\t\t\t\t\tmultiplier: this.options.defaultListMultiplier,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (results.depth > limits.depth) {\n\t\t\t\tthrow this.options.complexityError(ComplexityErrorKind.Depth, limits.depth, results.depth);\n\t\t\t}\n\n\t\t\tif (results.breadth > limits.breadth) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Breadth,\n\t\t\t\t\tlimits.breadth,\n\t\t\t\t\tresults.breadth,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (results.complexity > limits.complexity) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Complexity,\n\t\t\t\t\tlimits.complexity,\n\t\t\t\t\tresults.complexity,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn next(root, args, ctx, info);\n\t\t};\n\t}\n\n\tbuild = (_module: ModuleBuilder, mapper: ResolverMapper) => {\n\t\tfor (const type of mapper.getTypes()) {\n\t\t\tif (type !== 'Query' && type !== 'Mutation' && type !== 'Subscription') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (type !== 'Subscription') {\n\t\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\t\tmapper.prependMiddleware(type, field, this.createComplexityMiddleware());\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\tmapper.prependMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());\n\t\t\t}\n\t\t}\n\t};\n}\n","import { ValidationError } from '@baeta/errors';\nimport {\n\ttype FieldNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\ttype InlineFragmentNode,\n\tKind,\n\ttype SelectionNode,\n\ttype SelectionSetNode,\n\tgetNamedType,\n\tisInterfaceType,\n\tisObjectType,\n\tisOutputType,\n} from 'graphql';\nimport { isListOrNullableList } from '../utils/graphlq.ts';\nimport { capitalize } from '../utils/string.ts';\nimport { type FieldSettingsMap, getFieldComplexitySettings } from './field-settings.ts';\n\ninterface ComplexityDefaults {\n\tcomplexity: number;\n\tmultiplier: number;\n}\n\nexport function calculateComplexity<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst operationName = capitalize(info.operation.operation);\n\tconst operationType = info.schema.getType(operationName);\n\n\tif (!operationType || !isOutputType(operationType)) {\n\t\tthrow new ValidationError(`Unsupported operation ${operationName}`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\toperationType,\n\t\tinfo.operation.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromSelectionSet<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselectionSet: SelectionSetNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst result = {\n\t\tdepth: 0,\n\t\tbreadth: 0,\n\t\tcomplexity: 0,\n\t};\n\n\tfor (const selection of selectionSet.selections) {\n\t\tconst selectionResult = complexityFromSelection(\n\t\t\tctx,\n\t\t\tinfo,\n\t\t\ttype,\n\t\t\tselection,\n\t\t\tfieldSettingsMap,\n\t\t\tdefaults,\n\t\t);\n\t\tresult.complexity += selectionResult.complexity;\n\t\tresult.breadth += selectionResult.breadth;\n\t\tresult.depth = Math.max(result.depth, selectionResult.depth);\n\t}\n\n\treturn result;\n}\n\nfunction complexityFromSelection<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: SelectionNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tif (selection.kind === Kind.FIELD) {\n\t\treturn complexityFromField(ctx, info, type, selection, fieldSettingsMap, defaults);\n\t}\n\n\tif (selection.kind === Kind.FRAGMENT_SPREAD) {\n\t\tconst fragment = info.fragments[selection.name.value];\n\n\t\tif (!fragment) {\n\t\t\tthrow new ValidationError(`Fragment ${selection.name.value} not found`);\n\t\t}\n\n\t\treturn complexityFromFragment(ctx, info, type, fragment, fieldSettingsMap, defaults);\n\t}\n\n\treturn complexityFromFragment(ctx, info, type, selection, fieldSettingsMap, defaults);\n}\n\nfunction complexityFromFragment<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfragment: FragmentDefinitionNode | InlineFragmentNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fragmentType = fragment.typeCondition\n\t\t? info.schema.getType(fragment.typeCondition.name.value)\n\t\t: type;\n\n\tif (!isOutputType(fragmentType)) {\n\t\tthrow new ValidationError(`Unsupported fragment type ${fragmentType}`);\n\t}\n\n\tif (!fragmentType) {\n\t\tthrow new ValidationError(`Fragment type ${fragmentType} not found`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tfragmentType,\n\t\tfragment.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromField<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: FieldNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fieldName = selection.name.value;\n\n\tconst field =\n\t\tisObjectType(type) || isInterfaceType(type) ? type.getFields()[fieldName] : undefined;\n\n\tif (!field && !fieldName.startsWith('__')) {\n\t\tthrow new ValidationError(`Field ${fieldName} not found on type ${type.name}`);\n\t}\n\n\tif (!field) {\n\t\treturn {\n\t\t\tdepth: 1,\n\t\t\tbreadth: 1,\n\t\t\tcomplexity: 1,\n\t\t};\n\t}\n\n\tconst fieldComplexitySettings = getFieldComplexitySettings(\n\t\tctx,\n\t\tinfo,\n\t\ttype,\n\t\tfield,\n\t\tselection,\n\t\tfieldName,\n\t\tfieldSettingsMap,\n\t);\n\n\tif (fieldComplexitySettings === false) {\n\t\treturn {\n\t\t\tdepth: 0,\n\t\t\tbreadth: 0,\n\t\t\tcomplexity: 0,\n\t\t};\n\t}\n\n\tlet depth = 1;\n\tlet breadth = 1;\n\tlet complexity = 0;\n\n\tconst listMultiplier = fieldComplexitySettings?.multiplier ?? defaults.multiplier;\n\tconst multiplier = field && isListOrNullableList(field.type) ? listMultiplier : 1;\n\n\tcomplexity += (fieldComplexitySettings?.complexity ?? defaults.complexity) * multiplier;\n\n\tif (!field || !selection.selectionSet) {\n\t\treturn {\n\t\t\tdepth,\n\t\t\tbreadth,\n\t\t\tcomplexity,\n\t\t};\n\t}\n\n\tconst subSelection = complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tgetNamedType(field.type),\n\t\tselection.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n\n\tdepth += subSelection.depth;\n\tbreadth += subSelection.breadth;\n\tcomplexity += subSelection.complexity * Math.max(multiplier, 1);\n\n\treturn {\n\t\tdepth,\n\t\tbreadth,\n\t\tcomplexity,\n\t};\n}\n","import { GraphQLList, GraphQLNonNull, type GraphQLOutputType } from 'graphql';\n\nexport function isListOrNullableList(type: GraphQLOutputType): boolean {\n\tif (type instanceof GraphQLList) {\n\t\treturn true;\n\t}\n\n\tif (type instanceof GraphQLNonNull) {\n\t\treturn isListOrNullableList(type.ofType);\n\t}\n\n\treturn false;\n}\n","export function capitalize(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import {\n\ttype FieldNode,\n\ttype GraphQLField,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\tgetArgumentValues,\n} from 'graphql';\n\nexport type FieldSettingsMap = Record<\n\tstring,\n\t// biome-ignore lint/suspicious/noExplicitAny: Match any type from the original code\n\tRecord<string, GetFieldSettings<any, any> | undefined> | undefined\n>;\n\nexport type FieldSettings = {\n\tcomplexity?: number;\n\tmultiplier?: number;\n};\n\nexport type GetFieldSettingsArgs<Context, Args> = {\n\targs: Args;\n\tctx: Context;\n};\n\nexport type GetFieldSettings<Context, Args> = (\n\tparams: GetFieldSettingsArgs<Context, Args>,\n) => FieldSettings | false;\n\nexport function getFieldComplexitySettings<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfield: GraphQLField<unknown, unknown>,\n\tselection: FieldNode,\n\tfieldName: string,\n\tfieldSettingsMap: FieldSettingsMap,\n) {\n\tconst args = getArgumentValues(field, selection, info.variableValues);\n\tconst customComplexity = fieldSettingsMap[type.name]?.[fieldName];\n\n\tif (customComplexity) {\n\t\treturn customComplexity({ args, ctx });\n\t}\n\n\tconst wildCardComplexity = fieldSettingsMap[type.name]?.['*'];\n\n\tif (wildCardComplexity) {\n\t\treturn wildCardComplexity({ args, ctx });\n\t}\n}\n\nexport function registerFieldSettingsSetter<Context, Args>(\n\ttype: string,\n\tfield: string,\n\tfn: GetFieldSettings<Context, Args>,\n\tmap: FieldSettingsMap,\n) {\n\tmap[type] ??= {};\n\tmap[type][field] = fn;\n}\n","import { ValidationError } from '@baeta/errors';\nimport type { GraphQLError } from 'graphql';\n\nexport enum ComplexityErrorKind {\n\tDepth = 'DepthExceeded',\n\tBreadth = 'BreadthExceeded',\n\tComplexity = 'ComplexityExceeded',\n}\n\nexport type GetComplexityError = (\n\tkind: ComplexityErrorKind,\n\tlimits: number,\n\tresults: number,\n) => GraphQLError;\n\nexport function getDefaultComplexityError(\n\tkind: ComplexityErrorKind,\n\tlimit: number,\n\tresult: number,\n): GraphQLError {\n\tif (kind === ComplexityErrorKind.Depth) {\n\t\treturn new ValidationError(`Depth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Breadth) {\n\t\treturn new ValidationError(`Breadth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Complexity) {\n\t\treturn new ValidationError(`Complexity limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tthrow new Error('Unknown complexity error kind');\n}\n","import { type GetComplexityError, getDefaultComplexityError } from './complexity-errors.ts';\nimport type { GetComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityExtensionOptions<Context> {\n\tlimit?: GetComplexityLimit<Context>;\n\tdefaultComplexity?: number;\n\tdefaultListMultiplier?: number;\n\tcomplexityError?: GetComplexityError;\n}\n\nexport const defaultLimits = {\n\tdepth: 10,\n\tbreadth: 50,\n\tcomplexity: 1000,\n};\n\nexport type NormalizedOptions<Context> = Required<ComplexityExtensionOptions<Context>>;\n\nexport function normalizeOptions<Context>(\n\toptions: ComplexityExtensionOptions<Context>,\n): NormalizedOptions<Context> {\n\treturn {\n\t\tlimit: options.limit ?? defaultLimits,\n\t\tdefaultComplexity: options.defaultComplexity ?? 1,\n\t\tdefaultListMultiplier: options.defaultListMultiplier ?? 10,\n\t\tcomplexityError: options.complexityError ?? getDefaultComplexityError,\n\t};\n}\n","import { createContextStore } from '@baeta/core';\nimport type { ComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityStore {\n\tlimits: Required<ComplexityLimit>;\n\tcacheComplexity: (fn: () => Required<ComplexityLimit>) => Required<ComplexityLimit>;\n}\n\nexport const complexityStoreKey = Symbol('complexity-extension');\n\nexport const [getComplexityStore, setComplexityStoreLoader] =\n\tcreateContextStore<ComplexityStore>(complexityStoreKey);\n","import type { ComplexityLimit } from './complexity-limits.ts';\nimport { setComplexityStoreLoader } from './store.ts';\n\nexport function loadComplexityStore<T>(\n\tctx: T,\n\tgetLimits: ComplexityLimit | ((ctx: T) => ComplexityLimit | Promise<ComplexityLimit>) | undefined,\n\tdefaultLimits: Required<ComplexityLimit>,\n) {\n\tsetComplexityStoreLoader(ctx, async () => {\n\t\tconst limits = typeof getLimits === 'function' ? await getLimits(ctx) : getLimits;\n\n\t\tlet cache: Required<ComplexityLimit> | undefined = undefined;\n\n\t\tconst cacheComplexity = (fn: () => Required<ComplexityLimit>) => {\n\t\t\tif (cache) {\n\t\t\t\treturn cache;\n\t\t\t}\n\n\t\t\tcache = fn();\n\t\t\treturn cache;\n\t\t};\n\n\t\treturn {\n\t\t\tlimits: {\n\t\t\t\tdepth: limits?.depth ?? defaultLimits.depth,\n\t\t\t\tbreadth: limits?.breadth ?? defaultLimits.breadth,\n\t\t\t\tcomplexity: limits?.complexity ?? defaultLimits.complexity,\n\t\t\t},\n\t\t\tcacheComplexity,\n\t\t};\n\t});\n}\n","import './lib/global-types.ts';\n\nimport { ComplexityExtension } from './lib/complexity-extension.ts';\nimport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport { ComplexityErrorKind, type GetComplexityError } from './lib/complexity-errors.ts';\nexport type { ComplexityLimit, GetComplexityLimit } from './lib/complexity-limits.ts';\nexport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport function complexityExtension<Ctx>(options?: ComplexityExtensionOptions<Ctx>) {\n\treturn () => new ComplexityExtension(options);\n}\n"]}
package/dist/index.js CHANGED
@@ -308,12 +308,12 @@ var ComplexityExtension = class extends Extension {
308
308
  }
309
309
  if (type !== "Subscription") {
310
310
  for (const field of mapper.getTypeFields(type)) {
311
- mapper.addMiddleware(type, field, this.createComplexityMiddleware());
311
+ mapper.prependMiddleware(type, field, this.createComplexityMiddleware());
312
312
  }
313
313
  continue;
314
314
  }
315
315
  for (const field of mapper.getTypeFields(type)) {
316
- mapper.addMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());
316
+ mapper.prependMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());
317
317
  }
318
318
  }
319
319
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/complexity-extension.ts","../lib/complexity-calculator.ts","../utils/graphlq.ts","../utils/string.ts","../lib/field-settings.ts","../lib/complexity-errors.ts","../lib/complexity-options.ts","../lib/store.ts","../lib/store-loader.ts","../index.ts"],"sourcesContent":["import {\n\tExtension,\n\ttype ModuleBuilder,\n\ttype NativeMiddleware,\n\ttype ResolverMapper,\n} from '@baeta/core/sdk';\nimport { calculateComplexity } from './complexity-calculator.ts';\nimport { ComplexityErrorKind } from './complexity-errors.ts';\nimport {\n\ttype ComplexityExtensionOptions,\n\tdefaultLimits,\n\tnormalizeOptions,\n} from './complexity-options.ts';\nimport { type FieldSettingsMap, registerFieldSettingsSetter } from './field-settings.ts';\nimport { loadComplexityStore } from './store-loader.ts';\nimport { getComplexityStore } from './store.ts';\n\nexport class ComplexityExtension<Ctx> extends Extension {\n\tprivate readonly options: Required<ComplexityExtensionOptions<Ctx>>;\n\n\tconstructor(options: ComplexityExtensionOptions<Ctx> = {}) {\n\t\tsuper();\n\t\tthis.options = normalizeOptions(options);\n\t}\n\n\tprivate fieldSettingsMap: FieldSettingsMap = {};\n\n\tgetTypeExtensions = <Root, Context>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t): BaetaExtensions.TypeExtensions<Root, Context> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, '*', fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetResolverExtensions = <Result, Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t\tfield: string,\n\t): BaetaExtensions.ResolverExtensions<Result, Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetSubscriptionExtensions = <Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\tfield: string,\n\t): BaetaExtensions.SubscriptionExtensions<Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter('Subscription', field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tcreateComplexityMiddleware<Result, Root, Context, Args>(): NativeMiddleware<\n\t\tResult,\n\t\tRoot,\n\t\tContext,\n\t\tArgs\n\t> {\n\t\treturn (next) => async (root, args, ctx, info) => {\n\t\t\tloadComplexityStore(ctx as unknown as Ctx, this.options.limit, defaultLimits);\n\n\t\t\tconst store = await getComplexityStore(ctx);\n\n\t\t\tconst limits = store.limits;\n\n\t\t\tconst results = store.cacheComplexity(() => {\n\t\t\t\treturn calculateComplexity(ctx as unknown as Ctx, info, this.fieldSettingsMap, {\n\t\t\t\t\tcomplexity: this.options.defaultComplexity,\n\t\t\t\t\tmultiplier: this.options.defaultListMultiplier,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (results.depth > limits.depth) {\n\t\t\t\tthrow this.options.complexityError(ComplexityErrorKind.Depth, limits.depth, results.depth);\n\t\t\t}\n\n\t\t\tif (results.breadth > limits.breadth) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Breadth,\n\t\t\t\t\tlimits.breadth,\n\t\t\t\t\tresults.breadth,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (results.complexity > limits.complexity) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Complexity,\n\t\t\t\t\tlimits.complexity,\n\t\t\t\t\tresults.complexity,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn next(root, args, ctx, info);\n\t\t};\n\t}\n\n\tbuild = (_module: ModuleBuilder, mapper: ResolverMapper) => {\n\t\tfor (const type of mapper.getTypes()) {\n\t\t\tif (type !== 'Query' && type !== 'Mutation' && type !== 'Subscription') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (type !== 'Subscription') {\n\t\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\t\tmapper.addMiddleware(type, field, this.createComplexityMiddleware());\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\tmapper.addMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());\n\t\t\t}\n\t\t}\n\t};\n}\n","import { ValidationError } from '@baeta/errors';\nimport {\n\ttype FieldNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\ttype InlineFragmentNode,\n\tKind,\n\ttype SelectionNode,\n\ttype SelectionSetNode,\n\tgetNamedType,\n\tisInterfaceType,\n\tisObjectType,\n\tisOutputType,\n} from 'graphql';\nimport { isListOrNullableList } from '../utils/graphlq.ts';\nimport { capitalize } from '../utils/string.ts';\nimport { type FieldSettingsMap, getFieldComplexitySettings } from './field-settings.ts';\n\ninterface ComplexityDefaults {\n\tcomplexity: number;\n\tmultiplier: number;\n}\n\nexport function calculateComplexity<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst operationName = capitalize(info.operation.operation);\n\tconst operationType = info.schema.getType(operationName);\n\n\tif (!operationType || !isOutputType(operationType)) {\n\t\tthrow new ValidationError(`Unsupported operation ${operationName}`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\toperationType,\n\t\tinfo.operation.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromSelectionSet<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselectionSet: SelectionSetNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst result = {\n\t\tdepth: 0,\n\t\tbreadth: 0,\n\t\tcomplexity: 0,\n\t};\n\n\tfor (const selection of selectionSet.selections) {\n\t\tconst selectionResult = complexityFromSelection(\n\t\t\tctx,\n\t\t\tinfo,\n\t\t\ttype,\n\t\t\tselection,\n\t\t\tfieldSettingsMap,\n\t\t\tdefaults,\n\t\t);\n\t\tresult.complexity += selectionResult.complexity;\n\t\tresult.breadth += selectionResult.breadth;\n\t\tresult.depth = Math.max(result.depth, selectionResult.depth);\n\t}\n\n\treturn result;\n}\n\nfunction complexityFromSelection<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: SelectionNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tif (selection.kind === Kind.FIELD) {\n\t\treturn complexityFromField(ctx, info, type, selection, fieldSettingsMap, defaults);\n\t}\n\n\tif (selection.kind === Kind.FRAGMENT_SPREAD) {\n\t\tconst fragment = info.fragments[selection.name.value];\n\n\t\tif (!fragment) {\n\t\t\tthrow new ValidationError(`Fragment ${selection.name.value} not found`);\n\t\t}\n\n\t\treturn complexityFromFragment(ctx, info, type, fragment, fieldSettingsMap, defaults);\n\t}\n\n\treturn complexityFromFragment(ctx, info, type, selection, fieldSettingsMap, defaults);\n}\n\nfunction complexityFromFragment<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfragment: FragmentDefinitionNode | InlineFragmentNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fragmentType = fragment.typeCondition\n\t\t? info.schema.getType(fragment.typeCondition.name.value)\n\t\t: type;\n\n\tif (!isOutputType(fragmentType)) {\n\t\tthrow new ValidationError(`Unsupported fragment type ${fragmentType}`);\n\t}\n\n\tif (!fragmentType) {\n\t\tthrow new ValidationError(`Fragment type ${fragmentType} not found`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tfragmentType,\n\t\tfragment.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromField<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: FieldNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fieldName = selection.name.value;\n\n\tconst field =\n\t\tisObjectType(type) || isInterfaceType(type) ? type.getFields()[fieldName] : undefined;\n\n\tif (!field && !fieldName.startsWith('__')) {\n\t\tthrow new ValidationError(`Field ${fieldName} not found on type ${type.name}`);\n\t}\n\n\tif (!field) {\n\t\treturn {\n\t\t\tdepth: 1,\n\t\t\tbreadth: 1,\n\t\t\tcomplexity: 1,\n\t\t};\n\t}\n\n\tconst fieldComplexitySettings = getFieldComplexitySettings(\n\t\tctx,\n\t\tinfo,\n\t\ttype,\n\t\tfield,\n\t\tselection,\n\t\tfieldName,\n\t\tfieldSettingsMap,\n\t);\n\n\tif (fieldComplexitySettings === false) {\n\t\treturn {\n\t\t\tdepth: 0,\n\t\t\tbreadth: 0,\n\t\t\tcomplexity: 0,\n\t\t};\n\t}\n\n\tlet depth = 1;\n\tlet breadth = 1;\n\tlet complexity = 0;\n\n\tconst listMultiplier = fieldComplexitySettings?.multiplier ?? defaults.multiplier;\n\tconst multiplier = field && isListOrNullableList(field.type) ? listMultiplier : 1;\n\n\tcomplexity += (fieldComplexitySettings?.complexity ?? defaults.complexity) * multiplier;\n\n\tif (!field || !selection.selectionSet) {\n\t\treturn {\n\t\t\tdepth,\n\t\t\tbreadth,\n\t\t\tcomplexity,\n\t\t};\n\t}\n\n\tconst subSelection = complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tgetNamedType(field.type),\n\t\tselection.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n\n\tdepth += subSelection.depth;\n\tbreadth += subSelection.breadth;\n\tcomplexity += subSelection.complexity * Math.max(multiplier, 1);\n\n\treturn {\n\t\tdepth,\n\t\tbreadth,\n\t\tcomplexity,\n\t};\n}\n","import { GraphQLList, GraphQLNonNull, type GraphQLOutputType } from 'graphql';\n\nexport function isListOrNullableList(type: GraphQLOutputType): boolean {\n\tif (type instanceof GraphQLList) {\n\t\treturn true;\n\t}\n\n\tif (type instanceof GraphQLNonNull) {\n\t\treturn isListOrNullableList(type.ofType);\n\t}\n\n\treturn false;\n}\n","export function capitalize(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import {\n\ttype FieldNode,\n\ttype GraphQLField,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\tgetArgumentValues,\n} from 'graphql';\n\nexport type FieldSettingsMap = Record<\n\tstring,\n\t// biome-ignore lint/suspicious/noExplicitAny: Match any type from the original code\n\tRecord<string, GetFieldSettings<any, any> | undefined> | undefined\n>;\n\nexport type FieldSettings = {\n\tcomplexity?: number;\n\tmultiplier?: number;\n};\n\nexport type GetFieldSettingsArgs<Context, Args> = {\n\targs: Args;\n\tctx: Context;\n};\n\nexport type GetFieldSettings<Context, Args> = (\n\tparams: GetFieldSettingsArgs<Context, Args>,\n) => FieldSettings | false;\n\nexport function getFieldComplexitySettings<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfield: GraphQLField<unknown, unknown>,\n\tselection: FieldNode,\n\tfieldName: string,\n\tfieldSettingsMap: FieldSettingsMap,\n) {\n\tconst args = getArgumentValues(field, selection, info.variableValues);\n\tconst customComplexity = fieldSettingsMap[type.name]?.[fieldName];\n\n\tif (customComplexity) {\n\t\treturn customComplexity({ args, ctx });\n\t}\n\n\tconst wildCardComplexity = fieldSettingsMap[type.name]?.['*'];\n\n\tif (wildCardComplexity) {\n\t\treturn wildCardComplexity({ args, ctx });\n\t}\n}\n\nexport function registerFieldSettingsSetter<Context, Args>(\n\ttype: string,\n\tfield: string,\n\tfn: GetFieldSettings<Context, Args>,\n\tmap: FieldSettingsMap,\n) {\n\tmap[type] ??= {};\n\tmap[type][field] = fn;\n}\n","import { ValidationError } from '@baeta/errors';\nimport type { GraphQLError } from 'graphql';\n\nexport enum ComplexityErrorKind {\n\tDepth = 'DepthExceeded',\n\tBreadth = 'BreadthExceeded',\n\tComplexity = 'ComplexityExceeded',\n}\n\nexport type GetComplexityError = (\n\tkind: ComplexityErrorKind,\n\tlimits: number,\n\tresults: number,\n) => GraphQLError;\n\nexport function getDefaultComplexityError(\n\tkind: ComplexityErrorKind,\n\tlimit: number,\n\tresult: number,\n): GraphQLError {\n\tif (kind === ComplexityErrorKind.Depth) {\n\t\treturn new ValidationError(`Depth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Breadth) {\n\t\treturn new ValidationError(`Breadth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Complexity) {\n\t\treturn new ValidationError(`Complexity limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tthrow new Error('Unknown complexity error kind');\n}\n","import { type GetComplexityError, getDefaultComplexityError } from './complexity-errors.ts';\nimport type { GetComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityExtensionOptions<Context> {\n\tlimit?: GetComplexityLimit<Context>;\n\tdefaultComplexity?: number;\n\tdefaultListMultiplier?: number;\n\tcomplexityError?: GetComplexityError;\n}\n\nexport const defaultLimits = {\n\tdepth: 10,\n\tbreadth: 50,\n\tcomplexity: 1000,\n};\n\nexport type NormalizedOptions<Context> = Required<ComplexityExtensionOptions<Context>>;\n\nexport function normalizeOptions<Context>(\n\toptions: ComplexityExtensionOptions<Context>,\n): NormalizedOptions<Context> {\n\treturn {\n\t\tlimit: options.limit ?? defaultLimits,\n\t\tdefaultComplexity: options.defaultComplexity ?? 1,\n\t\tdefaultListMultiplier: options.defaultListMultiplier ?? 10,\n\t\tcomplexityError: options.complexityError ?? getDefaultComplexityError,\n\t};\n}\n","import { createContextStore } from '@baeta/core';\nimport type { ComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityStore {\n\tlimits: Required<ComplexityLimit>;\n\tcacheComplexity: (fn: () => Required<ComplexityLimit>) => Required<ComplexityLimit>;\n}\n\nexport const complexityStoreKey = Symbol('complexity-extension');\n\nexport const [getComplexityStore, setComplexityStoreLoader] =\n\tcreateContextStore<ComplexityStore>(complexityStoreKey);\n","import type { ComplexityLimit } from './complexity-limits.ts';\nimport { setComplexityStoreLoader } from './store.ts';\n\nexport function loadComplexityStore<T>(\n\tctx: T,\n\tgetLimits: ComplexityLimit | ((ctx: T) => ComplexityLimit | Promise<ComplexityLimit>) | undefined,\n\tdefaultLimits: Required<ComplexityLimit>,\n) {\n\tsetComplexityStoreLoader(ctx, async () => {\n\t\tconst limits = typeof getLimits === 'function' ? await getLimits(ctx) : getLimits;\n\n\t\tlet cache: Required<ComplexityLimit> | undefined = undefined;\n\n\t\tconst cacheComplexity = (fn: () => Required<ComplexityLimit>) => {\n\t\t\tif (cache) {\n\t\t\t\treturn cache;\n\t\t\t}\n\n\t\t\tcache = fn();\n\t\t\treturn cache;\n\t\t};\n\n\t\treturn {\n\t\t\tlimits: {\n\t\t\t\tdepth: limits?.depth ?? defaultLimits.depth,\n\t\t\t\tbreadth: limits?.breadth ?? defaultLimits.breadth,\n\t\t\t\tcomplexity: limits?.complexity ?? defaultLimits.complexity,\n\t\t\t},\n\t\t\tcacheComplexity,\n\t\t};\n\t});\n}\n","import './lib/global-types.ts';\n\nimport { ComplexityExtension } from './lib/complexity-extension.ts';\nimport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport { ComplexityErrorKind, type GetComplexityError } from './lib/complexity-errors.ts';\nexport type { ComplexityLimit, GetComplexityLimit } from './lib/complexity-limits.ts';\nexport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport function complexityExtension<Ctx>(options?: ComplexityExtensionOptions<Ctx>) {\n\treturn () => new ComplexityExtension(options);\n}\n"],"mappings":";AAAA;AAAA,EACC;AAAA,OAIM;;;ACLP,SAAS,uBAAuB;AAChC;AAAA,EAMC;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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,MAC1F;AAEA,UAAI,QAAQ,UAAU,OAAO,SAAS;AACrC,cAAM,KAAK,QAAQ;AAAA;AAAA,UAElB,OAAO;AAAA,UACP,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,UAAI,QAAQ,aAAa,OAAO,YAAY;AAC3C,cAAM,KAAK,QAAQ;AAAA;AAAA,UAElB,OAAO;AAAA,UACP,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO,KAAK,MAAM,MAAM,KAAK,IAAI;AAAA,IAClC;AAAA,EACD;AAAA,EAEA,QAAQ,CAAC,SAAwB,WAA2B;AAC3D,eAAW,QAAQ,OAAO,SAAS,GAAG;AACrC,UAAI,SAAS,WAAW,SAAS,cAAc,SAAS,gBAAgB;AACvE;AAAA,MACD;AAEA,UAAI,SAAS,gBAAgB;AAC5B,mBAAW,SAAS,OAAO,cAAc,IAAI,GAAG;AAC/C,iBAAO,cAAc,MAAM,OAAO,KAAK,2BAA2B,CAAC;AAAA,QACpE;AACA;AAAA,MACD;AAEA,iBAAW,SAAS,OAAO,cAAc,IAAI,GAAG;AAC/C,eAAO,cAAc,MAAM,GAAG,KAAK,cAAc,KAAK,2BAA2B,CAAC;AAAA,MACnF;AAAA,IACD;AAAA,EACD;AACD;;;ASlHO,SAAS,oBAAyB,SAA2C;AACnF,SAAO,MAAM,IAAI,oBAAoB,OAAO;AAC7C;","names":["ValidationError","ComplexityErrorKind","defaultLimits"]}
1
+ {"version":3,"sources":["../lib/complexity-extension.ts","../lib/complexity-calculator.ts","../utils/graphlq.ts","../utils/string.ts","../lib/field-settings.ts","../lib/complexity-errors.ts","../lib/complexity-options.ts","../lib/store.ts","../lib/store-loader.ts","../index.ts"],"sourcesContent":["import {\n\tExtension,\n\ttype ModuleBuilder,\n\ttype NativeMiddleware,\n\ttype ResolverMapper,\n} from '@baeta/core/sdk';\nimport { calculateComplexity } from './complexity-calculator.ts';\nimport { ComplexityErrorKind } from './complexity-errors.ts';\nimport {\n\ttype ComplexityExtensionOptions,\n\tdefaultLimits,\n\tnormalizeOptions,\n} from './complexity-options.ts';\nimport { type FieldSettingsMap, registerFieldSettingsSetter } from './field-settings.ts';\nimport { loadComplexityStore } from './store-loader.ts';\nimport { getComplexityStore } from './store.ts';\n\nexport class ComplexityExtension<Ctx> extends Extension {\n\tprivate readonly options: Required<ComplexityExtensionOptions<Ctx>>;\n\n\tconstructor(options: ComplexityExtensionOptions<Ctx> = {}) {\n\t\tsuper();\n\t\tthis.options = normalizeOptions(options);\n\t}\n\n\tprivate fieldSettingsMap: FieldSettingsMap = {};\n\n\tgetTypeExtensions = <Root, Context>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t): BaetaExtensions.TypeExtensions<Root, Context> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, '*', fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetResolverExtensions = <Result, Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\ttype: string,\n\t\tfield: string,\n\t): BaetaExtensions.ResolverExtensions<Result, Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter(type, field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tgetSubscriptionExtensions = <Root, Context, Args>(\n\t\t_module: ModuleBuilder,\n\t\tfield: string,\n\t): BaetaExtensions.SubscriptionExtensions<Root, Context, Args> => {\n\t\treturn {\n\t\t\t$complexity: (fn) => {\n\t\t\t\tregisterFieldSettingsSetter('Subscription', field, fn, this.fieldSettingsMap);\n\t\t\t},\n\t\t};\n\t};\n\n\tcreateComplexityMiddleware<Result, Root, Context, Args>(): NativeMiddleware<\n\t\tResult,\n\t\tRoot,\n\t\tContext,\n\t\tArgs\n\t> {\n\t\treturn (next) => async (root, args, ctx, info) => {\n\t\t\tloadComplexityStore(ctx as unknown as Ctx, this.options.limit, defaultLimits);\n\n\t\t\tconst store = await getComplexityStore(ctx);\n\n\t\t\tconst limits = store.limits;\n\n\t\t\tconst results = store.cacheComplexity(() => {\n\t\t\t\treturn calculateComplexity(ctx as unknown as Ctx, info, this.fieldSettingsMap, {\n\t\t\t\t\tcomplexity: this.options.defaultComplexity,\n\t\t\t\t\tmultiplier: this.options.defaultListMultiplier,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (results.depth > limits.depth) {\n\t\t\t\tthrow this.options.complexityError(ComplexityErrorKind.Depth, limits.depth, results.depth);\n\t\t\t}\n\n\t\t\tif (results.breadth > limits.breadth) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Breadth,\n\t\t\t\t\tlimits.breadth,\n\t\t\t\t\tresults.breadth,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (results.complexity > limits.complexity) {\n\t\t\t\tthrow this.options.complexityError(\n\t\t\t\t\tComplexityErrorKind.Complexity,\n\t\t\t\t\tlimits.complexity,\n\t\t\t\t\tresults.complexity,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn next(root, args, ctx, info);\n\t\t};\n\t}\n\n\tbuild = (_module: ModuleBuilder, mapper: ResolverMapper) => {\n\t\tfor (const type of mapper.getTypes()) {\n\t\t\tif (type !== 'Query' && type !== 'Mutation' && type !== 'Subscription') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (type !== 'Subscription') {\n\t\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\t\tmapper.prependMiddleware(type, field, this.createComplexityMiddleware());\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const field of mapper.getTypeFields(type)) {\n\t\t\t\tmapper.prependMiddleware(type, `${field}.subscribe`, this.createComplexityMiddleware());\n\t\t\t}\n\t\t}\n\t};\n}\n","import { ValidationError } from '@baeta/errors';\nimport {\n\ttype FieldNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\ttype InlineFragmentNode,\n\tKind,\n\ttype SelectionNode,\n\ttype SelectionSetNode,\n\tgetNamedType,\n\tisInterfaceType,\n\tisObjectType,\n\tisOutputType,\n} from 'graphql';\nimport { isListOrNullableList } from '../utils/graphlq.ts';\nimport { capitalize } from '../utils/string.ts';\nimport { type FieldSettingsMap, getFieldComplexitySettings } from './field-settings.ts';\n\ninterface ComplexityDefaults {\n\tcomplexity: number;\n\tmultiplier: number;\n}\n\nexport function calculateComplexity<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst operationName = capitalize(info.operation.operation);\n\tconst operationType = info.schema.getType(operationName);\n\n\tif (!operationType || !isOutputType(operationType)) {\n\t\tthrow new ValidationError(`Unsupported operation ${operationName}`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\toperationType,\n\t\tinfo.operation.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromSelectionSet<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselectionSet: SelectionSetNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst result = {\n\t\tdepth: 0,\n\t\tbreadth: 0,\n\t\tcomplexity: 0,\n\t};\n\n\tfor (const selection of selectionSet.selections) {\n\t\tconst selectionResult = complexityFromSelection(\n\t\t\tctx,\n\t\t\tinfo,\n\t\t\ttype,\n\t\t\tselection,\n\t\t\tfieldSettingsMap,\n\t\t\tdefaults,\n\t\t);\n\t\tresult.complexity += selectionResult.complexity;\n\t\tresult.breadth += selectionResult.breadth;\n\t\tresult.depth = Math.max(result.depth, selectionResult.depth);\n\t}\n\n\treturn result;\n}\n\nfunction complexityFromSelection<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: SelectionNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tif (selection.kind === Kind.FIELD) {\n\t\treturn complexityFromField(ctx, info, type, selection, fieldSettingsMap, defaults);\n\t}\n\n\tif (selection.kind === Kind.FRAGMENT_SPREAD) {\n\t\tconst fragment = info.fragments[selection.name.value];\n\n\t\tif (!fragment) {\n\t\t\tthrow new ValidationError(`Fragment ${selection.name.value} not found`);\n\t\t}\n\n\t\treturn complexityFromFragment(ctx, info, type, fragment, fieldSettingsMap, defaults);\n\t}\n\n\treturn complexityFromFragment(ctx, info, type, selection, fieldSettingsMap, defaults);\n}\n\nfunction complexityFromFragment<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfragment: FragmentDefinitionNode | InlineFragmentNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fragmentType = fragment.typeCondition\n\t\t? info.schema.getType(fragment.typeCondition.name.value)\n\t\t: type;\n\n\tif (!isOutputType(fragmentType)) {\n\t\tthrow new ValidationError(`Unsupported fragment type ${fragmentType}`);\n\t}\n\n\tif (!fragmentType) {\n\t\tthrow new ValidationError(`Fragment type ${fragmentType} not found`);\n\t}\n\n\treturn complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tfragmentType,\n\t\tfragment.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n}\n\nfunction complexityFromField<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tselection: FieldNode,\n\tfieldSettingsMap: FieldSettingsMap,\n\tdefaults: ComplexityDefaults,\n) {\n\tconst fieldName = selection.name.value;\n\n\tconst field =\n\t\tisObjectType(type) || isInterfaceType(type) ? type.getFields()[fieldName] : undefined;\n\n\tif (!field && !fieldName.startsWith('__')) {\n\t\tthrow new ValidationError(`Field ${fieldName} not found on type ${type.name}`);\n\t}\n\n\tif (!field) {\n\t\treturn {\n\t\t\tdepth: 1,\n\t\t\tbreadth: 1,\n\t\t\tcomplexity: 1,\n\t\t};\n\t}\n\n\tconst fieldComplexitySettings = getFieldComplexitySettings(\n\t\tctx,\n\t\tinfo,\n\t\ttype,\n\t\tfield,\n\t\tselection,\n\t\tfieldName,\n\t\tfieldSettingsMap,\n\t);\n\n\tif (fieldComplexitySettings === false) {\n\t\treturn {\n\t\t\tdepth: 0,\n\t\t\tbreadth: 0,\n\t\t\tcomplexity: 0,\n\t\t};\n\t}\n\n\tlet depth = 1;\n\tlet breadth = 1;\n\tlet complexity = 0;\n\n\tconst listMultiplier = fieldComplexitySettings?.multiplier ?? defaults.multiplier;\n\tconst multiplier = field && isListOrNullableList(field.type) ? listMultiplier : 1;\n\n\tcomplexity += (fieldComplexitySettings?.complexity ?? defaults.complexity) * multiplier;\n\n\tif (!field || !selection.selectionSet) {\n\t\treturn {\n\t\t\tdepth,\n\t\t\tbreadth,\n\t\t\tcomplexity,\n\t\t};\n\t}\n\n\tconst subSelection = complexityFromSelectionSet(\n\t\tctx,\n\t\tinfo,\n\t\tgetNamedType(field.type),\n\t\tselection.selectionSet,\n\t\tfieldSettingsMap,\n\t\tdefaults,\n\t);\n\n\tdepth += subSelection.depth;\n\tbreadth += subSelection.breadth;\n\tcomplexity += subSelection.complexity * Math.max(multiplier, 1);\n\n\treturn {\n\t\tdepth,\n\t\tbreadth,\n\t\tcomplexity,\n\t};\n}\n","import { GraphQLList, GraphQLNonNull, type GraphQLOutputType } from 'graphql';\n\nexport function isListOrNullableList(type: GraphQLOutputType): boolean {\n\tif (type instanceof GraphQLList) {\n\t\treturn true;\n\t}\n\n\tif (type instanceof GraphQLNonNull) {\n\t\treturn isListOrNullableList(type.ofType);\n\t}\n\n\treturn false;\n}\n","export function capitalize(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import {\n\ttype FieldNode,\n\ttype GraphQLField,\n\ttype GraphQLNamedType,\n\ttype GraphQLResolveInfo,\n\tgetArgumentValues,\n} from 'graphql';\n\nexport type FieldSettingsMap = Record<\n\tstring,\n\t// biome-ignore lint/suspicious/noExplicitAny: Match any type from the original code\n\tRecord<string, GetFieldSettings<any, any> | undefined> | undefined\n>;\n\nexport type FieldSettings = {\n\tcomplexity?: number;\n\tmultiplier?: number;\n};\n\nexport type GetFieldSettingsArgs<Context, Args> = {\n\targs: Args;\n\tctx: Context;\n};\n\nexport type GetFieldSettings<Context, Args> = (\n\tparams: GetFieldSettingsArgs<Context, Args>,\n) => FieldSettings | false;\n\nexport function getFieldComplexitySettings<Context>(\n\tctx: Context,\n\tinfo: GraphQLResolveInfo,\n\ttype: GraphQLNamedType,\n\tfield: GraphQLField<unknown, unknown>,\n\tselection: FieldNode,\n\tfieldName: string,\n\tfieldSettingsMap: FieldSettingsMap,\n) {\n\tconst args = getArgumentValues(field, selection, info.variableValues);\n\tconst customComplexity = fieldSettingsMap[type.name]?.[fieldName];\n\n\tif (customComplexity) {\n\t\treturn customComplexity({ args, ctx });\n\t}\n\n\tconst wildCardComplexity = fieldSettingsMap[type.name]?.['*'];\n\n\tif (wildCardComplexity) {\n\t\treturn wildCardComplexity({ args, ctx });\n\t}\n}\n\nexport function registerFieldSettingsSetter<Context, Args>(\n\ttype: string,\n\tfield: string,\n\tfn: GetFieldSettings<Context, Args>,\n\tmap: FieldSettingsMap,\n) {\n\tmap[type] ??= {};\n\tmap[type][field] = fn;\n}\n","import { ValidationError } from '@baeta/errors';\nimport type { GraphQLError } from 'graphql';\n\nexport enum ComplexityErrorKind {\n\tDepth = 'DepthExceeded',\n\tBreadth = 'BreadthExceeded',\n\tComplexity = 'ComplexityExceeded',\n}\n\nexport type GetComplexityError = (\n\tkind: ComplexityErrorKind,\n\tlimits: number,\n\tresults: number,\n) => GraphQLError;\n\nexport function getDefaultComplexityError(\n\tkind: ComplexityErrorKind,\n\tlimit: number,\n\tresult: number,\n): GraphQLError {\n\tif (kind === ComplexityErrorKind.Depth) {\n\t\treturn new ValidationError(`Depth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Breadth) {\n\t\treturn new ValidationError(`Breadth limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tif (kind === ComplexityErrorKind.Complexity) {\n\t\treturn new ValidationError(`Complexity limit of ${limit} exceeded, got: ${result}`);\n\t}\n\n\tthrow new Error('Unknown complexity error kind');\n}\n","import { type GetComplexityError, getDefaultComplexityError } from './complexity-errors.ts';\nimport type { GetComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityExtensionOptions<Context> {\n\tlimit?: GetComplexityLimit<Context>;\n\tdefaultComplexity?: number;\n\tdefaultListMultiplier?: number;\n\tcomplexityError?: GetComplexityError;\n}\n\nexport const defaultLimits = {\n\tdepth: 10,\n\tbreadth: 50,\n\tcomplexity: 1000,\n};\n\nexport type NormalizedOptions<Context> = Required<ComplexityExtensionOptions<Context>>;\n\nexport function normalizeOptions<Context>(\n\toptions: ComplexityExtensionOptions<Context>,\n): NormalizedOptions<Context> {\n\treturn {\n\t\tlimit: options.limit ?? defaultLimits,\n\t\tdefaultComplexity: options.defaultComplexity ?? 1,\n\t\tdefaultListMultiplier: options.defaultListMultiplier ?? 10,\n\t\tcomplexityError: options.complexityError ?? getDefaultComplexityError,\n\t};\n}\n","import { createContextStore } from '@baeta/core';\nimport type { ComplexityLimit } from './complexity-limits.ts';\n\nexport interface ComplexityStore {\n\tlimits: Required<ComplexityLimit>;\n\tcacheComplexity: (fn: () => Required<ComplexityLimit>) => Required<ComplexityLimit>;\n}\n\nexport const complexityStoreKey = Symbol('complexity-extension');\n\nexport const [getComplexityStore, setComplexityStoreLoader] =\n\tcreateContextStore<ComplexityStore>(complexityStoreKey);\n","import type { ComplexityLimit } from './complexity-limits.ts';\nimport { setComplexityStoreLoader } from './store.ts';\n\nexport function loadComplexityStore<T>(\n\tctx: T,\n\tgetLimits: ComplexityLimit | ((ctx: T) => ComplexityLimit | Promise<ComplexityLimit>) | undefined,\n\tdefaultLimits: Required<ComplexityLimit>,\n) {\n\tsetComplexityStoreLoader(ctx, async () => {\n\t\tconst limits = typeof getLimits === 'function' ? await getLimits(ctx) : getLimits;\n\n\t\tlet cache: Required<ComplexityLimit> | undefined = undefined;\n\n\t\tconst cacheComplexity = (fn: () => Required<ComplexityLimit>) => {\n\t\t\tif (cache) {\n\t\t\t\treturn cache;\n\t\t\t}\n\n\t\t\tcache = fn();\n\t\t\treturn cache;\n\t\t};\n\n\t\treturn {\n\t\t\tlimits: {\n\t\t\t\tdepth: limits?.depth ?? defaultLimits.depth,\n\t\t\t\tbreadth: limits?.breadth ?? defaultLimits.breadth,\n\t\t\t\tcomplexity: limits?.complexity ?? defaultLimits.complexity,\n\t\t\t},\n\t\t\tcacheComplexity,\n\t\t};\n\t});\n}\n","import './lib/global-types.ts';\n\nimport { ComplexityExtension } from './lib/complexity-extension.ts';\nimport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport { ComplexityErrorKind, type GetComplexityError } from './lib/complexity-errors.ts';\nexport type { ComplexityLimit, GetComplexityLimit } from './lib/complexity-limits.ts';\nexport type { ComplexityExtensionOptions } from './lib/complexity-options.ts';\n\nexport function complexityExtension<Ctx>(options?: ComplexityExtensionOptions<Ctx>) {\n\treturn () => new ComplexityExtension(options);\n}\n"],"mappings":";AAAA;AAAA,EACC;AAAA,OAIM;;;ACLP,SAAS,uBAAuB;AAChC;AAAA,EAMC;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;;;ACdP,SAAS,aAAa,sBAA8C;AAE7D,SAAS,qBAAqB,MAAkC;AACtE,MAAI,gBAAgB,aAAa;AAChC,WAAO;AAAA,EACR;AAEA,MAAI,gBAAgB,gBAAgB;AACnC,WAAO,qBAAqB,KAAK,MAAM;AAAA,EACxC;AAEA,SAAO;AACR;;;ACZO,SAAS,WAAW,KAAa;AACvC,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAA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AK,MAAM,MAAM,KAAK,IAAI;AAAA,IAClC;AAAA,EACD;AAAA,EAEA,QAAQ,CAAC,SAAwB,WAA2B;AAC3D,eAAW,QAAQ,OAAO,SAAS,GAAG;AACrC,UAAI,SAAS,WAAW,SAAS,cAAc,SAAS,gBAAgB;AACvE;AAAA,MACD;AAEA,UAAI,SAAS,gBAAgB;AAC5B,mBAAW,SAAS,OAAO,cAAc,IAAI,GAAG;AAC/C,iBAAO,kBAAkB,MAAM,OAAO,KAAK,2BAA2B,CAAC;AAAA,QACxE;AACA;AAAA,MACD;AAEA,iBAAW,SAAS,OAAO,cAAc,IAAI,GAAG;AAC/C,eAAO,kBAAkB,MAAM,GAAG,KAAK,cAAc,KAAK,2BAA2B,CAAC;AAAA,MACvF;AAAA,IACD;AAAA,EACD;AACD;;;ASlHO,SAAS,oBAAyB,SAA2C;AACnF,SAAO,MAAM,IAAI,oBAAoB,OAAO;AAC7C;","names":["ValidationError","ComplexityErrorKind","defaultLimits"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/extension-complexity",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -45,13 +45,13 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@baeta/builder": "^0.0.0",
48
- "@baeta/core": "^0.1.2",
48
+ "@baeta/core": "^0.1.3",
49
49
  "@baeta/tsconfig": "^0.0.0",
50
50
  "graphql": "^16.9.0",
51
51
  "typescript": "^5.6.3"
52
52
  },
53
53
  "peerDependencies": {
54
- "@baeta/core": "^0.1.2",
54
+ "@baeta/core": "^0.1.3",
55
55
  "graphql": "^16.6.0"
56
56
  },
57
57
  "engines": {