@openclaw/discord 2026.7.1 → 2026.7.2-beta.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 (92) hide show
  1. package/dist/action-runtime-api.js +1 -1
  2. package/dist/{allow-list-C-MqM-B_.js → allow-list-B7qOH5xu.js} +22 -1
  3. package/dist/{api-DPRqYi4Z.js → api--f62GFaS.js} +38 -23
  4. package/dist/api.js +15 -15
  5. package/dist/approval-custom-id-NYPYj9Po.js +58 -0
  6. package/dist/{approval-handler.runtime-Bw2pZNk1.js → approval-handler.runtime-DeyIiw5I.js} +28 -23
  7. package/dist/approval-message-safety-C-8BL6Kv.js +47 -0
  8. package/dist/{audit-MLpDpN3Z.js → audit-Df2w046a.js} +3 -3
  9. package/dist/{channel-actions-D_fjVUZ_.js → channel-actions-ChpBSRcu.js} +6 -4
  10. package/dist/{channel-actions.runtime-CVHlFqQg.js → channel-actions.runtime-D8V8tyCq.js} +41 -12
  11. package/dist/channel-config-api.js +1 -1
  12. package/dist/{channel-DGWPH5u3.js → channel-nYmJ7FKQ.js} +275 -62
  13. package/dist/channel-plugin-api.js +1 -1
  14. package/dist/{channel.setup-tZcpIn4e.js → channel.setup-DyihrqHH.js} +3 -3
  15. package/dist/{components-BIBizbtZ.js → components-BVrfRS-F.js} +78 -52
  16. package/dist/config-api-B18fR8M5.js +3 -0
  17. package/dist/{config-schema-BgIhO3ko.js → config-schema-_bUKcWRm.js} +42 -82
  18. package/dist/conversation-identity-BpkAzklg.js +94 -0
  19. package/dist/{directory-config-ByaUKL1f.js → directory-config-BUe-qq_C.js} +1 -1
  20. package/dist/directory-contract-api.js +1 -1
  21. package/dist/{directory-live-BX79ImQA.js → directory-live-DZByMdPO.js} +6 -6
  22. package/dist/{doctor-Bgoxm5AN.js → doctor-bMaWXFKu.js} +5 -4
  23. package/dist/doctor-contract-api.js +1 -1
  24. package/dist/{doctor-contract-CU7lnZTF.js → doctor-contract-wId6pV41.js} +41 -37
  25. package/dist/{handle-action.guild-admin-CgJSNVui.js → handle-action.guild-admin-C_PQcBEV.js} +12 -12
  26. package/dist/index.js +1 -1
  27. package/dist/legacy-state-migrations-api.js +24 -2
  28. package/dist/{manager.runtime-DaB-CTrt.js → manager.runtime-3RVMVkyx.js} +546 -154
  29. package/dist/{message-handler-DcgvugZt.js → message-handler-CIxWq5Yh.js} +8 -9
  30. package/dist/{message-handler.preflight-DvLXiYVH.js → message-handler.preflight-BI86IbHz.js} +46 -22
  31. package/dist/{message-handler.process-Cjf30P_B.js → message-handler.process-bPS_9_tb.js} +241 -107
  32. package/dist/{message-utils-B_3yA5bN.js → message-utils-D4j07taS.js} +2 -3
  33. package/dist/{outbound-adapter-82RWi_SR.js → outbound-adapter-Czny0Fae.js} +16 -68
  34. package/dist/outbound-components-oJKLj62G.js +99 -0
  35. package/dist/pluralkit-UXq1OyUI.js +40 -0
  36. package/dist/{probe-D1ImJEo2.js → probe-DxjMBeVG.js} +1 -1
  37. package/dist/{probe.runtime-B1dsEeBD.js → probe.runtime-Bc8Oo6e8.js} +1 -1
  38. package/dist/{provider-BkfbC9FQ.js → provider-DWvDNb4J.js} +702 -236
  39. package/dist/{provider-session.runtime-BDjyFw6Y.js → provider-session.runtime-D5pCGibh.js} +3 -3
  40. package/dist/provider.runtime-C2iIfbTs.js +2 -0
  41. package/dist/{resolve-allowlist-common-CWbE8XlH.js → resolve-allowlist-common-B9S8LLBd.js} +5 -5
  42. package/dist/{resolve-channels-CcpvWoRa.js → resolve-channels-BrkWOKdG.js} +7 -7
  43. package/dist/{resolve-users-DJamun9s.js → resolve-users-OjrXXvJP.js} +5 -5
  44. package/dist/{runtime-C6rRmQ6l.js → runtime-C618lis9.js} +223 -33
  45. package/dist/runtime-api.actions.js +2 -2
  46. package/dist/runtime-api.js +23 -23
  47. package/dist/runtime-api.lookup.js +5 -5
  48. package/dist/runtime-api.monitor-DSbfGnzS.js +6 -0
  49. package/dist/runtime-api.monitor.js +7 -7
  50. package/dist/runtime-api.send.js +5 -5
  51. package/dist/runtime-api.threads.js +5 -5
  52. package/dist/{send-iJ0B4bAX.js → send-BFpa_DHn.js} +21 -12
  53. package/dist/{send.components-D0I39utR.js → send.components-BaXQJKWT.js} +15 -10
  54. package/dist/{send.outbound-Bj61Q3a0.js → send.outbound-BlA6VzSE.js} +22 -12
  55. package/dist/{send.receipt-BpBQED_5.js → send.receipt-aegk69an.js} +59 -75
  56. package/dist/{send.shared-wAwMhHDN.js → send.shared-Xz7IMVpu.js} +44 -20
  57. package/dist/{sender-identity-CEsfDF0L.js → sender-identity-C62lBe18.js} +1 -1
  58. package/dist/session-binding-contract-api.js +1 -1
  59. package/dist/setup-plugin-api.js +1 -1
  60. package/dist/{shared-BQVKfnev.js → shared-BLYBt5SA.js} +3 -3
  61. package/dist/{subagent-hooks-B-bJxxGg.js → subagent-hooks-DKJ4p-Oy.js} +2 -2
  62. package/dist/subagent-hooks-api.js +1 -1
  63. package/dist/{system-events-DVnqSyTt.js → system-events-DKwfE-2z.js} +2 -2
  64. package/dist/{target-resolver-CwHaSLt3.js → target-resolver-BQyEHyeS.js} +2 -2
  65. package/dist/targets-DvItNIvP.js +3 -0
  66. package/dist/thread-binding-api-BDZJD4na.js +4 -0
  67. package/dist/thread-binding-api.js +1 -3
  68. package/dist/{thread-bindings-DsTxqu3E.js → thread-bindings-BbzjUuNB.js} +26 -43
  69. package/dist/{thread-bindings.discord-api-BjIf9lGs.js → thread-bindings.discord-api-DJD3qwIN.js} +8 -10
  70. package/dist/{thread-bindings.manager-Bwmtqc3E.js → thread-bindings.manager-BIBm6bQd.js} +4 -4
  71. package/dist/{thread-bindings.session-updates-Chs3HgGa.js → thread-bindings.session-updates-eRcJlzIU.js} +1 -1
  72. package/dist/{thread-bindings.state-iSWjCYjB.js → thread-bindings.state-9VAxhVf6.js} +3 -14
  73. package/dist/{timeouts-C5TBc_9x.js → timeouts-ZRc9Lw4y.js} +3 -15
  74. package/dist/timeouts.js +1 -1
  75. package/dist/{transcripts-source-BvvM5Ns9.js → transcripts-source-CLZ5X8fh.js} +1 -1
  76. package/dist/transcripts-source-api.js +1 -1
  77. package/dist/{typing-BVcJgILg.js → typing-BnYT7Szq.js} +2 -2
  78. package/node_modules/p-map/index.d.ts +155 -0
  79. package/node_modules/p-map/index.js +284 -0
  80. package/node_modules/p-map/license +9 -0
  81. package/node_modules/p-map/package.json +57 -0
  82. package/node_modules/p-map/readme.md +190 -0
  83. package/npm-shrinkwrap.json +16 -3
  84. package/openclaw.plugin.json +70 -2
  85. package/package.json +6 -4
  86. package/dist/config-api-JiPdJeb0.js +0 -2
  87. package/dist/conversation-identity-DWC5d8Sy.js +0 -272
  88. package/dist/pluralkit-DcD-3EcL.js +0 -24
  89. package/dist/preview-streaming-DXT8oJdo.js +0 -8
  90. package/dist/provider.runtime-WrJXikSv.js +0 -2
  91. package/dist/runtime-api.monitor-C2_WVtJf.js +0 -6
  92. package/dist/targets-69w7c3vU.js +0 -3
