@remotion/renderer 3.0.31 → 3.1.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 (93) hide show
  1. package/dist/browser/NetworkManager.js +1 -5
  2. package/dist/combine-videos.d.ts +2 -1
  3. package/dist/combine-videos.js +8 -2
  4. package/dist/convert-number-of-gif-loops-to-ffmpeg.d.ts +1 -0
  5. package/dist/convert-number-of-gif-loops-to-ffmpeg.js +17 -0
  6. package/dist/ensure-frames-in-order.d.ts +1 -1
  7. package/dist/ensure-frames-in-order.js +3 -2
  8. package/dist/ensure-presentation-timestamp.d.ts +1 -1
  9. package/dist/ensure-presentation-timestamp.js +9 -10
  10. package/dist/extract-frame-from-video.js +4 -2
  11. package/dist/get-codec-name.js +3 -0
  12. package/dist/get-duration-from-frame-range.d.ts +1 -2
  13. package/dist/get-duration-from-frame-range.js +13 -9
  14. package/dist/get-extension-from-codec.d.ts +1 -1
  15. package/dist/get-extension-from-codec.js +5 -0
  16. package/dist/index.d.ts +4 -3
  17. package/dist/index.js +3 -1
  18. package/dist/mime-types.d.ts +1 -1
  19. package/dist/mime-types.js +2 -2
  20. package/dist/prespawn-ffmpeg.js +2 -2
  21. package/dist/render-frames.d.ts +1 -0
  22. package/dist/render-frames.js +12 -16
  23. package/dist/render-media.d.ts +2 -0
  24. package/dist/render-media.js +11 -4
  25. package/dist/render-still.js +1 -1
  26. package/dist/stitch-frames-to-video.d.ts +1 -0
  27. package/dist/stitch-frames-to-video.js +32 -22
  28. package/dist/validate-output-filename.js +5 -0
  29. package/package.json +8 -10
  30. package/tsconfig.json +2 -1
  31. package/vitest.config.ts +8 -0
  32. package/dist/abort.d.ts +0 -7
  33. package/dist/abort.js +0 -20
  34. package/dist/assets/cleanup-assets.d.ts +0 -2
  35. package/dist/assets/cleanup-assets.js +0 -2
  36. package/dist/browser/ConnectionTransport.d.ts +0 -21
  37. package/dist/browser/ConnectionTransport.js +0 -17
  38. package/dist/browser/EmulationManager.d.ts +0 -7
  39. package/dist/browser/EmulationManager.js +0 -40
  40. package/dist/browser/Page.d.ts +0 -74
  41. package/dist/browser/Page.js +0 -283
  42. package/dist/browser/compat.d.ts +0 -2
  43. package/dist/browser/compat.js +0 -17
  44. package/dist/browser/environment.d.ts +0 -16
  45. package/dist/browser/environment.js +0 -19
  46. package/dist/browser/ws.d.ts +0 -287
  47. package/dist/browser/ws.js +0 -21
  48. package/dist/cancel.d.ts +0 -7
  49. package/dist/cancel.js +0 -25
  50. package/dist/ensure-faststart.d.ts +0 -1
  51. package/dist/ensure-faststart.js +0 -14
  52. package/dist/faststart/atom.d.ts +0 -35
  53. package/dist/faststart/atom.js +0 -138
  54. package/dist/faststart/index.d.ts +0 -0
  55. package/dist/faststart/index.js +0 -1
  56. package/dist/faststart/options.d.ts +0 -6
  57. package/dist/faststart/options.js +0 -2
  58. package/dist/faststart/qt-faststart.d.ts +0 -18
  59. package/dist/faststart/qt-faststart.js +0 -66
  60. package/dist/faststart/update-chunk-offsets.d.ts +0 -10
  61. package/dist/faststart/update-chunk-offsets.js +0 -114
  62. package/dist/faststart/util.d.ts +0 -9
  63. package/dist/faststart/util.js +0 -34
  64. package/dist/get-duration-of-asset.d.ts +0 -7
  65. package/dist/get-duration-of-asset.js +0 -36
  66. package/dist/is-vp9-video.d.ts +0 -3
  67. package/dist/is-vp9-video.js +0 -24
  68. package/dist/offthread/index.d.ts +0 -0
  69. package/dist/offthread/index.js +0 -1
  70. package/dist/render-gif.d.ts +0 -2
  71. package/dist/render-gif.js +0 -242
  72. package/dist/serve-handler/glob-slash.d.ts +0 -1
  73. package/dist/serve-handler/glob-slash.js +0 -12
  74. package/dist/should-use-vp9-decoder.d.ts +0 -0
  75. package/dist/should-use-vp9-decoder.js +0 -1
  76. package/dist/stitch-frames-to-gif.d.ts +0 -8
  77. package/dist/stitch-frames-to-gif.js +0 -128
  78. package/dist/validate-fps-for-gif.d.ts +0 -2
  79. package/dist/validate-fps-for-gif.js +0 -9
  80. package/dist/validate-offthreadvideo-image-format.d.ts +0 -1
  81. package/dist/validate-offthreadvideo-image-format.js +0 -15
  82. package/dist/ws/buffer-util.d.ts +0 -10
  83. package/dist/ws/buffer-util.js +0 -123
  84. package/dist/ws/constants.d.ts +0 -10
  85. package/dist/ws/constants.js +0 -13
  86. package/dist/ws/event-target.d.ts +0 -155
  87. package/dist/ws/event-target.js +0 -203
  88. package/dist/ws/extension.d.ts +0 -16
  89. package/dist/ws/extension.js +0 -232
  90. package/dist/ws/limiter.d.ts +0 -34
  91. package/dist/ws/limiter.js +0 -41
  92. package/dist/ws/permessage_deflate.d.ts +0 -152
  93. package/dist/ws/permessage_deflate.js +0 -409
