oneentry 1.0.111 → 1.0.112

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/README.md CHANGED
@@ -401,7 +401,7 @@ Example return:
401
401
  "id": 1764,
402
402
  "updatedDate": "2025-01-31T21:53:39.276Z",
403
403
  "version": 10,
404
- "identifier": "my-id",
404
+ "identifier": "my_id",
405
405
  "title": "Set for pages",
406
406
  "schema": {
407
407
  "attribute1": {
@@ -409,7 +409,7 @@ Example return:
409
409
  "type": "string",
410
410
  "isPrice": false,
411
411
  "original": true,
412
- "identifier": "stroka",
412
+ "identifier": "string",
413
413
  "localizeInfos": {
414
414
  "en_US": {
415
415
  "title": "String"
@@ -460,7 +460,7 @@ Example return:
460
460
  >
461
461
  >**schema:** Record<string, string> <br>
462
462
  >*Schema JSON description (attributes used by the set) of the attribute set* <br>
463
- >example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "stroka", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } } <br>
463
+ >example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "string", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } } <br>
464
464
  >
465
465
  >**title:** string <br>
466
466
  >*Attribute set name* <br>
@@ -722,7 +722,7 @@ Example return:
722
722
  "type": "string",
723
723
  "isPrice": false,
724
724
  "original": true,
725
- "identifier": "stroka",
725
+ "identifier": "string",
726
726
  "localizeInfos": {
727
727
  "en_US": {
728
728
  "title": "String"
@@ -764,7 +764,7 @@ Example return:
764
764
  >
765
765
  >**schema*:** Record<string, string> <br>
766
766
  >*Schema JSON description (attributes used by the set) of the attribute set* <br>
767
- >example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "stroka", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } } <br>
767
+ >example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "string", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } } <br>
768
768
  >
769
769
  >**isVisible*:** boolean <br>
770
770
  >*Visibility flag of the set* <br>
@@ -52,11 +52,31 @@ export default abstract class SyncModules {
52
52
  [k: string]: unknown;
53
53
  };
54
54
  /**
55
- * addTimeIntervalsToSchedules
55
+ * Function to add days to a date
56
56
  *
57
- * @param schedules
57
+ * @param date
58
+ * @param days
58
59
  * @returns
59
60
  */
61
+ protected _addDays(date: string | number | Date, days: number): Date;
62
+ /**
63
+ * Function to generate intervals for a specific date
64
+ *
65
+ * @param date
66
+ * @param schedule
67
+ * @param utcIntervals
68
+ */
69
+ protected _generateIntervalsForDate(date: string | number | Date, schedule: {
70
+ inEveryWeek: any;
71
+ times: any[];
72
+ inEveryMonth: any;
73
+ }, utcIntervals: any[][]): void;
74
+ /**
75
+ * Add TimeIntervals to schedules
76
+ *
77
+ * @param schedules
78
+ * @returns schedules with timeIntervals
79
+ */
60
80
  protected _addTimeIntervalsToSchedules(schedules: any[]): any[];
61
81
  /**
62
82
  * normalizeAttr
@@ -124,62 +124,85 @@ class SyncModules {
124
124
  }
125
125
  }
126
126
  /**
127
- * addTimeIntervalsToSchedules
127
+ * Function to add days to a date
128
128
  *
129
- * @param schedules
129
+ * @param date
130
+ * @param days
130
131
  * @returns
131
132
  */
