dochub-sdk 0.1.358 → 0.1.360

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.
@@ -33,6 +33,8 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
33
33
  onRefresher: any = null; // Таймер отложенного выполнения обновления
34
34
  followFiles: string[] | undefined = undefined; // Список файлов за изменениями которых нужно следить
35
35
  baseURI: string | undefined = undefined; // URI документа от которого должны разрешаться все относительные ссылки
36
+ templateURI: string | undefined = undefined; // URI файла шаблона, если он определен
37
+ sourceURI: string | undefined = undefined; // Файла источника, если он определен как файл
36
38
  error: string | null = null; // Ошибка
37
39
  isPending = true; // Признак внутренней работы. Например загрузка данных.
38
40
  /**
@@ -171,18 +173,16 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
171
173
  if (!this.profile?.source) throw new DocHubError('Document must have field "source" in profile!');
172
174
  this.isPending = true;
173
175
  await this.refreshFilesFollow();
174
- const template = (this.getType() === DocHubDocumentType.content) && this.profile?.template
175
- && (await DocHub.dataLake.pullFile(
176
- DocHub.dataLake.resolveURI(this.baseURI || this.profile?.template, this.profile?.template)
177
- ));
178
- let result: AxiosResponse = (template || (this.getType() === DocHubDocumentType.data))
176
+ // Если есть шаблон, загружаем его
177
+ const template = (this.getType() === DocHubDocumentType.content) && this.templateURI
178
+ && (await DocHub.dataLake.pullFile(this.templateURI));
179
+ let result: AxiosResponse | null = (template || (this.getType() === DocHubDocumentType.data))
179
180
  && { data: await DocHub.dataLake.resolveDataSetProfile(this.profile, {
180
181
  params: this.params,
181
182
  baseURI: this.baseURI
182
183
  }) } as AxiosResponse
183
- || (await DocHub.dataLake.pullFile(
184
- DocHub.dataLake.resolveURI(this.baseURI || this.profile?.source as string, this.profile?.source as string)
185
- ));
184
+ || (this.sourceURI ? await DocHub.dataLake.pullFile(this.sourceURI) : null);
185
+ if (!result) throw new DocHubError(`Can not render document [${this.profile?.$base}]`);
186
186
  // Валидируем данные по структуре, если это требуется
187
187
  if (template || (this.getType() === DocHubDocumentType.data)) {
188
188
  const rules = new ajv({ allErrors: true });
@@ -216,26 +216,40 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
216
216
  }
217
217
  }
218
218
 
219
- // Обновляет URI файла за которым установлено наблюдение
219
+ // Обновляет URI файлов за которым установлено наблюдение
220
220
  async refreshFilesFollow(disable = false): Promise<void> {
221
221
  // Очищаем ранее установленные отслеживания
222
222
  for(const uri of this.followFiles || []) {
223
223
  DocHub.dataLake.unfollowFile(uri, this.onRefresh);
224
224
  }
225
+ // Сбрасываем URI файлов
226
+ this.templateURI = undefined;
227
+ this.sourceURI = undefined;
228
+ this.baseURI = undefined;
225
229
  // Если нужно только очистить отслеживание - выходим
226
230
  if (disable) return;
227
- const followFiles: string[] = [];
228
231
  // Иначе...
232
+ const followFiles: string[] = [];
229
233
  // Определяем базовый файл
230
234
  this.baseURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
231
235
  // Если определить его не удалось, вываливаемся в ошибку
232
236
  if (!this.baseURI) throw new DocHubError(`Can not resolve base URI for base path [${this.profile.$base}]`);
237
+ const baseStruct = this.profile.$base.split('/');
233
238
  // Если указан шаблон, добавляем его в отслеживаемые файлы
234
239
  if(this.profile?.template) {
235
- followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile.template));
240
+ debugger;
241
+ const templatePath = [...baseStruct, 'template'].join('/');
242
+ this.templateURI = (await DocHub.dataLake.getURIForPath(templatePath) || []).pop()
243
+ || DocHub.dataLake.resolveURI(this.baseURI, this.profile.template);
244
+ if (!this.templateURI) throw new DocHubError(`Can not resolve template URI for path [${templatePath}]`);
245
+ followFiles.push(this.templateURI);
236
246
  } else if (typeof this.profile?.source === 'string' && this.getType() === DocHubDocumentType.content) {
237
247
  // Если шаблона нет, но документ предполагает работу с содержимым файла, то отслеживаем source
238
- followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile?.source));
248
+ const sourcePath = [...baseStruct, 'source'].join('/');
249
+ this.sourceURI = (await DocHub.dataLake.getURIForPath(sourcePath) || []).pop()
250
+ || DocHub.dataLake.resolveURI(this.baseURI, this.profile.source);
251
+ if (!this.sourceURI) throw new DocHubError(`Can not resolve source URI for path [${sourcePath}]`);
252
+ followFiles.push(this.sourceURI);
239
253
  }
240
254
  // Даем возможность повлиять на список отслеживаемых файлов через переопределенный метод
241
255
  this.followFiles = await this.processingFollowFiles(followFiles);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dochub-sdk",
3
- "version": "0.1.358",
3
+ "version": "0.1.360",
4
4
  "description": "The DocHub System Development Kit.",
5
5
  "private": false,
6
6
  "main": "index.ts",