@@ -1,155 +0,0 @@
1
- declare const kCode: unique symbol;
2
- declare const kData: unique symbol;
3
- declare const kError: unique symbol;
4
- declare const kMessage: unique symbol;
5
- declare const kReason: unique symbol;
6
- declare const kTarget: unique symbol;
7
- declare const kType: unique symbol;
8
- declare const kWasClean: unique symbol;
9
- /**
10
- * Class representing an event.
11
- */
12
- export declare class Event {
13
- /**
14
- * Create a new `Event`.
15
- *
16
- * @param {String} type The name of the event
17
- * @throws {TypeError} If the `type` argument is not specified
18
- */
19
- [kTarget]: null;
20
- [kType]: string;
21
- constructor(type: string);
22
- /**
23
- * @type {*}
24
- */
25
- get target(): null;
26
- /**
27
- * @type {String}
28
- */
29
- get type(): string;
30
- }
31
- /**
32
- * Class representing a close event.
33
- *
34
- * @extends Event
35
- */
36
- export declare class CloseEvent extends Event {
37
- /**
38
- * Create a new `CloseEvent`.
39
- *
40
- * @param {String} type The name of the event
41
- * @param {Object} [options] A dictionary object that allows for setting
42
- * attributes via object members of the same name
43
- * @param {Number} [options.code=0] The status code explaining why the
44
- * connection was closed
45
- * @param {String} [options.reason=''] A human-readable string explaining why
46
- * the connection was closed
47
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
48
- * connection was cleanly closed
49
- */
50
- [kCode]: number;
51
- [kReason]: string;
52
- [kWasClean]: boolean;
53
- constructor(type: string, options?: {
54
- code?: number;
55
- reason?: string;
56
- wasClean?: boolean;
57
- });
58
- /**
59
- * @type {Number}
60
- */
61
- get code(): number;
62
- /**
63
- * @type {String}
64
- */
65
- get reason(): string;
66
- /**
67
- * @type {Boolean}
68
- */
69
- get wasClean(): boolean;
70
- }
71
- /**
72
- * Class representing an error event.
73
- *
74
- * @extends Event
75
- */
76
- export declare class ErrorEvent extends Event {
77
- /**
78
- * Create a new `ErrorEvent`.
79
- *
80
- * @param {String} type The name of the event
81
- * @param {Object} [options] A dictionary object that allows for setting
82
- * attributes via object members of the same name
83
- * @param {*} [options.error=null] The error that generated this event
84
- * @param {String} [options.message=''] The error message
85
- */
86
- [kError]: Error | null;
87
- [kMessage]: string;
88
- constructor(type: string, options?: {
89
- error?: Error;
90
- message?: string;
91
- });
92
- /**
93
- * @type {*}
94
- */
95
- get error(): Error | null;
96
- /**
97
- * @type {String}
98
- */
99
- get message(): string;
100
- }
101
- /**
102
- * Class representing a message event.
103
- *
104
- * @extends Event
105
- */
106
- export declare class MessageEvent extends Event {
107
- /**
108
- * Create a new `MessageEvent`.
109
- *
110
- * @param {String} type The name of the event
111
- * @param {Object} [options] A dictionary object that allows for setting
112
- * attributes via object members of the same name
113
- * @param {*} [options.data=null] The message content
114
- */
115
- [kData]: unknown;
116
- constructor(type: string, options?: {
117
- data?: unknown;
118
- });
119
- /**
120
- * @type {*}
121
- */
122
- get data(): unknown;
123
- }
124
- /**
125
- * This provides methods for emulating the `EventTarget` interface. It's not
126
- * meant to be used directly.
127
- *
128
- * @mixin
129
- */
130
- export declare const EventTarget: {
131
- /**
132
- * Register an event listener.
133
- *
134
- * @param {String} type A string representing the event type to listen for
135
- * @param {Function} listener The listener to add
136
- * @param {Object} [options] An options object specifies characteristics about
137
- * the event listener
138
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
139
- * listener should be invoked at most once after being added. If `true`,
140
- * the listener would be automatically removed when invoked.
141
- * @public
142
- */
143
- addEventListener(type: 'message' | 'close' | 'error' | 'open', listener: (event: MessageEvent | CloseEvent | ErrorEvent | Event) => void, options?: {
144
- once?: boolean;
145
- }): void;
146
- /**
147
- * Remove an event listener.
148
- *
149
- * @param {String} type A string representing the event type to remove
150
- * @param {Function} handler The listener to remove
151
- * @public
152
- */
153
- removeEventListener(type: string, handler: () => undefined): void;
154
- };
155
- export {};
@@ -1,203 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventTarget = exports.MessageEvent = exports.ErrorEvent = exports.CloseEvent = exports.Event = void 0;
4
- const { kForOnEventAttribute, kListener } = require('./constants');
5
- const kCode = Symbol('kCode');
6
- const kData = Symbol('kData');
7
- const kError = Symbol('kError');
8
- const kMessage = Symbol('kMessage');
9
- const kReason = Symbol('kReason');
10
- const kTarget = Symbol('kTarget');
11
- const kType = Symbol('kType');
12
- const kWasClean = Symbol('kWasClean');
13
- /**
14
- * Class representing an event.
15
- */
16
- class Event {
17
- constructor(type) {
18
- this[kTarget] = null;
19
- this[kType] = type;
20
- }
21
- /**
22
- * @type {*}
23
- */
24
- get target() {
25
- return this[kTarget];
26
- }
27
- /**
28
- * @type {String}
29
- */
30
- get type() {
31
- return this[kType];
32
- }
33
- }
34
- exports.Event = Event;
35
- Object.defineProperty(Event.prototype, 'target', { enumerable: true });
36
- Object.defineProperty(Event.prototype, 'type', { enumerable: true });
37
- /**
38
- * Class representing a close event.
39
- *
40
- * @extends Event
41
- */
42
- class CloseEvent extends Event {
43
- constructor(type, options = {}) {
44
- super(type);
45
- this[kCode] = options.code === undefined ? 0 : options.code;
46
- this[kReason] = options.reason === undefined ? '' : options.reason;
47
- this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
48
- }
49
- /**
50
- * @type {Number}
51
- */
52
- get code() {
53
- return this[kCode];
54
- }
55
- /**
56
- * @type {String}
57
- */
58
- get reason() {
59
- return this[kReason];
60
- }
61
- /**
62
- * @type {Boolean}
63
- */
64
- get wasClean() {
65
- return this[kWasClean];
66
- }
67
- }
68
- exports.CloseEvent = CloseEvent;
69
- Object.defineProperty(CloseEvent.prototype, 'code', { enumerable: true });
70
- Object.defineProperty(CloseEvent.prototype, 'reason', { enumerable: true });
71
- Object.defineProperty(CloseEvent.prototype, 'wasClean', { enumerable: true });
72
- /**
73
- * Class representing an error event.
74
- *
75
- * @extends Event
76
- */
77
- class ErrorEvent extends Event {
78
- constructor(type, options = {}) {
79
- super(type);
80
- this[kError] = options.error === undefined ? null : options.error;
81
- this[kMessage] = options.message === undefined ? '' : options.message;
82
- }
83
- /**
84
- * @type {*}
85
- */
86
- get error() {
87
- return this[kError];
88
- }
89
- /**
90
- * @type {String}
91
- */
92
- get message() {
93
- return this[kMessage];
94
- }
95
- }
96
- exports.ErrorEvent = ErrorEvent;
97
- Object.defineProperty(ErrorEvent.prototype, 'error', { enumerable: true });
98
- Object.defineProperty(ErrorEvent.prototype, 'message', { enumerable: true });
99
- /**
100
- * Class representing a message event.
101
- *
102
- * @extends Event
103
- */
104
- class MessageEvent extends Event {
105
- constructor(type, options = {}) {
106
- super(type);
107
- this[kData] = options.data === undefined ? null : options.data;
108
- }
109
- /**
110
- * @type {*}
111
- */
112
- get data() {
113
- return this[kData];
114
- }
115
- }
116
- exports.MessageEvent = MessageEvent;
117
- Object.defineProperty(MessageEvent.prototype, 'data', { enumerable: true });
118
- /**
119
- * This provides methods for emulating the `EventTarget` interface. It's not
120
- * meant to be used directly.
121
- *
122
- * @mixin
123
- */
124
- exports.EventTarget = {
125
- /**
126
- * Register an event listener.
127
- *
128
- * @param {String} type A string representing the event type to listen for
129
- * @param {Function} listener The listener to add
130
- * @param {Object} [options] An options object specifies characteristics about
131
- * the event listener
132
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
133
- * listener should be invoked at most once after being added. If `true`,
134
- * the listener would be automatically removed when invoked.
135
- * @public
136
- */
137
- addEventListener(type, listener, options = {}) {
138
- let wrapper;
139
- if (type === 'message') {
140
- wrapper = function (data, isBinary) {
141
- const event = new MessageEvent('message', {
142
- data: isBinary ? data : data.toString(),
143
- });
144
- event[kTarget] = this;
145
- listener.call(this, event);
146
- };
147
- }
148
- else if (type === 'close') {
149
- wrapper = function (code, message) {
150
- const event = new CloseEvent('close', {
151
- code,
152
- reason: message.toString(),
153
- wasClean: this._closeFrameReceived && this._closeFrameSent,
154
- });
155
- event[kTarget] = this;
156
- listener.call(this, event);
157
- };
158
- }
159
- else if (type === 'error') {
160
- wrapper = function (error) {
161
- const event = new ErrorEvent('error', {
162
- error,
163
- message: error.message,
164
- });
165
- event[kTarget] = this;
166
- listener.call(this, event);
167
- };
168
- }
169
- else if (type === 'open') {
170
- wrapper = function () {
171
- const event = new Event('open');
172
- event[kTarget] = this;
173
- listener.call(this, event);
174
- };
175
- }
176
- else {
177
- return;
178
- }
179
- wrapper[kForOnEventAttribute] = Boolean(options[kForOnEventAttribute]);
180
- wrapper[kListener] = listener;
181
- if (options.once) {
182
- this.once(type, wrapper);
183
- }
184
- else {
185
- this.on(type, wrapper);
186
- }
187
- },
188
- /**
189
- * Remove an event listener.
190
- *
191
- * @param {String} type A string representing the event type to remove
192
- * @param {Function} handler The listener to remove
193
- * @public
194
- */
195
- removeEventListener(type, handler) {
196
- for (const listener of this.listeners(type)) {
197
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
198
- this.removeListener(type, listener);
199
- break;
200
- }
201
- }
202
- },
203
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * Parses the `Sec-WebSocket-Extensions` header into an object.
3
- *
4
- * @param {String} header The field value of the header
5
- * @return {Object} The parsed object
6
- * @public
7
- */
8
- export declare function parse(header: string): any;
9
- /**
10
- * Builds the `Sec-WebSocket-Extensions` header field value.
11
- *
12
- * @param {Object} extensions The map of extensions and parameters to format
13
- * @return {String} A string representing the given object
14
- * @public
15
- */
16
- export declare function format(extensions: Record<string, Record<string, any>>): string;
@@ -1,232 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.format = exports.parse = void 0;
4
- const { tokenChars } = require('./validation');
5
- /**
6
- * Adds an offer to the map of extension offers or a parameter to the map of
7
- * parameters.
8
- *
9
- * @param {Object} dest The map of extension offers or parameters
10
- * @param {String} name The extension or parameter name
11
- * @param {(Object|Boolean|String)} elem The extension parameters or the
12
- * parameter value
13
- * @private
14
- */
15
- function push(dest, name, elem) {
16
- if (dest[name] === undefined)
17
- dest[name] = [elem];
18
- else
19
- dest[name].push(elem);
20
- }
21
- /**
22
- * Parses the `Sec-WebSocket-Extensions` header into an object.
23
- *
24
- * @param {String} header The field value of the header
25
- * @return {Object} The parsed object
26
- * @public
27
- */
28
- function parse(header) {
29
- const offers = Object.create(null);
30
- let params = Object.create(null);
31
- let mustUnescape = false;
32
- let isEscaping = false;
33
- let inQuotes = false;
34
- let extensionName;
35
- let paramName;
36
- let start = -1;
37
- let code = -1;
38
- let end = -1;
39
- let i = 0;
40
- for (; i < header.length; i++) {
41
- code = header.charCodeAt(i);
42
- if (extensionName === undefined) {
43
- if (end === -1 && tokenChars[code] === 1) {
44
- if (start === -1)
45
- start = i;
46
- }
47
- else if (i !== 0 &&
48
- (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */) {
49
- if (end === -1 && start !== -1)
50
- end = i;
51
- }
52
- else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
53
- if (start === -1) {
54
- throw new SyntaxError(`Unexpected character at index ${i}`);
55
- }
56
- if (end === -1)
57
- end = i;
58
- const name = header.slice(start, end);
59
- if (code === 0x2c) {
60
- push(offers, name, params);
61
- params = Object.create(null);
62
- }
63
- else {
64
- extensionName = name;
65
- }
66
- // eslint-disable-next-line no-multi-assign
67
- start = end = -1;
68
- }
69
- else {
70
- throw new SyntaxError(`Unexpected character at index ${i}`);
71
- }
72
- }
73
- else if (paramName === undefined) {
74
- if (end === -1 && tokenChars[code] === 1) {
75
- if (start === -1)
76
- start = i;
77
- }
78
- else if (code === 0x20 || code === 0x09) {
79
- if (end === -1 && start !== -1)
80
- end = i;
81
- }
82
- else if (code === 0x3b || code === 0x2c) {
83
- if (start === -1) {
84
- throw new SyntaxError(`Unexpected character at index ${i}`);
85
- }
86
- if (end === -1)
87
- end = i;
88
- push(params, header.slice(start, end), true);
89
- if (code === 0x2c) {
90
- push(offers, extensionName, params);
91
- params = Object.create(null);
92
- extensionName = undefined;
93
- }
94
- // eslint-disable-next-line no-multi-assign
95
- start = end = -1;
96
- }
97
- else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
98
- paramName = header.slice(start, i);
99
- // eslint-disable-next-line no-multi-assign
100
- start = end = -1;
101
- }
102
- else {
103
- throw new SyntaxError(`Unexpected character at index ${i}`);
104
- }
105
- }
106
- else {
107
- //
108
- // The value of a quoted-string after unescaping must conform to the
109
- // token ABNF, so only token characters are valid.
110
- // Ref: https://tools.ietf.org/html/rfc6455#section-9.1
111
- //
112
- // eslint-disable-next-line no-lonely-if
113
- if (isEscaping) {
114
- if (tokenChars[code] !== 1) {
115
- throw new SyntaxError(`Unexpected character at index ${i}`);
116
- }
117
- if (start === -1)
118
- start = i;
119
- else if (!mustUnescape)
120
- mustUnescape = true;
121
- isEscaping = false;
122
- }
123
- else if (inQuotes) {
124
- if (tokenChars[code] === 1) {
125
- if (start === -1)
126
- start = i;
127
- }
128
- else if (code === 0x22 /* '"' */ && start !== -1) {
129
- inQuotes = false;
130
- end = i;
131
- }
132
- else if (code === 0x5c /* '\' */) {
133
- isEscaping = true;
134
- }
135
- else {
136
- throw new SyntaxError(`Unexpected character at index ${i}`);
137
- }
138
- }
139
- else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
140
- inQuotes = true;
141
- }
142
- else if (end === -1 && tokenChars[code] === 1) {
143
- if (start === -1)
144
- start = i;
145
- }
146
- else if (start !== -1 && (code === 0x20 || code === 0x09)) {
147
- if (end === -1)
148
- end = i;
149
- }
150
- else if (code === 0x3b || code === 0x2c) {
151
- if (start === -1) {
152
- throw new SyntaxError(`Unexpected character at index ${i}`);
153
- }
154
- if (end === -1)
155
- end = i;
156
- let value = header.slice(start, end);
157
- if (mustUnescape) {
158
- value = value.replace(/\\/g, '');
159
- mustUnescape = false;
160
- }
161
- push(params, paramName, value);
162
- if (code === 0x2c) {
163
- push(offers, extensionName, params);
164
- params = Object.create(null);
165
- extensionName = undefined;
166
- }
167
- paramName = undefined;
168
- // eslint-disable-next-line no-multi-assign
169
- start = end = -1;
170
- }
171
- else {
172
- throw new SyntaxError(`Unexpected character at index ${i}`);
173
- }
174
- }
175
- }
176
- if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {
177
- throw new SyntaxError('Unexpected end of input');
178
- }
179
- if (end === -1)
180
- end = i;
181
- const token = header.slice(start, end);
182
- if (extensionName === undefined) {
183
- push(offers, token, params);
184
- }
185
- else {
186
- if (paramName === undefined) {
187
- push(params, token, true);
188
- }
189
- else if (mustUnescape) {
190
- push(params, paramName, token.replace(/\\/g, ''));
191
- }
192
- else {
193
- push(params, paramName, token);
194
- }
195
- push(offers, extensionName, params);
196
- }
197
- return offers;
198
- }
199
- exports.parse = parse;
200
- /**
201
- * Builds the `Sec-WebSocket-Extensions` header field value.
202
- *
203
- * @param {Object} extensions The map of extensions and parameters to format
204
- * @return {String} A string representing the given object
205
- * @public
206
- */
207
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
- function format(extensions) {
209
- return Object.keys(extensions)
210
- .map((extension) => {
211
- let configurations = extensions[extension];
212
- if (!Array.isArray(configurations))
213
- configurations = [configurations];
214
- return (configurations
215
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
216
- .map((params) => {
217
- return [extension]
218
- .concat(Object.keys(params).map((k) => {
219
- let values = params[k];
220
- if (!Array.isArray(values))
221
- values = [values];
222
- return values
223
- .map((v) => (v === true ? k : `${k}=${v}`))
224
- .join('; ');
225
- }))
226
- .join('; ');
227
- })
228
- .join(', '));
229
- })
230
- .join(', ');
231
- }
232
- exports.format = format;
@@ -1,34 +0,0 @@
1
- declare const kDone: unique symbol;
2
- declare const kRun: unique symbol;
3
- /**
4
- * A very simple job queue with adjustable concurrency. Adapted from
5
- * https://github.com/STRML/async-limiter
6
- */
7
- declare type Job = (fn: () => void) => void;
8
- export declare class Limiter {
9
- /**
10
- * Creates a new `Limiter`.
11
- *
12
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
13
- * to run concurrently
14
- */
15
- [kDone]: () => void;
16
- pending: number;
17
- concurrency: number;
18
- jobs: Job[];
19
- constructor(concurrency: number);
20
- /**
21
- * Adds a job to the queue.
22
- *
23
- * @param {Function} job The job to run
24
- * @public
25
- */
26
- add(job: Job): void;
27
- /**
28
- * Removes a job from the queue and runs it if possible.
29
- *
30
- * @private
31
- */
32
- [kRun](): void;
33
- }
34
- export {};
@@ -1,41 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Limiter = void 0;
4
- const kDone = Symbol('kDone');
5
- const kRun = Symbol('kRun');
6
- class Limiter {
7
- constructor(concurrency) {
8
- this[kDone] = () => {
9
- this.pending--;
10
- this[kRun]();
11
- };
12
- this.concurrency = concurrency || Infinity;
13
- this.jobs = [];
14
- this.pending = 0;
15
- }
16
- /**
17
- * Adds a job to the queue.
18
- *
19
- * @param {Function} job The job to run
20
- * @public
21
- */
22
- add(job) {
23
- this.jobs.push(job);
24
- this[kRun]();
25
- }
26
- /**
27
- * Removes a job from the queue and runs it if possible.
28
- *
29
- * @private
30
- */
31
- [kRun]() {
32
- if (this.pending === this.concurrency)
33
- return;
34
- if (this.jobs.length) {
35
- const job = this.jobs.shift();
36
- this.pending++;
37
- job === null || job === void 0 ? void 0 : job(this[kDone]);
38
- }
39
- }
40
- }
41
- exports.Limiter = Limiter;