dochub-sdk 0.1.181 → 0.1.182

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.
@@ -29,7 +29,8 @@ export enum DocHubDocumentType {
29
29
  @Component
30
30
  export class DocHubDocumentProto extends DocHubComponentProto implements IDocHubEditableComponent {
31
31
  onRefresher: any = null; // Таймер отложенного выполнения обновления
32
- followURI: string | undefined; // URI файла за которым установлено слежение
32
+ followFiles: string[] | undefined; // Список файлов за изменениями которых нужно следить
33
+ baseURI: string | undefined; // URI документа от которого должны разрешаться все относительные ссылки
33
34
  error: string | null = null; // Ошибка
34
35
  isPending = true; // Признак внутренней работы. Например загрузка данных.
35
36
 
@@ -70,7 +71,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
70
71
 
71
72
  destroyed() {
72
73
  // Отключаем слежку за файлом
73
- this.refreshFileFollow(true);
74
+ this.refreshFilesFollow(true);
74
75
  }
75
76
 
76
77
  /**
@@ -84,7 +85,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
84
85
  * Открываем редактор
85
86
  */
86
87
  openEditor(): void {
87
- this.followURI && DocHub.dataLake.openFileEditor(this.followURI, {
88
+ this.baseURI && DocHub.dataLake.openFileEditor(this.baseURI, {
88
89
  targetPath: this.profile.$base
89
90
  });
90
91
  }
@@ -105,6 +106,16 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
105
106
  throw new DocHubError(`The document has ${this.getType()} type. It must have processingContent method. But, the method is not implemented.`);
106
107
  }
107
108
 
109
+ /**
110
+ * Возвращает список отслеживаемых файлов.
111
+ * Может быть переопределен.
112
+ * @param files - Список файлов которые предполагается отслеживать
113
+ * @returns - Список файлов для отслеживания
114
+ */
115
+ async processingFollowFiles(files: string[]): Promise<string[]> {
116
+ return files;
117
+ }
118
+
108
119
  /**
109
120
  * Возвращает схему данных для контроля структуры и состава данных.
110
121
  * Необходимо переопределить.
@@ -114,7 +125,8 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
114
125
  }
115
126
 
116
127
  /**
117
- * Возвращает тип документа
128
+ * Возвращает тип документа.
129
+ * Может быть переопределен.
118
130
  */
119
131
  getType(): DocHubDocumentType {
120
132
  return DocHubDocumentType.content;
@@ -134,18 +146,18 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
134
146
  try {
135
147
  if (!this.profile?.source) throw new DocHubError('Document must have field "source" in profile!');
136
148
  this.isPending = true;
137
- await this.refreshFileFollow();
149
+ await this.refreshFilesFollow();
138
150
  const template = (this.getType() === DocHubDocumentType.content) && this.profile?.template
139
151
  && (await DocHub.dataLake.pullFile(
140
- DocHub.dataLake.resolveURI(this.followURI || this.profile?.template, this.profile?.template)
152
+ DocHub.dataLake.resolveURI(this.baseURI || this.profile?.template, this.profile?.template)
141
153
  ));
142
154
  let result: AxiosResponse = (template || (this.getType() === DocHubDocumentType.data))
143
155
  && { data: await DocHub.dataLake.resolveDataSetProfile(this.profile, {
144
156
  params: this.params,
145
- baseURI: this.followURI
157
+ baseURI: this.baseURI
146
158
  }) } as AxiosResponse
147
159
  || (await DocHub.dataLake.pullFile(
148
- DocHub.dataLake.resolveURI(this.followURI || this.profile?.source as string, this.profile?.source as string)
160
+ DocHub.dataLake.resolveURI(this.baseURI || this.profile?.source as string, this.profile?.source as string)
149
161
  ));
150
162
  // Валидируем данные по структуре, если это требуется
151
163
  if (template || (this.getType() === DocHubDocumentType.data)) {
@@ -181,12 +193,33 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
181
193
  }
182
194
 
183
195
  // Обновляет URI файла за которым установлено наблюдение
184
- async refreshFileFollow(disable = false): Promise<void> {
185
- // Устанавливаем слежение за файлом для оперативного обновления
186
- this.followURI && DocHub.dataLake.unfollowFile(this.followURI, this.onRefresh);
187
- if (!disable) {
188
- this.followURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
189
- this.followURI && DocHub.dataLake.followFile(this.followURI, this.onRefresh);
196
+ async refreshFilesFollow(disable = false): Promise<void> {
197
+ // Очищаем ранее установленные отслеживания
198
+ for(const uri of this.followFiles || []) {
199
+ DocHub.dataLake.unfollowFile(uri, this.onRefresh);
200
+ }
201
+ const followFiles: string[] = [];
202
+ // Если нужно только очистить отслеживание - выходим
203
+ if (disable) return;
204
+ // Иначе...
205
+ // Определяем базовый файл
206
+ this.baseURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
207
+ // Если определить его не удалось, вываливаемся в ошибку
208
+ if (!this.baseURI) throw new DocHubError(`Can not resolve base URI for base path [${this.profile.$base}]`);
209
+ // Добавляем его в отслеживание
210
+ this.baseURI && followFiles.push(this.baseURI);
211
+ // Если указан шаблон, добавляем его в отслеживаемые файлы
212
+ if(this.profile?.template) {
213
+ followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile.template));
214
+ } else if (typeof this.profile?.source === 'string' && this.getType() === DocHubDocumentType.content) {
215
+ // Если шаблона нет, но документ предполагает работу с содержимым файла, то отслеживаем source
216
+ followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile?.source));
217
+ }
218
+ // Даем возможность повлиять на список отслеживаемых файлов через переопределенный метод
219
+ this.followFiles = await this.processingFollowFiles(followFiles);
220
+ // Устанавливаем отслеживание
221
+ for(const uri of this.followFiles || []) {
222
+ DocHub.dataLake.followFile(uri, this.onRefresh);
190
223
  }
191
224
  }
192
225
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dochub-sdk",
3
- "version": "0.1.181",
3
+ "version": "0.1.182",
4
4
  "description": "The DocHub System Development Kit.",
5
5
  "private": false,
6
6
  "main": "index.ts",