@stuntman/server 0.2.4 → 0.3.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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/api/api.d.ts +1 -1
  3. package/dist/api/api.d.ts.map +1 -1
  4. package/dist/api/api.js +53 -54
  5. package/dist/api/api.js.map +1 -1
  6. package/dist/api/utils.js +9 -18
  7. package/dist/api/utils.js.map +1 -1
  8. package/dist/api/validators.js +38 -43
  9. package/dist/api/validators.js.map +1 -1
  10. package/dist/bin/stuntman.js +3 -5
  11. package/dist/bin/stuntman.js.map +1 -1
  12. package/dist/index.js +1 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/ipUtils.d.ts +1 -1
  15. package/dist/ipUtils.d.ts.map +1 -1
  16. package/dist/ipUtils.js +18 -44
  17. package/dist/ipUtils.js.map +1 -1
  18. package/dist/mock.d.ts +1 -1
  19. package/dist/mock.d.ts.map +1 -1
  20. package/dist/mock.js +66 -69
  21. package/dist/mock.js.map +1 -1
  22. package/dist/requestContext.js +6 -8
  23. package/dist/requestContext.js.map +1 -1
  24. package/dist/ruleExecutor.d.ts.map +1 -1
  25. package/dist/ruleExecutor.js +28 -34
  26. package/dist/ruleExecutor.js.map +1 -1
  27. package/dist/rules/catchAll.js +4 -7
  28. package/dist/rules/catchAll.js.map +1 -1
  29. package/dist/rules/echo.js +3 -6
  30. package/dist/rules/echo.js.map +1 -1
  31. package/dist/rules/index.d.ts.map +1 -1
  32. package/dist/rules/index.js +3 -7
  33. package/dist/rules/index.js.map +1 -1
  34. package/dist/rules/loadRules.d.ts +1 -1
  35. package/dist/rules/loadRules.d.ts.map +1 -1
  36. package/dist/rules/loadRules.js +18 -48
  37. package/dist/rules/loadRules.js.map +1 -1
  38. package/dist/storage.d.ts +3 -3
  39. package/dist/storage.d.ts.map +1 -1
  40. package/dist/storage.js +7 -15
  41. package/dist/storage.js.map +1 -1
  42. package/package.json +26 -20
  43. package/src/api/api.ts +5 -1
  44. package/src/mock.ts +1 -1
  45. package/src/ruleExecutor.ts +5 -5
  46. package/src/rules/index.ts +1 -1
  47. package/src/rules/loadRules.ts +2 -2
  48. package/src/storage.ts +2 -2
@@ -1,4 +1,4 @@
1
- import AwaitLock from 'await-lock';
1
+ import { Lock } from 'async-await-mutex-lock';
2
2
  import { AppError, DEFAULT_RULE_PRIORITY, HttpCode, errorToLog, logger } from '@stuntman/shared';
3
3
  import type * as Stuntman from '@stuntman/shared';
4
4
  import { CUSTOM_RULES, DEFAULT_RULES } from './rules';
@@ -17,7 +17,7 @@ const transformMockRuleToLive = (rule: Stuntman.Rule): Stuntman.LiveRule => {
17
17
  class RuleExecutor implements Stuntman.RuleExecutorInterface {
18
18
  // TODO persistent rule storage maybe
19
19
  private _rules: Stuntman.LiveRule[];
20
- private rulesLock = new AwaitLock();
20
+ private rulesLock = new Lock();
21
21
 
22
22
  private get enabledRules(): readonly Stuntman.LiveRule[] {
23
23
  if (!this._rules) {
@@ -42,7 +42,7 @@ class RuleExecutor implements Stuntman.RuleExecutorInterface {
42
42
  if (!this.hasExpired()) {
43
43
  return;
44
44
  }
45
- await this.rulesLock.acquireAsync();
45
+ await this.rulesLock.acquire();
46
46
  const now = Date.now();
47
47
  try {
48
48
  this._rules = this._rules.filter((r) => {
@@ -59,7 +59,7 @@ class RuleExecutor implements Stuntman.RuleExecutorInterface {
59
59
 
60
60
  async addRule(rule: Stuntman.Rule, overwrite?: boolean): Promise<Stuntman.LiveRule> {
61
61
  await this.cleanUpExpired();
62
- await this.rulesLock.acquireAsync();
62
+ await this.rulesLock.acquire();
63
63
  try {
64
64
  if (this._rules.some((r) => r.id === rule.id)) {
65
65
  if (!overwrite) {
@@ -90,7 +90,7 @@ class RuleExecutor implements Stuntman.RuleExecutorInterface {
90
90
  async removeRule(rule: Stuntman.Rule): Promise<void>;
91
91
  async removeRule(ruleOrId: string | Stuntman.Rule): Promise<void> {
92
92
  await this.cleanUpExpired();
93
- await this.rulesLock.acquireAsync();
93
+ await this.rulesLock.acquire();
94
94
  try {
95
95
  this._removeRule(ruleOrId);
96
96
  } finally {
@@ -2,4 +2,4 @@ import type * as Stuntman from '@stuntman/shared';
2
2
  import { loadRules } from './loadRules';
3
3
  export { DEFAULT_RULES } from './loadRules';
4
4
 
5
- export const CUSTOM_RULES: Stuntman.DeployedRule[] = loadRules();
5
+ export const CUSTOM_RULES: Stuntman.DeployedRule[] = await loadRules();
@@ -8,7 +8,7 @@ import type * as Stuntman from '@stuntman/shared';
8
8
 
9
9
  export const DEFAULT_RULES: Stuntman.DeployedRule[] = [catchAllRule, echoRule];
10
10
 
11
- export const loadRules = (): Stuntman.DeployedRule[] => {
11
+ export const loadRules = async (): Promise<Stuntman.DeployedRule[]> => {
12
12
  const customRules: Stuntman.DeployedRule[] = [];
13
13
  if (!stuntmanConfig.mock.rulesPath || !fs.existsSync(stuntmanConfig.mock.rulesPath)) {
14
14
  logger.debug({ rulesPath: stuntmanConfig.mock.rulesPath }, `additional rules directory not found`);
@@ -30,7 +30,7 @@ export const loadRules = (): Stuntman.DeployedRule[] => {
30
30
  for (const filePath of filePaths) {
31
31
  // TODO add .ts rule support
32
32
  try {
33
- const loadedFile = tsImport.loadSync(filePath, { useCache: false });
33
+ const loadedFile = await tsImport.load(filePath, { useCache: false });
34
34
  // eslint-disable-next-line @typescript-eslint/no-var-requires
35
35
  const exportedRules = (Object.values(loadedFile) as Stuntman.DeployedRule[]).filter((rule) => {
36
36
  if (!rule || !rule.id || typeof rule.matches !== 'function') {
package/src/storage.ts CHANGED
@@ -1,8 +1,8 @@
1
- import LRUCache from 'lru-cache';
1
+ import { LRUCache } from 'lru-cache';
2
2
  import type * as Stuntman from '@stuntman/shared';
3
3
  import sizeof from 'object-sizeof';
4
4
 
5
- const DNS_CACHE_OPTIONS: LRUCache.Options<string, string> = {
5
+ const DNS_CACHE_OPTIONS: any = {
6
6
  max: 1000,
7
7
  ttl: 1000 * 60 * 15,
8
8
  allowStale: false,