@chainlink/external-adapter-framework 2.10.0 → 2.11.1

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 (32) hide show
  1. package/README.md +1 -1
  2. package/adapter/market-status.d.ts +6 -0
  3. package/adapter/market-status.js +22 -0
  4. package/adapter/market-status.js.map +1 -1
  5. package/config/index.js +1 -1
  6. package/generator-adapter/node_modules/.yarn-integrity +8 -8
  7. package/generator-adapter/node_modules/@types/node/README.md +1 -1
  8. package/generator-adapter/node_modules/@types/node/package.json +2 -2
  9. package/generator-adapter/node_modules/@types/node/process.d.ts +7 -0
  10. package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.js +1 -3
  11. package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.js.map +1 -1
  12. package/generator-adapter/node_modules/@yeoman/adapter/package.json +3 -3
  13. package/generator-adapter/node_modules/@yeoman/types/package.json +3 -3
  14. package/generator-adapter/node_modules/p-queue/dist/index.d.ts +181 -11
  15. package/generator-adapter/node_modules/p-queue/dist/index.js +366 -45
  16. package/generator-adapter/node_modules/p-queue/dist/options copy.d.ts +121 -0
  17. package/generator-adapter/node_modules/p-queue/dist/options copy.js +1 -0
  18. package/generator-adapter/node_modules/p-queue/dist/options.d.ts +26 -7
  19. package/generator-adapter/node_modules/p-queue/dist/priority-queue.d.ts +1 -0
  20. package/generator-adapter/node_modules/p-queue/dist/priority-queue.js +12 -6
  21. package/generator-adapter/node_modules/p-queue/dist/queue.d.ts +1 -0
  22. package/generator-adapter/node_modules/p-queue/package.json +19 -27
  23. package/generator-adapter/node_modules/p-queue/readme.md +541 -19
  24. package/generator-adapter/node_modules/p-timeout/index.d.ts +2 -4
  25. package/generator-adapter/node_modules/p-timeout/index.js +23 -50
  26. package/generator-adapter/node_modules/p-timeout/package.json +11 -9
  27. package/generator-adapter/node_modules/p-timeout/readme.md +11 -9
  28. package/generator-adapter/package.json +3 -3
  29. package/package.json +8 -7
  30. package/validation/market-status.d.ts +6 -0
  31. package/validation/market-status.js +69 -0
  32. package/validation/market-status.js.map +1 -0
@@ -1,39 +1,13 @@
1
1
  export class TimeoutError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'TimeoutError';
5
- }
6
- }
2
+ name = 'TimeoutError';
7
3
 
