goods-exporter 0.5.6 → 1.1.2

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/bundle.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Stream, Writable } from 'stream';
1
+ import { Writable } from 'stream';
2
2
 
3
3
  interface Product {
4
4
  /**
@@ -590,7 +590,7 @@ interface Brand {
590
590
  declare abstract class FormatterAbstract {
591
591
  abstract formatterName: string;
592
592
  abstract fileExtension: Extension;
593
- abstract format(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<Stream>;
593
+ abstract format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<void>;
594
594
  }
595
595
  interface FormatterOptions {
596
596
  shopName?: string;
@@ -600,6 +600,7 @@ interface FormatterOptions {
600
600
  declare enum Extension {
601
601
  CSV = "csv",
602
602
  YML = "yml",
603
+ XML = "xml",
603
604
  XLSX = "xlsx",
604
605
  JSON = "json"
605
606
  }
@@ -607,49 +608,49 @@ declare enum Extension {
607
608
  declare class CSVFormatter implements FormatterAbstract {
608
609
  formatterName: string;
609
610
  fileExtension: Extension;
610
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
611
+ format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
611
612
  }
612
613
 
613
614
  declare class ExcelFormatter implements FormatterAbstract {
614
615
  formatterName: string;
615
616
  fileExtension: Extension;
616
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
617
+ format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
617
618
  }
618
619
 
619
620
  declare class InsalesFormatter implements FormatterAbstract {
620
621
  formatterName: string;
621
622
  fileExtension: Extension;
622
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
623
+ format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
623
624
  }
624
625
 
625
626
  declare class JSONFormatter implements FormatterAbstract {
626
627
  formatterName: string;
627
628
  fileExtension: Extension;
628
- format(products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<Stream>;
629
+ format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<void>;
629
630
  }
630
631
 
631
632
  declare class SimpleJSONFormatter implements FormatterAbstract {
632
633
  formatterName: string;
633
634
  fileExtension: Extension;
634
- format(products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<Stream>;
635
+ format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<void>;
635
636
  }
636
637
 
637
638
  declare class TgShopFormatter implements FormatterAbstract {
638
639
  formatterName: string;
639
640
  fileExtension: Extension;
640
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
641
+ format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
641
642
  }
642
643
 
643
644
  declare class TildaFormatter implements FormatterAbstract {
644
645
  formatterName: string;
645
646
  fileExtension: Extension;
646
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
647
+ format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
647
648
  }
648
649
 
649
650
  declare class YMLFormatter implements FormatterAbstract {
650
651
  formatterName: string;
651
652
  fileExtension: Extension;
652
- format(products: Product[], categories?: Category[], brands?: Brand[], options?: FormatterOptions): Promise<Stream>;
653
+ format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], options?: FormatterOptions): Promise<void>;
653
654
  private getBrands;
654
655
  private getCategories;
655
656
  private getOffer;
@@ -43,6 +43,7 @@ class FormatterAbstract {
43
43
  var Extension = /* @__PURE__ */ ((Extension2) => {
44
44
  Extension2["CSV"] = "csv";
45
45
  Extension2["YML"] = "yml";
46
+ Extension2["XML"] = "xml";
46
47
  Extension2["XLSX"] = "xlsx";
47
48
  Extension2["JSON"] = "json";
48
49
  return Extension2;
@@ -56,7 +57,7 @@ class CSVFormatter {
56
57
  __publicField$8(this, "formatterName", "CSV");
57
58
  __publicField$8(this, "fileExtension", Extension.CSV);
58
59
  }
59
- async format(products, categories, _, __) {
60
+ async format(writableStream, products, categories, _, __) {
60
61
  const mappedCategories = {};
61
62
  categories?.forEach(({ id, name }) => mappedCategories[id] = name);
62
63
  const csvStream = new CSVStream({
@@ -64,6 +65,7 @@ class CSVFormatter {
64
65
  emptyFieldValue: "",
65
66
  lineSeparator: "\n"
66
67
  });
68
+ csvStream.getWritableStream().pipe(writableStream);
67
69
  const columns = /* @__PURE__ */ new Set([
68
70
  "url",
69
71
  "productId",
@@ -113,7 +115,6 @@ class CSVFormatter {
113
115
  csvStream.addRow(row);
114
116
  });
115
117
  csvStream.getWritableStream().end();
116
- return csvStream.getWritableStream();
117
118
  }
118
119
  }
119
120
 
@@ -126,7 +127,7 @@ class ExcelFormatter {
126
127
  __publicField$7(this, "formatterName", "Excel");
127
128
  __publicField$7(this, "fileExtension", Extension.XLSX);
128
129
  }
129
- async format(products, categories, _, __) {
130
+ async format(writableStream, products, categories, _, __) {
130
131
  const mappedCategories = {};
131
132
  categories?.forEach(({ id, name }) => mappedCategories[id] = name);
132
133
  const columns = /* @__PURE__ */ new Set([
@@ -160,9 +161,8 @@ class ExcelFormatter {
160
161
  if (value) columns.add(key);
161
162
  });
162
163
  });
163
- const passThroughStream = new stream$3.PassThrough();
164
164
  const workbook = new stream$2.xlsx.WorkbookWriter({
165
- stream: passThroughStream
165
+ stream: writableStream
166
166
  });
167
167
  const worksheet = workbook.addWorksheet("products");
168
168
  worksheet.columns = Array.from(columns).map((column) => ({
@@ -187,8 +187,6 @@ class ExcelFormatter {
187
187
  });
188
188
  worksheet.commit();
189
189
  await workbook.commit();
190
- passThroughStream.end();
191
- return passThroughStream;
192
190
  }
193
191
  }
194
192
 
@@ -201,7 +199,7 @@ class InsalesFormatter {
201
199
  __publicField$6(this, "formatterName", "Insales");
202
200
  __publicField$6(this, "fileExtension", Extension.XLSX);
203
201
  }
204
- async format(products, categories, _, __) {
202
+ async format(writableStream, products, categories, _, __) {
205
203
  const mappedCategories = {};
206
204
  categories?.forEach(
207
205
  (category) => mappedCategories[category.id] = category
@@ -239,9 +237,8 @@ class InsalesFormatter {
239
237
  });
240
238
  return categories2;
241
239
  };
242
- const passThroughStream = new stream$3.PassThrough();
243
240
  const workbook = new stream$1.xlsx.WorkbookWriter({
244
- stream: passThroughStream
241
+ stream: writableStream
245
242
  });
246
243
  const worksheet = workbook.addWorksheet("products");
247
244
  const columns = /* @__PURE__ */ new Set([
@@ -326,8 +323,6 @@ class InsalesFormatter {
326
323
  });
327
324
  worksheet.commit();
328
325
  await workbook.commit();
329
- passThroughStream.end();
330
- return passThroughStream;
331
326
  }
332
327
  }
333
328
 
@@ -339,12 +334,13 @@ class JSONFormatter {
339
334
  __publicField$5(this, "formatterName", "JSON");
340
335
  __publicField$5(this, "fileExtension", Extension.JSON);
341
336
  }
342
- async format(products, categories, brands, _) {
343
- return new jsonStreamStringify.JsonStreamStringify({
337
+ async format(writableStream, products, categories, brands, _) {
338
+ const stream = new jsonStreamStringify.JsonStreamStringify({
344
339
  categories,
345
340
  brands,
346
341
  products
347
342
  });
343
+ stream.pipe(writableStream);
348
344
  }
349
345
  }
350
346
 
@@ -356,7 +352,7 @@ class SimpleJSONFormatter {
356
352
  __publicField$4(this, "formatterName", "JSON");
357
353
  __publicField$4(this, "fileExtension", Extension.JSON);
358
354
  }
359
- async format(products, categories, brands, _) {
355
+ async format(writableStream, products, categories, brands, _) {
360
356
  const groupedProduct = /* @__PURE__ */ new Map();
361
357
  products.forEach((product) => {
362
358
  if (product.parentId !== void 0) return;
@@ -371,11 +367,12 @@ class SimpleJSONFormatter {
371
367
  if (!parent) return;
372
368
  parent.children.push(product);
373
369
  });
374
- return new jsonStreamStringify.JsonStreamStringify({
370
+ const stream = new jsonStreamStringify.JsonStreamStringify({
375
371
  categories,
376
372
  brands,
377
373
  products: Array.from(groupedProduct.values())
378
374
  });
375
+ stream.pipe(writableStream);
379
376
  }
380
377
  }
381
378
 
@@ -388,7 +385,7 @@ class TgShopFormatter {
388
385
  __publicField$3(this, "formatterName", "TgShop");
389
386
  __publicField$3(this, "fileExtension", Extension.XLSX);
390
387
  }
391
- async format(products, categories, _, __) {
388
+ async format(writableStream, products, categories, _, __) {
392
389
  const getParameter = (product, key) => product.params?.find((value) => value.key === key);
393
390
  const convertProduct = (product) => ({
394
391
  "category id": product.categoryId,
@@ -406,9 +403,8 @@ class TgShopFormatter {
406
403
  size: getParameter(product, "size")?.value,
407
404
  priority: void 0
408
405
  });
409
- const passThroughStream = new stream$3.PassThrough();
410
406
  const workbook = new stream.xlsx.WorkbookWriter({
411
- stream: passThroughStream
407
+ stream: writableStream
412
408
  });
413
409
  const categoryWorksheet = workbook.addWorksheet("categories");
414
410
  const productsWorksheet = workbook.addWorksheet("offers");
@@ -455,7 +451,6 @@ class TgShopFormatter {
455
451
  categoryWorksheet.commit();
456
452
  productsWorksheet.commit();
457
453
  await workbook.commit();
458
- return passThroughStream;
459
454
  }
460
455
  }
461
456
 
@@ -467,7 +462,7 @@ class TildaFormatter {
467
462
  __publicField$2(this, "formatterName", "Tilda");
468
463
  __publicField$2(this, "fileExtension", Extension.CSV);
469
464
  }
470
- async format(products, categories, _, __) {
465
+ async format(writableStream, products, categories, _, __) {
471
466
  const mappedCategories = {};
472
467
  categories?.forEach(({ id, name }) => mappedCategories[id] = name);
473
468
  const csvStream = new CSVStream({
@@ -475,6 +470,7 @@ class TildaFormatter {
475
470
  emptyFieldValue: "",
476
471
  lineSeparator: "\n"
477
472
  });
473
+ csvStream.getWritableStream().pipe(writableStream);
478
474
  const columns = /* @__PURE__ */ new Set([
479
475
  "SKU",
480
476
  "Brand",
@@ -508,7 +504,6 @@ class TildaFormatter {
508
504
  csvStream.addRow(row);
509
505
  });
510
506
  csvStream.getWritableStream().end();
511
- return csvStream.getWritableStream();
512
507
  }
513
508
  }
514
509
 
@@ -520,8 +515,9 @@ class YMLFormatter {
520
515
  __publicField$1(this, "formatterName", "YMl");
521
516
  __publicField$1(this, "fileExtension", Extension.YML);
522
517
  }
523
- async format(products, categories, brands, options) {
518
+ async format(writableStream, products, categories, brands, options) {
524
519
  const result = new stream$3.PassThrough();
520
+ result.pipe(writableStream);
525
521
  const builder = new fastXmlParser.XMLBuilder({
526
522
  ignoreAttributes: false,
527
523
  cdataPropName: "__cdata",
@@ -569,7 +565,6 @@ class YMLFormatter {
569
565
  result.write("</yml_catalog>\n");
570
566
  result.end();
571
567
  });
572
- return result;
573
568
  }
574
569
  getBrands(brands) {
575
570
  if (!brands) return [];
@@ -702,13 +697,14 @@ class GoodsExporter {
702
697
  let transformedProducts = products;
703
698
  for (const transformer of this.transformers)
704
699
  transformedProducts = await transformer(transformedProducts);
705
- const stream = await this.formatter.format(
700
+ const writableStream = this.exporter();
701
+ await this.formatter.format(
702
+ writableStream,
706
703
  transformedProducts,
707
704
  categories,
708
705
  brands,
709
706
  option
710
707
  );
711
- stream.pipe(this.exporter());
712
708
  }
713
709
  }
714
710