@configura/web-api 2.2.0-alpha.1 → 2.2.0-alpha.3
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/.eslintrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +633 -633
- package/dist/CatalogueAPI.js +312 -312
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +359 -344
- package/dist/CfgProduct.js +1005 -992
- package/dist/CfgReferencePathHelper.d.ts +26 -26
- package/dist/CfgReferencePathHelper.js +26 -26
- package/dist/index.d.ts +24 -24
- package/dist/index.js +24 -24
- package/dist/io/CfgHistoryManager.d.ts +83 -83
- package/dist/io/CfgHistoryManager.js +144 -144
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -21
- package/dist/io/CfgHistoryToProdConfConnector.js +50 -50
- package/dist/io/CfgIOManager.d.ts +53 -53
- package/dist/io/CfgIOManager.js +134 -134
- package/dist/io/CfgIOProdConfConnector.d.ts +54 -54
- package/dist/io/CfgIOProdConfConnector.js +139 -139
- package/dist/io/CfgIOWarningSupplier.d.ts +3 -3
- package/dist/io/CfgIOWarningSupplier.js +1 -1
- package/dist/io/CfgObservableStateManager.d.ts +25 -25
- package/dist/io/CfgObservableStateManager.js +69 -69
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -15
- package/dist/io/CfgObservableStateToProdConfConnector.js +17 -17
- package/dist/io/CfgWindowEventManager.d.ts +21 -21
- package/dist/io/CfgWindowEventManager.js +38 -38
- package/dist/io/CfgWindowMessageManager.d.ts +40 -40
- package/dist/io/CfgWindowMessageManager.js +91 -91
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -17
- package/dist/io/CfgWindowMessageToProdConfConnector.js +19 -19
- package/dist/io/index.d.ts +8 -8
- package/dist/io/index.js +8 -8
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +199 -199
- package/dist/productConfiguration/CfgFeature.js +691 -691
- package/dist/productConfiguration/CfgOption.d.ts +160 -160
- package/dist/productConfiguration/CfgOption.js +464 -464
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +136 -129
- package/dist/productConfiguration/CfgProductConfiguration.js +355 -346
- package/dist/productConfiguration/filters.d.ts +17 -17
- package/dist/productConfiguration/filters.js +141 -141
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +65 -65
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +89 -87
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +47 -47
- package/dist/syncGroups/SyncGroupsHandler.js +370 -370
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +39 -39
- package/dist/syncGroups/SyncGroupsState.js +167 -167
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +589 -589
- package/dist/tasks/TaskHandler.d.ts +77 -77
- package/dist/tasks/TaskHandler.js +276 -276
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -32
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +282 -282
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +187 -187
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +185 -185
- package/dist/tests/testData/testDataConstraints.d.ts +3 -3
- package/dist/tests/testData/testDataConstraints.js +174 -174
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +189 -189
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +121 -121
- package/dist/utilitiesCatalogueData.d.ts +47 -47
- package/dist/utilitiesCatalogueData.js +180 -180
- package/dist/utilitiesCataloguePermission.d.ts +38 -38
- package/dist/utilitiesCataloguePermission.js +79 -79
- package/dist/utilitiesConfiguration.d.ts +28 -28
- package/dist/utilitiesConfiguration.js +200 -200
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +114 -114
- package/package.json +3 -3
|
@@ -1,276 +1,276 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { augmentErrorMessage, Observable } from "@configura/web-utilities";
|
|
11
|
-
import { dtoExportFormatNames, dtoRenderFormatNames, } from "../CatalogueAPI.js";
|
|
12
|
-
import { convertDtoProductConfToV1 } from "../utilitiesConfiguration.js";
|
|
13
|
-
import { isExportFormat, isRenderFormat } from "./formats.js";
|
|
14
|
-
export class _TaskHandlerInternal {
|
|
15
|
-
constructor(api) {
|
|
16
|
-
this.api = api;
|
|
17
|
-
this.changeObservable = new Observable();
|
|
18
|
-
this.tasks = [];
|
|
19
|
-
this._notifyAllOfChange = () => {
|
|
20
|
-
const freshRef = TaskHandler._makeNewRefFrom(this);
|
|
21
|
-
this.changeObservable.notifyAll({ freshRef });
|
|
22
|
-
};
|
|
23
|
-
this.destroy = () => {
|
|
24
|
-
this.changeObservable.stopAllListen();
|
|
25
|
-
for (const task of this.tasks) {
|
|
26
|
-
task.abort();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
this.start = (format, product, renderParams, getPreviewUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
if (isRenderFormat(format)) {
|
|
31
|
-
if (!this.hasRender) {
|
|
32
|
-
throw new Error("Render has not been activated for this Catalogue");
|
|
33
|
-
}
|
|
34
|
-
if (renderParams === undefined) {
|
|
35
|
-
throw new Error("renderParams must be set for render");
|
|
36
|
-
}
|
|
37
|
-
yield TaskRender.make(this, format, product, renderParams, getPreviewUrl);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (isExportFormat(format)) {
|
|
41
|
-
if (!this.hasExport) {
|
|
42
|
-
throw new Error("Export has not been activated for this Catalogue");
|
|
43
|
-
}
|
|
44
|
-
yield TaskExport.make(this, format, product, getPreviewUrl);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
throw new Error("Unknown export format");
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
get hasExport() {
|
|
51
|
-
return this.api.hasFeature("export");
|
|
52
|
-
}
|
|
53
|
-
get hasRender() {
|
|
54
|
-
return this.api.hasFeature("render");
|
|
55
|
-
}
|
|
56
|
-
get availableFormats() {
|
|
57
|
-
const result = [];
|
|
58
|
-
if (this.hasExport) {
|
|
59
|
-
result.push(...dtoExportFormatNames);
|
|
60
|
-
}
|
|
61
|
-
if (this.hasRender) {
|
|
62
|
-
result.push(...dtoRenderFormatNames);
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
addTask(task) {
|
|
67
|
-
this.tasks.push(task);
|
|
68
|
-
this._notifyAllOfChange();
|
|
69
|
-
}
|
|
70
|
-
removeTask(task) {
|
|
71
|
-
const i = this.tasks.indexOf(task);
|
|
72
|
-
this.tasks.splice(i, 1);
|
|
73
|
-
this._notifyAllOfChange();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export class TaskHandler {
|
|
77
|
-
constructor(_internal) {
|
|
78
|
-
this._internal = _internal;
|
|
79
|
-
this.destroy = () => this._internal.destroy();
|
|
80
|
-
this.start = (format, product, renderParams, getPreviewUrl) => __awaiter(this, void 0, void 0, function* () { return this._internal.start(format, product, renderParams, getPreviewUrl); });
|
|
81
|
-
this.listenForChange = (l) => this._internal.changeObservable.listen(l);
|
|
82
|
-
this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
|
|
83
|
-
}
|
|
84
|
-
static make(api) {
|
|
85
|
-
return new this(new _TaskHandlerInternal(api));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Makes an object wrapping the passed object. This is not a clone method,
|
|
89
|
-
* it is a method to make a new outer reference. Like a shallow copy.
|
|
90
|
-
* We use this to help frameworks that are build around using equals to detect change.
|
|
91
|
-
*/
|
|
92
|
-
static _makeNewRefFrom(internal) {
|
|
93
|
-
return new this(internal);
|
|
94
|
-
}
|
|
95
|
-
get tasks() {
|
|
96
|
-
return this._internal.tasks;
|
|
97
|
-
}
|
|
98
|
-
get hasExport() {
|
|
99
|
-
return this._internal.hasExport;
|
|
100
|
-
}
|
|
101
|
-
get hasRender() {
|
|
102
|
-
return this._internal.hasRender;
|
|
103
|
-
}
|
|
104
|
-
get availableFormats() {
|
|
105
|
-
return this._internal.availableFormats;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export class Task {
|
|
109
|
-
constructor(taskHandler, format, product, getPreviewUrl) {
|
|
110
|
-
this.taskHandler = taskHandler;
|
|
111
|
-
this.format = format;
|
|
112
|
-
this._status = "pending";
|
|
113
|
-
this._start = () => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const result = yield this.postInit();
|
|
115
|
-
this._uuid = result.uuid;
|
|
116
|
-
this._created = result.created;
|
|
117
|
-
this._modified = result.modified;
|
|
118
|
-
this.setStatus(result.status);
|
|
119
|
-
this.scheduleRefresh();
|
|
120
|
-
});
|
|
121
|
-
this.startAndRegister = () => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
try {
|
|
123
|
-
yield this._start();
|
|
124
|
-
this.taskHandler.addTask(this);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
this.setStatus("failed");
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
this.restart = () => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
try {
|
|
133
|
-
this.stop();
|
|
134
|
-
this.setStatus("pending");
|
|
135
|
-
yield this._start();
|
|
136
|
-
}
|
|
137
|
-
catch (e) {
|
|
138
|
-
this.setStatus("failed");
|
|
139
|
-
throw e;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
this.scheduleRefresh = () => {
|
|
143
|
-
this._timerId = setTimeout(this.refresh, 1000);
|
|
144
|
-
};
|
|
145
|
-
this.refresh = () => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
try {
|
|
147
|
-
const result = yield this.pollStatus();
|
|
148
|
-
this._modified = result.modified;
|
|
149
|
-
const status = result.status;
|
|
150
|
-
switch (status) {
|
|
151
|
-
case "finished": {
|
|
152
|
-
const url = result.url;
|
|
153
|
-
if (!url) {
|
|
154
|
-
throw new Error("No URL from finished task");
|
|
155
|
-
}
|
|
156
|
-
this._url = url;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case "failed":
|
|
160
|
-
break;
|
|
161
|
-
case "running":
|
|
162
|
-
case "pending":
|
|
163
|
-
this.scheduleRefresh();
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
this.setStatus(status);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
this.setStatus("failed");
|
|
170
|
-
console.error(e);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
this.abort = () => {
|
|
174
|
-
this._status = "abandoned";
|
|
175
|
-
this.stop();
|
|
176
|
-
this.taskHandler.removeTask(this);
|
|
177
|
-
};
|
|
178
|
-
this._productParams = product.prodParams;
|
|
179
|
-
this._apiSelection = convertDtoProductConfToV1(product.getDtoConf());
|
|
180
|
-
if (getPreviewUrl !== undefined) {
|
|
181
|
-
void getPreviewUrl().then((dataUrl) => {
|
|
182
|
-
this._previewUrl = dataUrl;
|
|
183
|
-
this.taskHandler._notifyAllOfChange();
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
setStatus(status) {
|
|
188
|
-
const isChange = this._status !== status;
|
|
189
|
-
this._status = status;
|
|
190
|
-
if (isChange) {
|
|
191
|
-
this.taskHandler._notifyAllOfChange();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
get status() {
|
|
195
|
-
return this._status;
|
|
196
|
-
}
|
|
197
|
-
get uuid() {
|
|
198
|
-
if (this._uuid === undefined) {
|
|
199
|
-
throw new Error("Should not happen");
|
|
200
|
-
}
|
|
201
|
-
return this._uuid;
|
|
202
|
-
}
|
|
203
|
-
get created() {
|
|
204
|
-
if (this._created === undefined) {
|
|
205
|
-
throw new Error("Should not happen");
|
|
206
|
-
}
|
|
207
|
-
return this._created;
|
|
208
|
-
}
|
|
209
|
-
get modified() {
|
|
210
|
-
if (this._modified === undefined) {
|
|
211
|
-
throw new Error("Should not happen");
|
|
212
|
-
}
|
|
213
|
-
return this._modified;
|
|
214
|
-
}
|
|
215
|
-
get url() {
|
|
216
|
-
return this._url;
|
|
217
|
-
}
|
|
218
|
-
get previewUrl() {
|
|
219
|
-
return this._previewUrl;
|
|
220
|
-
}
|
|
221
|
-
stop() {
|
|
222
|
-
clearInterval(this._timerId);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
class TaskRender extends Task {
|
|
226
|
-
constructor(taskHandler, format, product, taskParams, getPreviewUrl) {
|
|
227
|
-
super(taskHandler, format, product, getPreviewUrl);
|
|
228
|
-
this.taskParams = taskParams;
|
|
229
|
-
}
|
|
230
|
-
static make(taskHandler, format, product, taskParams, getPreviewUrl) {
|
|
231
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
const t = new TaskRender(taskHandler, format, product, taskParams, getPreviewUrl);
|
|
233
|
-
yield t.startAndRegister();
|
|
234
|
-
return t;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
postInit() {
|
|
238
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
try {
|
|
240
|
-
return (yield this.taskHandler.api.postRender(this._productParams, Object.assign(Object.assign(Object.assign({}, this._apiSelection), this.taskParams), { format: this.format, width: Math.floor(this.taskParams.width), height: Math.floor(this.taskParams.height) }))).renderStatus;
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
throw augmentErrorMessage(e, "Start render request failure");
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
pollStatus() {
|
|
248
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
return (yield this.taskHandler.api.getRenderById({ uuid: this.uuid })).renderStatus;
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
class TaskExport extends Task {
|
|
254
|
-
static make(taskHandler, format, product, getPreviewUrl) {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
const t = new TaskExport(taskHandler, format, product, getPreviewUrl);
|
|
257
|
-
yield t.startAndRegister();
|
|
258
|
-
return t;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
postInit() {
|
|
262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
-
try {
|
|
264
|
-
return (yield this.taskHandler.api.postExport(this._productParams, Object.assign(Object.assign({}, this._apiSelection), { format: this.format, preferUnzipped: true }))).exportStatus;
|
|
265
|
-
}
|
|
266
|
-
catch (e) {
|
|
267
|
-
throw augmentErrorMessage(e, "Start export request failure");
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
pollStatus() {
|
|
272
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
-
return (yield this.taskHandler.api.getExportById({ uuid: this.uuid })).exportStatus;
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { augmentErrorMessage, Observable } from "@configura/web-utilities";
|
|
11
|
+
import { dtoExportFormatNames, dtoRenderFormatNames, } from "../CatalogueAPI.js";
|
|
12
|
+
import { convertDtoProductConfToV1 } from "../utilitiesConfiguration.js";
|
|
13
|
+
import { isExportFormat, isRenderFormat } from "./formats.js";
|
|
14
|
+
export class _TaskHandlerInternal {
|
|
15
|
+
constructor(api) {
|
|
16
|
+
this.api = api;
|
|
17
|
+
this.changeObservable = new Observable();
|
|
18
|
+
this.tasks = [];
|
|
19
|
+
this._notifyAllOfChange = () => {
|
|
20
|
+
const freshRef = TaskHandler._makeNewRefFrom(this);
|
|
21
|
+
this.changeObservable.notifyAll({ freshRef });
|
|
22
|
+
};
|
|
23
|
+
this.destroy = () => {
|
|
24
|
+
this.changeObservable.stopAllListen();
|
|
25
|
+
for (const task of this.tasks) {
|
|
26
|
+
task.abort();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.start = (format, product, renderParams, getPreviewUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (isRenderFormat(format)) {
|
|
31
|
+
if (!this.hasRender) {
|
|
32
|
+
throw new Error("Render has not been activated for this Catalogue");
|
|
33
|
+
}
|
|
34
|
+
if (renderParams === undefined) {
|
|
35
|
+
throw new Error("renderParams must be set for render");
|
|
36
|
+
}
|
|
37
|
+
yield TaskRender.make(this, format, product, renderParams, getPreviewUrl);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (isExportFormat(format)) {
|
|
41
|
+
if (!this.hasExport) {
|
|
42
|
+
throw new Error("Export has not been activated for this Catalogue");
|
|
43
|
+
}
|
|
44
|
+
yield TaskExport.make(this, format, product, getPreviewUrl);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Unknown export format");
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
get hasExport() {
|
|
51
|
+
return this.api.hasFeature("export");
|
|
52
|
+
}
|
|
53
|
+
get hasRender() {
|
|
54
|
+
return this.api.hasFeature("render");
|
|
55
|
+
}
|
|
56
|
+
get availableFormats() {
|
|
57
|
+
const result = [];
|
|
58
|
+
if (this.hasExport) {
|
|
59
|
+
result.push(...dtoExportFormatNames);
|
|
60
|
+
}
|
|
61
|
+
if (this.hasRender) {
|
|
62
|
+
result.push(...dtoRenderFormatNames);
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
addTask(task) {
|
|
67
|
+
this.tasks.push(task);
|
|
68
|
+
this._notifyAllOfChange();
|
|
69
|
+
}
|
|
70
|
+
removeTask(task) {
|
|
71
|
+
const i = this.tasks.indexOf(task);
|
|
72
|
+
this.tasks.splice(i, 1);
|
|
73
|
+
this._notifyAllOfChange();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class TaskHandler {
|
|
77
|
+
constructor(_internal) {
|
|
78
|
+
this._internal = _internal;
|
|
79
|
+
this.destroy = () => this._internal.destroy();
|
|
80
|
+
this.start = (format, product, renderParams, getPreviewUrl) => __awaiter(this, void 0, void 0, function* () { return this._internal.start(format, product, renderParams, getPreviewUrl); });
|
|
81
|
+
this.listenForChange = (l) => this._internal.changeObservable.listen(l);
|
|
82
|
+
this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
|
|
83
|
+
}
|
|
84
|
+
static make(api) {
|
|
85
|
+
return new this(new _TaskHandlerInternal(api));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Makes an object wrapping the passed object. This is not a clone method,
|
|
89
|
+
* it is a method to make a new outer reference. Like a shallow copy.
|
|
90
|
+
* We use this to help frameworks that are build around using equals to detect change.
|
|
91
|
+
*/
|
|
92
|
+
static _makeNewRefFrom(internal) {
|
|
93
|
+
return new this(internal);
|
|
94
|
+
}
|
|
95
|
+
get tasks() {
|
|
96
|
+
return this._internal.tasks;
|
|
97
|
+
}
|
|
98
|
+
get hasExport() {
|
|
99
|
+
return this._internal.hasExport;
|
|
100
|
+
}
|
|
101
|
+
get hasRender() {
|
|
102
|
+
return this._internal.hasRender;
|
|
103
|
+
}
|
|
104
|
+
get availableFormats() {
|
|
105
|
+
return this._internal.availableFormats;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export class Task {
|
|
109
|
+
constructor(taskHandler, format, product, getPreviewUrl) {
|
|
110
|
+
this.taskHandler = taskHandler;
|
|
111
|
+
this.format = format;
|
|
112
|
+
this._status = "pending";
|
|
113
|
+
this._start = () => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const result = yield this.postInit();
|
|
115
|
+
this._uuid = result.uuid;
|
|
116
|
+
this._created = result.created;
|
|
117
|
+
this._modified = result.modified;
|
|
118
|
+
this.setStatus(result.status);
|
|
119
|
+
this.scheduleRefresh();
|
|
120
|
+
});
|
|
121
|
+
this.startAndRegister = () => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
try {
|
|
123
|
+
yield this._start();
|
|
124
|
+
this.taskHandler.addTask(this);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
this.setStatus("failed");
|
|
128
|
+
throw e;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
this.restart = () => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
try {
|
|
133
|
+
this.stop();
|
|
134
|
+
this.setStatus("pending");
|
|
135
|
+
yield this._start();
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
this.setStatus("failed");
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
this.scheduleRefresh = () => {
|
|
143
|
+
this._timerId = setTimeout(this.refresh, 1000);
|
|
144
|
+
};
|
|
145
|
+
this.refresh = () => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
try {
|
|
147
|
+
const result = yield this.pollStatus();
|
|
148
|
+
this._modified = result.modified;
|
|
149
|
+
const status = result.status;
|
|
150
|
+
switch (status) {
|
|
151
|
+
case "finished": {
|
|
152
|
+
const url = result.url;
|
|
153
|
+
if (!url) {
|
|
154
|
+
throw new Error("No URL from finished task");
|
|
155
|
+
}
|
|
156
|
+
this._url = url;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "failed":
|
|
160
|
+
break;
|
|
161
|
+
case "running":
|
|
162
|
+
case "pending":
|
|
163
|
+
this.scheduleRefresh();
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
this.setStatus(status);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
this.setStatus("failed");
|
|
170
|
+
console.error(e);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
this.abort = () => {
|
|
174
|
+
this._status = "abandoned";
|
|
175
|
+
this.stop();
|
|
176
|
+
this.taskHandler.removeTask(this);
|
|
177
|
+
};
|
|
178
|
+
this._productParams = product.prodParams;
|
|
179
|
+
this._apiSelection = convertDtoProductConfToV1(product.getDtoConf());
|
|
180
|
+
if (getPreviewUrl !== undefined) {
|
|
181
|
+
void getPreviewUrl().then((dataUrl) => {
|
|
182
|
+
this._previewUrl = dataUrl;
|
|
183
|
+
this.taskHandler._notifyAllOfChange();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
setStatus(status) {
|
|
188
|
+
const isChange = this._status !== status;
|
|
189
|
+
this._status = status;
|
|
190
|
+
if (isChange) {
|
|
191
|
+
this.taskHandler._notifyAllOfChange();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
get status() {
|
|
195
|
+
return this._status;
|
|
196
|
+
}
|
|
197
|
+
get uuid() {
|
|
198
|
+
if (this._uuid === undefined) {
|
|
199
|
+
throw new Error("Should not happen");
|
|
200
|
+
}
|
|
201
|
+
return this._uuid;
|
|
202
|
+
}
|
|
203
|
+
get created() {
|
|
204
|
+
if (this._created === undefined) {
|
|
205
|
+
throw new Error("Should not happen");
|
|
206
|
+
}
|
|
207
|
+
return this._created;
|
|
208
|
+
}
|
|
209
|
+
get modified() {
|
|
210
|
+
if (this._modified === undefined) {
|
|
211
|
+
throw new Error("Should not happen");
|
|
212
|
+
}
|
|
213
|
+
return this._modified;
|
|
214
|
+
}
|
|
215
|
+
get url() {
|
|
216
|
+
return this._url;
|
|
217
|
+
}
|
|
218
|
+
get previewUrl() {
|
|
219
|
+
return this._previewUrl;
|
|
220
|
+
}
|
|
221
|
+
stop() {
|
|
222
|
+
clearInterval(this._timerId);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
class TaskRender extends Task {
|
|
226
|
+
constructor(taskHandler, format, product, taskParams, getPreviewUrl) {
|
|
227
|
+
super(taskHandler, format, product, getPreviewUrl);
|
|
228
|
+
this.taskParams = taskParams;
|
|
229
|
+
}
|
|
230
|
+
static make(taskHandler, format, product, taskParams, getPreviewUrl) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const t = new TaskRender(taskHandler, format, product, taskParams, getPreviewUrl);
|
|
233
|
+
yield t.startAndRegister();
|
|
234
|
+
return t;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
postInit() {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
try {
|
|
240
|
+
return (yield this.taskHandler.api.postRender(this._productParams, Object.assign(Object.assign(Object.assign({}, this._apiSelection), this.taskParams), { format: this.format, width: Math.floor(this.taskParams.width), height: Math.floor(this.taskParams.height) }))).renderStatus;
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
throw augmentErrorMessage(e, "Start render request failure");
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
pollStatus() {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
return (yield this.taskHandler.api.getRenderById({ uuid: this.uuid })).renderStatus;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
class TaskExport extends Task {
|
|
254
|
+
static make(taskHandler, format, product, getPreviewUrl) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
const t = new TaskExport(taskHandler, format, product, getPreviewUrl);
|
|
257
|
+
yield t.startAndRegister();
|
|
258
|
+
return t;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
postInit() {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
try {
|
|
264
|
+
return (yield this.taskHandler.api.postExport(this._productParams, Object.assign(Object.assign({}, this._apiSelection), { format: this.format, preferUnzipped: true }))).exportStatus;
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
throw augmentErrorMessage(e, "Start export request failure");
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
pollStatus() {
|
|
272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
return (yield this.taskHandler.api.getExportById({ uuid: this.uuid })).exportStatus;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
package/dist/tasks/formats.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DtoExportFormat, DtoRenderFormat } from "../CatalogueAPI.js";
|
|
2
|
-
export declare type RenderOrExportFormat = DtoRenderFormat | DtoExportFormat;
|
|
3
|
-
export declare function isRenderFormat(type: unknown): type is DtoRenderFormat;
|
|
4
|
-
export declare function isExportFormat(type: unknown): type is DtoExportFormat;
|
|
1
|
+
import { DtoExportFormat, DtoRenderFormat } from "../CatalogueAPI.js";
|
|
2
|
+
export declare type RenderOrExportFormat = DtoRenderFormat | DtoExportFormat;
|
|
3
|
+
export declare function isRenderFormat(type: unknown): type is DtoRenderFormat;
|
|
4
|
+
export declare function isExportFormat(type: unknown): type is DtoExportFormat;
|
|
5
5
|
//# sourceMappingURL=formats.d.ts.map
|
package/dist/tasks/formats.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { dtoExportFormatNames, dtoRenderFormatNames, } from "../CatalogueAPI.js";
|
|
2
|
-
export function isRenderFormat(type) {
|
|
3
|
-
return dtoRenderFormatNames.some((f) => type === f);
|
|
4
|
-
}
|
|
5
|
-
export function isExportFormat(type) {
|
|
6
|
-
return dtoExportFormatNames.some((f) => type === f);
|
|
7
|
-
}
|
|
1
|
+
import { dtoExportFormatNames, dtoRenderFormatNames, } from "../CatalogueAPI.js";
|
|
2
|
+
export function isRenderFormat(type) {
|
|
3
|
+
return dtoRenderFormatNames.some((f) => type === f);
|
|
4
|
+
}
|
|
5
|
+
export function isExportFormat(type) {
|
|
6
|
+
return dtoExportFormatNames.some((f) => type === f);
|
|
7
|
+
}
|