goods-exporter 1.3.1 → 1.3.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.
@@ -1,11 +1,54 @@
1
- import { writeWithDrain as writeWithDrain$1 } from 'src/utils';
1
+ import { once } from 'events';
2
2
  import { PassThrough } from 'stream';
3
3
  import pkg from 'exceljs';
4
4
  import { JsonStreamStringify } from 'json-stream-stringify';
5
- import { once } from 'events';
6
5
  import { XMLBuilder } from 'fast-xml-parser';
7
6
  import fs from 'fs';
8
7
 
8
+ const buildCategoryPaths = (categories) => {
9
+ const idToCategory = /* @__PURE__ */ new Map();
10
+ categories.forEach((category) => {
11
+ idToCategory.set(category.id, category);
12
+ });
13
+ const categoryPaths = /* @__PURE__ */ new Map();
14
+ categories.forEach((category) => {
15
+ const path = [];
16
+ let currentCategory = category;
17
+ while (currentCategory) {
18
+ path.unshift(currentCategory);
19
+ if (currentCategory.parentId !== void 0) {
20
+ currentCategory = idToCategory.get(currentCategory.parentId);
21
+ } else {
22
+ currentCategory = void 0;
23
+ }
24
+ }
25
+ categoryPaths.set(category.id, path);
26
+ });
27
+ return categoryPaths;
28
+ };
29
+
30
+ const writeWithDrain = (stream) => {
31
+ return async (chunk) => {
32
+ const canWrite = stream.write(chunk);
33
+ if (!canWrite) {
34
+ await once(stream, "drain");
35
+ }
36
+ };
37
+ };
38
+
39
+ const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
40
+
41
+ const urlQueryEncode = (inputUrl) => {
42
+ try {
43
+ const url = new URL(inputUrl);
44
+ url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
45
+ return url.toString();
46
+ } catch (error) {
47
+ console.error("Invalid URL:", error);
48
+ return "";
49
+ }
50
+ };
51
+
9
52
  var __defProp$b = Object.defineProperty;
10
53
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
54
  var __publicField$b = (obj, key, value) => {
@@ -19,7 +62,7 @@ class CSVStream {
19
62
  __publicField$b(this, "lineSeparator", "\n");
20
63
  __publicField$b(this, "emptyFieldValue", "");
21
64
  __publicField$b(this, "columns", /* @__PURE__ */ new Set());
22
- __publicField$b(this, "writer", writeWithDrain$1(this.stream));
65
+ __publicField$b(this, "writer", writeWithDrain(this.stream));
23
66
  if (delimiter !== void 0)
24
67
  this.delimiter = delimiter;
25
68
  if (lineSeparator !== void 0)
@@ -545,50 +588,6 @@ class TildaFormatter {
545
588
  }
546
589
  }
547
590
 
548
- const buildCategoryPaths = (categories) => {
549
- const idToCategory = /* @__PURE__ */ new Map();
550
- categories.forEach((category) => {
551
- idToCategory.set(category.id, category);
552
- });
553
- const categoryPaths = /* @__PURE__ */ new Map();
554
- categories.forEach((category) => {
555
- const path = [];
556
- let currentCategory = category;
557
- while (currentCategory) {
558
- path.unshift(currentCategory);
559
- if (currentCategory.parentId !== void 0) {
560
- currentCategory = idToCategory.get(currentCategory.parentId);
561
- } else {
562
- currentCategory = void 0;
563
- }
564
- }
565
- categoryPaths.set(category.id, path);
566
- });
567
- return categoryPaths;
568
- };
569
-
570
- const writeWithDrain = (stream) => {
571
- return async (chunk) => {
572
- const canWrite = stream.write(chunk);
573
- if (!canWrite) {
574
- await once(stream, "drain");
575
- }
576
- };
577
- };
578
-
579
- const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
580
-
581
- const urlQueryEncode = (inputUrl) => {
582
- try {
583
- const url = new URL(inputUrl);
584
- url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
585
- return url.toString();
586
- } catch (error) {
587
- console.error("Invalid URL:", error);
588
- return "";
589
- }
590
- };
591
-
592
591
  var __defProp$3 = Object.defineProperty;
593
592
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
594
593
  var __publicField$3 = (obj, key, value) => {
@@ -861,7 +860,7 @@ class YMLFormatter {
861
860
  result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
862
861
  result.write('<yml_catalog date="' + date + '">\n');
863
862
  result.write("<shop>\n");
864
- const resultWriter = writeWithDrain$1(result);
863
+ const resultWriter = writeWithDrain(result);
865
864
  if (options?.shopName) {
866
865
  await resultWriter(builder.build({ name: options.shopName }));
867
866
  await resultWriter("\n");
@@ -887,7 +886,7 @@ class YMLFormatter {
887
886
  }
888
887
  await resultWriter("<offers>\n");
889
888
  const offerStream = new PassThrough();
890
- const offerWriter = writeWithDrain$1(offerStream);
889
+ const offerWriter = writeWithDrain(offerStream);
891
890
  offerStream.pipe(result, { end: false });
892
891
  for (const product of products) {
893
892
  const offer = builder.build({ offer: this.getOffer(product) });