dochub-sdk 0.1.156 → 0.1.157

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.
@@ -0,0 +1,131 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import { Vue, Prop, Watch, Component } from 'vue-property-decorator';
3
+ import { DocHub, IDocHubEditableComponent, IDocHubPresentationProfile, IDocHubPresentationsParams } from '../..';
4
+
5
+ import ajv from 'ajv';
6
+ import ajv_localize from 'ajv-i18n/localize/ru';
7
+
8
+ @Component
9
+ export class DocHubDocumentProto extends Vue implements IDocHubEditableComponent {
10
+ onRefresher: any = null; // Таймер отложенного выполнения обновления
11
+ followURI: string | null = null; // URI файла за которым установлено слежение
12
+ error: string | null = null; // Ошибка
13
+
14
+ /**
15
+ * Профиль документа
16
+ */
17
+ @Prop({
18
+ type: Object,
19
+ required: true
20
+ }) readonly profile: IDocHubPresentationProfile;
21
+
22
+ /**
23
+ * Параметры
24
+ */
25
+ @Prop({
26
+ type: Object,
27
+ default: {}
28
+ }) readonly params: IDocHubPresentationsParams;
29
+
30
+ /**
31
+ * Следим за изменением профиля документа
32
+ */
33
+ @Watch('profile') onProfileChanged() {
34
+ this.onRefresh();
35
+ }
36
+
37
+ /**
38
+ * Следим за изменением параметров
39
+ */
40
+ @Watch('params') onParamsChanged() {
41
+ this.onRefresh();
42
+ }
43
+
44
+ mounted() {
45
+ // При монтировании компонента в DOM, генерируем событие обновления
46
+ this.onRefresh();
47
+ }
48
+
49
+ destroyed() {
50
+ // Отключаем слежку за файлом
51
+ this.refreshFileFollow(true);
52
+ }
53
+
54
+ /**
55
+ * Подтверждаем, что презентация может редактироваться
56
+ * @returns
57
+ */
58
+ isEditable(): boolean {
59
+ return true;
60
+ }
61
+ /**
62
+ * Открываем редактор
63
+ */
64
+ openEditor(): void {
65
+ this.followURI && DocHub.dataLake.openFileEditor(this.followURI, {
66
+ targetPath: this.profile.$base
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Обработка полученных данных документа.
72
+ * Необходимо переопределить.
73
+ */
74
+ processingData(data: any | undefined) {}
75
+
76
+ /**
77
+ * Возвращает схему данных для контроля структуры и состава данных.
78
+ * Необходимо переопределить.
79
+ */
80
+ getSchemaData(): any {}
81
+
82
+ /**
83
+ * Для переопределения
84
+ */
85
+ async doRefresh(): Promise<void> {
86
+ try {
87
+ await this.refreshFileFollow();
88
+ if (this.profile?.source) {
89
+ DocHub.dataLake.pullData(this.profile.source, this.params).then(async(result) => {
90
+ // Валидируем данные по структуре
91
+ const rules = new ajv({ allErrors: true });
92
+ const validator = rules.compile(this.getSchemaData());
93
+ if (!validator(result)) {
94
+ ajv_localize(validator.errors);
95
+ this.error = JSON.stringify(validator.errors, null, 4);
96
+ return;
97
+ }
98
+ // Если все в порядке, вызываем процессинг данных
99
+ this.processingData(result);
100
+ this.error = null;
101
+ });
102
+ } else this.processingData(undefined);
103
+ } catch (error) {
104
+ // eslint-disable-next-line no-console
105
+ console.error(error);
106
+ this.error = error;
107
+ this.processingData(undefined);
108
+ }
109
+ }
110
+
111
+ // Обновляет URI файла за которым установлено наблюдение
112
+ async refreshFileFollow(disable = false): Promise<void> {
113
+ // Устанавливаем слежение за файлом для оперативного обновления
114
+ this.followURI && DocHub.dataLake.unfollowFile(this.followURI, this.onRefresh);
115
+ if (!disable) {
116
+ this.followURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop() || null;
117
+ this.followURI && DocHub.dataLake.followFile(this.followURI, this.onRefresh);
118
+ }
119
+ }
120
+
121
+ // Обработчик события обновления
122
+ onRefresh(): void {
123
+ // Если обработчик уже запущен, останавливаем его
124
+ if (this.onRefresher) clearTimeout(this.onRefresher);
125
+ // Для исключения избыточных обращений к Data Lake откладываем обновление на 50мс
126
+ this.onRefresher = setTimeout(() => {
127
+ this.onRefresher = null;
128
+ this.doRefresh();
129
+ }, 50);
130
+ }
131
+ }
@@ -0,0 +1 @@
1
+ export * from './Documents';
package/index.ts CHANGED
@@ -5,7 +5,6 @@ export * from './interfaces/contexts';
5
5
  export * from './interfaces/constructors';
6
6
  export * from './interfaces/collaborations';
7
7
  export * from './interfaces/datalake';
8
- export * from './interfaces/documents';
9
8
  export * from './interfaces/editors';
10
9
  export * from './interfaces/eventbus';
11
10
  export * from './interfaces/localstorage';
@@ -1,6 +1,5 @@
1
1
  import { IDocHubContentProviders } from './providers';
2
2
  import { IDocHubProtocols } from './protocols';
3
- import { IDocHubDocuments } from './documents';
4
3
  import { IDocHubDataLake } from './datalake';
5
4
  import { IDocHubConstructors } from './constructors';
6
5
  import { IDocHubObjects } from './objects';
@@ -48,12 +47,6 @@ export interface IDocHubCore {
48
47
  * Протоколы доступа к данным
49
48
  */
50
49
  protocols: IDocHubProtocols;
51
- /**
52
- * !!!!!!!!!!! УСТАРЕЛО !!!!!!!!!!!
53
- * См presentations
54
- * Документы
55
- */
56
- documents: IDocHubDocuments;
57
50
  /**
58
51
  * Презентации сущностей
59
52
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dochub-sdk",
3
- "version": "0.1.156",
3
+ "version": "0.1.157",
4
4
  "description": "The DocHub System Development Kit.",
5
5
  "private": false,
6
6
  "main": "index.ts",
@@ -23,6 +23,9 @@
23
23
  "author": "R.Piontik",
24
24
  "license": "GPLV3",
25
25
  "dependencies": {
26
- "axios": "0.21.4"
26
+ "ajv": "8.17.1",
27
+ "ajv-i18n": "4.2.0",
28
+ "axios": "0.21.4",
29
+ "vue-property-decorator": "9.1.2"
27
30
  }
28
31
  }
@@ -1,26 +0,0 @@
1
- /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
2
- /* Нужно отказаться от отдельного представления "Документ" и мигрировать к универсальным презентациям и объектам */
3
- /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
4
-
5
-
6
- /**
7
- * Интерфейс, который требуется реализовать объектам документов
8
- */
9
- export interface IDocHubDocument {}
10
-
11
- /**
12
- * Интерфейс управления документами
13
- */
14
- export interface IDocHubDocuments {
15
- /**
16
- * Регистрирует тип документа
17
- * @param type - Тип документа. Например "markdown"
18
- * @param document - Объект реализующий документ
19
- */
20
- register(type: string, document: IDocHubDocument);
21
- /**
22
- * Возвращает зарегистрированные документы
23
- * @returns - Массив зарегистрированных типов документов
24
- */
25
- fetch(): string[];
26
- }