8
- /**
9
- An error to be thrown when the request is aborted by AbortController.
10
- DOMException is thrown instead of this Error when DOMException is available.
11
- */
12
- export class AbortError extends Error {
13
- constructor(message) {
14
- super();
15
- this.name = 'AbortError';
16
- this.message = message;
4
+ constructor(message, options) {
5
+ super(message, options);
6
+ Error.captureStackTrace?.(this, TimeoutError);
17
7
  }
18
8
  }
19
9
 
20
- /**
21
- TODO: Remove AbortError and just throw DOMException when targeting Node 18.
22
- */
23
- const getDOMException = errorMessage => globalThis.DOMException === undefined
24
- ? new AbortError(errorMessage)
25
- : new DOMException(errorMessage);
26
-
27
- /**
28
- TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
29
- */
30
- const getAbortedReason = signal => {
31
- const reason = signal.reason === undefined
32
- ? getDOMException('This operation was aborted.')
33
- : signal.reason;
34
-
35
- return reason instanceof Error ? reason : getDOMException(reason);
36
- };
10
+ const getAbortedReason = signal => signal.reason ?? new DOMException('This operation was aborted.', 'AbortError');
37
11
 
38
12
  export default function pTimeout(promise, options) {
39
13
  const {
@@ -41,40 +15,42 @@ export default function pTimeout(promise, options) {
41
15
  fallback,
42
16
  message,
43
17
  customTimers = {setTimeout, clearTimeout},
18
+ signal,
44
19
  } = options;
45
20
 
46
21
  let timer;
22
+ let abortHandler;
47
23
 
48
24
  const wrappedPromise = new Promise((resolve, reject) => {
49
25
  if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
50
26
  throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
51
27
  }
52
28
 
53
- if (options.signal) {
54
- const {signal} = options;
55
- if (signal.aborted) {
56
- reject(getAbortedReason(signal));
57
- }
29
+ if (signal?.aborted) {
30
+ reject(getAbortedReason(signal));
31
+ return;
32
+ }
58
33
 
59
- const abortHandler = () => {
34
+ if (signal) {
35
+ abortHandler = () => {
60
36
  reject(getAbortedReason(signal));
61
37
  };
62
38
 
63
39
  signal.addEventListener('abort', abortHandler, {once: true});
64
-
65
- promise.finally(() => {
66
- signal.removeEventListener('abort', abortHandler);
67
- });
68
40
  }
69
41
 
42
+ // Use .then() instead of async IIFE to preserve stack traces
43
+ // eslint-disable-next-line promise/prefer-await-to-then, promise/prefer-catch
44
+ promise.then(resolve, reject);
45
+
70
46
  if (milliseconds === Number.POSITIVE_INFINITY) {
71
- promise.then(resolve, reject);
72
47
  return;
73
48
  }
74
49
 
75
50
  // We create the error outside of `setTimeout` to preserve the stack trace.
76
51
  const timeoutError = new TimeoutError();
77
52
 
53
+ // `.call(undefined, ...)` is needed for custom timers to avoid context issues
78
54
  timer = customTimers.setTimeout.call(undefined, () => {
79
55
  if (fallback) {
80
56
  try {
@@ -99,21 +75,18 @@ export default function pTimeout(promise, options) {
99
75
  reject(timeoutError);
100
76
  }
101
77
  }, milliseconds);
102
-
103
- (async () => {
104
- try {
105
- resolve(await promise);
106
- } catch (error) {
107
- reject(error);
108
- }
109
- })();
110
78
  });
111
79
 
80
+ // eslint-disable-next-line promise/prefer-await-to-then
112
81
  const cancelablePromise = wrappedPromise.finally(() => {
113
82
  cancelablePromise.clear();
83
+ if (abortHandler && signal) {
84
+ signal.removeEventListener('abort', abortHandler);
85
+ }
114
86
  });
115
87
 
116
88
  cancelablePromise.clear = () => {
89
+ // `.call(undefined, ...)` is needed for custom timers to avoid context issues
117
90
  customTimers.clearTimeout.call(undefined, timer);
118
91
  timer = undefined;
119
92
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "p-timeout",
3
- "version": "6.1.3",
3
+ "version": "7.0.1",
4
4
  "description": "Timeout a promise after a specified amount of time",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/p-timeout",
@@ -11,11 +11,13 @@
11
11
  "url": "https://sindresorhus.com"
12
12
  },
13
13
  "type": "module",
14
- "exports": "./index.js",
15
- "types": "./index.d.ts",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
16
18
  "sideEffects": false,
17
19
  "engines": {
18
- "node": ">=14.16"
20
+ "node": ">=20"
19
21
  },
20
22
  "scripts": {
21
23
  "test": "xo && ava && tsd"
@@ -38,13 +40,13 @@
38
40
  "bluebird"
39
41
  ],
40
42
  "devDependencies": {
41
- "ava": "^4.3.1",
42
- "delay": "^5.0.0",
43
+ "ava": "^6.4.1",
44
+ "delay": "^6.0.0",
43
45
  "in-range": "^3.0.0",
44
46
  "p-cancelable": "^4.0.1",
45
- "sinon": "^19.0.2",
47
+ "sinon": "^21.0.0",
46
48
  "time-span": "^5.1.0",
47
- "tsd": "^0.22.0",
48
- "xo": "^0.54.2"
49
+ "tsd": "^0.33.0",
50
+ "xo": "^1.2.2"
49
51
  }
50
52
  }
@@ -54,7 +54,7 @@ Passing `Infinity` will cause it to never time out.
54
54
  ##### message
55
55
 
56
56
  Type: `string | Error | false`\
57
- Default: `'Promise timed out after 50 milliseconds'`
57
+ Default: `'Promise timed out after {milliseconds} milliseconds'`
58
58
 
59
59
  Specify a custom error message or error to throw when it times out:
60
60
 
@@ -78,6 +78,8 @@ Type: `Function`
78
78
 
79
79
  Do something other than rejecting with an error on timeout.
80
80
 
81
+ The function can return a value or a promise.
82
+
81
83
  You could for example retry:
82
84
 
83
85
  ```js
@@ -89,8 +91,10 @@ const delayedPromise = () => setTimeout(200);
89
91
  await pTimeout(delayedPromise(), {
90
92
  milliseconds: 50,
91
93
  fallback: () => {
92
- return pTimeout(delayedPromise(), {milliseconds: 300});
93
- },
94
+ return pTimeout(delayedPromise(), {
95
+ milliseconds: 300
96
+ });
97
+ }
94
98
  });
95
99
  ```
96
100
 
@@ -105,8 +109,8 @@ Useful for testing purposes, in particular to work around [`sinon.useFakeTimers(
105
109
  Example:
106
110
 
107
111
  ```js
108
- import {setTimeout} from 'node:timers/promises';
109
112
  import pTimeout from 'p-timeout';
113
+ import sinon from 'sinon';
110
114
 
111
115
  const originalSetTimeout = setTimeout;
112
116
  const originalClearTimeout = clearTimeout;
@@ -123,13 +127,11 @@ await pTimeout(doSomething(), {
123
127
  });
124
128
  ```
125
129
 
126
- #### signal
130
+ ##### signal
127
131
 
128
132
  Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
129
133
 
130
- You can abort the promise using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
131
-
132
- *Requires Node.js 16 or later.*
134
+ Abort the promise.
133
135
 
134
136
  ```js
135
137
  import pTimeout from 'p-timeout';
@@ -164,7 +166,7 @@ Exposed for instance checking and sub-classing.
164
166
 
165
167
  > Modern alternative to `p-timeout`
166
168
 
167
- Asynchronous functions like `fetch` can accept an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), which can be conveniently created with [`AbortSignal.timeout()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static).
169
+ Async functions like `fetch` can accept an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), which can be conveniently created with [`AbortSignal.timeout()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static).
168
170
 
169
171
  The advantage over `p-timeout` is that the promise-generating function (like `fetch`) is actually notified that the user is no longer expecting an answer, so it can interrupt its work and free resources.
170
172
 
@@ -12,9 +12,9 @@
12
12
  ],
13
13
  "devDependencies": {
14
14
  "yeoman-generator": "7.5.1",
15
- "@yeoman/types": "1.8.0",
15
+ "@yeoman/types": "1.9.1",
16
16
  "mem-fs": "4.1.2",
17
- "@yeoman/adapter": "3.1.0",
18
- "@types/node": "24.10.0"
17
+ "@yeoman/adapter": "3.1.1",
18
+ "@types/node": "24.10.1"
19
19
  }
20
20
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@chainlink/external-adapter-framework",
3
- "version": "2.10.0",
3
+ "version": "2.11.1",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "repository": "git://github.com/smartcontractkit/ea-framework-js.git",
7
7
  "dependencies": {
8
8
  "ajv": "8.17.1",
9
9
  "axios": "1.13.2",
10
- "eventsource": "4.0.0",
10
+ "eventsource": "4.1.0",
11
11
  "fastify": "5.6.2",
12
12
  "ioredis": "5.8.2",
13
13
  "mock-socket": "9.3.1",
@@ -15,7 +15,8 @@
15
15
  "pino-pretty": "13.1.2",
16
16
  "prom-client": "15.1.3",
17
17
  "redlock": "5.0.0-beta.2",
18
- "ws": "8.18.3"
18
+ "ws": "8.18.3",
19
+ "@date-fns/tz": "1.4.1"
19
20
  },
20
21
  "scripts": {
21
22
  "build": "rm -rf dist/src && mkdir -p ./dist/src && cp package.json dist/src && cp README.md dist/src && tsc && yarn pre-build-generator",
@@ -37,17 +38,17 @@
37
38
  },
38
39
  "devDependencies": {
39
40
  "@sinonjs/fake-timers": "15.0.0",
40
- "@types/node": "24.10.0",
41
+ "@types/node": "24.10.1",
41
42
  "@types/sinonjs__fake-timers": "15.0.1",
42
43
  "@types/ws": "8.18.1",
43
- "@typescript-eslint/eslint-plugin": "8.46.3",
44
- "@typescript-eslint/parser": "8.46.3",
44
+ "@typescript-eslint/eslint-plugin": "8.47.0",
45
+ "@typescript-eslint/parser": "8.47.0",
45
46
  "ava": "6.4.1",
46
47
  "axios-mock-adapter": "2.1.0",
47
48
  "c8": "10.1.3",
48
49
  "eslint": "9.39.1",
49
50
  "eslint-config-prettier": "10.1.8",
50
- "eslint-plugin-tsdoc": "0.4.0",
51
+ "eslint-plugin-tsdoc": "0.5.0",
51
52
  "mocksse": "1.0.4",
52
53
  "prettier": "3.6.2",
53
54
  "ts-node": "10.9.2",
@@ -0,0 +1,6 @@
1
+ export declare const parseWeekendString: (weekend?: string) => {
2
+ start: string;
3
+ end: string;
4
+ tz: string;
5
+ };
6
+ export declare const isWeekendNow: (weekend?: string) => boolean;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWeekendNow = exports.parseWeekendString = void 0;
4
+ const error_1 = require("../validation/error");
5
+ const tz_1 = require("@date-fns/tz");
6
+ const parseWeekendString = (weekend) => {
7
+ const dayHour = /[0-6](0\d|1\d|2[0-3])/;
8
+ const timezonePattern = /[^\s]+/;
9
+ const regex = new RegExp(`^(${dayHour.source})-(${dayHour.source}):(${timezonePattern.source})$`);
10
+ const match = weekend?.match(regex);
11
+ if (!match) {
12
+ throw new error_1.AdapterInputError({
13
+ statusCode: 400,
14
+ message: '[Param: weekend] does not match format of DHH-DHH:TZ',
15
+ });
16
+ }
17
+ const result = {
18
+ start: match[1],
19
+ end: match[3],
20
+ tz: match[5],
21
+ };
22
+ try {
23
+ // eslint-disable-next-line new-cap
24
+ Intl.DateTimeFormat(undefined, { timeZone: result.tz });
25
+ }
26
+ catch (error) {
27
+ throw new error_1.AdapterInputError({
28
+ statusCode: 400,
29
+ message: `timezone ${result.tz} in [Param: weekend] is not valid: ${error}`,
30
+ });
31
+ }
32
+ return result;
33
+ };
34
+ exports.parseWeekendString = parseWeekendString;
35
+ const isWeekendNow = (weekend) => {
36
+ const parsed = (0, exports.parseWeekendString)(weekend);
37
+ const startDay = Number(parsed.start[0]);
38
+ const startHour = Number(parsed.start.slice(1));
39
+ const endDay = Number(parsed.end[0]);
40
+ const endHour = Number(parsed.end.slice(1));
41
+ const nowDay = tz_1.TZDate.tz(parsed.tz).getDay();
42
+ const nowHour = tz_1.TZDate.tz(parsed.tz).getHours();
43
+ // Case 1: weekend does NOT wrap around the week
44
+ if (startDay < endDay || (startDay === endDay && startHour < endHour)) {
45
+ if (nowDay < startDay || nowDay > endDay) {
46
+ return false;
47
+ }
48
+ else if (nowDay === startDay && nowHour < startHour) {
49
+ return false;
50
+ }
51
+ else if (nowDay === endDay && nowHour >= endHour) {
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+ // Case 2: weekend wraps around (e.g. Fri → Sun)
57
+ if (nowDay > startDay || nowDay < endDay) {
58
+ return true;
59
+ }
60
+ else if (nowDay === startDay && nowHour >= startHour) {
61
+ return true;
62
+ }
63
+ else if (nowDay === endDay && nowHour < endHour) {
64
+ return true;
65
+ }
66
+ return false;
67
+ };
68
+ exports.isWeekendNow = isWeekendNow;
69
+ //# sourceMappingURL=market-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"market-status.js","sourceRoot":"","sources":["../../../src/validation/market-status.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AACvD,qCAAqC;AAE9B,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,MAAM,OAAO,GAAG,uBAAuB,CAAA;IACvC,MAAM,eAAe,GAAG,QAAQ,CAAA;IAChC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,MAAM,OAAO,CAAC,MAAM,MAAM,eAAe,CAAC,MAAM,IAAI,CAAC,CAAA;IAEjG,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,yBAAiB,CAAC;YAC1B,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,sDAAsD;SAChE,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACf,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;QACb,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;KACb,CAAA;IAED,IAAI,CAAC;QACH,mCAAmC;QACnC,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,yBAAiB,CAAC;YAC1B,UAAU,EAAE,G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