@envelop/rate-limiter 3.0.0-alpha-25d99ca.0 → 3.0.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 (3) hide show
  1. package/index.js +31 -35
  2. package/index.mjs +31 -35
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -27,43 +27,39 @@ const useRateLimiter = (options) => {
27
27
  rateLimiterFn,
28
28
  });
29
29
  },
30
- onExecute() {
31
- return {
32
- async onResolverCalled({ args, root, context, info }) {
33
- var _a, _b, _c;
34
- const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
35
- if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
36
- const maxNode = (_a = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')) === null || _a === void 0 ? void 0 : _a.value;
37
- const windowNode = (_b = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')) === null || _b === void 0 ? void 0 : _b.value;
38
- const messageNode = (_c = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')) === null || _c === void 0 ? void 0 : _c.value;
39
- const message = messageNode.value;
40
- const max = parseInt(maxNode.value);
41
- const window = windowNode.value;
42
- const id = options.identifyFn(context);
43
- const errorMessage = await context.rateLimiterFn({ parent: root, args, context, info }, {
44
- max,
45
- window,
46
- message: interpolate(message, {
47
- id,
48
- }),
30
+ async onResolverCalled({ args, root, context, info }) {
31
+ var _a, _b, _c;
32
+ const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
33
+ if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
34
+ const maxNode = (_a = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')) === null || _a === void 0 ? void 0 : _a.value;
35
+ const windowNode = (_b = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')) === null || _b === void 0 ? void 0 : _b.value;
36
+ const messageNode = (_c = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')) === null || _c === void 0 ? void 0 : _c.value;
37
+ const message = messageNode.value;
38
+ const max = parseInt(maxNode.value);
39
+ const window = windowNode.value;
40
+ const id = options.identifyFn(context);
41
+ const errorMessage = await context.rateLimiterFn({ parent: root, args, context, info }, {
42
+ max,
43
+ window,
44
+ message: interpolate(message, {
45
+ id,
46
+ }),
47
+ });
48
+ if (errorMessage) {
49
+ if (options.onRateLimitError) {
50
+ options.onRateLimitError({
51
+ error: errorMessage,
52
+ identifier: id,
53
+ context,
54
+ info,
49
55
  });
50
- if (errorMessage) {
51
- if (options.onRateLimitError) {
52
- options.onRateLimitError({
53
- error: errorMessage,
54
- identifier: id,
55
- context,
56
- info,
57
- });
58
- }
59
- if (options.transformError) {
60
- throw options.transformError(errorMessage);
61
- }
62
- throw new Error(errorMessage);
63
- }
64
56
  }
65
- },
66
- };
57
+ if (options.transformError) {
58
+ throw options.transformError(errorMessage);
59
+ }
60
+ throw new Error(errorMessage);
61
+ }
62
+ }
67
63
  },
68
64
  };
69
65
  };
package/index.mjs CHANGED
@@ -23,43 +23,39 @@ const useRateLimiter = (options) => {
23
23
  rateLimiterFn,
24
24
  });
25
25
  },
26
- onExecute() {
27
- return {
28
- async onResolverCalled({ args, root, context, info }) {
29
- var _a, _b, _c;
30
- const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
31
- if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
32
- const maxNode = (_a = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')) === null || _a === void 0 ? void 0 : _a.value;
33
- const windowNode = (_b = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')) === null || _b === void 0 ? void 0 : _b.value;
34
- const messageNode = (_c = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')) === null || _c === void 0 ? void 0 : _c.value;
35
- const message = messageNode.value;
36
- const max = parseInt(maxNode.value);
37
- const window = windowNode.value;
38
- const id = options.identifyFn(context);
39
- const errorMessage = await context.rateLimiterFn({ parent: root, args, context, info }, {
40
- max,
41
- window,
42
- message: interpolate(message, {
43
- id,
44
- }),
26
+ async onResolverCalled({ args, root, context, info }) {
27
+ var _a, _b, _c;
28
+ const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
29
+ if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
30
+ const maxNode = (_a = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')) === null || _a === void 0 ? void 0 : _a.value;
31
+ const windowNode = (_b = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')) === null || _b === void 0 ? void 0 : _b.value;
32
+ const messageNode = (_c = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')) === null || _c === void 0 ? void 0 : _c.value;
33
+ const message = messageNode.value;
34
+ const max = parseInt(maxNode.value);
35
+ const window = windowNode.value;
36
+ const id = options.identifyFn(context);
37
+ const errorMessage = await context.rateLimiterFn({ parent: root, args, context, info }, {
38
+ max,
39
+ window,
40
+ message: interpolate(message, {
41
+ id,
42
+ }),
43
+ });
44
+ if (errorMessage) {
45
+ if (options.onRateLimitError) {
46
+ options.onRateLimitError({
47
+ error: errorMessage,
48
+ identifier: id,
49
+ context,
50
+ info,
45
51
  });
46
- if (errorMessage) {
47
- if (options.onRateLimitError) {
48
- options.onRateLimitError({
49
- error: errorMessage,
50
- identifier: id,
51
- context,
52
- info,
53
- });
54
- }
55
- if (options.transformError) {
56
- throw options.transformError(errorMessage);
57
- }
58
- throw new Error(errorMessage);
59
- }
60
52
  }
61
- },
62
- };
53
+ if (options.transformError) {
54
+ throw options.transformError(errorMessage);
55
+ }
56
+ throw new Error(errorMessage);
57
+ }
58
+ }
63
59
  },
64
60
  };
65
61
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/rate-limiter",
3
- "version": "3.0.0-alpha-25d99ca.0",
3
+ "version": "3.0.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "1.8.0-alpha-25d99ca.0",
6
+ "@envelop/core": "^2.0.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {