@loaders.gl/schema 3.0.12 → 3.0.13
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.
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/category/mesh/mesh-utils.js +16 -16
- package/dist/es5/category/mesh/mesh-utils.js.map +1 -1
- package/dist/es5/index.js +46 -46
- package/dist/es5/lib/schema/impl/enum.js +1 -1
- package/dist/es5/lib/schema/impl/field.js +19 -32
- package/dist/es5/lib/schema/impl/field.js.map +1 -1
- package/dist/es5/lib/schema/impl/schema.js +54 -119
- package/dist/es5/lib/schema/impl/schema.js.map +1 -1
- package/dist/es5/lib/schema/impl/type.js +375 -693
- package/dist/es5/lib/schema/impl/type.js.map +1 -1
- package/dist/es5/lib/schema/index.js +36 -36
- package/dist/es5/lib/schema-utils/deduce-table-schema.js +9 -9
- package/dist/es5/lib/schema-utils/deduce-table-schema.js.map +1 -1
- package/dist/es5/lib/schema-utils/get-type-info.js +3 -3
- package/dist/es5/lib/schema-utils/get-type-info.js.map +1 -1
- package/dist/es5/lib/table/base-table-batch-aggregator.js +42 -53
- package/dist/es5/lib/table/base-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/table/columnar-table-batch-aggregator.js +71 -90
- package/dist/es5/lib/table/columnar-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/table/row-table-batch-aggregator.js +59 -70
- package/dist/es5/lib/table/row-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/table/table-batch-builder.js +113 -133
- package/dist/es5/lib/table/table-batch-builder.js.map +1 -1
- package/dist/es5/lib/utils/async-queue.js +81 -164
- package/dist/es5/lib/utils/async-queue.js.map +1 -1
- package/dist/es5/lib/utils/row-utils.js +4 -4
- package/dist/es5/lib/utils/row-utils.js.map +1 -1
- package/dist/esm/lib/schema/impl/field.js +1 -1
- package/dist/esm/lib/schema/impl/field.js.map +1 -1
- package/dist/esm/lib/schema/impl/type.js +7 -7
- package/dist/esm/lib/schema/impl/type.js.map +1 -1
- package/package.json +2 -2
|
@@ -7,10 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
11
|
|
|
16
12
|
var _baseTableBatchAggregator = _interopRequireDefault(require("./base-table-batch-aggregator"));
|
|
@@ -19,22 +15,17 @@ var _rowTableBatchAggregator = _interopRequireDefault(require("./row-table-batch
|
|
|
19
15
|
|
|
20
16
|
var _columnarTableBatchAggregator = _interopRequireDefault(require("./columnar-table-batch-aggregator"));
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
-
|
|
26
|
-
var DEFAULT_OPTIONS = {
|
|
18
|
+
const DEFAULT_OPTIONS = {
|
|
27
19
|
shape: 'array-row-table',
|
|
28
20
|
batchSize: 'auto',
|
|
29
21
|
batchDebounceMs: 0,
|
|
30
22
|
limit: 0,
|
|
31
23
|
_limitMB: 0
|
|
32
24
|
};
|
|
33
|
-
|
|
25
|
+
const ERR_MESSAGE = 'TableBatchBuilder';
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(0, _classCallCheck2.default)(this, TableBatchBuilder);
|
|
27
|
+
class TableBatchBuilder {
|
|
28
|
+
constructor(schema, options) {
|
|
38
29
|
(0, _defineProperty2.default)(this, "schema", void 0);
|
|
39
30
|
(0, _defineProperty2.default)(this, "options", void 0);
|
|
40
31
|
(0, _defineProperty2.default)(this, "aggregator", null);
|
|
@@ -46,161 +37,150 @@ var TableBatchBuilder = function () {
|
|
|
46
37
|
(0, _defineProperty2.default)(this, "totalBytes", 0);
|
|
47
38
|
(0, _defineProperty2.default)(this, "rowBytes", 0);
|
|
48
39
|
this.schema = schema;
|
|
49
|
-
this.options =
|
|
40
|
+
this.options = { ...DEFAULT_OPTIONS,
|
|
41
|
+
...options
|
|
42
|
+
};
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
value: function limitReached() {
|
|
55
|
-
var _this$options, _this$options2;
|
|
45
|
+
limitReached() {
|
|
46
|
+
var _this$options, _this$options2;
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (Boolean((_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
48
|
+
if (Boolean((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.limit) && this.totalLength >= this.options.limit) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
64
51
|
|
|
65
|
-
|
|
52
|
+
if (Boolean((_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
53
|
+
return true;
|
|
66
54
|
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "addRow",
|
|
69
|
-
value: function addRow(row) {
|
|
70
|
-
if (this.limitReached()) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
55
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.totalBytes += this.rowBytes;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
77
58
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.addObjectRow(row);
|
|
82
|
-
}
|
|
59
|
+
addRow(row) {
|
|
60
|
+
if (this.limitReached()) {
|
|
61
|
+
return;
|
|
83
62
|
}
|
|
84
|
-
}, {
|
|
85
|
-
key: "addArrayRow",
|
|
86
|
-
value: function addArrayRow(row) {
|
|
87
|
-
if (!this.aggregator) {
|
|
88
|
-
var TableBatchType = this._getTableBatchType();
|
|
89
63
|
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
this.totalLength++;
|
|
65
|
+
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
66
|
+
this.totalBytes += this.rowBytes;
|
|
92
67
|
|
|
93
|
-
|
|
68
|
+
if (Array.isArray(row)) {
|
|
69
|
+
this.addArrayRow(row);
|
|
70
|
+
} else {
|
|
71
|
+
this.addObjectRow(row);
|
|
94
72
|
}
|
|
95
|
-
}
|
|
96
|
-
key: "addObjectRow",
|
|
97
|
-
value: function addObjectRow(row) {
|
|
98
|
-
if (!this.aggregator) {
|
|
99
|
-
var TableBatchType = this._getTableBatchType();
|
|
73
|
+
}
|
|
100
74
|
|
|
101
|
-
|
|
102
|
-
|
|
75
|
+
addArrayRow(row) {
|
|
76
|
+
if (!this.aggregator) {
|
|
77
|
+
const TableBatchType = this._getTableBatchType();
|
|
103
78
|
|
|
104
|
-
this.aggregator.
|
|
79
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
105
80
|
}
|
|
106
|
-
}, {
|
|
107
|
-
key: "chunkComplete",
|
|
108
|
-
value: function chunkComplete(chunk) {
|
|
109
|
-
if (chunk instanceof ArrayBuffer) {
|
|
110
|
-
this.bytesUsed += chunk.byteLength;
|
|
111
|
-
}
|
|
112
81
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
82
|
+
this.aggregator.addArrayRow(row);
|
|
83
|
+
}
|
|
116
84
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return this._isFull() ? this._getBatch(options) : null;
|
|
85
|
+
addObjectRow(row) {
|
|
86
|
+
if (!this.aggregator) {
|
|
87
|
+
const TableBatchType = this._getTableBatchType();
|
|
88
|
+
|
|
89
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
123
90
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
91
|
+
|
|
92
|
+
this.aggregator.addObjectRow(row);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
chunkComplete(chunk) {
|
|
96
|
+
if (chunk instanceof ArrayBuffer) {
|
|
97
|
+
this.bytesUsed += chunk.byteLength;
|
|
128
98
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
99
|
+
|
|
100
|
+
if (typeof chunk === 'string') {
|
|
101
|
+
this.bytesUsed += chunk.length;
|
|
133
102
|
}
|
|
134
|
-
}, {
|
|
135
|
-
key: "_isFull",
|
|
136
|
-
value: function _isFull() {
|
|
137
|
-
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
103
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
104
|
+
this.isChunkComplete = true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getFullBatch(options) {
|
|
108
|
+
return this._isFull() ? this._getBatch(options) : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getFinalBatch(options) {
|
|
112
|
+
return this._getBatch(options);
|
|
113
|
+
}
|
|
148
114
|
|
|
149
|
-
|
|
115
|
+
_estimateRowMB(row) {
|
|
116
|
+
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_isFull() {
|
|
120
|
+
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.options.batchSize === 'auto') {
|
|
125
|
+
if (!this.isChunkComplete) {
|
|
150
126
|
return false;
|
|
151
127
|
}
|
|
128
|
+
} else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
152
131
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return true;
|
|
132
|
+
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
133
|
+
return false;
|
|
156
134
|
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "_getBatch",
|
|
159
|
-
value: function _getBatch(options) {
|
|
160
|
-
if (!this.aggregator) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
135
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
136
|
+
this.isChunkComplete = false;
|
|
137
|
+
this.lastBatchEmittedMs = Date.now();
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_getBatch(options) {
|
|
142
|
+
if (!this.aggregator) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
167
145
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
171
|
-
Object.assign(normalizedBatch, options);
|
|
172
|
-
this.batchCount++;
|
|
173
|
-
this.aggregator = null;
|
|
174
|
-
return normalizedBatch;
|
|
146
|
+
if (options !== null && options !== void 0 && options.bytesUsed) {
|
|
147
|
+
this.bytesUsed = options.bytesUsed;
|
|
175
148
|
}
|
|
176
|
-
}, {
|
|
177
|
-
key: "_getTableBatchType",
|
|
178
|
-
value: function _getTableBatchType() {
|
|
179
|
-
switch (this.options.shape) {
|
|
180
|
-
case 'row-table':
|
|
181
|
-
return _baseTableBatchAggregator.default;
|
|
182
149
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
150
|
+
const normalizedBatch = this.aggregator.getBatch();
|
|
151
|
+
normalizedBatch.count = this.batchCount;
|
|
152
|
+
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
153
|
+
Object.assign(normalizedBatch, options);
|
|
154
|
+
this.batchCount++;
|
|
155
|
+
this.aggregator = null;
|
|
156
|
+
return normalizedBatch;
|
|
157
|
+
}
|
|
186
158
|
|
|
187
|
-
|
|
188
|
-
|
|
159
|
+
_getTableBatchType() {
|
|
160
|
+
switch (this.options.shape) {
|
|
161
|
+
case 'row-table':
|
|
162
|
+
return _baseTableBatchAggregator.default;
|
|
189
163
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
164
|
+
case 'array-row-table':
|
|
165
|
+
case 'object-row-table':
|
|
166
|
+
return _rowTableBatchAggregator.default;
|
|
194
167
|
|
|
195
|
-
|
|
168
|
+
case 'columnar-table':
|
|
169
|
+
return _columnarTableBatchAggregator.default;
|
|
196
170
|
|
|
197
|
-
|
|
171
|
+
case 'arrow-table':
|
|
172
|
+
if (!TableBatchBuilder.ArrowBatch) {
|
|
198
173
|
throw new Error(ERR_MESSAGE);
|
|
199
|
-
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return TableBatchBuilder.ArrowBatch;
|
|
177
|
+
|
|
178
|
+
default:
|
|
179
|
+
throw new Error(ERR_MESSAGE);
|
|
200
180
|
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
204
184
|
|
|
205
185
|
exports.default = TableBatchBuilder;
|
|
206
186
|
(0, _defineProperty2.default)(TableBatchBuilder, "ArrowBatch", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/table/table-batch-builder.ts"],"names":["DEFAULT_OPTIONS","shape","batchSize","batchDebounceMs","limit","_limitMB","ERR_MESSAGE","TableBatchBuilder","schema","options","Date","now","Boolean","totalLength","totalBytes","row","limitReached","rowBytes","_estimateRowMB","Array","isArray","addArrayRow","addObjectRow","aggregator","TableBatchType","_getTableBatchType","chunk","ArrayBuffer","bytesUsed","byteLength","length","isChunkComplete","_isFull","_getBatch","Object","keys","rowCount","lastBatchEmittedMs","normalizedBatch","getBatch","count","batchCount","assign","BaseTableBatchAggregator","RowTableBatchAggregator","ColumnarTableBatchAggregator","ArrowBatch","Error"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;;;;;AAgBA,IAAMA,eAAmD,GAAG;AAC1DC,EAAAA,KAAK,EAAE,iBADmD;AAE1DC,EAAAA,SAAS,EAAE,MAF+C;AAG1DC,EAAAA,eAAe,EAAE,CAHyC;AAI1DC,EAAAA,KAAK,EAAE,CAJmD;AAK1DC,EAAAA,QAAQ,EAAE;AALgD,CAA5D;AAQA,IAAMC,WAAW,GAAG,mBAApB;;IAGqBC,iB;AAenB,6BAAYC,MAAZ,EAA4BC,OAA5B,EAAgE;AAAA;AAAA;AAAA;AAAA,sDAXd,IAWc;AAAA,sDAVnC,CAUmC;AAAA,qDATpC,CASoC;AAAA,2DAR7B,KAQ6B;AAAA,8DAP3BC,IAAI,CAACC,GAAL,EAO2B;AAAA,uDANlC,CAMkC;AAAA,sDALnC,CAKmC;AAAA,oDAJrC,CAIqC;AAC9D,SAAKH,MAAL,GAAcA,MAAd;AACA,SAAKC,OAAL,mCAAmBT,eAAnB,GAAuCS,OAAvC;AACD;;;;WAED,wBAAwB;AAAA;;AACtB,UAAIG,OAAO,kBAAC,KAAKH,OAAN,kDAAC,cAAcL,KAAf,CAAP,IAAgC,KAAKS,WAAL,IAAoB,KAAKJ,OAAL,CAAaL,KAArE,EAA4E;AAC1E,eAAO,IAAP;AACD;;AACD,UAAIQ,OAAO,mBAAC,KAAKH,OAAN,mDAAC,eAAcJ,QAAf,CAAP,IAAmC,KAAKS,UAA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GAAiBnB,OAAO,CAACmB,SAAzB;AACD;;AACD,UAAMU,eAAe,GAAG,KAAKf,UAAL,CAAgBgB,QAAhB,EAAxB;AACAD,MAAAA,eAAe,CAACE,KAAhB,GAAwB,KAAKC,UAA7B;AACAH,MAAAA,eAAe,CAACV,SAAhB,GAA4B,KAAKA,SAAjC;AACAM,MAAAA,MAAM,CAACQ,MAAP,CAAcJ,eAAd,EAA+B7B,OAA/B;AAEA,WAAKgC,UAAL;AACA,WAAKlB,UAAL,GAAkB,IAAlB;AACA,aAAOe,eAAP;AACD;;;WAED,8BAAoD;AAClD,cAAQ,KAAK7B,OAAL,CAAaR,KAArB;AACE,aAAK,WAAL;AACE,iBAAO0C,iCAAP;;AACF,aAAK,iBAAL;AACA,aAAK,kBAAL;AACE,iBAAOC,gCAAP;;AACF,aAAK,gBAAL;AACE,iBAAOC,qCAAP;;AACF,aAAK,aAAL;AACE,cAAI,CAACtC,iBAAiB,CAACuC,UAAvB,EAAmC;AACjC,kBAAM,IAAIC,KAAJ,CAAUzC,WAAV,CAAN;AACD;;AACD,iBAAOC,iBAAiB,CAACuC,UAAzB;;AACF;AACE,gBAAM,IAAIC,KAAJ,CAAUzC,WAAV,CAAN;AAdJ;AAgBD;;;;;;8BA1JkBC,iB","sourcesContent":["import type {Schema} from '../schema';\nimport type {TableBatch} from '../../category/table';\nimport type {TableBatchAggregator, TableBatchConstructor} from './table-batch-aggregator';\nimport BaseTableBatchAggregator from './base-table-batch-aggregator';\nimport RowTableBatchAggregator from './row-table-batch-aggregator';\nimport ColumnarTableBatchAggregator from './columnar-table-batch-aggregator';\n\n// TODO define interface instead\ntype TableBatchBuilderOptions = {\n shape: 'row-table' | 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';\n batchSize?: number | 'auto';\n batchDebounceMs?: number;\n limit: number;\n _limitMB: number;\n};\n\ntype GetBatchOptions = {\n bytesUsed?: number;\n [key: string]: any;\n};\n\nconst DEFAULT_OPTIONS: Required<TableBatchBuilderOptions> = {\n shape: 'array-row-table',\n batchSize: 'auto',\n batchDebounceMs: 0,\n limit: 0,\n _limitMB: 0\n};\n\nconst ERR_MESSAGE = 'TableBatchBuilder';\n\n/** Incrementally builds batches from a stream of rows */\nexport default class TableBatchBuilder {\n schema: Schema;\n options: Required<TableBatchBuilderOptions>;\n\n private aggregator: TableBatchAggregator | null = null;\n private batchCount: number = 0;\n private bytesUsed: number = 0;\n private isChunkComplete: boolean = false;\n private lastBatchEmittedMs: number = Date.now();\n private totalLength: number = 0;\n private totalBytes: number = 0;\n private rowBytes: number = 0;\n\n static ArrowBatch?: TableBatchConstructor;\n\n constructor(schema: Schema, options?: TableBatchBuilderOptions) {\n this.schema = schema;\n this.options = {...DEFAULT_OPTIONS, ...options};\n }\n\n limitReached(): boolean {\n if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {\n return true;\n }\n if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {\n return true;\n }\n return false;\n }\n\n /** @deprecated Use addArrayRow or addObjectRow */\n addRow(row: any[] | {[columnName: string]: any}): void {\n if (this.limitReached()) {\n return;\n }\n this.totalLength++;\n this.rowBytes = this.rowBytes || this._estimateRowMB(row);\n this.totalBytes += this.rowBytes;\n if (Array.isArray(row)) {\n this.addArrayRow(row);\n } else {\n this.addObjectRow(row);\n }\n }\n\n /** Add one row to the batch */\n protected addArrayRow(row: any[]) {\n if (!this.aggregator) {\n const TableBatchType = this._getTableBatchType();\n this.aggregator = new TableBatchType(this.schema, this.options);\n }\n this.aggregator.addArrayRow(row);\n }\n\n /** Add one row to the batch */\n protected addObjectRow(row: {[columnName: string]: any}): void {\n if (!this.aggregator) {\n const TableBatchType = this._getTableBatchType();\n this.aggregator = new TableBatchType(this.schema, this.options);\n }\n this.aggregator.addObjectRow(row);\n }\n\n /** Mark an incoming raw memory chunk has completed */\n chunkComplete(chunk: ArrayBuffer | string): void {\n if (chunk instanceof ArrayBuffer) {\n this.bytesUsed += chunk.byteLength;\n }\n if (typeof chunk === 'string') {\n this.bytesUsed += chunk.length;\n }\n this.isChunkComplete = true;\n }\n\n getFullBatch(options?: GetBatchOptions): TableBatch | null {\n return this._isFull() ? this._getBatch(options) : null;\n }\n\n getFinalBatch(options?: GetBatchOptions): TableBatch | null {\n return this._getBatch(options);\n }\n\n // INTERNAL\n\n _estimateRowMB(row) {\n return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;\n }\n\n private _isFull(): boolean {\n // No batch, not ready\n if (!this.aggregator || this.aggregator.rowCount() === 0) {\n return false;\n }\n\n // if batchSize === 'auto' we wait for chunk to complete\n // if batchSize === number, ensure we have enough rows\n if (this.options.batchSize === 'auto') {\n if (!this.isChunkComplete) {\n return false;\n }\n } else if (this.options.batchSize > this.aggregator.rowCount()) {\n return false;\n }\n\n // Debounce batches\n if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {\n return false;\n }\n\n // Emit batch\n this.isChunkComplete = false;\n this.lastBatchEmittedMs = Date.now();\n return true;\n }\n\n /**\n * bytesUsed can be set via chunkComplete or via getBatch*\n */\n private _getBatch(options?: GetBatchOptions): TableBatch | null {\n if (!this.aggregator) {\n return null;\n }\n\n // TODO - this can overly increment bytes used?\n if (options?.bytesUsed) {\n this.bytesUsed = options.bytesUsed;\n }\n const normalizedBatch = this.aggregator.getBatch() as TableBatch;\n normalizedBatch.count = this.batchCount;\n normalizedBatch.bytesUsed = this.bytesUsed;\n Object.assign(normalizedBatch, options);\n\n this.batchCount++;\n this.aggregator = null;\n return normalizedBatch;\n }\n\n private _getTableBatchType(): TableBatchConstructor {\n switch (this.options.shape) {\n case 'row-table':\n return BaseTableBatchAggregator;\n case 'array-row-table':\n case 'object-row-table':\n return RowTableBatchAggregator;\n case 'columnar-table':\n return ColumnarTableBatchAggregator;\n case 'arrow-table':\n if (!TableBatchBuilder.ArrowBatch) {\n throw new Error(ERR_MESSAGE);\n }\n return TableBatchBuilder.ArrowBatch;\n default:\n throw new Error(ERR_MESSAGE);\n }\n }\n}\n"],"file":"table-batch-builder.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/table/table-batch-builder.ts"],"names":["DEFAULT_OPTIONS","shape","batchSize","batchDebounceMs","limit","_limitMB","ERR_MESSAGE","TableBatchBuilder","constructor","schema","options","Date","now","limitReached","Boolean","totalLength","totalBytes","addRow","row","rowBytes","_estimateRowMB","Array","isArray","addArrayRow","addObjectRow","aggregator","TableBatchType","_getTableBatchType","chunkComplete","chunk","ArrayBuffer","bytesUsed","byteLength","length","isChunkComplete","getFullBatch","_isFull","_getBatch","getFinalBatch","Object","keys","rowCount","lastBatchEmittedMs","normalizedBatch","getBatch","count","batchCount","assign","BaseTableBatchAggregator","RowTableBatchAggregator","ColumnarTableBatchAggregator","ArrowBatch","Error"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAgBA,MAAMA,eAAmD,GAAG;AAC1DC,EAAAA,KAAK,EAAE,iBADmD;AAE1DC,EAAAA,SAAS,EAAE,MAF+C;AAG1DC,EAAAA,eAAe,EAAE,CAHyC;AAI1DC,EAAAA,KAAK,EAAE,CAJmD;AAK1DC,EAAAA,QAAQ,EAAE;AALgD,CAA5D;AAQA,MAAMC,WAAW,GAAG,mBAApB;;AAGe,MAAMC,iBAAN,CAAwB;AAerCC,EAAAA,WAAW,CAACC,MAAD,EAAiBC,OAAjB,EAAqD;AAAA;AAAA;AAAA,sDAXd,IAWc;AAAA,sDAVnC,CAUmC;AAAA,qDATpC,CASoC;AAAA,2DAR7B,KAQ6B;AAAA,8DAP3BC,IAAI,CAACC,GAAL,EAO2B;AAAA,uDANlC,CAMkC;AAAA,sDALnC,CAKmC;AAAA,oDAJrC,CAIqC;AAC9D,SAAKH,MAAL,GAAcA,MAAd;AACA,SAAKC,OAAL,GAAe,EAAC,GAAGV,eAAJ;AAAqB,SAAGU;AAAxB,KAAf;AACD;;AAEDG,EAAAA,YAAY,GAAY;AAAA;;AACtB,QAAIC,OAAO,kBAAC,KAAKJ,OAAN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D,SAAKR,eAAL,GAAuB,KAAvB;AACA,SAAKQ,kBAAL,GAA0B/B,IAAI,CAACC,GAAL,EAA1B;AACA,WAAO,IAAP;AACD;;AAKOyB,EAAAA,SAAS,CAAC3B,OAAD,EAA+C;AAC9D,QAAI,CAAC,KAAKe,UAAV,EAAsB;AACpB,aAAO,IAAP;AACD;;AAGD,QAAIf,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEqB,SAAb,EAAwB;AACtB,WAAKA,SAAL,GAAiBrB,OAAO,CAACqB,SAAzB;AACD;;AACD,UAAMY,eAAe,GAAG,KAAKlB,UAAL,CAAgBmB,QAAhB,EAAxB;AACAD,IAAAA,eAAe,CAACE,KAAhB,GAAwB,KAAKC,UAA7B;AACAH,IAAAA,eAAe,CAACZ,SAAhB,GAA4B,KAAKA,SAAjC;AACAQ,IAAAA,MAAM,CAACQ,MAAP,CAAcJ,eAAd,EAA+BjC,OAA/B;AAEA,SAAKoC,UAAL;AACA,SAAKrB,UAAL,GAAkB,IAAlB;AACA,WAAOkB,eAAP;AACD;;AAEOhB,EAAAA,kBAAkB,GAA0B;AAClD,YAAQ,KAAKjB,OAAL,CAAaT,KAArB;AACE,WAAK,WAAL;AACE,eAAO+C,iCAAP;;AACF,WAAK,iBAAL;AACA,WAAK,kBAAL;AACE,eAAOC,gCAAP;;AACF,WAAK,gBAAL;AACE,eAAOC,qCAAP;;AACF,WAAK,aAAL;AACE,YAAI,CAAC3C,iBAAiB,CAAC4C,UAAvB,EAAmC;AACjC,gBAAM,IAAIC,KAAJ,CAAU9C,WAAV,CAAN;AACD;;AACD,eAAOC,iBAAiB,CAAC4C,UAAzB;;AACF;AACE,cAAM,IAAIC,KAAJ,CAAU9C,WAAV,CAAN;AAdJ;AAgBD;;AA1JoC;;;8BAAlBC,iB","sourcesContent":["import type {Schema} from '../schema';\nimport type {TableBatch} from '../../category/table';\nimport type {TableBatchAggregator, TableBatchConstructor} from './table-batch-aggregator';\nimport BaseTableBatchAggregator from './base-table-batch-aggregator';\nimport RowTableBatchAggregator from './row-table-batch-aggregator';\nimport ColumnarTableBatchAggregator from './columnar-table-batch-aggregator';\n\n// TODO define interface instead\ntype TableBatchBuilderOptions = {\n shape: 'row-table' | 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';\n batchSize?: number | 'auto';\n batchDebounceMs?: number;\n limit: number;\n _limitMB: number;\n};\n\ntype GetBatchOptions = {\n bytesUsed?: number;\n [key: string]: any;\n};\n\nconst DEFAULT_OPTIONS: Required<TableBatchBuilderOptions> = {\n shape: 'array-row-table',\n batchSize: 'auto',\n batchDebounceMs: 0,\n limit: 0,\n _limitMB: 0\n};\n\nconst ERR_MESSAGE = 'TableBatchBuilder';\n\n/** Incrementally builds batches from a stream of rows */\nexport default class TableBatchBuilder {\n schema: Schema;\n options: Required<TableBatchBuilderOptions>;\n\n private aggregator: TableBatchAggregator | null = null;\n private batchCount: number = 0;\n private bytesUsed: number = 0;\n private isChunkComplete: boolean = false;\n private lastBatchEmittedMs: number = Date.now();\n private totalLength: number = 0;\n private totalBytes: number = 0;\n private rowBytes: number = 0;\n\n static ArrowBatch?: TableBatchConstructor;\n\n constructor(schema: Schema, options?: TableBatchBuilderOptions) {\n this.schema = schema;\n this.options = {...DEFAULT_OPTIONS, ...options};\n }\n\n limitReached(): boolean {\n if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {\n return true;\n }\n if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {\n return true;\n }\n return false;\n }\n\n /** @deprecated Use addArrayRow or addObjectRow */\n addRow(row: any[] | {[columnName: string]: any}): void {\n if (this.limitReached()) {\n return;\n }\n this.totalLength++;\n this.rowBytes = this.rowBytes || this._estimateRowMB(row);\n this.totalBytes += this.rowBytes;\n if (Array.isArray(row)) {\n this.addArrayRow(row);\n } else {\n this.addObjectRow(row);\n }\n }\n\n /** Add one row to the batch */\n protected addArrayRow(row: any[]) {\n if (!this.aggregator) {\n const TableBatchType = this._getTableBatchType();\n this.aggregator = new TableBatchType(this.schema, this.options);\n }\n this.aggregator.addArrayRow(row);\n }\n\n /** Add one row to the batch */\n protected addObjectRow(row: {[columnName: string]: any}): void {\n if (!this.aggregator) {\n const TableBatchType = this._getTableBatchType();\n this.aggregator = new TableBatchType(this.schema, this.options);\n }\n this.aggregator.addObjectRow(row);\n }\n\n /** Mark an incoming raw memory chunk has completed */\n chunkComplete(chunk: ArrayBuffer | string): void {\n if (chunk instanceof ArrayBuffer) {\n this.bytesUsed += chunk.byteLength;\n }\n if (typeof chunk === 'string') {\n this.bytesUsed += chunk.length;\n }\n this.isChunkComplete = true;\n }\n\n getFullBatch(options?: GetBatchOptions): TableBatch | null {\n return this._isFull() ? this._getBatch(options) : null;\n }\n\n getFinalBatch(options?: GetBatchOptions): TableBatch | null {\n return this._getBatch(options);\n }\n\n // INTERNAL\n\n _estimateRowMB(row) {\n return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;\n }\n\n private _isFull(): boolean {\n // No batch, not ready\n if (!this.aggregator || this.aggregator.rowCount() === 0) {\n return false;\n }\n\n // if batchSize === 'auto' we wait for chunk to complete\n // if batchSize === number, ensure we have enough rows\n if (this.options.batchSize === 'auto') {\n if (!this.isChunkComplete) {\n return false;\n }\n } else if (this.options.batchSize > this.aggregator.rowCount()) {\n return false;\n }\n\n // Debounce batches\n if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {\n return false;\n }\n\n // Emit batch\n this.isChunkComplete = false;\n this.lastBatchEmittedMs = Date.now();\n return true;\n }\n\n /**\n * bytesUsed can be set via chunkComplete or via getBatch*\n */\n private _getBatch(options?: GetBatchOptions): TableBatch | null {\n if (!this.aggregator) {\n return null;\n }\n\n // TODO - this can overly increment bytes used?\n if (options?.bytesUsed) {\n this.bytesUsed = options.bytesUsed;\n }\n const normalizedBatch = this.aggregator.getBatch() as TableBatch;\n normalizedBatch.count = this.batchCount;\n normalizedBatch.bytesUsed = this.bytesUsed;\n Object.assign(normalizedBatch, options);\n\n this.batchCount++;\n this.aggregator = null;\n return normalizedBatch;\n }\n\n private _getTableBatchType(): TableBatchConstructor {\n switch (this.options.shape) {\n case 'row-table':\n return BaseTableBatchAggregator;\n case 'array-row-table':\n case 'object-row-table':\n return RowTableBatchAggregator;\n case 'columnar-table':\n return ColumnarTableBatchAggregator;\n case 'arrow-table':\n if (!TableBatchBuilder.ArrowBatch) {\n throw new Error(ERR_MESSAGE);\n }\n return TableBatchBuilder.ArrowBatch;\n default:\n throw new Error(ERR_MESSAGE);\n }\n }\n}\n"],"file":"table-batch-builder.js"}
|
|
@@ -8,59 +8,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.takeAsync = takeAsync;
|
|
9
9
|
exports.default = void 0;
|
|
10
10
|
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
|
|
13
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
|
-
|
|
15
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
20
|
-
|
|
21
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
22
|
-
|
|
23
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
24
|
-
|
|
25
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
26
|
-
|
|
27
|
-
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
13
|
+
let _Symbol$asyncIterator;
|
|
28
14
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
34
|
-
|
|
35
|
-
var ArrayQueue = function (_Array) {
|
|
36
|
-
(0, _inherits2.default)(ArrayQueue, _Array);
|
|
37
|
-
|
|
38
|
-
var _super = _createSuper(ArrayQueue);
|
|
15
|
+
class ArrayQueue extends Array {
|
|
16
|
+
enqueue(value) {
|
|
17
|
+
return this.push(value);
|
|
18
|
+
}
|
|
39
19
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return _super.apply(this, arguments);
|
|
20
|
+
dequeue() {
|
|
21
|
+
return this.shift();
|
|
43
22
|
}
|
|
44
23
|
|
|
45
|
-
|
|
46
|
-
key: "enqueue",
|
|
47
|
-
value: function enqueue(value) {
|
|
48
|
-
return this.push(value);
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "dequeue",
|
|
52
|
-
value: function dequeue() {
|
|
53
|
-
return this.shift();
|
|
54
|
-
}
|
|
55
|
-
}]);
|
|
56
|
-
return ArrayQueue;
|
|
57
|
-
}((0, _wrapNativeSuper2.default)(Array));
|
|
24
|
+
}
|
|
58
25
|
|
|
59
26
|
_Symbol$asyncIterator = Symbol.asyncIterator;
|
|
60
27
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(0, _classCallCheck2.default)(this, AsyncQueue);
|
|
28
|
+
class AsyncQueue {
|
|
29
|
+
constructor() {
|
|
64
30
|
(0, _defineProperty2.default)(this, "_values", void 0);
|
|
65
31
|
(0, _defineProperty2.default)(this, "_settlers", void 0);
|
|
66
32
|
(0, _defineProperty2.default)(this, "_closed", void 0);
|
|
@@ -69,145 +35,96 @@ var AsyncQueue = function () {
|
|
|
69
35
|
this._closed = false;
|
|
70
36
|
}
|
|
71
37
|
|
|
72
|
-
(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
done: true
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this._closed = true;
|
|
38
|
+
close() {
|
|
39
|
+
while (this._settlers.length > 0) {
|
|
40
|
+
this._settlers.dequeue().resolve({
|
|
41
|
+
done: true
|
|
42
|
+
});
|
|
82
43
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
44
|
+
|
|
45
|
+
this._closed = true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
[_Symbol$asyncIterator]() {
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
enqueue(value) {
|
|
53
|
+
if (this._closed) {
|
|
54
|
+
throw new Error('Closed');
|
|
87
55
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
throw new Error('Closed');
|
|
56
|
+
|
|
57
|
+
if (this._settlers.length > 0) {
|
|
58
|
+
if (this._values.length > 0) {
|
|
59
|
+
throw new Error('Illegal internal state');
|
|
93
60
|
}
|
|
94
61
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var settler = this._settlers.dequeue();
|
|
101
|
-
|
|
102
|
-
if (value instanceof Error) {
|
|
103
|
-
settler.reject(value);
|
|
104
|
-
} else {
|
|
105
|
-
settler.resolve({
|
|
106
|
-
value: value
|
|
107
|
-
});
|
|
108
|
-
}
|
|
62
|
+
const settler = this._settlers.dequeue();
|
|
63
|
+
|
|
64
|
+
if (value instanceof Error) {
|
|
65
|
+
settler.reject(value);
|
|
109
66
|
} else {
|
|
110
|
-
|
|
67
|
+
settler.resolve({
|
|
68
|
+
value
|
|
69
|
+
});
|
|
111
70
|
}
|
|
71
|
+
} else {
|
|
72
|
+
this._values.enqueue(value);
|
|
112
73
|
}
|
|
113
|
-
}
|
|
114
|
-
key: "next",
|
|
115
|
-
value: function next() {
|
|
116
|
-
var _this = this;
|
|
117
|
-
|
|
118
|
-
if (this._values.length > 0) {
|
|
119
|
-
var value = this._values.dequeue();
|
|
74
|
+
}
|
|
120
75
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
76
|
+
next() {
|
|
77
|
+
if (this._values.length > 0) {
|
|
78
|
+
const value = this._values.dequeue();
|
|
124
79
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
80
|
+
if (value instanceof Error) {
|
|
81
|
+
return Promise.reject(value);
|
|
128
82
|
}
|
|
129
83
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
84
|
+
return Promise.resolve({
|
|
85
|
+
value
|
|
86
|
+
});
|
|
87
|
+
}
|
|
134
88
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
89
|
+
if (this._closed) {
|
|
90
|
+
if (this._settlers.length > 0) {
|
|
91
|
+
throw new Error('Illegal internal state');
|
|
138
92
|
}
|
|
139
93
|
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
resolve: resolve,
|
|
143
|
-
reject: reject
|
|
144
|
-
});
|
|
94
|
+
return Promise.resolve({
|
|
95
|
+
done: true
|
|
145
96
|
});
|
|
146
97
|
}
|
|
147
|
-
}]);
|
|
148
|
-
return AsyncQueue;
|
|
149
|
-
}();
|
|
150
98
|
|
|
151
|
-
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
this._settlers.enqueue({
|
|
101
|
+
resolve,
|
|
102
|
+
reject
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
152
106
|
|
|
153
|
-
function takeAsync(_x) {
|
|
154
|
-
return _takeAsync.apply(this, arguments);
|
|
155
107
|
}
|
|
156
108
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
_context.next = 14;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
_context.next = 6;
|
|
182
|
-
return iterator.next();
|
|
183
|
-
|
|
184
|
-
case 6:
|
|
185
|
-
_yield$iterator$next = _context.sent;
|
|
186
|
-
value = _yield$iterator$next.value;
|
|
187
|
-
done = _yield$iterator$next.done;
|
|
188
|
-
|
|
189
|
-
if (!done) {
|
|
190
|
-
_context.next = 11;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return _context.abrupt("break", 14);
|
|
195
|
-
|
|
196
|
-
case 11:
|
|
197
|
-
result.push(value);
|
|
198
|
-
_context.next = 3;
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
case 14:
|
|
202
|
-
return _context.abrupt("return", result);
|
|
203
|
-
|
|
204
|
-
case 15:
|
|
205
|
-
case "end":
|
|
206
|
-
return _context.stop();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}, _callee);
|
|
210
|
-
}));
|
|
211
|
-
return _takeAsync.apply(this, arguments);
|
|
109
|
+
exports.default = AsyncQueue;
|
|
110
|
+
|
|
111
|
+
async function takeAsync(asyncIterable, count = Infinity) {
|
|
112
|
+
const result = [];
|
|
113
|
+
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
114
|
+
|
|
115
|
+
while (result.length < count) {
|
|
116
|
+
const {
|
|
117
|
+
value,
|
|
118
|
+
done
|
|
119
|
+
} = await iterator.next();
|
|
120
|
+
|
|
121
|
+
if (done) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
result.push(value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return result;
|
|
212
129
|
}
|
|
213
130
|
//# sourceMappingURL=async-queue.js.map
|