@shapediver/viewer.session 3.0.0

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.
Files changed (84) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +1 -0
  3. package/dist/implementation/ExportApi.d.ts +36 -0
  4. package/dist/implementation/ExportApi.d.ts.map +1 -0
  5. package/dist/implementation/ExportApi.js +140 -0
  6. package/dist/implementation/ExportApi.js.map +1 -0
  7. package/dist/implementation/FileParameterApi.d.ts +10 -0
  8. package/dist/implementation/FileParameterApi.d.ts.map +1 -0
  9. package/dist/implementation/FileParameterApi.js +50 -0
  10. package/dist/implementation/FileParameterApi.js.map +1 -0
  11. package/dist/implementation/OutputApi.d.ts +38 -0
  12. package/dist/implementation/OutputApi.d.ts.map +1 -0
  13. package/dist/implementation/OutputApi.js +165 -0
  14. package/dist/implementation/OutputApi.js.map +1 -0
  15. package/dist/implementation/ParameterApi.d.ts +38 -0
  16. package/dist/implementation/ParameterApi.d.ts.map +1 -0
  17. package/dist/implementation/ParameterApi.js +151 -0
  18. package/dist/implementation/ParameterApi.js.map +1 -0
  19. package/dist/implementation/SessionApi.d.ts +98 -0
  20. package/dist/implementation/SessionApi.d.ts.map +1 -0
  21. package/dist/implementation/SessionApi.js +361 -0
  22. package/dist/implementation/SessionApi.js.map +1 -0
  23. package/dist/implementation/data/OutputApiData.d.ts +20 -0
  24. package/dist/implementation/data/OutputApiData.d.ts.map +1 -0
  25. package/dist/implementation/data/OutputApiData.js +51 -0
  26. package/dist/implementation/data/OutputApiData.js.map +1 -0
  27. package/dist/implementation/data/SessionApiData.d.ts +20 -0
  28. package/dist/implementation/data/SessionApiData.d.ts.map +1 -0
  29. package/dist/implementation/data/SessionApiData.js +51 -0
  30. package/dist/implementation/data/SessionApiData.js.map +1 -0
  31. package/dist/index.d.ts +40 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +120 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/interfaces/IExportApi.d.ts +27 -0
  36. package/dist/interfaces/IExportApi.d.ts.map +1 -0
  37. package/dist/interfaces/IExportApi.js +3 -0
  38. package/dist/interfaces/IExportApi.js.map +1 -0
  39. package/dist/interfaces/IFileParameterApi.d.ts +35 -0
  40. package/dist/interfaces/IFileParameterApi.d.ts.map +1 -0
  41. package/dist/interfaces/IFileParameterApi.js +3 -0
  42. package/dist/interfaces/IFileParameterApi.js.map +1 -0
  43. package/dist/interfaces/IOutputApi.d.ts +75 -0
  44. package/dist/interfaces/IOutputApi.d.ts.map +1 -0
  45. package/dist/interfaces/IOutputApi.js +3 -0
  46. package/dist/interfaces/IOutputApi.js.map +1 -0
  47. package/dist/interfaces/IParameterApi.d.ts +46 -0
  48. package/dist/interfaces/IParameterApi.d.ts.map +1 -0
  49. package/dist/interfaces/IParameterApi.js +3 -0
  50. package/dist/interfaces/IParameterApi.js.map +1 -0
  51. package/dist/interfaces/ISessionApi.d.ts +477 -0
  52. package/dist/interfaces/ISessionApi.d.ts.map +1 -0
  53. package/dist/interfaces/ISessionApi.js +3 -0
  54. package/dist/interfaces/ISessionApi.js.map +1 -0
  55. package/dist/interfaces/data/IOutputApiData.d.ts +7 -0
  56. package/dist/interfaces/data/IOutputApiData.d.ts.map +1 -0
  57. package/dist/interfaces/data/IOutputApiData.js +3 -0
  58. package/dist/interfaces/data/IOutputApiData.js.map +1 -0
  59. package/dist/interfaces/data/ISessionApiData.d.ts +7 -0
  60. package/dist/interfaces/data/ISessionApiData.d.ts.map +1 -0
  61. package/dist/interfaces/data/ISessionApiData.js +3 -0
  62. package/dist/interfaces/data/ISessionApiData.js.map +1 -0
  63. package/dist/main.d.ts +37 -0
  64. package/dist/main.d.ts.map +1 -0
  65. package/dist/main.js +96 -0
  66. package/dist/main.js.map +1 -0
  67. package/package.json +63 -0
  68. package/src/implementation/ExportApi.ts +158 -0
  69. package/src/implementation/FileParameterApi.ts +34 -0
  70. package/src/implementation/OutputApi.ts +178 -0
  71. package/src/implementation/ParameterApi.ts +176 -0
  72. package/src/implementation/SessionApi.ts +408 -0
  73. package/src/implementation/data/OutputApiData.ts +53 -0
  74. package/src/implementation/data/SessionApiData.ts +53 -0
  75. package/src/index.ts +225 -0
  76. package/src/interfaces/IExportApi.ts +29 -0
  77. package/src/interfaces/IFileParameterApi.ts +39 -0
  78. package/src/interfaces/IOutputApi.ts +85 -0
  79. package/src/interfaces/IParameterApi.ts +55 -0
  80. package/src/interfaces/ISessionApi.ts +461 -0
  81. package/src/interfaces/data/IOutputApiData.ts +16 -0
  82. package/src/interfaces/data/ISessionApiData.ts +16 -0
  83. package/src/main.ts +95 -0
  84. package/tsconfig.json +17 -0