132
- _addTimeIntervalsToSchedules(schedules) {
133
- // Function to add days
134
- function addDays(date, days) {
135
- const result = new Date(date);
136
- result.setUTCDate(result.getUTCDate() + days);
137
- return result;
133
+ _addDays(date, days) {
134
+ const result = new Date(date);
135
+ result.setUTCDate(result.getUTCDate() + days);
136
+ return result;
137
+ }
138
+ /**
139
+ * Function to generate intervals for a specific date
140
+ *
141
+ * @param date
142
+ * @param schedule
143
+ * @param utcIntervals
144
+ */
145
+ _generateIntervalsForDate(date, schedule, utcIntervals) {
146
+ // Generate intervals based on weekly repetition
147
+ if (schedule.inEveryWeek) {
148
+ for (let week = 0; week < 4; week++) {
149
+ schedule.times.forEach((timeRange) => {
150
+ const [startTime, endTime] = timeRange;
151
+ const intervalStart = this._addDays(date, week * 7);
152
+ intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
153
+ const intervalEnd = this._addDays(date, week * 7);
154
+ intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
155
+ utcIntervals.push([
156
+ intervalStart.toISOString(),
157
+ intervalEnd.toISOString(),
158
+ ]);
159
+ });
160
+ }
138
161
  }
139
- // Function to add months
140
- function addMonths(date, months) {
141
- const result = new Date(date);
142
- result.setUTCMonth(result.getUTCMonth() + months);
143
- return result;
162
+ // Generate intervals based on monthly repetition
163
+ if (schedule.inEveryMonth) {
164
+ for (let month = 0; month < 12; month++) {
165
+ schedule.times.forEach((timeRange) => {
166
+ const [startTime, endTime] = timeRange;
167
+ const intervalStart = new Date(date);
168
+ intervalStart.setUTCMonth(intervalStart.getUTCMonth() + month);
169
+ intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
170
+ const intervalEnd = new Date(date);
171
+ intervalEnd.setUTCMonth(intervalEnd.getUTCMonth() + month);
172
+ intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
173
+ utcIntervals.push([
174
+ intervalStart.toISOString(),
175
+ intervalEnd.toISOString(),
176
+ ]);
177
+ });
178
+ }
144
179
  }
180
+ }
181
+ /**
182
+ * Add TimeIntervals to schedules
183
+ *
184
+ * @param schedules
185
+ * @returns schedules with timeIntervals
186
+ */
187
+ _addTimeIntervalsToSchedules(schedules) {
145
188
  schedules.forEach((scheduleGroup) => {
146
189
  scheduleGroup.values.forEach((schedule) => {
147
190
  const utcIntervals = [];
148
- const baseDate = new Date(schedule.dates[0]); // We use the first date as the base date
149
- // Generate intervals based on weekly repetition
150
- if (schedule.inEveryWeek) {
151
- for (let week = 0; week < 4; week++) {
152
- schedule.times.forEach((timeRange) => {
153
- const [startTime, endTime] = timeRange;
154
- const startDate = addDays(baseDate, week * 7);
155
- startDate.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
156
- const endDate = addDays(baseDate, week * 7);
157
- endDate.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
158
- utcIntervals.push([
159
- startDate.toISOString(),
160
- endDate.toISOString(),
161
- ]);
162
- });
163
- }
191
+ const startDate = new Date(schedule.dates[0]);
192
+ const endDate = new Date(schedule.dates[1]);
193
+ // Check if the dates are the same
194
+ const isSameDay = startDate.toISOString() === endDate.toISOString();
195
+ // If the dates are the same, process only the first date
196
+ if (isSameDay) {
197
+ this._generateIntervalsForDate(startDate, schedule, utcIntervals);
164
198
  }
165
- // Generate intervals based on monthly repetition
166
- if (schedule.inEveryMonth) {
167
- for (let month = 0; month < 12; month++) {
168
- // Предполагаем 12 месяцев в году
169
- schedule.times.forEach((timeRange) => {
170
- const [startTime, endTime] = timeRange;
171
- const startDate = addMonths(baseDate, month);
172
- startDate.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
173
- const endDate = addMonths(baseDate, month);
174
- endDate.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
175
- utcIntervals.push([
176
- startDate.toISOString(),
177
- endDate.toISOString(),
178
- ]);
179
- });
199
+ else {
200
+ // Otherwise, process each day in the range
201
+ for (let currentDate = new Date(startDate); currentDate <= endDate; currentDate = this._addDays(currentDate, 1)) {
202
+ this._generateIntervalsForDate(currentDate, schedule, utcIntervals);
180
203
  }
181
204
  }
182
- // Add the calculated intervals to the new timeIntervals field
205
+ // Add calculated intervals to the new field timeIntervals
183
206
  schedule.timeIntervals = utcIntervals;
184
207
  });
185
208
  });
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.111",
3
+ "version": "1.0.112",
4
4
  "description": "OneEntry NPM package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "type": "module",
7
8
  "files": [
8
9
  "/dist"
9
10
  ],
@@ -47,9 +48,9 @@
47
48
  "@microsoft/tsdoc": "^0.15.1",
48
49
  "@types/eslint-config-prettier": "^6.11.3",
49
50
  "@types/jest": "^29.5.14",
50
- "@types/node": "^22.13.0",
51
- "@typescript-eslint/eslint-plugin": "^8.22.0",
52
- "@typescript-eslint/parser": "^8.22.0",
51
+ "@types/node": "^22.13.4",
52
+ "@typescript-eslint/eslint-plugin": "^8.24.0",
53
+ "@typescript-eslint/parser": "^8.24.0",
53
54
  "eslint": "^8.57.1",
54
55
  "eslint-config-prettier": "^10.0.1",
55
56
  "eslint-plugin-import": "^2.31.0",
@@ -58,8 +59,8 @@
58
59
  "eslint-plugin-simple-import-sort": "^12.1.1",
59
60
  "jest": "^29.7.0",
60
61
  "npm-run-all": "^4.1.5",
61
- "prettier": "^3.4.2",
62
+ "prettier": "^3.5.1",
62
63
  "ts-jest": "^29.2.5",
63
64
  "typescript": "^5.7.3"
64
65
  }
65
- }
66
+ }