@@ -0,0 +1,155 @@
1
+ type BaseOptions = {
2
+ /**
3
+ Number of concurrently pending promises returned by `mapper`.
4
+
5
+ Must be an integer from 1 and up or `Infinity`.
6
+
7
+ @default Infinity
8
+ */
9
+ readonly concurrency?: number;
10
+ };
11
+
12
+ export type Options = BaseOptions & {
13
+ /**
14
+ When `true`, the first mapper rejection will be rejected back to the consumer.
15
+
16
+ When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) containing all the errors from the rejected promises.
17
+
18
+ Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. Use the `signal` option for abort control.
19
+
20
+ @default true
21
+ */
22
+ readonly stopOnError?: boolean;
23
+
24
+ /**
25
+ You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
26
+
27
+ @example
28
+ ```
29
+ import pMap from 'p-map';
30
+ import delay from 'delay';
31
+
32
+ const abortController = new AbortController();
33
+
34
+ setTimeout(() => {
35
+ abortController.abort();
36
+ }, 500);
37
+
38
+ const mapper = async value => value;
39
+
40
+ await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
41
+ // Throws AbortError (DOMException) after 500 ms.
42
+ ```
43
+ */
44
+ readonly signal?: AbortSignal | undefined;
45
+ };
46
+
47
+ export type IterableOptions = BaseOptions & {
48
+ /**
49
+ Maximum number of promises returned by `mapper` that have resolved but not yet collected by the consumer of the async iterable. Calls to `mapper` will be limited so that there is never too much backpressure.
50
+
51
+ Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
52
+
53
+ Default: `options.concurrency`
54
+ */
55
+ readonly backpressure?: number;
56
+ };
57
+
58
+ type MaybePromise<T> = T | Promise<T>;
59
+
60
+ /**
61
+ Function which is called for every item in `input`. Expected to return a `Promise` or value.
62
+
63
+ @param element - Iterated element.
64
+ @param index - Index of the element in the source array.
65
+ */
66
+ export type Mapper<Element = any, NewElement = unknown> = (
67
+ element: Element,
68
+ index: number
69
+ ) => MaybePromise<NewElement | typeof pMapSkip>;
70
+
71
+ /**
72
+ @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
73
+ @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
74
+ @returns A `Promise` that is fulfilled when all promises in `input` and the ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
75
+
76
+ @example
77
+ ```
78
+ import pMap from 'p-map';
79
+ import got from 'got';
80
+
81
+ const sites = [
82
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
83
+ 'https://avajs.dev',
84
+ 'https://github.com'
85
+ ];
86
+
87
+ const mapper = async site => {
88
+ const {requestUrl} = await got.head(site);
89
+ return requestUrl;
90
+ };
91
+
92
+ const result = await pMap(sites, mapper, {concurrency: 2});
93
+
94
+ console.log(result);
95
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
96
+ ```
97
+ */
98
+ export default function pMap<Element, NewElement>(
99
+ input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
100
+ mapper: Mapper<Element, NewElement>,
101
+ options?: Options
102
+ ): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
103
+
104
+ /**
105
+ @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
106
+ @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
107
+ @returns An async iterable that streams each return value from `mapper` in order.
108
+
109
+ @example
110
+ ```
111
+ import {pMapIterable} from 'p-map';
112
+
113
+ // Multiple posts are fetched concurrently, with limited concurrency and backpressure
114
+ for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) {
115
+ console.log(post);
116
+ };
117
+ ```
118
+ */
119
+ export function pMapIterable<Element, NewElement>(
120
+ input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
121
+ mapper: Mapper<Element, NewElement>,
122
+ options?: IterableOptions
123
+ ): AsyncIterable<Exclude<NewElement, typeof pMapSkip>>;
124
+
125
+ /**
126
+ Return this value from a `mapper` function to skip including the value in the returned array.
127
+
128
+ @example
129
+ ```
130
+ import pMap, {pMapSkip} from 'p-map';
131
+ import got from 'got';
132
+
133
+ const sites = [
134
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
135
+ 'https://avajs.dev',
136
+ 'https://example.invalid',
137
+ 'https://github.com'
138
+ ];
139
+
140
+ const mapper = async site => {
141
+ try {
142
+ const {requestUrl} = await got.head(site);
143
+ return requestUrl;
144
+ } catch {
145
+ return pMapSkip;
146
+ }
147
+ };
148
+
149
+ const result = await pMap(sites, mapper, {concurrency: 2});
150
+
151
+ console.log(result);
152
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
153
+ ```
154
+ */
155
+ export const pMapSkip: unique symbol;
@@ -0,0 +1,284 @@
1
+ export default async function pMap(
2
+ iterable,
3
+ mapper,
4
+ {
5
+ concurrency = Number.POSITIVE_INFINITY,
6
+ stopOnError = true,
7
+ signal,
8
+ } = {},
9
+ ) {
10
+ return new Promise((resolve_, reject_) => {
11
+ if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
12
+ throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
13
+ }
14
+
15
+ if (typeof mapper !== 'function') {
16
+ throw new TypeError('Mapper function is required');
17
+ }
18
+
19
+ if (!((Number.isSafeInteger(concurrency) && concurrency >= 1) || concurrency === Number.POSITIVE_INFINITY)) {
20
+ throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
21
+ }
22
+
23
+ const result = [];
24
+ const errors = [];
25
+ const skippedIndexesMap = new Map();
26
+ let isRejected = false;
27
+ let isResolved = false;
28
+ let isIterableDone = false;
29
+ let resolvingCount = 0;
30
+ let currentIndex = 0;
31
+ const iterator = iterable[Symbol.iterator] === undefined ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
32
+
33
+ const signalListener = () => {
34
+ reject(signal.reason);
35
+ };
36
+
37
+ const cleanup = () => {
38
+ signal?.removeEventListener('abort', signalListener);
39
+ };
40
+
41
+ const resolve = value => {
42
+ resolve_(value);
43
+ cleanup();
44
+ };
45
+
46
+ const reject = reason => {
47
+ isRejected = true;
48
+ isResolved = true;
49
+ reject_(reason);
50
+ cleanup();
51
+ };
52
+
53
+ if (signal) {
54
+ if (signal.aborted) {
55
+ reject(signal.reason);
56
+ }
57
+
58
+ signal.addEventListener('abort', signalListener, {once: true});
59
+ }
60
+
61
+ const next = async () => {
62
+ if (isResolved) {
63
+ return;
64
+ }
65
+
66
+ const nextItem = await iterator.next();
67
+
68
+ const index = currentIndex;
69
+ currentIndex++;
70
+
71
+ // Note: `iterator.next()` can be called many times in parallel.
72
+ // This can cause multiple calls to this `next()` function to
73
+ // receive a `nextItem` with `done === true`.
74
+ // The shutdown logic that rejects/resolves must be protected
75
+ // so it runs only one time as the `skippedIndex` logic is
76
+ // non-idempotent.
77
+ if (nextItem.done) {
78
+ isIterableDone = true;
79
+
80
+ if (resolvingCount === 0 && !isResolved) {
81
+ if (!stopOnError && errors.length > 0) {
82
+ reject(new AggregateError(errors)); // eslint-disable-line unicorn/error-message
83
+ return;
84
+ }
85
+
86
+ isResolved = true;
87
+
88
+ if (skippedIndexesMap.size === 0) {
89
+ resolve(result);
90
+ return;
91
+ }
92
+
93
+ const pureResult = [];
94
+
95
+ // Support multiple `pMapSkip`'s.
96
+ for (const [index, value] of result.entries()) {
97
+ if (skippedIndexesMap.get(index) === pMapSkip) {
98
+ continue;
99
+ }
100
+
101
+ pureResult.push(value);
102
+ }
103
+
104
+ resolve(pureResult);
105
+ }
106
+
107
+ return;
108
+ }
109
+
110
+ resolvingCount++;
111
+
112
+ // Intentionally detached
113
+ (async () => {
114
+ try {
115
+ const element = await nextItem.value;
116
+
117
+ if (isResolved) {
118
+ return;
119
+ }
120
+
121
+ const value = await mapper(element, index);
122
+
123
+ // Use Map to stage the index of the element.
124
+ if (value === pMapSkip) {
125
+ skippedIndexesMap.set(index, value);
126
+ }
127
+
128
+ result[index] = value;
129
+
130
+ resolvingCount--;
131
+ await next();
132
+ } catch (error) {
133
+ if (stopOnError) {
134
+ reject(error);
135
+ } else {
136
+ errors.push(error);
137
+ resolvingCount--;
138
+
139
+ // In that case we can't really continue regardless of `stopOnError` state
140
+ // since an iterable is likely to continue throwing after it throws once.
141
+ // If we continue calling `next()` indefinitely we will likely end up
142
+ // in an infinite loop of failed iteration.
143
+ try {
144
+ await next();
145
+ } catch (error) {
146
+ reject(error);
147
+ }
148
+ }
149
+ }
150
+ })();
151
+ };
152
+
153
+ // Create the concurrent runners in a detached (non-awaited)
154
+ // promise. We need this so we can await the `next()` calls
155
+ // to stop creating runners before hitting the concurrency limit
156
+ // if the iterable has already been marked as done.
157
+ // NOTE: We *must* do this for async iterators otherwise we'll spin up
158
+ // infinite `next()` calls by default and never start the event loop.
159
+ (async () => {
160
+ for (let index = 0; index < concurrency; index++) {
161
+ try {
162
+ // eslint-disable-next-line no-await-in-loop
163
+ await next();
164
+ } catch (error) {
165
+ reject(error);
166
+ break;
167
+ }
168
+
169
+ if (isIterableDone || isRejected) {
170
+ break;
171
+ }
172
+ }
173
+ })();
174
+ });
175
+ }
176
+
177
+ export function pMapIterable(
178
+ iterable,
179
+ mapper,
180
+ {
181
+ concurrency = Number.POSITIVE_INFINITY,
182
+ backpressure = concurrency,
183
+ } = {},
184
+ ) {
185
+ if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
186
+ throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
187
+ }
188
+
189
+ if (typeof mapper !== 'function') {
190
+ throw new TypeError('Mapper function is required');
191
+ }
192
+
193
+ if (!((Number.isSafeInteger(concurrency) && concurrency >= 1) || concurrency === Number.POSITIVE_INFINITY)) {
194
+ throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
195
+ }
196
+
197
+ if (!((Number.isSafeInteger(backpressure) && backpressure >= concurrency) || backpressure === Number.POSITIVE_INFINITY)) {
198
+ throw new TypeError(`Expected \`backpressure\` to be an integer from \`concurrency\` (${concurrency}) and up or \`Infinity\`, got \`${backpressure}\` (${typeof backpressure})`);
199
+ }
200
+
201
+ return {
202
+ async * [Symbol.asyncIterator]() {
203
+ const iterator = iterable[Symbol.asyncIterator] === undefined ? iterable[Symbol.iterator]() : iterable[Symbol.asyncIterator]();
204
+
205
+ const promises = [];
206
+ let pendingPromisesCount = 0;
207
+ let isDone = false;
208
+ let index = 0;
209
+
210
+ function trySpawn() {
211
+ if (isDone || !(pendingPromisesCount < concurrency && promises.length < backpressure)) {
212
+ return;
213
+ }
214
+
215
+ pendingPromisesCount++;
216
+
217
+ const promise = (async () => {
218
+ const {done, value} = await iterator.next();
219
+
220
+ if (done) {
221
+ pendingPromisesCount--;
222
+ return {done: true};
223
+ }
224
+
225
+ // Spawn if still below concurrency and backpressure limit
226
+ trySpawn();
227
+
228
+ try {
229
+ const currentIndex = index++;
230
+ const returnValue = await mapper(await value, currentIndex);
231
+
232
+ pendingPromisesCount--;
233
+
234
+ if (returnValue === pMapSkip) {
235
+ const index = promises.indexOf(promise);
236
+
237
+ if (index > 0) {
238
+ promises.splice(index, 1);
239
+ }
240
+ }
241
+
242
+ // Spawn if still below backpressure limit and just dropped below concurrency limit
243
+ trySpawn();
244
+
245
+ return {done: false, value: returnValue};
246
+ } catch (error) {
247
+ pendingPromisesCount--;
248
+ isDone = true;
249
+ return {error};
250
+ }
251
+ })();
252
+
253
+ promises.push(promise);
254
+ }
255
+
256
+ trySpawn();
257
+
258
+ while (promises.length > 0) {
259
+ const {error, done, value} = await promises[0]; // eslint-disable-line no-await-in-loop
260
+
261
+ promises.shift();
262
+
263
+ if (error) {
264
+ throw error;
265
+ }
266
+
267
+ if (done) {
268
+ return;
269
+ }
270
+
271
+ // Spawn if just dropped below backpressure limit and below the concurrency limit
272
+ trySpawn();
273
+
274
+ if (value === pMapSkip) {
275
+ continue;
276
+ }
277
+
278
+ yield value;
279
+ }
280
+ },
281
+ };
282
+ }
283
+
284
+ export const pMapSkip = Symbol('skip');
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "p-map",
3
+ "version": "7.0.5",
4
+ "description": "Map over promises concurrently",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/p-map",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "scripts": {
23
+ "test": "xo && ava && tsd"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts"
28
+ ],
29
+ "keywords": [
30
+ "promise",
31
+ "map",
32
+ "resolved",
33
+ "wait",
34
+ "collection",
35
+ "iterable",
36
+ "iterator",
37
+ "race",
38
+ "fulfilled",
39
+ "async",
40
+ "await",
41
+ "promises",
42
+ "concurrently",
43
+ "concurrency",
44
+ "parallel",
45
+ "bluebird"
46
+ ],
47
+ "devDependencies": {
48
+ "ava": "^5.2.0",
49
+ "chalk": "^5.3.0",
50
+ "delay": "^6.0.0",
51
+ "in-range": "^3.0.0",
52
+ "random-int": "^3.0.0",
53
+ "time-span": "^5.1.0",
54
+ "tsd": "^0.29.0",
55
+ "xo": "^0.56.0"
56
+ }
57
+ }
@@ -0,0 +1,190 @@
1
+ # p-map
2
+
3
+ > Map over promises concurrently
4
+
5
+ Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
6
+
7
+ This is different from `Promise.all()` in that you can control the concurrency and also decide whether or not to stop iterating when there's an error.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install p-map
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import pMap from 'p-map';
19
+ import got from 'got';
20
+
21
+ const sites = [
22
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
23
+ 'https://avajs.dev',
24
+ 'https://github.com'
25
+ ];
26
+
27
+ const mapper = async site => {
28
+ const {requestUrl} = await got.head(site);
29
+ return requestUrl;
30
+ };
31
+
32
+ const result = await pMap(sites, mapper, {concurrency: 2});
33
+
34
+ console.log(result);
35
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### pMap(input, mapper, options?)
41
+
42
+ Returns a `Promise` that is fulfilled when all promises in `input` and the ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
43
+
44
+ ### pMapIterable(input, mapper, options?)
45
+
46
+ Returns an async iterable that streams each return value from `mapper` in order.
47
+
48
+ ```js
49
+ import {pMapIterable} from 'p-map';
50
+
51
+ // Multiple posts are fetched concurrently, with limited concurrency and backpressure
52
+ for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) {
53
+ console.log(post);
54
+ };
55
+ ```
56
+
57
+ #### input
58
+
59
+ Type: `AsyncIterable<Promise<unknown> | unknown> | Iterable<Promise<unknown> | unknown>`
60
+
61
+ Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item.
62
+
63
+ Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
64
+
65
+ #### mapper(element, index)
66
+
67
+ Type: `Function`
68
+
69
+ Expected to return a `Promise` or value.
70
+
71
+ #### options
72
+
73
+ Type: `object`
74
+
75
+ ##### concurrency
76
+
77
+ Type: `number` *(Integer)*\
78
+ Default: `Infinity`\
79
+ Minimum: `1`
80
+
81
+ Number of concurrently pending promises returned by `mapper`.
82
+
83
+ ##### backpressure
84
+
85
+ **Only for `pMapIterable`**
86
+
87
+ Type: `number` *(Integer)*\
88
+ Default: `options.concurrency`\
89
+ Minimum: `options.concurrency`
90
+
91
+ Maximum number of promises returned by `mapper` that have resolved but not yet collected by the consumer of the async iterable. Calls to `mapper` will be limited so that there is never too much backpressure.
92
+
93
+ Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
94
+
95
+ ##### stopOnError
96
+
97
+ **Only for `pMap`**
98
+
99
+ Type: `boolean`\
100
+ Default: `true`
101
+
102
+ When `true`, the first mapper rejection will be rejected back to the consumer.
103
+
104
+ When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) containing all the errors from the rejected promises.
105
+
106
+ Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. Use the `signal` option for abort control.
107
+
108
+ ##### signal
109
+
110
+ **Only for `pMap`**
111
+
112
+ Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
113
+
114
+ You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
115
+
116
+ ```js
117
+ import pMap from 'p-map';
118
+ import delay from 'delay';
119
+
120
+ const abortController = new AbortController();
121
+
122
+ setTimeout(() => {
123
+ abortController.abort();
124
+ }, 500);
125
+
126
+ const mapper = async value => value;
127
+
128
+ await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
129
+ // Throws AbortError (DOMException) after 500 ms.
130
+ ```
131
+
132
+ ### pMapSkip
133
+
134
+ Return this value from a `mapper` function to skip including the value in the returned array.
135
+
136
+ ```js
137
+ import pMap, {pMapSkip} from 'p-map';
138
+ import got from 'got';
139
+
140
+ const sites = [
141
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
142
+ 'https://avajs.dev',
143
+ 'https://example.invalid',
144
+ 'https://github.com'
145
+ ];
146
+
147
+ const mapper = async site => {
148
+ try {
149
+ const {requestUrl} = await got.head(site);
150
+ return requestUrl;
151
+ } catch {
152
+ return pMapSkip;
153
+ }
154
+ };
155
+
156
+ const result = await pMap(sites, mapper, {concurrency: 2});
157
+
158
+ console.log(result);
159
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
160
+ ```
161
+
162
+ ## Recipes
163
+
164
+ ### Rate limiting
165
+
166
+ This package controls how many mapper promises run concurrently. To limit how often the mapper starts, compose it with a rate limiter like [`p-throttle`](https://github.com/sindresorhus/p-throttle):
167
+
168
+ ```js
169
+ import pThrottle from 'p-throttle';
170
+ import pMap from 'p-map';
171
+
172
+ const throttle = pThrottle({
173
+ limit: 1,
174
+ interval: 1000,
175
+ strict: true,
176
+ });
177
+
178
+ const result = await pMap(input, throttle(mapper), {concurrency: 2});
179
+ ```
180
+
181
+ For more advanced scheduling, use [`p-queue`](https://github.com/sindresorhus/p-queue).
182
+
183
+ ## Related
184
+
185
+ - [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
186
+ - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
187
+ - [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
188
+ - [p-props](https://github.com/sindresorhus/p-props) - Like `Promise.all()` but for `Map` and `Object`
189
+ - [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
190
+ - [More…](https://github.com/sindresorhus/promise-fun)