@@ -0,0 +1,176 @@
1
+ import { InputValidator, Logger } from '@shapediver/viewer.shared.services';
2
+ import { IParameter } from '@shapediver/viewer.session-engine.session-engine';
3
+ import { IParameterApi } from '../interfaces/IParameterApi';
4
+ import { PARAMETER_TYPE, PARAMETER_VISUALIZATION } from '@shapediver/viewer.shared.types';
5
+ import { ShapeDiverResponseParameterGroup, ShapeDiverResponseParameterStructure } from '@shapediver/sdk.geometry-api-sdk-v2';
6
+
7
+ export class ParameterApi<T> implements IParameterApi<T> {
8
+ // #region Properties (3)
9
+
10
+ readonly #inputValidator: InputValidator = InputValidator.instance;
11
+ readonly #logger: Logger = Logger.instance;
12
+ readonly #parameter: IParameter<T>;
13
+
14
+ // #endregion Properties (3)
15
+
16
+ // #region Constructors (1)
17
+
18
+ constructor(parameter: IParameter<T>) {
19
+ this.#parameter = parameter;
20
+ }
21
+
22
+ // #endregion Constructors (1)
23
+
24
+ // #region Public Getters And Setters (25)
25
+
26
+ public get choices(): string[] | undefined {
27
+ return this.#parameter.choices;
28
+ }
29
+
30
+ public get decimalplaces(): number | undefined {
31
+ return this.#parameter.decimalplaces;
32
+ }
33
+
34
+ public get defval(): string {
35
+ return this.#parameter.defval;
36
+ }
37
+
38
+ public get displayname(): string | undefined {
39
+ return this.#parameter.displayname;
40
+ }
41
+
42
+ public set displayname(value: string | undefined) {
43
+ const scope = 'displayname';
44
+ this.#inputValidator.validateAndError(`ParameterApi.${scope}`, value, 'string', false);
45
+ this.#parameter.displayname = value;
46
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.displayname}.`);
47
+ }
48
+
49
+ public get expression(): string | undefined {
50
+ return this.#parameter.expression;
51
+ }
52
+
53
+ public get format(): string[] | undefined {
54
+ return this.#parameter.format;
55
+ }
56
+
57
+ public get group(): ShapeDiverResponseParameterGroup | undefined {
58
+ return this.#parameter.group;
59
+ }
60
+
61
+ public get hidden(): boolean {
62
+ return this.#parameter.hidden;
63
+ }
64
+
65
+ public set hidden(value: boolean) {
66
+ const scope = 'hidden';
67
+ this.#inputValidator.validateAndError(`ParameterApi.${scope}`, value, 'boolean');
68
+ this.#parameter.hidden = value;
69
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.hidden}.`);
70
+ }
71
+
72
+ public get id(): string {
73
+ return this.#parameter.id;
74
+ }
75
+
76
+ public get max(): number | undefined {
77
+ return this.#parameter.max;
78
+ }
79
+
80
+ public get min(): number | undefined {
81
+ return this.#parameter.min;
82
+ }
83
+
84
+ public get name(): string {
85
+ return this.#parameter.name;
86
+ }
87
+
88
+ public get order(): number | undefined {
89
+ return this.#parameter.order;
90
+ }
91
+
92
+ public set order(value: number | undefined) {
93
+ const scope = 'order';
94
+ this.#inputValidator.validateAndError(`ParameterApi.${scope}`, value, 'number', false);
95
+ this.#parameter.order = value;
96
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.order}.`);
97
+ }
98
+
99
+ public get sessionValue(): T | string {
100
+ return this.#parameter.sessionValue;
101
+ }
102
+
103
+ public set sessionValue(value: T | string) {
104
+ const scope = 'sessionValue';
105
+ this.#parameter.sessionValue = value;
106
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.value}.`);
107
+ }
108
+
109
+ public get structure(): ShapeDiverResponseParameterStructure | undefined {
110
+ return this.#parameter.structure;
111
+ }
112
+
113
+ public get tooltip(): string | undefined {
114
+ return this.#parameter.tooltip;
115
+ }
116
+
117
+ public set tooltip(value: string | undefined) {
118
+ const scope = 'tooltip';
119
+ this.#inputValidator.validateAndError(`ParameterApi.${scope}`, value, 'string', false);
120
+ this.#parameter.tooltip = value;
121
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.tooltip}.`);
122
+ }
123
+
124
+ public get type(): PARAMETER_TYPE {
125
+ return <PARAMETER_TYPE>this.#parameter.type;
126
+ }
127
+
128
+ public get value(): T | string {
129
+ return this.#parameter.value;
130
+ }
131
+
132
+ public set value(value: T | string) {
133
+ const scope = 'value';
134
+ this.isValid(value, true);
135
+ this.#parameter.value = value;
136
+ this.#logger.debug(`ParameterApi.${scope}: ${scope} was set to ${this.#parameter.value}.`);
137
+ }
138
+
139
+ public get visualization(): PARAMETER_VISUALIZATION | undefined {
140
+ return <PARAMETER_VISUALIZATION>this.#parameter.visualization;
141
+ }
142
+
143
+ // #endregion Public Getters And Setters (25)
144
+
145
+ // #region Public Methods (4)
146
+
147
+ public isValid(value: unknown, throwError?: boolean): boolean {
148
+ const scope = 'isValid';
149
+ this.#inputValidator.validateAndError(`ParameterApi.${scope}`, throwError, 'boolean', false);
150
+
151
+ if (throwError === false) {
152
+ try {
153
+ this.#parameter.isValid(value);
154
+ } catch (e) {
155
+ return false;
156
+ }
157
+ return true;
158
+ } else {
159
+ return this.#parameter.isValid(value);
160
+ }
161
+ }
162
+
163
+ public resetToDefaultValue(): void {
164
+ return this.#parameter.resetToDefaultValue();
165
+ }
166
+
167
+ public resetToSessionValue(): void {
168
+ return this.#parameter.resetToSessionValue();
169
+ }
170
+
171
+ public stringify(): string {
172
+ return this.#parameter.stringify();
173
+ }
174
+
175
+ // #endregion Public Methods (4)
176
+ }
@@ -0,0 +1,408 @@
1
+ import { CreationControlCenterSession, ICreationControlCenterSession } from '@shapediver/viewer.creation-control-center.session';
2
+ import { ExportApi } from './ExportApi';
3
+ import { FileParameter, SessionEngine } from '@shapediver/viewer.session-engine.session-engine';
4
+ import { FileParameterApi } from './FileParameterApi';
5
+ import { GLTFConverter } from '@shapediver/viewer.data-engine.gltf-converter';
6
+ import { IExportApi } from '../interfaces/IExportApi';
7
+ import {
8
+ InputValidator,
9
+ Logger,
10
+ ShapeDiverViewerSessionError,
11
+ StateEngine
12
+ } from '@shapediver/viewer.shared.services';
13
+ import { IOutputApi } from '../interfaces/IOutputApi';
14
+ import { IParameterApi } from '../interfaces//IParameterApi';
15
+ import { ISessionApi } from '../interfaces/ISessionApi';
16
+ import { ISettingsSections } from '@shapediver/viewer.shared.types';
17
+ import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
18
+ import { OutputApi } from './OutputApi';
19
+ import { ParameterApi } from './ParameterApi';
20
+ import { SessionApiData } from './data/SessionApiData';
21
+ import { ShapeDiverRequestExport, ShapeDiverResponseDto } from '@shapediver/sdk.geometry-api-sdk-v2';
22
+
23
+ export class SessionApi implements ISessionApi {
24
+ // #region Properties (9)
25
+
26
+ readonly #creationControlCenterSession: ICreationControlCenterSession = CreationControlCenterSession.instance;
27
+ readonly #exports: { [key: string]: IExportApi; } = {};
28
+ readonly #gltfConverter: GLTFConverter = GLTFConverter.instance;
29
+ readonly #inputValidator: InputValidator = InputValidator.instance;
30
+ readonly #logger: Logger = Logger.instance;
31
+ readonly #outputs: { [key: string]: IOutputApi; } = {};
32
+ readonly #parameters: { [key: string]: IParameterApi<unknown>; } = {};
33
+ readonly #sessionEngine: SessionEngine;
34
+ readonly #stateEngine: StateEngine = StateEngine.instance;
35
+
36
+ // #endregion Properties (9)
37
+
38
+ // #region Constructors (1)
39
+
40
+ constructor(sessionEngine: SessionEngine) {
41
+ this.#sessionEngine = sessionEngine;
42
+ if (!this.#sessionEngine.initialized)
43
+ throw new ShapeDiverViewerSessionError('Session could not be initialized.');
44
+
45
+ this.#sessionEngine.updateCallback = (newNode?: ITreeNode) => {
46
+ if (!newNode) return;
47
+
48
+ if (newNode.data.findIndex(d => d instanceof SessionApiData) === -1)
49
+ newNode.addData(new SessionApiData(this));
50
+ };
51
+ this.#sessionEngine.updateCallback(this.node, this.node);
52
+
53
+ for (const o in this.#sessionEngine.outputs)
54
+ this.#outputs[o] = new OutputApi(this.#sessionEngine.outputs[o]);
55
+
56
+ for (const e in this.#sessionEngine.exports)
57
+ this.#exports[e] = new ExportApi(this.#sessionEngine.exports[e]);
58
+
59
+ for (const p in this.#sessionEngine.parameters) {
60
+ if (this.#sessionEngine.parameters[p] instanceof FileParameter) {
61
+ this.#parameters[p] = new FileParameterApi(<FileParameter>this.#sessionEngine.parameters[p]);
62
+ } else {
63
+ this.#parameters[p] = new ParameterApi(this.#sessionEngine.parameters[p]);
64
+ }
65
+ }
66
+ }
67
+
68
+ // #endregion Constructors (1)
69
+
70
+ // #region Public Getters And Setters (28)
71
+
72
+ public get automaticSceneUpdate(): boolean {
73
+ return this.#sessionEngine.automaticSceneUpdate;
74
+ }
75
+
76
+ public set automaticSceneUpdate(value: boolean) {
77
+ const scope = 'automaticSceneUpdate';
78
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'boolean');
79
+ this.#sessionEngine.automaticSceneUpdate = value;
80
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
81
+ }
82
+
83
+ public get commitParameters(): boolean {
84
+ return this.#sessionEngine.settingsEngine.general.commitParameters;
85
+ }
86
+
87
+ public set commitParameters(value: boolean) {
88
+ const scope = 'commitParameters';
89
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'boolean');
90
+ this.#sessionEngine.settingsEngine.general.commitParameters = value;
91
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
92
+ }
93
+
94
+ public get commitSettings(): boolean {
95
+ return this.#sessionEngine.settingsEngine.general.commitSettings;
96
+ }
97
+
98
+ public set commitSettings(value: boolean) {
99
+ const scope = 'commitSettings';
100
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'boolean');
101
+ this.#sessionEngine.settingsEngine.general.commitSettings = value;
102
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
103
+ }
104
+
105
+ public get customizeOnParameterChange(): boolean {
106
+ return this.#sessionEngine.customizeOnParameterChange;
107
+ }
108
+
109
+ public set customizeOnParameterChange(value: boolean) {
110
+ const scope = 'customizeOnParameterChange';
111
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'boolean');
112
+ this.#sessionEngine.customizeOnParameterChange = value;
113
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
114
+ }
115
+
116
+ public get excludeViewports(): string[] {
117
+ return this.#sessionEngine.excludeViewports;
118
+ }
119
+
120
+ public set excludeViewports(value: string[]) {
121
+ const scope = 'excludeViewports';
122
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'stringArray');
123
+ this.#sessionEngine.excludeViewports = value;
124
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
125
+ }
126
+
127
+ public get exports(): { [key: string]: IExportApi; } {
128
+ return this.#exports;
129
+ }
130
+
131
+ public get guid(): string | undefined {
132
+ return this.#sessionEngine.guid;
133
+ }
134
+
135
+ public get id(): string {
136
+ return this.#sessionEngine.id;
137
+ }
138
+
139
+ public get initialized(): boolean {
140
+ return this.#sessionEngine.initialized;
141
+ }
142
+
143
+ public get jwtToken(): string | undefined {
144
+ return this.#sessionEngine.jwtToken;
145
+ }
146
+
147
+ public get loadSdtf(): boolean {
148
+ return this.#sessionEngine.loadSdtf;
149
+ }
150
+
151
+ public set loadSdtf(value: boolean) {
152
+ const scope = 'loadSdtf';
153
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'boolean');
154
+ this.#sessionEngine.loadSdtf = value;
155
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
156
+ }
157
+
158
+ public get modelViewUrl(): string {
159
+ return this.#sessionEngine.modelViewUrl;
160
+ }
161
+
162
+ public get node(): ITreeNode {
163
+ return this.#sessionEngine.node;
164
+ }
165
+
166
+ public get outputs(): { [key: string]: IOutputApi; } {
167
+ return this.#outputs;
168
+ }
169
+
170
+ public get parameterDefaultValues(): { [key: string]: unknown; } {
171
+ const parameterDefaultValues: { [key: string]: unknown; } = {};
172
+ for (const key in this.parameters)
173
+ parameterDefaultValues[key] = this.parameters[key].defval;
174
+ return parameterDefaultValues;
175
+ }
176
+
177
+ public get parameterSessionValues(): { [key: string]: unknown; } {
178
+ const parameterSessionValues: { [key: string]: unknown; } = {};
179
+ for (const key in this.parameters)
180
+ parameterSessionValues[key] = this.parameters[key].sessionValue;
181
+ return parameterSessionValues;
182
+ }
183
+
184
+ public get parameterValues(): { [key: string]: unknown; } {
185
+ const parameterValues: { [key: string]: unknown; } = {};
186
+ for (const key in this.parameters)
187
+ parameterValues[key] = this.parameters[key].value;
188
+ return parameterValues;
189
+ }
190
+
191
+ public get parameters(): { [key: string]: IParameterApi<unknown>; } {
192
+ return this.#parameters;
193
+ }
194
+
195
+ public get refreshJwtToken(): (() => Promise<string>) | undefined {
196
+ return this.#sessionEngine.refreshJwtToken;
197
+ }
198
+
199
+ public set refreshJwtToken(value: (() => Promise<string>) | undefined) {
200
+ const scope = 'refreshJwtToken';
201
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'function', false);
202
+ this.#sessionEngine.refreshJwtToken = value;
203
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
204
+ }
205
+
206
+ public get ticket(): string | undefined {
207
+ return this.#sessionEngine.ticket;
208
+ }
209
+
210
+ public get updateCallback(): ((newNode: ITreeNode, oldNode: ITreeNode) => void | Promise<void>) | null {
211
+ return this.#sessionEngine.updateCallback;
212
+ }
213
+
214
+ public set updateCallback(value: ((newNode: ITreeNode, oldNode: ITreeNode) => void | Promise<void>) | null) {
215
+ const scope = 'updateCallback';
216
+ if (value) this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'function', false);
217
+ this.#sessionEngine.updateCallback = async (newNode: ITreeNode, oldNode: ITreeNode) => {
218
+ if (newNode.data.findIndex(d => d instanceof SessionApiData) === -1)
219
+ newNode.addData(new SessionApiData(this));
220
+ if (value) await Promise.resolve(value(newNode, oldNode));
221
+ };
222
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was updated to ${value}.`);
223
+ }
224
+
225
+ // #endregion Public Getters And Setters (28)
226
+
227
+ // #region Public Methods (31)
228
+
229
+ public applySettings(response: ShapeDiverResponseDto, sections?: ISettingsSections): Promise<void> {
230
+ const scope = 'applySettings';
231
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, response, 'object');
232
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, sections, 'object', false);
233
+ return this.#creationControlCenterSession.applySettings(this.id, response, sections);
234
+ }
235
+
236
+ public canGoBack(): boolean {
237
+ return this.#sessionEngine.canGoBack();
238
+ }
239
+
240
+ public canGoForward(): boolean {
241
+ return this.#sessionEngine.canGoForward();
242
+ }
243
+
244
+ public cancelCustomization(): void {
245
+ this.#sessionEngine.cancelCustomization();
246
+ }
247
+
248
+ public async close(): Promise<void> {
249
+ return await this.#creationControlCenterSession.closeSessionEngine(this.id);
250
+ }
251
+
252
+ public async convertToGlTF(): Promise<Blob> {
253
+ for (const r in this.#stateEngine.viewportEngines)
254
+ this.#stateEngine.viewportEngines[r].update('SessionApi.convertToGlTF');
255
+
256
+ const result = await this.#gltfConverter.convert(this.node, false);
257
+ return new Blob([result], { type: 'application/octet-stream' });
258
+ }
259
+
260
+ public customize(parameterValues?: { [key: string]: unknown; }, force: boolean = false, waitForViewportUpdate: boolean = false): Promise<ITreeNode> {
261
+ const scope = 'customize';
262
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, parameterValues, 'object', false);
263
+
264
+ // if there are parameter values specified, we set them directly
265
+ // the validation happens in the setter of the ParameterApi
266
+ if (parameterValues)
267
+ for (const p in parameterValues)
268
+ this.parameters[p].value = parameterValues[p];
269
+
270
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, force, 'boolean', false);
271
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, waitForViewportUpdate, 'boolean', false);
272
+ return this.#sessionEngine.customize(force, waitForViewportUpdate);
273
+ }
274
+
275
+ public customizeParallel(parameterValues: { [key: string]: unknown; }): Promise<ITreeNode> {
276
+ const scope = 'customizeParallel';
277
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, parameterValues, 'object');
278
+ return this.#sessionEngine.customizeParallel(parameterValues) as Promise<ITreeNode>;
279
+ }
280
+
281
+ public customizeResult(parameterValues: { [key: string]: unknown; }): Promise<ShapeDiverResponseDto> {
282
+ const scope = 'customizeResult';
283
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, parameterValues, 'object');
284
+ return this.#sessionEngine.customizeParallel(parameterValues, false) as Promise<ShapeDiverResponseDto>;
285
+ }
286
+
287
+ public getExportById(id: string): IExportApi | null {
288
+ const scope = 'getExportById';
289
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, id, 'string');
290
+ return this.#exports[id];
291
+ }
292
+
293
+ public getExportByName(name: string): IExportApi[] {
294
+ const scope = 'getExportByName';
295
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, name, 'string');
296
+ return Object.values(this.#exports).filter(e => e.name === name);
297
+ }
298
+
299
+ public getExportByType(type: string): IExportApi[] {
300
+ const scope = 'getExportByType';
301
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, type, 'string');
302
+ return Object.values(this.#exports).filter(e => e.type === type);
303
+ }
304
+
305
+ public getOutputByFormat(format: string): IOutputApi[] {
306
+ const scope = 'getOutputByFormat';
307
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, format, 'string');
308
+ return Object.values(this.#outputs).filter(o => o.format.includes(format));
309
+ }
310
+
311
+ public getOutputById(id: string): IOutputApi | null {
312
+ const scope = 'getOutputById';
313
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, id, 'string');
314
+ return this.#outputs[id];
315
+ }
316
+
317
+ public getOutputByName(name: string): IOutputApi[] {
318
+ const scope = 'getOutputByName';
319
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, name, 'string');
320
+ return Object.values(this.#outputs).filter(o => o.name === name);
321
+ }
322
+
323
+ public getParameterById(id: string): IParameterApi<unknown> | null {
324
+ const scope = 'getParameterById';
325
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, id, 'string');
326
+ return this.#parameters[id];
327
+ }
328
+
329
+ public getParameterByName(name: string): IParameterApi<unknown>[] {
330
+ const scope = 'getParameterByName';
331
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, name, 'string');
332
+ return Object.values(this.#parameters).filter(p => p.name === name);
333
+ }
334
+
335
+ public getParameterByType(type: string): IParameterApi<unknown>[] {
336
+ const scope = 'getParameterByType';
337
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, type, 'string');
338
+ return Object.values(this.#parameters).filter(p => p.type === type);
339
+ }
340
+
341
+ public goBack(): Promise<ITreeNode> {
342
+ return this.#sessionEngine.goBack();
343
+ }
344
+
345
+ public goForward(): Promise<ITreeNode> {
346
+ return this.#sessionEngine.goForward();
347
+ }
348
+
349
+ public async loadCachedOutputs(outputs: { [key: string]: string; }): Promise<{ [key: string]: ITreeNode | undefined }> {
350
+ return await this.#sessionEngine.loadCachedOutputsParallel(outputs);
351
+ }
352
+
353
+ public async requestExports(body: ShapeDiverRequestExport, loadOutputs?: boolean, maxWaitMsec?: number): Promise<ShapeDiverResponseDto> {
354
+ const scope = 'requestExports';
355
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, body, 'object');
356
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, loadOutputs, 'boolean', false);
357
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, maxWaitMsec, 'number', false);
358
+ return this.#sessionEngine.requestExports(body, loadOutputs, maxWaitMsec);
359
+ }
360
+
361
+ public resetParameterValues(force: boolean = false, waitForViewportUpdate: boolean = false): Promise<ITreeNode> {
362
+ const scope = 'resetParameterValues';
363
+ for (const p in this.parameters)
364
+ this.parameters[p].value = this.parameters[p].defval;
365
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, force, 'boolean', false);
366
+ return this.#sessionEngine.customize(force, waitForViewportUpdate);
367
+ }
368
+
369
+ public resetSettings(sections?: ISettingsSections): Promise<void> {
370
+ const scope = 'applySettings';
371
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, sections, 'object', false);
372
+ return this.#creationControlCenterSession.resetSettings(this.id, sections);
373
+ }
374
+
375
+ public saveDefaultParameterValues(): Promise<boolean> {
376
+ return this.#sessionEngine.saveDefaultParameterValues();
377
+ }
378
+
379
+ public saveSettings(viewportId?: string): Promise<boolean> {
380
+ const scope = 'saveDefaultParameterValues';
381
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, viewportId, 'string', false);
382
+ return this.#creationControlCenterSession.saveSettings(this.id, viewportId);
383
+ }
384
+
385
+ public saveUiProperties(): Promise<boolean> {
386
+ return this.#sessionEngine.saveUiProperties();
387
+ }
388
+
389
+ public async setJwtToken(value: string): Promise<void> {
390
+ const scope = 'setJwtToken';
391
+ this.#inputValidator.validateAndError(`SessionApi.${scope}`, value, 'string', false);
392
+ await this.#sessionEngine.setJwtToken(value);
393
+ this.#logger.debug(`SessionApi.${scope}: ${scope} was set to ${value}`);
394
+ return;
395
+ }
396
+
397
+ public updateOutputs(waitForViewportUpdate: boolean = false): Promise<ITreeNode> {
398
+ return this.#sessionEngine.updateOutputs(undefined, waitForViewportUpdate);
399
+ }
400
+
401
+ public async uploadFileParameters(values: { [key: string]: string | File | Blob }): Promise<{ [key: string]: string }> {
402
+ const fileParameters: { [key: string]: string | File | Blob } = values || {};
403
+ const fileParameterIds = await this.#sessionEngine.uploadFileParameters(fileParameters);
404
+ return fileParameterIds;
405
+ }
406
+
407
+ // #endregion Public Methods (31)
408
+ }
@@ -0,0 +1,53 @@
1
+ import { AbstractTreeNodeData } from '@shapediver/viewer.shared.node-tree';
2
+ import { IOutputApi } from '../../interfaces/IOutputApi';
3
+ import { IOutputApiData } from '../../interfaces/data/IOutputApiData';
4
+
5
+ export class OutputApiData extends AbstractTreeNodeData implements IOutputApiData {
6
+ // #region Properties (1)
7
+
8
+ #api: IOutputApi;
9
+
10
+ // #endregion Properties (1)
11
+
12
+ // #region Constructors (1)
13
+
14
+ /**
15
+ * Creates a OutputApi data node.
16
+ *
17
+ * @param _data the data as key- value pairs
18
+ * @param id the id
19
+ */
20
+ constructor(
21
+ api: IOutputApi,
22
+ id?: string,
23
+ version?: string
24
+ ) {
25
+ super(id, version);
26
+ this.#api = api;
27
+ }
28
+
29
+ // #endregion Constructors (1)
30
+
31
+ // #region Public Getters And Setters (2)
32
+
33
+ public get api(): IOutputApi {
34
+ return this.#api;
35
+ }
36
+
37
+ public set api(value: IOutputApi) {
38
+ this.#api = value;
39
+ }
40
+
41
+ // #endregion Public Getters And Setters (2)
42
+
43
+ // #region Public Methods (1)
44
+
45
+ /**
46
+ * Clones the scene graph data.
47
+ */
48
+ public clone(): IOutputApiData {
49
+ return new OutputApiData(this.api, this.id, this.version);
50
+ }
51
+
52
+ // #endregion Public Methods (1)
53
+ }
@@ -0,0 +1,53 @@
1
+ import { AbstractTreeNodeData } from '@shapediver/viewer.shared.node-tree';
2
+ import { ISessionApi } from '../../interfaces/ISessionApi';
3
+ import { ISessionApiData } from '../../interfaces/data/ISessionApiData';
4
+
5
+ export class SessionApiData extends AbstractTreeNodeData implements ISessionApiData {
6
+ // #region Properties (1)
7
+
8
+ #api: ISessionApi;
9
+
10
+ // #endregion Properties (1)
11
+
12
+ // #region Constructors (1)
13
+
14
+ /**
15
+ * Creates a SessionApi data node.
16
+ *
17
+ * @param _data the data as key- value pairs
18
+ * @param id the id
19
+ */
20
+ constructor(
21
+ api: ISessionApi,
22
+ id?: string,
23
+ version?: string
24
+ ) {
25
+ super(id, version);
26
+ this.#api = api;
27
+ }
28
+
29
+ // #endregion Constructors (1)
30
+
31
+ // #region Public Getters And Setters (2)
32
+
33
+ public get api(): ISessionApi {
34
+ return this.#api;
35
+ }
36
+
37
+ public set api(value: ISessionApi) {
38
+ this.#api = value;
39
+ }
40
+
41
+ // #endregion Public Getters And Setters (2)
42
+
43
+ // #region Public Methods (1)
44
+
45
+ /**
46
+ * Clones the scene graph data.
47
+ */
48
+ public clone(): ISessionApiData {
49
+ return new SessionApiData(this.api, this.id, this.version);
50
+ }
51
+
52
+ // #endregion Public Methods (1)
53
+ }