@checkly/playwright-core 1.48.23 → 1.48.24-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 (71) hide show
  1. package/lib/generated/clockSource.js +1 -2
  2. package/lib/generated/consoleApiSource.js +1 -2
  3. package/lib/generated/injectedScriptSource.js +1 -2
  4. package/lib/generated/pollingRecorderSource.js +1 -2
  5. package/lib/generated/utilityScriptSource.js +1 -2
  6. package/lib/generated/webSocketMockSource.js +1 -2
  7. package/lib/vite/traceViewer/assets/codeMirrorModule-lDjkI8Ax.js +24 -0
  8. package/lib/vite/traceViewer/assets/inspectorTab-BPzhNk9r.js +64 -0
  9. package/lib/vite/traceViewer/assets/workbench-DLv_q9ji.js +9 -0
  10. package/lib/vite/traceViewer/embedded.BIubxTi3.js +2 -0
  11. package/lib/vite/traceViewer/embedded.html +3 -3
  12. package/lib/vite/traceViewer/index.DPD22sZn.js +2 -0
  13. package/lib/vite/traceViewer/index.html +3 -3
  14. package/lib/vite/traceViewer/recorder.BaRuS6Pc.js +2 -0
  15. package/lib/vite/traceViewer/recorder.html +2 -2
  16. package/lib/vite/traceViewer/uiMode.B11wexdJ.js +5 -0
  17. package/lib/vite/traceViewer/uiMode.html +3 -3
  18. package/package.json +1 -1
  19. package/lib/client/clientStackTrace.js +0 -65
  20. package/lib/client/fileUtils.js +0 -31
  21. package/lib/client/platform.js +0 -71
  22. package/lib/client/timeoutSettings.js +0 -65
  23. package/lib/client/webSocket.js +0 -106
  24. package/lib/server/callLog.js +0 -79
  25. package/lib/server/harBackend.js +0 -157
  26. package/lib/server/localUtils.js +0 -203
  27. package/lib/server/recorder/chat.js +0 -177
  28. package/lib/server/storageScript.js +0 -160
  29. package/lib/server/timeoutSettings.js +0 -74
  30. package/lib/server/utils/ascii.js +0 -31
  31. package/lib/server/utils/comparators.js +0 -159
  32. package/lib/server/utils/crypto.js +0 -171
  33. package/lib/server/utils/debug.js +0 -38
  34. package/lib/server/utils/debugLogger.js +0 -93
  35. package/lib/server/utils/env.js +0 -53
  36. package/lib/server/utils/eventsHelper.js +0 -38
  37. package/lib/server/utils/expectUtils.js +0 -33
  38. package/lib/server/utils/fileUtils.js +0 -204
  39. package/lib/server/utils/happyEyeballs.js +0 -209
  40. package/lib/server/utils/hostPlatform.js +0 -145
  41. package/lib/server/utils/httpServer.js +0 -233
  42. package/lib/server/utils/image_tools/colorUtils.js +0 -98
  43. package/lib/server/utils/image_tools/compare.js +0 -108
  44. package/lib/server/utils/image_tools/imageChannel.js +0 -70
  45. package/lib/server/utils/image_tools/stats.js +0 -102
  46. package/lib/server/utils/linuxUtils.js +0 -58
  47. package/lib/server/utils/network.js +0 -160
  48. package/lib/server/utils/nodePlatform.js +0 -140
  49. package/lib/server/utils/pipeTransport.js +0 -82
  50. package/lib/server/utils/processLauncher.js +0 -248
  51. package/lib/server/utils/profiler.js +0 -52
  52. package/lib/server/utils/socksProxy.js +0 -570
  53. package/lib/server/utils/spawnAsync.js +0 -45
  54. package/lib/server/utils/task.js +0 -58
  55. package/lib/server/utils/userAgent.js +0 -91
  56. package/lib/server/utils/wsServer.js +0 -128
  57. package/lib/server/utils/zipFile.js +0 -75
  58. package/lib/server/utils/zones.js +0 -54
  59. package/lib/utils/isomorphic/ariaSnapshot.js +0 -392
  60. package/lib/utils/isomorphic/assert.js +0 -25
  61. package/lib/utils/isomorphic/colors.js +0 -65
  62. package/lib/utils/isomorphic/headers.js +0 -52
  63. package/lib/utils/isomorphic/manualPromise.js +0 -107
  64. package/lib/utils/isomorphic/multimap.js +0 -73
  65. package/lib/utils/isomorphic/rtti.js +0 -41
  66. package/lib/utils/isomorphic/semaphore.js +0 -51
  67. package/lib/utils/isomorphic/stackTrace.js +0 -169
  68. package/lib/utils/isomorphic/time.js +0 -25
  69. package/lib/utils/isomorphic/timeoutRunner.js +0 -66
  70. package/lib/utils/isomorphic/types.js +0 -5
  71. package/lib/utils.js +0 -447
