@envelop/rate-limiter 3.4.0-alpha-aca44e1.0 → 4.0.0-alpha-d0d0776.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 +4 -6
  2. package/index.mjs +4 -6
  3. package/package.json +19 -7
package/index.js CHANGED
@@ -5,12 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const graphqlRateLimit = require('graphql-rate-limit');
6
6
 
7
7
  function getDirective(info, name) {
8
- var _a;
9
8
  const { parentType, fieldName, schema } = info;
10
9
  const schemaType = schema.getType(parentType.name);
11
10
  const field = schemaType.getFields()[fieldName];
12
11
  const astNode = field.astNode;
13
- const rateLimitDirective = (_a = astNode === null || astNode === void 0 ? void 0 : astNode.directives) === null || _a === void 0 ? void 0 : _a.find(d => d.name.value === name);
12
+ const rateLimitDirective = astNode?.directives?.find(d => d.name.value === name);
14
13
  return rateLimitDirective || null;
15
14
  }
16
15
 
@@ -28,12 +27,11 @@ const useRateLimiter = (options) => {
28
27
  });
29
28
  },
30
29
  async onResolverCalled({ args, root, context, info }) {
31
- var _a, _b, _c;
32
30
  const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
33
31
  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;
32
+ const maxNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')?.value;
33
+ const windowNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')?.value;
34
+ const messageNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')?.value;
37
35
  const message = messageNode.value;
38
36
  const max = parseInt(maxNode.value);
39
37
  const window = windowNode.value;
package/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  import { getGraphQLRateLimiter } from 'graphql-rate-limit';
2
2
 
3
3
  function getDirective(info, name) {
4
- var _a;
5
4
  const { parentType, fieldName, schema } = info;
6
5
  const schemaType = schema.getType(parentType.name);
7
6
  const field = schemaType.getFields()[fieldName];
8
7
  const astNode = field.astNode;
9
- const rateLimitDirective = (_a = astNode === null || astNode === void 0 ? void 0 : astNode.directives) === null || _a === void 0 ? void 0 : _a.find(d => d.name.value === name);
8
+ const rateLimitDirective = astNode?.directives?.find(d => d.name.value === name);
10
9
  return rateLimitDirective || null;
11
10
  }
12
11
 
@@ -24,12 +23,11 @@ const useRateLimiter = (options) => {
24
23
  });
25
24
  },
26
25
  async onResolverCalled({ args, root, context, info }) {
27
- var _a, _b, _c;
28
26
  const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
29
27
  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;
28
+ const maxNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')?.value;
29
+ const windowNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')?.value;
30
+ const messageNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')?.value;
33
31
  const message = messageNode.value;
34
32
  const max = parseInt(maxNode.value);
35
33
  const window = windowNode.value;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/rate-limiter",
3
- "version": "3.4.0-alpha-aca44e1.0",
3
+ "version": "4.0.0-alpha-d0d0776.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-aca44e1.0",
6
+ "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/dotansimha/envelop.git",
14
+ "url": "https://github.com/n1ru4l/envelop.git",
15
15
  "directory": "packages/plugins/rate-limiter"
16
16
  },
17
17
  "author": "Dotan Simha <dotansimha@gmail.com>",
@@ -24,12 +24,24 @@
24
24
  },
25
25
  "exports": {
26
26
  ".": {
27
- "require": "./index.js",
28
- "import": "./index.mjs"
27
+ "require": {
28
+ "default": "./index.js",
29
+ "types": "./index.d.ts"
30
+ },
31
+ "import": {
32
+ "default": "./index.mjs",
33
+ "types": "./index.d.ts"
34
+ }
29
35
  },
30
36
  "./*": {
31
- "require": "./*.js",
32
- "import": "./*.mjs"
37
+ "require": {
38
+ "default": "./*.js",
39
+ "types": "./*.d.ts"
40
+ },
41
+ "import": {
42
+ "default": "./*.mjs",
43
+ "types": "./*.d.ts"
44
+ }
33
45
  },
34
46
  "./package.json": "./package.json"
35
47
  }