@shaxpir/duiduidui-models 1.7.4 → 1.7.6

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.
@@ -131,7 +131,26 @@ class Progress extends Content_1.Content {
131
131
  this.checkDisposed("Progress.setStreaks");
132
132
  if (!shaxpir_common_1.Struct.equals(this.payload.streaks, streaks)) {
133
133
  const batch = new Operation_1.BatchOperation(this);
134
- batch.setPathValue(['payload', 'streaks'], streaks);
134
+ // If streaks already exist, do field-by-field updates for more granular OT ops
135
+ if (this.payload.streaks) {
136
+ // Update daily streak fields
137
+ batch.setPathValue(['payload', 'streaks', 'daily', 'current'], streaks.daily.current);
138
+ batch.setPathValue(['payload', 'streaks', 'daily', 'longest'], streaks.daily.longest);
139
+ // Update weekly streak
140
+ batch.setPathValue(['payload', 'streaks', 'weekly', 'current'], streaks.weekly.current);
141
+ // Update monthly streak
142
+ batch.setPathValue(['payload', 'streaks', 'monthly', 'current'], streaks.monthly.current);
143
+ // Update last_activity fields
144
+ batch.setPathValue(['payload', 'streaks', 'last_activity', 'date'], streaks.last_activity.date);
145
+ batch.setPathValue(['payload', 'streaks', 'last_activity', 'week'], streaks.last_activity.week);
146
+ batch.setPathValue(['payload', 'streaks', 'last_activity', 'month'], streaks.last_activity.month);
147
+ // Update total_days
148
+ batch.setPathValue(['payload', 'streaks', 'total_days'], streaks.total_days);
149
+ }
150
+ else {
151
+ // No existing streaks, set the entire object
152
+ batch.setPathValue(['payload', 'streaks'], streaks);
153
+ }
135
154
  batch.commit();
136
155
  }
137
156
  }
@@ -94,10 +94,10 @@ class Streaks {
94
94
  }
95
95
  }
96
96
  // Calculate monthly streak
97
- // Extract YYYY-MM from CompactDate (format: YYYY-MM-DD)
97
+ // Extract YYYYMM from CompactDate
98
98
  const monthlyActivity = new Set();
99
99
  for (const date of activityDates) {
100
- const month = date.substring(0, 7); // Extract YYYY-MM
100
+ const month = shaxpir_common_1.Time.getYearMonth(date);
101
101
  monthlyActivity.add(month);
102
102
  }
103
103
  const sortedMonths = Array.from(monthlyActivity).sort();
@@ -110,10 +110,7 @@ class Streaks {
110
110
  }
111
111
  else {
112
112
  // Check if consecutive month
113
- const [lastYear, lastMonthNum] = lastMonth.split('-').map(Number);
114
- const [currentYear, currentMonthNum] = month.split('-').map(Number);
115
- if ((currentYear === lastYear && currentMonthNum === lastMonthNum + 1) ||
116
- (currentYear === lastYear + 1 && lastMonthNum === 12 && currentMonthNum === 1)) {
113
+ if (shaxpir_common_1.Time.areConsecutiveMonths(lastMonth, month)) {
117
114
  monthlyStreak++;
118
115
  }
119
116
  else {
@@ -123,23 +120,13 @@ class Streaks {
123
120
  lastMonth = month;
124
121
  }
125
122
  // Check if current month streak is active
126
- const currentMonth = today.substring(0, 7); // Extract YYYY-MM
123
+ const currentMonth = shaxpir_common_1.Time.getYearMonth(today);
127
124
  const lastActiveMonth = sortedMonths[sortedMonths.length - 1];
128
125
  const lastMonthDate = shaxpir_common_1.Time.plus(today, -30, 'days');
129
- const previousMonth = shaxpir_common_1.Time.dateFrom(lastMonthDate).substring(0, 7);
126
+ const previousMonth = shaxpir_common_1.Time.getYearMonth(shaxpir_common_1.Time.dateFrom(lastMonthDate));
130
127
  if (lastActiveMonth === currentMonth || lastActiveMonth === previousMonth) {
131
128
  monthlyCurrent = monthlyStreak;
132
129
  }
133
- // Get week string for last activity (ISO week format)
134
- const getWeekString = (date) => {
135
- // Simple week calculation: YYYY-Www where ww is week of year
136
- const [year, month, day] = date.split('-').map(Number);
137
- const dateObj = new Date(year, month - 1, day);
138
- const startOfYear = new Date(year, 0, 1);
139
- const dayOfYear = Math.floor((dateObj.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000)) + 1;
140
- const weekNumber = Math.ceil(dayOfYear / 7);
141
- return `${year}-W${weekNumber.toString().padStart(2, '0')}`;
142
- };
143
130
  // We know lastDate has a value since activityDates.length > 0
144
131
  const finalLastDate = lastDate || activityDates[activityDates.length - 1];
145
132
  return {
@@ -155,8 +142,8 @@ class Streaks {
155
142
  },
156
143
  last_activity: {
157
144
  date: finalLastDate,
158
- week: getWeekString(finalLastDate),
159
- month: finalLastDate.substring(0, 7)
145
+ week: shaxpir_common_1.Time.getWeekString(finalLastDate),
146
+ month: shaxpir_common_1.Time.getYearMonth(finalLastDate)
160
147
  },
161
148
  total_days: activityDates.length
162
149
  };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"
7
7
  },
8
8
  "scripts": {
9
9
  "build": "tsc",
10
- "test": "mocha tests",
11
- "test:watch": "mocha -w tests"
10
+ "test": "npm run build && mocha -r ts-node/register tests/**/*.ts",
11
+ "test:watch": "npm run build && mocha -r ts-node/register -w tests/**/*.ts"
12
12
  },
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
@@ -18,16 +18,19 @@
18
18
  "dependencies": {
19
19
  "@shaxpir/duiduidui-models": "^1.4.14",
20
20
  "@shaxpir/sharedb": "^6.0.6",
21
- "@shaxpir/shaxpir-common": "1.4.0",
21
+ "@shaxpir/shaxpir-common": "^1.4.1",
22
22
  "ot-json1": "1.0.1",
23
23
  "ot-text-unicode": "4.0.0",
24
24
  "reconnecting-websocket": "4.4.0"
25
25
  },
26
26
  "devDependencies": {
27
+ "@types/chai": "^5.2.3",
27
28
  "@types/lodash": "^4.17.20",
29
+ "@types/mocha": "^10.0.10",
28
30
  "@types/node": "^18.0.50",
29
31
  "chai": "^4.3.7",
30
32
  "mocha": "^10.2.0",
33
+ "ts-node": "^10.9.2",
31
34
  "tslint": "^5.12.1",
32
35
  "typescript": "latest"
33
36
  }