@@ -1,392 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ParserError = exports.KeyParser = void 0;
7
- exports.parseAriaSnapshot = parseAriaSnapshot;
8
- exports.parseAriaSnapshotUnsafe = parseAriaSnapshotUnsafe;
9
- exports.valueOrRegex = valueOrRegex;
10
- /**
11
- * Copyright (c) Microsoft Corporation.
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
-
26
- // https://www.w3.org/TR/wai-aria-1.2/#role_definitions
27
-
28
- // We pass parsed template between worlds using JSON, make it easy.
29
-
30
- function parseAriaSnapshotUnsafe(yaml, text) {
31
- const result = parseAriaSnapshot(yaml, text);
32
- if (result.errors.length) throw new Error(result.errors[0].message);
33
- return result.fragment;
34
- }
35
- function parseAriaSnapshot(yaml, text, options = {}) {
36
- var _fragment$children;
37
- const lineCounter = new yaml.LineCounter();
38
- const parseOptions = {
39
- keepSourceTokens: true,
40
- lineCounter,
41
- ...options
42
- };
43
- const yamlDoc = yaml.parseDocument(text, parseOptions);
44
- const errors = [];
45
- const convertRange = range => {
46
- return [lineCounter.linePos(range[0]), lineCounter.linePos(range[1])];
47
- };
48
- const addError = error => {
49
- errors.push({
50
- message: error.message,
51
- range: [lineCounter.linePos(error.pos[0]), lineCounter.linePos(error.pos[1])]
52
- });
53
- };
54
- const convertSeq = (container, seq) => {
55
- for (const item of seq.items) {
56
- const itemIsString = item instanceof yaml.Scalar && typeof item.value === 'string';
57
- if (itemIsString) {
58
- const childNode = KeyParser.parse(item, parseOptions, errors);
59
- if (childNode) {
60
- container.children = container.children || [];
61
- container.children.push(childNode);
62
- }
63
- continue;
64
- }
65
- const itemIsMap = item instanceof yaml.YAMLMap;
66
- if (itemIsMap) {
67
- convertMap(container, item);
68
- continue;
69
- }
70
- errors.push({
71
- message: 'Sequence items should be strings or maps',
72
- range: convertRange(item.range || seq.range)
73
- });
74
- }
75
- };
76
- const convertMap = (container, map) => {
77
- for (const entry of map.items) {
78
- container.children = container.children || [];
79
- // Key must by a string
80
- const keyIsString = entry.key instanceof yaml.Scalar && typeof entry.key.value === 'string';
81
- if (!keyIsString) {
82
- errors.push({
83
- message: 'Only string keys are supported',
84
- range: convertRange(entry.key.range || map.range)
85
- });
86
- continue;
87
- }
88
- const key = entry.key;
89
- const value = entry.value;
90
-
91
- // - text: "text"
92
- if (key.value === 'text') {
93
- const valueIsString = value instanceof yaml.Scalar && typeof value.value === 'string';
94
- if (!valueIsString) {
95
- errors.push({
96
- message: 'Text value should be a string',
97
- range: convertRange(entry.value.range || map.range)
98
- });
99
- continue;
100
- }
101
- container.children.push({
102
- kind: 'text',
103
- text: valueOrRegex(value.value)
104
- });
105
- continue;
106
- }
107
-
108
- // role "name": ...
109
- const childNode = KeyParser.parse(key, parseOptions, errors);
110
- if (!childNode) continue;
111
-
112
- // - role "name": "text"
113
- const valueIsScalar = value instanceof yaml.Scalar;
114
- if (valueIsScalar) {
115
- const type = typeof value.value;
116
- if (type !== 'string' && type !== 'number' && type !== 'boolean') {
117
- errors.push({
118
- message: 'Node value should be a string or a sequence',
119
- range: convertRange(entry.value.range || map.range)
120
- });
121
- continue;
122
- }
123
- container.children.push({
124
- ...childNode,
125
- children: [{
126
- kind: 'text',
127
- text: valueOrRegex(String(value.value))
128
- }]
129
- });
130
- continue;
131
- }
132
-
133
- // - role "name":
134
- // - child
135
- const valueIsSequence = value instanceof yaml.YAMLSeq;
136
- if (valueIsSequence) {
137
- container.children.push(childNode);
138
- convertSeq(childNode, value);
139
- continue;
140
- }
141
- errors.push({
142
- message: 'Map values should be strings or sequences',
143
- range: convertRange(entry.value.range || map.range)
144
- });
145
- }
146
- };
147
- const fragment = {
148
- kind: 'role',
149
- role: 'fragment'
150
- };
151
- yamlDoc.errors.forEach(addError);
152
- if (errors.length) return {
153
- errors,
154
- fragment
155
- };
156
- if (!(yamlDoc.contents instanceof yaml.YAMLSeq)) {
157
- errors.push({
158
- message: 'Aria snapshot must be a YAML sequence, elements starting with " -"',
159
- range: yamlDoc.contents ? convertRange(yamlDoc.contents.range) : [{
160
- line: 0,
161
- col: 0
162
- }, {
163
- line: 0,
164
- col: 0
165
- }]
166
- });
167
- }
168
- if (errors.length) return {
169
- errors,
170
- fragment
171
- };
172
- convertSeq(fragment, yamlDoc.contents);
173
- if (errors.length) return {
174
- errors,
175
- fragment: emptyFragment
176
- };
177
- if (((_fragment$children = fragment.children) === null || _fragment$children === void 0 ? void 0 : _fragment$children.length) === 1) return {
178
- fragment: fragment.children[0],
179
- errors
180
- };
181
- return {
182
- fragment,
183
- errors
184
- };
185
- }
186
- const emptyFragment = {
187
- kind: 'role',
188
- role: 'fragment'
189
- };
190
- function normalizeWhitespace(text) {
191
- // TODO: why is this different from normalizeWhitespace in stringUtils.ts?
192
- return text.replace(/[\u200b\u00ad]/g, '').replace(/[\r\n\s\t]+/g, ' ').trim();
193
- }
194
- function valueOrRegex(value) {
195
- return value.startsWith('/') && value.endsWith('/') && value.length > 1 ? {
196
- pattern: value.slice(1, -1)
197
- } : normalizeWhitespace(value);
198
- }
199
- class KeyParser {
200
- static parse(text, options, errors) {
201
- try {
202
- return new KeyParser(text.value)._parse();
203
- } catch (e) {
204
- if (e instanceof ParserError) {
205
- const message = options.prettyErrors === false ? e.message : e.message + ':\n\n' + text.value + '\n' + ' '.repeat(e.pos) + '^\n';
206
- errors.push({
207
- message,
208
- range: [options.lineCounter.linePos(text.range[0]), options.lineCounter.linePos(text.range[0] + e.pos)]
209
- });
210
- return null;
211
- }
212
- throw e;
213
- }
214
- }
215
- constructor(input) {
216
- this._input = void 0;
217
- this._pos = void 0;
218
- this._length = void 0;
219
- this._input = input;
220
- this._pos = 0;
221
- this._length = input.length;
222
- }
223
- _peek() {
224
- return this._input[this._pos] || '';
225
- }
226
- _next() {
227
- if (this._pos < this._length) return this._input[this._pos++];
228
- return null;
229
- }
230
- _eof() {
231
- return this._pos >= this._length;
232
- }
233
- _isWhitespace() {
234
- return !this._eof() && /\s/.test(this._peek());
235
- }
236
- _skipWhitespace() {
237
- while (this._isWhitespace()) this._pos++;
238
- }
239
- _readIdentifier(type) {
240
- if (this._eof()) this._throwError(`Unexpected end of input when expecting ${type}`);
241
- const start = this._pos;
242
- while (!this._eof() && /[a-zA-Z]/.test(this._peek())) this._pos++;
243
- return this._input.slice(start, this._pos);
244
- }
245
- _readString() {
246
- let result = '';
247
- let escaped = false;
248
- while (!this._eof()) {
249
- const ch = this._next();
250
- if (escaped) {
251
- result += ch;
252
- escaped = false;
253
- } else if (ch === '\\') {
254
- escaped = true;
255
- } else if (ch === '"') {
256
- return result;
257
- } else {
258
- result += ch;
259
- }
260
- }
261
- this._throwError('Unterminated string');
262
- }
263
- _throwError(message, offset = 0) {
264
- throw new ParserError(message, offset || this._pos);
265
- }
266
- _readRegex() {
267
- let result = '';
268
- let escaped = false;
269
- let insideClass = false;
270
- while (!this._eof()) {
271
- const ch = this._next();
272
- if (escaped) {
273
- result += ch;
274
- escaped = false;
275
- } else if (ch === '\\') {
276
- escaped = true;
277
- result += ch;
278
- } else if (ch === '/' && !insideClass) {
279
- return {
280
- pattern: result
281
- };
282
- } else if (ch === '[') {
283
- insideClass = true;
284
- result += ch;
285
- } else if (ch === ']' && insideClass) {
286
- result += ch;
287
- insideClass = false;
288
- } else {
289
- result += ch;
290
- }
291
- }
292
- this._throwError('Unterminated regex');
293
- }
294
- _readStringOrRegex() {
295
- const ch = this._peek();
296
- if (ch === '"') {
297
- this._next();
298
- return normalizeWhitespace(this._readString());
299
- }
300
- if (ch === '/') {
301
- this._next();
302
- return this._readRegex();
303
- }
304
- return null;
305
- }
306
- _readAttributes(result) {
307
- let errorPos = this._pos;
308
- while (true) {
309
- this._skipWhitespace();
310
- if (this._peek() === '[') {
311
- this._next();
312
- this._skipWhitespace();
313
- errorPos = this._pos;
314
- const flagName = this._readIdentifier('attribute');
315
- this._skipWhitespace();
316
- let flagValue = '';
317
- if (this._peek() === '=') {
318
- this._next();
319
- this._skipWhitespace();
320
- errorPos = this._pos;
321
- while (this._peek() !== ']' && !this._isWhitespace() && !this._eof()) flagValue += this._next();
322
- }
323
- this._skipWhitespace();
324
- if (this._peek() !== ']') this._throwError('Expected ]');
325
- this._next(); // Consume ']'
326
- this._applyAttribute(result, flagName, flagValue || 'true', errorPos);
327
- } else {
328
- break;
329
- }
330
- }
331
- }
332
- _parse() {
333
- this._skipWhitespace();
334
- const role = this._readIdentifier('role');
335
- this._skipWhitespace();
336
- const name = this._readStringOrRegex() || '';
337
- const result = {
338
- kind: 'role',
339
- role,
340
- name
341
- };
342
- this._readAttributes(result);
343
- this._skipWhitespace();
344
- if (!this._eof()) this._throwError('Unexpected input');
345
- return result;
346
- }
347
- _applyAttribute(node, key, value, errorPos) {
348
- if (key === 'checked') {
349
- this._assert(value === 'true' || value === 'false' || value === 'mixed', 'Value of "checked\" attribute must be a boolean or "mixed"', errorPos);
350
- node.checked = value === 'true' ? true : value === 'false' ? false : 'mixed';
351
- return;
352
- }
353
- if (key === 'disabled') {
354
- this._assert(value === 'true' || value === 'false', 'Value of "disabled" attribute must be a boolean', errorPos);
355
- node.disabled = value === 'true';
356
- return;
357
- }
358
- if (key === 'expanded') {
359
- this._assert(value === 'true' || value === 'false', 'Value of "expanded" attribute must be a boolean', errorPos);
360
- node.expanded = value === 'true';
361
- return;
362
- }
363
- if (key === 'level') {
364
- this._assert(!isNaN(Number(value)), 'Value of "level" attribute must be a number', errorPos);
365
- node.level = Number(value);
366
- return;
367
- }
368
- if (key === 'pressed') {
369
- this._assert(value === 'true' || value === 'false' || value === 'mixed', 'Value of "pressed" attribute must be a boolean or "mixed"', errorPos);
370
- node.pressed = value === 'true' ? true : value === 'false' ? false : 'mixed';
371
- return;
372
- }
373
- if (key === 'selected') {
374
- this._assert(value === 'true' || value === 'false', 'Value of "selected" attribute must be a boolean', errorPos);
375
- node.selected = value === 'true';
376
- return;
377
- }
378
- this._assert(false, `Unsupported attribute [${key}]`, errorPos);
379
- }
380
- _assert(value, message, valuePos) {
381
- if (!value) this._throwError(message || 'Assertion error', valuePos);
382
- }
383
- }
384
- exports.KeyParser = KeyParser;
385
- class ParserError extends Error {
386
- constructor(message, pos) {
387
- super(message);
388
- this.pos = void 0;
389
- this.pos = pos;
390
- }
391
- }
392
- exports.ParserError = ParserError;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.assert = assert;
7
- /**
8
- * Copyright (c) Microsoft Corporation.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- function assert(value, message) {
24
- if (!value) throw new Error(message || 'Assertion error');
25
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.webColors = exports.noColors = void 0;
7
- /**
8
- * Copyright (c) Microsoft Corporation.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- const webColors = exports.webColors = {
24
- enabled: true,
25
- reset: text => applyStyle(0, 0, text),
26
- bold: text => applyStyle(1, 22, text),
27
- dim: text => applyStyle(2, 22, text),
28
- italic: text => applyStyle(3, 23, text),
29
- underline: text => applyStyle(4, 24, text),
30
- inverse: text => applyStyle(7, 27, text),
31
- hidden: text => applyStyle(8, 28, text),
32
- strikethrough: text => applyStyle(9, 29, text),
33
- black: text => applyStyle(30, 39, text),
34
- red: text => applyStyle(31, 39, text),
35
- green: text => applyStyle(32, 39, text),
36
- yellow: text => applyStyle(33, 39, text),
37
- blue: text => applyStyle(34, 39, text),
38
- magenta: text => applyStyle(35, 39, text),
39
- cyan: text => applyStyle(36, 39, text),
40
- white: text => applyStyle(37, 39, text),
41
- gray: text => applyStyle(90, 39, text),
42
- grey: text => applyStyle(90, 39, text)
43
- };
44
- const noColors = exports.noColors = {
45
- enabled: false,
46
- reset: t => t,
47
- bold: t => t,
48
- dim: t => t,
49
- italic: t => t,
50
- underline: t => t,
51
- inverse: t => t,
52
- hidden: t => t,
53
- strikethrough: t => t,
54
- black: t => t,
55
- red: t => t,
56
- green: t => t,
57
- yellow: t => t,
58
- blue: t => t,
59
- magenta: t => t,
60
- cyan: t => t,
61
- white: t => t,
62
- gray: t => t,
63
- grey: t => t
64
- };
65
- const applyStyle = (open, close, text) => `\u001b[${open}m${text}\u001b[${close}m`;
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.headersArrayToObject = headersArrayToObject;
7
- exports.headersObjectToArray = headersObjectToArray;
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- function headersObjectToArray(headers, separator, setCookieSeparator) {
25
- if (!setCookieSeparator) setCookieSeparator = separator;
26
- const result = [];
27
- for (const name in headers) {
28
- const values = headers[name];
29
- if (values === undefined) continue;
30
- if (separator) {
31
- const sep = name.toLowerCase() === 'set-cookie' ? setCookieSeparator : separator;
32
- for (const value of values.split(sep)) result.push({
33
- name,
34
- value: value.trim()
35
- });
36
- } else {
37
- result.push({
38
- name,
39
- value: values
40
- });
41
- }
42
- }
43
- return result;
44
- }
45
- function headersArrayToObject(headers, lowerCase) {
46
- const result = {};
47
- for (const {
48
- name,
49
- value
50
- } of headers) result[lowerCase ? name.toLowerCase() : name] = value;
51
- return result;
52
- }
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ManualPromise = exports.LongStandingScope = void 0;
7
- var _stackTrace = require("./stackTrace");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- class ManualPromise extends Promise {
25
- constructor() {
26
- let resolve;
27
- let reject;
28
- super((f, r) => {
29
- resolve = f;
30
- reject = r;
31
- });
32
- this._resolve = void 0;
33
- this._reject = void 0;
34
- this._isDone = void 0;
35
- this._isDone = false;
36
- this._resolve = resolve;
37
- this._reject = reject;
38
- }
39
- isDone() {
40
- return this._isDone;
41
- }
42
- resolve(t) {
43
- this._isDone = true;
44
- this._resolve(t);
45
- }
46
- reject(e) {
47
- this._isDone = true;
48
- this._reject(e);
49
- }
50
- static get [Symbol.species]() {
51
- return Promise;
52
- }
53
- get [Symbol.toStringTag]() {
54
- return 'ManualPromise';
55
- }
56
- }
57
- exports.ManualPromise = ManualPromise;
58
- class LongStandingScope {
59
- constructor() {
60
- this._terminateError = void 0;
61
- this._closeError = void 0;
62
- this._terminatePromises = new Map();
63
- this._isClosed = false;
64
- }
65
- reject(error) {
66
- this._isClosed = true;
67
- this._terminateError = error;
68
- for (const p of this._terminatePromises.keys()) p.resolve(error);
69
- }
70
- close(error) {
71
- this._isClosed = true;
72
- this._closeError = error;
73
- for (const [p, frames] of this._terminatePromises) p.resolve(cloneError(error, frames));
74
- }
75
- isClosed() {
76
- return this._isClosed;
77
- }
78
- static async raceMultiple(scopes, promise) {
79
- return Promise.race(scopes.map(s => s.race(promise)));
80
- }
81
- async race(promise) {
82
- return this._race(Array.isArray(promise) ? promise : [promise], false);
83
- }
84
- async safeRace(promise, defaultValue) {
85
- return this._race([promise], true, defaultValue);
86
- }
87
- async _race(promises, safe, defaultValue) {
88
- const terminatePromise = new ManualPromise();
89
- const frames = (0, _stackTrace.captureRawStack)();
90
- if (this._terminateError) terminatePromise.resolve(this._terminateError);
91
- if (this._closeError) terminatePromise.resolve(cloneError(this._closeError, frames));
92
- this._terminatePromises.set(terminatePromise, frames);
93
- try {
94
- return await Promise.race([terminatePromise.then(e => safe ? defaultValue : Promise.reject(e)), ...promises]);
95
- } finally {
96
- this._terminatePromises.delete(terminatePromise);
97
- }
98
- }
99
- }
100
- exports.LongStandingScope = LongStandingScope;
101
- function cloneError(error, frames) {
102
- const clone = new Error();
103
- clone.name = error.name;
104
- clone.message = error.message;
105
- clone.stack = [error.name + ':' + error.message, ...frames].join('\n');
106
- return clone;
107
- }