@limitkit/core 0.1.5 → 0.1.6

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/dist/index.js CHANGED
@@ -154,7 +154,7 @@ var RateLimiter = class {
154
154
  const algorithm = typeof rule.policy === "function" ? await rule.policy(ctx) : rule.policy;
155
155
  const key = typeof rule.key === "function" ? await rule.key(ctx) : rule.key;
156
156
  const cost = typeof rule.cost === "function" ? await rule.cost(ctx) : rule.cost;
157
- if (cost && cost <= 0)
157
+ if (cost !== void 0 && cost <= 0)
158
158
  throw new BadArgumentsException(
159
159
  `Cost must be a positive integer, got cost=${cost}`
160
160
  );
@@ -173,7 +173,7 @@ var RateLimiter = class {
173
173
  if (result.allowed) console.log(debugRules);
174
174
  else console.error(debugRules);
175
175
  }
176
- if (result.remaining === 0) {
176
+ if (!result.allowed) {
177
177
  if (this.debug) {
178
178
  const debugResults = {
179
179
  failedRule: rule.name,
@@ -182,12 +182,7 @@ var RateLimiter = class {
182
182
  };
183
183
  return debugResults;
184
184
  }
185
- return {
186
- ...result,
187
- reset: maxReset,
188
- limit: minLimit,
189
- remaining: minRemaining
190
- };
185
+ return result;
191
186
  }
192
187
  }
193
188
  if (this.debug) {
package/dist/index.mjs CHANGED
@@ -117,7 +117,7 @@ var RateLimiter = class {
117
117
  const algorithm = typeof rule.policy === "function" ? await rule.policy(ctx) : rule.policy;
118
118
  const key = typeof rule.key === "function" ? await rule.key(ctx) : rule.key;
119
119
  const cost = typeof rule.cost === "function" ? await rule.cost(ctx) : rule.cost;
120
- if (cost && cost <= 0)
120
+ if (cost !== void 0 && cost <= 0)
121
121
  throw new BadArgumentsException(
122
122
  `Cost must be a positive integer, got cost=${cost}`
123
123
  );
@@ -136,7 +136,7 @@ var RateLimiter = class {
136
136
  if (result.allowed) console.log(debugRules);
137
137
  else console.error(debugRules);
138
138
  }
139
- if (result.remaining === 0) {
139
+ if (!result.allowed) {
140
140
  if (this.debug) {
141
141
  const debugResults = {
142
142
  failedRule: rule.name,
@@ -145,12 +145,7 @@ var RateLimiter = class {
145
145
  };
146
146
  return debugResults;
147
147
  }
148
- return {
149
- ...result,
150
- reset: maxReset,
151
- limit: minLimit,
152
- remaining: minRemaining
153
- };
148
+ return result;
154
149
  }
155
150
  }
156
151
  if (this.debug) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limitkit/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",