chuvsu-js 5.2.1 → 5.2.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/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # chuvsu-js
2
2
 
3
+ > [!WARNING]
4
+ > Ооочень плохой вайбкод, библиотека будет переделана и не раз. Есть очень много пространства для упрощения использования и сохранения крутой архитектуры.
5
+
3
6
  Типизированная библиотека для сервисов ЧГУ им. И. Н. Ульянова:
4
7
 
5
8
  - `tt.chuvsu.ru` — расписания групп, преподавателей, аудиторий и вебинары;
@@ -597,9 +597,6 @@ export class TimetableRepository {
597
597
  if (!observation.subject.trim()) {
598
598
  throw new Error(`Empty lesson subject in ${source.sourceKey}/${observation.key}`);
599
599
  }
600
- if (!observation.type.trim()) {
601
- throw new Error(`Empty lesson type in ${source.sourceKey}/${observation.key}`);
602
- }
603
600
  const relations = [
604
601
  ["group", observation.groups, observation.groups.values.map((value) => value.group)],
605
602
  ["teacher", observation.teachers, observation.teachers.values],
@@ -62,6 +62,7 @@ export interface LessonSeries {
62
62
  academicYearStartYear: number;
63
63
  period: AcademicPeriod;
64
64
  subject: string;
65
+ /** Free-form portal label; empty when no source exposes one. */
65
66
  type: string;
66
67
  slotNumber?: number;
67
68
  time?: TimeRange;
@@ -84,6 +85,7 @@ export interface LessonOccurrence {
84
85
  nominalDate: LocalDate;
85
86
  scheduledDate: LocalDate;
86
87
  subject: string;
88
+ /** Free-form portal label; empty when no source exposes one. */
87
89
  type: string;
88
90
  slotNumber?: number;
89
91
  time?: TimeRange;
@@ -105,6 +107,7 @@ interface ObservationBase {
105
107
  /** Stable only inside one source page projection. */
106
108
  key: string;
107
109
  subject: string;
110
+ /** Free-form portal label; empty when this source does not expose one. */
108
111
  type: string;
109
112
  slotNumber?: number;
110
113
  time?: TimeRange;
@@ -2,8 +2,8 @@ import { parseHtml, parseTeacher, parseTime, parseWeekParity, parseWeeks, text,
2
2
  import { parseSemesterScheduleWith, parseSessionScheduleWith, } from "./full-schedule.js";
3
3
  import { parseGroupsString } from "./groups.js";
4
4
  import { parseSubstituteForDiv, parseSubstitutionDiv, parseTransferDiv, } from "./overlays.js";
5
- import { LESSON_TYPE_GLOBAL_RE, LESSON_TYPE_RE, FLEXIBLE_LESSON_TYPE_RE_I, SUBGROUP_ANNOTATION_RE, SUBGROUP_RE, WEEKS_GLOBAL_RE, WEEKS_RE, } from "./patterns.js";
6
- import { containsGroupCode, hasDistanceMarker, linesAfterSubject, stripDistanceMarker, } from "./entry-parts.js";
5
+ import { LESSON_TYPE_GLOBAL_RE, SUBGROUP_ANNOTATION_RE, SUBGROUP_RE, WEEKS_GLOBAL_RE, WEEKS_RE, } from "./patterns.js";
6
+ import { containsGroupCode, hasDistanceMarker, linesAfterSubject, parseLessonTypeAfterSubject, stripDistanceMarker, } from "./entry-parts.js";
7
7
  export function parseRoomInfo(html) {
8
8
  const doc = parseHtml(html);
9
9
  // Name: <span class="htext"><nobr>Аудитория <span style="color: blue;">NAME</span></nobr></span>
@@ -104,10 +104,11 @@ function parseRoomSemesterEntry(el) {
104
104
  cleanText = cleanText.replace(text(div), "");
105
105
  }
106
106
  const subjectEl = td.querySelector('span[style*="color: blue"]');
107
- const subject = subjectEl ? text(subjectEl) : "";
107
+ if (!subjectEl)
108
+ return null;
109
+ const subject = text(subjectEl);
108
110
  if (!subject)
109
111
  return null;
110
- const typeMatch = cleanText.match(LESSON_TYPE_RE);
111
112
  const weeksMatch = cleanText.match(WEEKS_RE);
112
113
  const subgroupMatch = cleanText.match(SUBGROUP_RE);
113
114
  const weekParity = parseWeekParity(cleanHtml);
@@ -127,7 +128,7 @@ function parseRoomSemesterEntry(el) {
127
128
  const groups = parseGroupsString(groupsLine);
128
129
  return {
129
130
  subject,
130
- type: typeMatch?.[1] ?? "",
131
+ type: parseLessonTypeAfterSubject(subjectEl),
131
132
  weeks: parseWeeks(weeksMatch?.[1] ?? ""),
132
133
  teacher: teacherLine ? parseTeacher(teacherLine) : undefined,
133
134
  groups: groups.length > 0 ? groups : undefined,
@@ -149,13 +150,14 @@ function parseRoomSessionEntry(td) {
149
150
  const fullHtml = td.innerHTML ?? "";
150
151
  const plainText = text(td);
151
152
  const subjectEl = td.querySelector('span[style*="color: blue"]');
152
- const subject = subjectEl ? text(subjectEl) : "";
153
+ if (!subjectEl)
154
+ return null;
155
+ const subject = text(subjectEl);
153
156
  if (!plainText || !subject)
154
157
  return null;
155
158
  const timeMatch = fullHtml.match(/<br\s*\/?>\s*(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/);
156
159
  if (!timeMatch)
157
160
  return null;
158
- const typeMatch = plainText.match(FLEXIBLE_LESSON_TYPE_RE_I);
159
161
  const parts = linesAfterSubject(fullHtml, subject);
160
162
  const teacherLine = parts.find((part) => !/^\d{2}:\d{2}\s*-\s*\d{2}:\d{2}$/.test(part) &&
161
163
  !containsGroupCode(stripDistanceMarker(part)));
@@ -165,7 +167,7 @@ function parseRoomSessionEntry(td) {
165
167
  return {
166
168
  lesson: {
167
169
  subject,
168
- type: typeMatch?.[1].replace(/\.$/, "").toLowerCase() ?? "",
170
+ type: parseLessonTypeAfterSubject(subjectEl).toLowerCase(),
169
171
  teacher: teacherLine ? parseTeacher(stripDistanceMarker(teacherLine)) : undefined,
170
172
  groups: groups.length > 0 ? groups : undefined,
171
173
  subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
@@ -6,3 +6,8 @@ export declare function linesAfterSubject(html: string, subject: string): string
6
6
  export declare function parseEntryRoom(html: string, subject: string): string;
7
7
  export declare function stripDistanceMarker(value: string): string;
8
8
  export declare function containsGroupCode(value: string): boolean;
9
+ /**
10
+ * Lesson type is free-form portal data. Its stable marker is position: the first
11
+ * parenthesized value immediately after the blue subject span.
12
+ */
13
+ export declare function parseLessonTypeAfterSubject(subjectElement: Element): string;
@@ -2,6 +2,9 @@ const BR_RE = /<br\s*\/?>/i;
2
2
  const TAG_RE = /<[^>]*>/g;
3
3
  const DISTANCE_RE = /(?:^|[^\p{L}\p{N}])(?:дистанционно|ДОТ)(?=$|[^\p{L}\p{N}])/iu;
4
4
  const GROUP_TOKEN_RE = /^[A-ZА-ЯЁ]{1,}(?:-[A-ZА-ЯЁa-zа-яё0-9]+)+$/u;
5
+ const LEADING_PARENTHESIZED_RE = /^\s*\(([^()]*)\)/u;
6
+ const WEEK_METADATA_RE = /(?:^|\s)нед\.?(?:\s|$)/iu;
7
+ const SUBGROUP_METADATA_RE = /^\d+\s*подгруппа$/iu;
5
8
  export function entryHtmlLines(html) {
6
9
  return html.split(BR_RE).map((line) => line.trim());
7
10
  }
@@ -50,3 +53,25 @@ export function stripDistanceMarker(value) {
50
53
  export function containsGroupCode(value) {
51
54
  return value.split(/\s+/).some((token) => GROUP_TOKEN_RE.test(token));
52
55
  }
56
+ /**
57
+ * Lesson type is free-form portal data. Its stable marker is position: the first
58
+ * parenthesized value immediately after the blue subject span.
59
+ */
60
+ export function parseLessonTypeAfterSubject(subjectElement) {
61
+ let suffix = "";
62
+ for (let sibling = subjectElement.nextSibling; sibling; sibling = sibling.nextSibling) {
63
+ if (sibling.tagName?.toLowerCase() === "br")
64
+ break;
65
+ suffix += sibling.textContent ?? "";
66
+ }
67
+ const candidate = suffix.match(LEADING_PARENTHESIZED_RE)?.[1]
68
+ ?.trim()
69
+ .replace(/\.$/, "") ?? "";
70
+ if (!candidate ||
71
+ WEEK_METADATA_RE.test(candidate) ||
72
+ SUBGROUP_METADATA_RE.test(candidate) ||
73
+ candidate.toUpperCase() === "ДОТ") {
74
+ return "";
75
+ }
76
+ return candidate;
77
+ }
@@ -1,7 +1,7 @@
1
1
  import { parseHtml, parseTeacher, parseTime, parseWeekParity, parseWeeks, text, } from "../../common/parse.js";
2
2
  import { parseSubstitutionDiv, parseTransferDiv, } from "./overlays.js";
3
- import { FLEXIBLE_LESSON_TYPE_RE_I, LESSON_TYPE_RE, SUBGROUP_RE, WEEKS_RE, } from "./patterns.js";
4
- import { hasDistanceMarker, containsGroupCode, linesAfterSubject, parseEntryRoom, stripDistanceMarker, } from "./entry-parts.js";
3
+ import { SUBGROUP_RE, WEEKS_RE } from "./patterns.js";
4
+ import { hasDistanceMarker, containsGroupCode, linesAfterSubject, parseLessonTypeAfterSubject, parseEntryRoom, stripDistanceMarker, } from "./entry-parts.js";
5
5
  export function parseGroupSchedule(html) {
6
6
  const doc = parseHtml(html);
7
7
  // Session layout has date-based cells with ids like "trd20251224"
@@ -99,10 +99,11 @@ function parseSemesterEntry(el) {
99
99
  cleanText = cleanText.replace(text(div), "");
100
100
  }
101
101
  const subjectEl = td.querySelector('span[style*="color: blue"]');
102
- const subject = subjectEl ? text(subjectEl) : "";
102
+ if (!subjectEl)
103
+ return null;
104
+ const subject = text(subjectEl);
103
105
  if (!subject)
104
106
  return null;
105
- const typeMatch = cleanText.match(LESSON_TYPE_RE);
106
107
  const weeksMatch = cleanText.match(WEEKS_RE);
107
108
  const room = parseEntryRoom(cleanHtml, subject);
108
109
  const teacherLine = linesAfterSubject(cleanHtml, subject).find((line) => {
@@ -114,7 +115,7 @@ function parseSemesterEntry(el) {
114
115
  return {
115
116
  room: room || undefined,
116
117
  subject,
117
- type: typeMatch?.[1] ?? "",
118
+ type: parseLessonTypeAfterSubject(subjectEl),
118
119
  weeks: parseWeeks(weeksMatch?.[1] ?? ""),
119
120
  teacher: teacherLine ? parseTeacher(teacherLine) : undefined,
120
121
  subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
@@ -170,13 +171,14 @@ function parseSessionEntry(td) {
170
171
  return null;
171
172
  const possibleChanges = (td.getAttribute("class") ?? "").includes("want") || undefined;
172
173
  const subjectEl = td.querySelector('span[style*="color: blue"]');
173
- const subject = subjectEl ? text(subjectEl) : "";
174
+ if (!subjectEl)
175
+ return null;
176
+ const subject = text(subjectEl);
174
177
  if (!subject)
175
178
  return null;
176
179
  const room = parseEntryRoom(fullHtml, subject);
177
180
  // Type: parenthesized text after </span>, case-insensitive
178
- const typeMatch = plainText.match(FLEXIBLE_LESSON_TYPE_RE_I);
179
- const type = typeMatch ? typeMatch[1].replace(/\.$/, "").toLowerCase() : "";
181
+ const type = parseLessonTypeAfterSubject(subjectEl).toLowerCase();
180
182
  const subgroupMatch = plainText.match(SUBGROUP_RE);
181
183
  const parts = linesAfterSubject(fullHtml, subject);
182
184
  const teacherPart = parts.find((part) => stripDistanceMarker(part).length > 0 &&
@@ -1,5 +1,5 @@
1
- export declare const LESSON_TYPE_PATTERN = "\u043B\u043A|\u043F\u0440|\u043B\u0431|\u0437\u0430\u0447\u043E|\u0437\u0430\u0447|\u044D\u043A\u0437|\u043A\u043E\u043D\u0441|\u043A\u043F|\u0438\u0437|\u0433\u0437|\u043A\u0440\u043F";
2
- export declare const FLEXIBLE_LESSON_TYPE_PATTERN = "(?:\u043B\u043A|\u043F\u0440|\u043B\u0431|\u0437\u0430\u0447\u043E|\u0437\u0430\u0447|\u044D\u043A\u0437|\u043A\u043E\u043D\u0441|\u043A\u043F|\u0438\u0437|\u0433\u0437|\u043A\u0440\u043F)\\.?|\u042D\u043A\u0437";
1
+ export declare const LESSON_TYPE_PATTERN = "\u043B\u043A|\u043F\u0440|\u043B\u0431|\u0437\u0430\u0447\u043E|\u0437\u0430\u0447|\u044D\u043A\u0437|\u043A\u043E\u043D\u0441|\u043A\u043F|\u0438\u0437|\u0433\u0437|\u043A\u0440\u043F|\u043A\u0440";
2
+ export declare const FLEXIBLE_LESSON_TYPE_PATTERN = "(?:\u043B\u043A|\u043F\u0440|\u043B\u0431|\u0437\u0430\u0447\u043E|\u0437\u0430\u0447|\u044D\u043A\u0437|\u043A\u043E\u043D\u0441|\u043A\u043F|\u0438\u0437|\u0433\u0437|\u043A\u0440\u043F|\u043A\u0440)\\.?|\u042D\u043A\u0437";
3
3
  export declare const LESSON_TYPE_RE: RegExp;
4
4
  export declare const LESSON_TYPE_RE_I: RegExp;
5
5
  export declare const FLEXIBLE_LESSON_TYPE_RE_I: RegExp;
@@ -1,4 +1,4 @@
1
- export const LESSON_TYPE_PATTERN = "лк|пр|лб|зачо|зач|экз|конс|кп|из|гз|крп";
1
+ export const LESSON_TYPE_PATTERN = "лк|пр|лб|зачо|зач|экз|конс|кп|из|гз|крп|кр";
2
2
  export const FLEXIBLE_LESSON_TYPE_PATTERN = `(?:${LESSON_TYPE_PATTERN})\\.?|Экз`;
3
3
  export const LESSON_TYPE_RE = new RegExp(`\\((${LESSON_TYPE_PATTERN})\\)`, "i");
4
4
  export const LESSON_TYPE_RE_I = new RegExp(`\\((${LESSON_TYPE_PATTERN})\\)`, "i");
@@ -2,8 +2,8 @@ import { parseHtml, parseTime, parseWeekParity, parseWeeks, text, } from "../../
2
2
  import { parseSemesterScheduleWith, parseSessionScheduleWith, } from "./full-schedule.js";
3
3
  import { parseGroupsString } from "./groups.js";
4
4
  import { parseSubstituteForDiv, parseSubstitutionDiv, parseTransferDiv, } from "./overlays.js";
5
- import { FLEXIBLE_LESSON_TYPE_RE_I, LESSON_TYPE_RE, SUBGROUP_RE, WEEKS_RE, } from "./patterns.js";
6
- import { containsGroupCode, hasDistanceMarker, linesAfterSubject, parseEntryRoom, stripDistanceMarker, } from "./entry-parts.js";
5
+ import { SUBGROUP_RE, WEEKS_RE } from "./patterns.js";
6
+ import { containsGroupCode, hasDistanceMarker, linesAfterSubject, parseEntryRoom, parseLessonTypeAfterSubject, stripDistanceMarker, } from "./entry-parts.js";
7
7
  export function parseTeacherSchedule(html) {
8
8
  const doc = parseHtml(html);
9
9
  if (doc.querySelector('td[id^="trd2"]')) {
@@ -49,10 +49,11 @@ function parseTeacherSemesterEntry(el) {
49
49
  cleanText = cleanText.replace(text(div), "");
50
50
  }
51
51
  const subjectEl = td.querySelector('span[style*="color: blue"]');
52
- const subject = subjectEl ? text(subjectEl) : "";
52
+ if (!subjectEl)
53
+ return null;
54
+ const subject = text(subjectEl);
53
55
  if (!subject)
54
56
  return null;
55
- const typeMatch = cleanText.match(LESSON_TYPE_RE);
56
57
  const weeksMatch = cleanText.match(WEEKS_RE);
57
58
  const room = parseEntryRoom(cleanHtml, subject);
58
59
  const groupsLine = linesAfterSubject(cleanHtml, subject).find((line) => containsGroupCode(stripDistanceMarker(line))) ?? "";
@@ -62,7 +63,7 @@ function parseTeacherSemesterEntry(el) {
62
63
  return {
63
64
  room: room || undefined,
64
65
  subject,
65
- type: typeMatch?.[1] ?? "",
66
+ type: parseLessonTypeAfterSubject(subjectEl),
66
67
  weeks: parseWeeks(weeksMatch?.[1] ?? ""),
67
68
  groups: groups.length > 0 ? groups : undefined,
68
69
  subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
@@ -79,12 +80,13 @@ function parseTeacherSessionEntry(td) {
79
80
  return null;
80
81
  const possibleChanges = (td.getAttribute("class") ?? "").includes("want") || undefined;
81
82
  const subjectEl = td.querySelector('span[style*="color: blue"]');
82
- const subject = subjectEl ? text(subjectEl) : "";
83
+ if (!subjectEl)
84
+ return null;
85
+ const subject = text(subjectEl);
83
86
  if (!subject)
84
87
  return null;
85
88
  const room = parseEntryRoom(fullHtml, subject);
86
- const typeMatch = plainText.match(FLEXIBLE_LESSON_TYPE_RE_I);
87
- const type = typeMatch ? typeMatch[1].replace(/\.$/, "").toLowerCase() : "";
89
+ const type = parseLessonTypeAfterSubject(subjectEl).toLowerCase();
88
90
  const subgroupMatch = plainText.match(SUBGROUP_RE);
89
91
  const timeMatch = fullHtml.match(/<br\s*\/?>\s*(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/);
90
92
  if (!timeMatch)
@@ -71,6 +71,7 @@ export interface ParsedLesson {
71
71
  /** Missing means this source projection does not expose room information. */
72
72
  room?: string | null;
73
73
  subject: string;
74
+ /** Free-form portal label; empty when this source does not expose one. */
74
75
  type: string;
75
76
  /** Recurrence range; absent for concrete session lessons or unknown evidence. */
76
77
  weeks?: WeekRange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chuvsu-js",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "Библиотека для расписания и личного кабинета ЧГУ им. И. Н. Ульянова",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",