@hpcc-js/marshaller 2.28.6 → 2.28.7
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/LICENSE +43 -43
- package/dist/index.es6.js +19 -19
- package/dist/index.es6.js.map +1 -1
- package/dist/index.js +17 -17
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +16 -16
- package/src/__package__.ts +3 -3
- package/src/dashy.css +239 -239
- package/src/dashy.ts +521 -521
- package/src/ddl1/DDLApi.ts +229 -229
- package/src/ddl1/FlyoutButton.ts +120 -120
- package/src/ddl1/Graph.ts +93 -93
- package/src/ddl1/HTML.ts +77 -77
- package/src/ddl1/HipieDDL.ts +2437 -2437
- package/src/ddl1/HipieDDLMixin.ts +380 -380
- package/src/ddl1/Tabbed.ts +91 -91
- package/src/ddl1/TargetMarshaller.ts +57 -57
- package/src/ddl2/PopupManager.ts +89 -89
- package/src/ddl2/activities/activity.ts +431 -431
- package/src/ddl2/activities/databomb.ts +237 -237
- package/src/ddl2/activities/datasource.ts +52 -52
- package/src/ddl2/activities/dspicker.ts +106 -106
- package/src/ddl2/activities/filter.ts +542 -542
- package/src/ddl2/activities/form.ts +153 -153
- package/src/ddl2/activities/groupby.ts +439 -439
- package/src/ddl2/activities/hipiepipeline.ts +114 -114
- package/src/ddl2/activities/limit.ts +49 -49
- package/src/ddl2/activities/logicalfile.ts +62 -62
- package/src/ddl2/activities/nullview.ts +12 -12
- package/src/ddl2/activities/project.ts +764 -764
- package/src/ddl2/activities/rest.ts +568 -568
- package/src/ddl2/activities/roxie.ts +490 -490
- package/src/ddl2/activities/sampledata.json +16264 -16264
- package/src/ddl2/activities/sort.ts +176 -176
- package/src/ddl2/activities/wuresult.ts +395 -395
- package/src/ddl2/dashboard.css +13 -13
- package/src/ddl2/dashboard.ts +330 -330
- package/src/ddl2/dashboardDockPanel.ts +123 -123
- package/src/ddl2/dashboardGrid.ts +202 -202
- package/src/ddl2/ddl.ts +410 -410
- package/src/ddl2/ddleditor.ts +60 -60
- package/src/ddl2/dsTable.ts +238 -238
- package/src/ddl2/dvTable.ts +31 -31
- package/src/ddl2/graphadapter.ts +297 -297
- package/src/ddl2/javascriptadapter.ts +354 -354
- package/src/ddl2/model/element.ts +398 -398
- package/src/ddl2/model/visualization.ts +351 -351
- package/src/ddl2/model/vizChartPanel.ts +149 -149
- package/src/ddl2/pipelinePanel.css +4 -4
- package/src/ddl2/pipelinePanel.ts +465 -465
- package/src/index.ts +26 -26
|
@@ -1,395 +1,395 @@
|
|
|
1
|
-
import { publish } from "@hpcc-js/common";
|
|
2
|
-
import { Result, Workunit, XSDXMLNode } from "@hpcc-js/comms";
|
|
3
|
-
import { DDL2 } from "@hpcc-js/ddl-shim";
|
|
4
|
-
import { AsyncOrderedQueue, debounce, hashSum } from "@hpcc-js/util";
|
|
5
|
-
import { ElementContainer } from "../model/element";
|
|
6
|
-
import { schemaRow2IField } from "./activity";
|
|
7
|
-
import { Datasource, DatasourceRef } from "./datasource";
|
|
8
|
-
|
|
9
|
-
export abstract class ESPResult extends Datasource {
|
|
10
|
-
protected _result: Result;
|
|
11
|
-
protected _schema: XSDXMLNode[] = [];
|
|
12
|
-
protected _meta: DDL2.IField[] = [];
|
|
13
|
-
protected _total: number;
|
|
14
|
-
private _data: ReadonlyArray<object> = [];
|
|
15
|
-
|
|
16
|
-
@publish(10, "number", "Number of samples")
|
|
17
|
-
samples: publish<this, number>;
|
|
18
|
-
@publish(100, "number", "Sample size")
|
|
19
|
-
sampleSize: publish<this, number>;
|
|
20
|
-
|
|
21
|
-
constructor(protected _ec: ElementContainer) {
|
|
22
|
-
super();
|
|
23
|
-
this
|
|
24
|
-
.samples(this._ec.samples())
|
|
25
|
-
.sampleSize(this._ec.sampleSize())
|
|
26
|
-
;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
hash(more: object = {}): string {
|
|
30
|
-
return hashSum({
|
|
31
|
-
samples: this.samples(),
|
|
32
|
-
sampleSize: this.sampleSize(),
|
|
33
|
-
...more
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
abstract _createResult(): Result;
|
|
38
|
-
|
|
39
|
-
_prevMetaHash: string;
|
|
40
|
-
refreshMetaPromise: Promise<void>;
|
|
41
|
-
refreshMeta(): Promise<void> {
|
|
42
|
-
if (this._prevMetaHash !== this.hash()) {
|
|
43
|
-
this._prevMetaHash = this.hash();
|
|
44
|
-
delete this.refreshMetaPromise;
|
|
45
|
-
}
|
|
46
|
-
if (!this.refreshMetaPromise) {
|
|
47
|
-
this.refreshMetaPromise = super.refreshMeta().then(() => {
|
|
48
|
-
this._result = this._createResult();
|
|
49
|
-
if (this._result) {
|
|
50
|
-
return this._result.refresh();
|
|
51
|
-
}
|
|
52
|
-
throw new Error("No valid result");
|
|
53
|
-
}).then(result => {
|
|
54
|
-
this._total = result.Total;
|
|
55
|
-
this._schema = result.fields();
|
|
56
|
-
this._meta = this._meta && this._meta.length ? this._meta : this._schema.map(schemaRow2IField);
|
|
57
|
-
}).catch(e => {
|
|
58
|
-
this._total = 0;
|
|
59
|
-
this._schema = [];
|
|
60
|
-
this._meta = [];
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return this.refreshMetaPromise;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
responseFields(): DDL2.IField[];
|
|
67
|
-
responseFields(_: DDL2.IField[]): this;
|
|
68
|
-
responseFields(_?: DDL2.IField[]): ReadonlyArray<DDL2.IField> | this {
|
|
69
|
-
if (!arguments.length) return this._meta;
|
|
70
|
-
this._meta = _;
|
|
71
|
-
this.refreshMeta();
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
|
|
76
|
-
return () => this.responseFields();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
exec(): Promise<void> {
|
|
80
|
-
return this._exec();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private _prevExecHash: string;
|
|
84
|
-
private _exec = debounce((): Promise<void> => {
|
|
85
|
-
if (this._prevExecHash !== this.hash()) {
|
|
86
|
-
this._prevExecHash = this.hash();
|
|
87
|
-
return super.exec().then(() => {
|
|
88
|
-
return this.sample();
|
|
89
|
-
}).then(response => {
|
|
90
|
-
this._data = this.fixInt64(response);
|
|
91
|
-
}).catch(e => {
|
|
92
|
-
this._data = [];
|
|
93
|
-
});
|
|
94
|
-
} else {
|
|
95
|
-
return Promise.resolve();
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
inData(): ReadonlyArray<object> {
|
|
100
|
-
return this._data;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
computeData(): ReadonlyArray<object> {
|
|
104
|
-
return this._data;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
total(): number {
|
|
108
|
-
return this._total;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ---
|
|
112
|
-
async fetch(from: number, count: number): Promise<any[]> {
|
|
113
|
-
if (count > this.samples() * this.sampleSize()) {
|
|
114
|
-
return this.sample();
|
|
115
|
-
}
|
|
116
|
-
return this._fetch(from, count);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private _fetchQ = new AsyncOrderedQueue();
|
|
120
|
-
private _fetch(from: number, count: number): Promise<any[]> {
|
|
121
|
-
return this._fetchQ.push(
|
|
122
|
-
this._result ? this._result
|
|
123
|
-
.fetchRows(from, count)
|
|
124
|
-
.catch(e => {
|
|
125
|
-
return [];
|
|
126
|
-
}) :
|
|
127
|
-
Promise.resolve([])
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private sample = debounce((samples: number = this.samples(), sampleSize: number = this.sampleSize()): Promise<any[]> => {
|
|
132
|
-
const pages: Array<Promise<any[]>> = [];
|
|
133
|
-
if (samples * sampleSize >= this.total()) {
|
|
134
|
-
pages.push(this._fetch(0, this.total()));
|
|
135
|
-
} else {
|
|
136
|
-
const lastPage = this.total() - sampleSize;
|
|
137
|
-
for (let i = 0; i < samples; ++i) {
|
|
138
|
-
pages.push(this._fetch(Math.floor(i * lastPage / samples), sampleSize));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return Promise.all(pages).then(responses => {
|
|
142
|
-
let retVal2: any[] = [];
|
|
143
|
-
for (const response of responses) {
|
|
144
|
-
retVal2 = retVal2.concat(response);
|
|
145
|
-
}
|
|
146
|
-
return retVal2;
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
ESPResult.prototype._class += " ESPResult";
|
|
151
|
-
|
|
152
|
-
export class WUResult extends ESPResult {
|
|
153
|
-
|
|
154
|
-
@publish(null, "widget", "Workunit")
|
|
155
|
-
_wu: WU;
|
|
156
|
-
wu(): WU;
|
|
157
|
-
wu(_: WU): this;
|
|
158
|
-
wu(_?: WU): this | WU {
|
|
159
|
-
if (!arguments.length) return this._wu;
|
|
160
|
-
this._wu = _;
|
|
161
|
-
this._wu.refreshMeta();
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
@publish("", "set", "Result Name", function (this: WUResult): string[] {
|
|
166
|
-
return this._wu !== undefined ? this._wu.resultNames() : [];
|
|
167
|
-
})
|
|
168
|
-
_resultName: string;
|
|
169
|
-
resultName(_: string): this;
|
|
170
|
-
resultName(): string;
|
|
171
|
-
resultName(_?: string): string | this {
|
|
172
|
-
if (_ === void 0) return this._resultName;
|
|
173
|
-
if (this._resultName !== _) {
|
|
174
|
-
this._resultName = _;
|
|
175
|
-
this.responseFields([]);
|
|
176
|
-
}
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
constructor(_ec: ElementContainer) {
|
|
181
|
-
super(_ec);
|
|
182
|
-
this._wu = new WU(this._ec);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
url(): string {
|
|
186
|
-
return this._wu.url();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
wuid(): string {
|
|
190
|
-
return this._wu.wuid();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
toDDL(): DDL2.IWUResult {
|
|
194
|
-
return {
|
|
195
|
-
type: "wuresult",
|
|
196
|
-
id: this.id(),
|
|
197
|
-
url: this._wu.url(),
|
|
198
|
-
wuid: this.wuid(),
|
|
199
|
-
outputs: {
|
|
200
|
-
[this.resultName()]: {
|
|
201
|
-
fields: this.responseFields()
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
fromDDL(ddl: DDL2.IWUResult, skipID = false): this {
|
|
208
|
-
if (ddl.outputs[this.resultName()]) {
|
|
209
|
-
return this.responseFields(ddl.outputs[this.resultName()].fields);
|
|
210
|
-
}
|
|
211
|
-
return this;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
static fromDDL(ec: ElementContainer, ddl: DDL2.IWUResult, wu: WU, resultName: string, skipID = false): WUResult {
|
|
215
|
-
return new WUResult(ec)
|
|
216
|
-
.wu(wu)
|
|
217
|
-
.resultName(resultName)
|
|
218
|
-
.fromDDL(ddl)
|
|
219
|
-
;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
_createResult(): Result {
|
|
223
|
-
if (this._wu.url() && this.wuid() && this.resultName()) {
|
|
224
|
-
return Result.attach({ baseUrl: this._wu.url(), hookSend: this._ec.hookSend() }, this.wuid(), this.resultName());
|
|
225
|
-
}
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
sourceHash(): string {
|
|
230
|
-
return super.hash({
|
|
231
|
-
wuid: this.wuid()
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
hash(more: object): string {
|
|
236
|
-
return super.hash({
|
|
237
|
-
ddl: this.toDDL()
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
label(): string {
|
|
242
|
-
return `${this.wuid()}\n${this.resultName()}`;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
WUResult.prototype._class += " WUResult";
|
|
246
|
-
|
|
247
|
-
export class WU extends Datasource {
|
|
248
|
-
@publish("", "string", "ESP Url (http://x.x.x.x:8010)")
|
|
249
|
-
_url: string;
|
|
250
|
-
url(): string;
|
|
251
|
-
url(_: string): this;
|
|
252
|
-
url(_?: string): this | string {
|
|
253
|
-
if (!arguments.length) return this._url;
|
|
254
|
-
this._url = _;
|
|
255
|
-
this.refreshMeta();
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
@publish("", "string", "Workunit ID")
|
|
260
|
-
_wuid: string;
|
|
261
|
-
wuid(): string;
|
|
262
|
-
wuid(_: string): this;
|
|
263
|
-
wuid(_?: string): this | string {
|
|
264
|
-
if (!arguments.length) return this._wuid;
|
|
265
|
-
this._wuid = _;
|
|
266
|
-
this.refreshMeta();
|
|
267
|
-
return this;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
protected _workunit: Workunit;
|
|
271
|
-
protected _outputs: { [id: string]: WUResult } = {};
|
|
272
|
-
|
|
273
|
-
constructor(private _ec: ElementContainer) {
|
|
274
|
-
super();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
toDDL(): DDL2.IWUResult {
|
|
278
|
-
const ddlOutputs: DDL2.OutputDict = {};
|
|
279
|
-
for (const resultName in this._outputs) {
|
|
280
|
-
ddlOutputs[resultName] = {
|
|
281
|
-
fields: this._outputs[resultName].responseFields()
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
type: "wuresult",
|
|
286
|
-
id: this.id(),
|
|
287
|
-
url: this.url(),
|
|
288
|
-
wuid: this.wuid(),
|
|
289
|
-
outputs: ddlOutputs
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
fromDDL(ddl: DDL2.IWUResult, skipID = false): this {
|
|
294
|
-
(skipID ? this : this.id(ddl.id))
|
|
295
|
-
.url(ddl.url)
|
|
296
|
-
.wuid(ddl.wuid)
|
|
297
|
-
;
|
|
298
|
-
const wuResults: { [id: string]: WUResult } = {};
|
|
299
|
-
for (const resultName in ddl.outputs) {
|
|
300
|
-
wuResults[resultName] = WUResult.fromDDL(this._ec, ddl, this, resultName);
|
|
301
|
-
}
|
|
302
|
-
this._outputs = wuResults;
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
static fromDDL(elementContainer: ElementContainer, ddl: DDL2.IWUResult, skipID = false): WU {
|
|
307
|
-
return new WU(elementContainer).fromDDL(ddl, skipID);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
hash(): string {
|
|
311
|
-
return hashSum({
|
|
312
|
-
url: this.url(),
|
|
313
|
-
wuid: this.wuid()
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
label(): string {
|
|
318
|
-
return this.wuid();
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
outputs(): WUResult[] {
|
|
322
|
-
const retVal = [];
|
|
323
|
-
for (const resultName in this._outputs) {
|
|
324
|
-
retVal.push(this._outputs[resultName]);
|
|
325
|
-
}
|
|
326
|
-
return retVal;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
outputDDL(): DDL2.OutputDict {
|
|
330
|
-
const retVal: DDL2.OutputDict = {};
|
|
331
|
-
for (const resultName in this._outputs) {
|
|
332
|
-
retVal[resultName] = {
|
|
333
|
-
fields: this._outputs[resultName].outFields() as DDL2.IField[]
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
return retVal;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
output(id: string): WUResult {
|
|
340
|
-
return this._outputs[id];
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
private _prevSourceHash: string;
|
|
344
|
-
private refreshMetaPromise: Promise<void>;
|
|
345
|
-
private _resultNames: string[] = [];
|
|
346
|
-
refreshMeta(): Promise<void> {
|
|
347
|
-
if (!this.url() || !this.wuid()) {
|
|
348
|
-
return Promise.resolve();
|
|
349
|
-
}
|
|
350
|
-
if (this._prevSourceHash !== this.hash()) {
|
|
351
|
-
this._prevSourceHash = this.hash();
|
|
352
|
-
delete this.refreshMetaPromise;
|
|
353
|
-
}
|
|
354
|
-
if (!this.refreshMetaPromise) {
|
|
355
|
-
this.refreshMetaPromise = super.refreshMeta().then(() => {
|
|
356
|
-
this._workunit = Workunit.attach({ baseUrl: this.url(), hookSend: this._ec.hookSend() }, this.wuid());
|
|
357
|
-
return this._workunit.fetchResults();
|
|
358
|
-
}).then(results => {
|
|
359
|
-
this._resultNames = results.map(r => r.Name);
|
|
360
|
-
}).catch(e => {
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
return this.refreshMetaPromise;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
resultNames(): string[] {
|
|
367
|
-
return this._resultNames;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
WU.prototype._class += " WU";
|
|
371
|
-
|
|
372
|
-
export class WUResultRef extends DatasourceRef {
|
|
373
|
-
|
|
374
|
-
datasource(): WUResult;
|
|
375
|
-
datasource(_: WUResult): this;
|
|
376
|
-
datasource(_?: WUResult): this | WUResult {
|
|
377
|
-
return super.datasource.apply(this, arguments);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
resultName(): string;
|
|
381
|
-
resultName(_: string): this;
|
|
382
|
-
resultName(_?: string): string | this {
|
|
383
|
-
if (!arguments.length) return this.datasource().resultName();
|
|
384
|
-
this.datasource().resultName(_);
|
|
385
|
-
return this;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
toDDL(): DDL2.IWUResultRef {
|
|
389
|
-
return {
|
|
390
|
-
id: this.datasource().wu().id(),
|
|
391
|
-
output: this.resultName()
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
WUResultRef.prototype._class += " WUResultRef";
|
|
1
|
+
import { publish } from "@hpcc-js/common";
|
|
2
|
+
import { Result, Workunit, XSDXMLNode } from "@hpcc-js/comms";
|
|
3
|
+
import { DDL2 } from "@hpcc-js/ddl-shim";
|
|
4
|
+
import { AsyncOrderedQueue, debounce, hashSum } from "@hpcc-js/util";
|
|
5
|
+
import { ElementContainer } from "../model/element";
|
|
6
|
+
import { schemaRow2IField } from "./activity";
|
|
7
|
+
import { Datasource, DatasourceRef } from "./datasource";
|
|
8
|
+
|
|
9
|
+
export abstract class ESPResult extends Datasource {
|
|
10
|
+
protected _result: Result;
|
|
11
|
+
protected _schema: XSDXMLNode[] = [];
|
|
12
|
+
protected _meta: DDL2.IField[] = [];
|
|
13
|
+
protected _total: number;
|
|
14
|
+
private _data: ReadonlyArray<object> = [];
|
|
15
|
+
|
|
16
|
+
@publish(10, "number", "Number of samples")
|
|
17
|
+
samples: publish<this, number>;
|
|
18
|
+
@publish(100, "number", "Sample size")
|
|
19
|
+
sampleSize: publish<this, number>;
|
|
20
|
+
|
|
21
|
+
constructor(protected _ec: ElementContainer) {
|
|
22
|
+
super();
|
|
23
|
+
this
|
|
24
|
+
.samples(this._ec.samples())
|
|
25
|
+
.sampleSize(this._ec.sampleSize())
|
|
26
|
+
;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
hash(more: object = {}): string {
|
|
30
|
+
return hashSum({
|
|
31
|
+
samples: this.samples(),
|
|
32
|
+
sampleSize: this.sampleSize(),
|
|
33
|
+
...more
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
abstract _createResult(): Result;
|
|
38
|
+
|
|
39
|
+
_prevMetaHash: string;
|
|
40
|
+
refreshMetaPromise: Promise<void>;
|
|
41
|
+
refreshMeta(): Promise<void> {
|
|
42
|
+
if (this._prevMetaHash !== this.hash()) {
|
|
43
|
+
this._prevMetaHash = this.hash();
|
|
44
|
+
delete this.refreshMetaPromise;
|
|
45
|
+
}
|
|
46
|
+
if (!this.refreshMetaPromise) {
|
|
47
|
+
this.refreshMetaPromise = super.refreshMeta().then(() => {
|
|
48
|
+
this._result = this._createResult();
|
|
49
|
+
if (this._result) {
|
|
50
|
+
return this._result.refresh();
|
|
51
|
+
}
|
|
52
|
+
throw new Error("No valid result");
|
|
53
|
+
}).then(result => {
|
|
54
|
+
this._total = result.Total;
|
|
55
|
+
this._schema = result.fields();
|
|
56
|
+
this._meta = this._meta && this._meta.length ? this._meta : this._schema.map(schemaRow2IField);
|
|
57
|
+
}).catch(e => {
|
|
58
|
+
this._total = 0;
|
|
59
|
+
this._schema = [];
|
|
60
|
+
this._meta = [];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return this.refreshMetaPromise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
responseFields(): DDL2.IField[];
|
|
67
|
+
responseFields(_: DDL2.IField[]): this;
|
|
68
|
+
responseFields(_?: DDL2.IField[]): ReadonlyArray<DDL2.IField> | this {
|
|
69
|
+
if (!arguments.length) return this._meta;
|
|
70
|
+
this._meta = _;
|
|
71
|
+
this.refreshMeta();
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
|
|
76
|
+
return () => this.responseFields();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exec(): Promise<void> {
|
|
80
|
+
return this._exec();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private _prevExecHash: string;
|
|
84
|
+
private _exec = debounce((): Promise<void> => {
|
|
85
|
+
if (this._prevExecHash !== this.hash()) {
|
|
86
|
+
this._prevExecHash = this.hash();
|
|
87
|
+
return super.exec().then(() => {
|
|
88
|
+
return this.sample();
|
|
89
|
+
}).then(response => {
|
|
90
|
+
this._data = this.fixInt64(response);
|
|
91
|
+
}).catch(e => {
|
|
92
|
+
this._data = [];
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
inData(): ReadonlyArray<object> {
|
|
100
|
+
return this._data;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
computeData(): ReadonlyArray<object> {
|
|
104
|
+
return this._data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
total(): number {
|
|
108
|
+
return this._total;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ---
|
|
112
|
+
async fetch(from: number, count: number): Promise<any[]> {
|
|
113
|
+
if (count > this.samples() * this.sampleSize()) {
|
|
114
|
+
return this.sample();
|
|
115
|
+
}
|
|
116
|
+
return this._fetch(from, count);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private _fetchQ = new AsyncOrderedQueue();
|
|
120
|
+
private _fetch(from: number, count: number): Promise<any[]> {
|
|
121
|
+
return this._fetchQ.push(
|
|
122
|
+
this._result ? this._result
|
|
123
|
+
.fetchRows(from, count)
|
|
124
|
+
.catch(e => {
|
|
125
|
+
return [];
|
|
126
|
+
}) :
|
|
127
|
+
Promise.resolve([])
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private sample = debounce((samples: number = this.samples(), sampleSize: number = this.sampleSize()): Promise<any[]> => {
|
|
132
|
+
const pages: Array<Promise<any[]>> = [];
|
|
133
|
+
if (samples * sampleSize >= this.total()) {
|
|
134
|
+
pages.push(this._fetch(0, this.total()));
|
|
135
|
+
} else {
|
|
136
|
+
const lastPage = this.total() - sampleSize;
|
|
137
|
+
for (let i = 0; i < samples; ++i) {
|
|
138
|
+
pages.push(this._fetch(Math.floor(i * lastPage / samples), sampleSize));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return Promise.all(pages).then(responses => {
|
|
142
|
+
let retVal2: any[] = [];
|
|
143
|
+
for (const response of responses) {
|
|
144
|
+
retVal2 = retVal2.concat(response);
|
|
145
|
+
}
|
|
146
|
+
return retVal2;
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
ESPResult.prototype._class += " ESPResult";
|
|
151
|
+
|
|
152
|
+
export class WUResult extends ESPResult {
|
|
153
|
+
|
|
154
|
+
@publish(null, "widget", "Workunit")
|
|
155
|
+
_wu: WU;
|
|
156
|
+
wu(): WU;
|
|
157
|
+
wu(_: WU): this;
|
|
158
|
+
wu(_?: WU): this | WU {
|
|
159
|
+
if (!arguments.length) return this._wu;
|
|
160
|
+
this._wu = _;
|
|
161
|
+
this._wu.refreshMeta();
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@publish("", "set", "Result Name", function (this: WUResult): string[] {
|
|
166
|
+
return this._wu !== undefined ? this._wu.resultNames() : [];
|
|
167
|
+
})
|
|
168
|
+
_resultName: string;
|
|
169
|
+
resultName(_: string): this;
|
|
170
|
+
resultName(): string;
|
|
171
|
+
resultName(_?: string): string | this {
|
|
172
|
+
if (_ === void 0) return this._resultName;
|
|
173
|
+
if (this._resultName !== _) {
|
|
174
|
+
this._resultName = _;
|
|
175
|
+
this.responseFields([]);
|
|
176
|
+
}
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
constructor(_ec: ElementContainer) {
|
|
181
|
+
super(_ec);
|
|
182
|
+
this._wu = new WU(this._ec);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
url(): string {
|
|
186
|
+
return this._wu.url();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
wuid(): string {
|
|
190
|
+
return this._wu.wuid();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
toDDL(): DDL2.IWUResult {
|
|
194
|
+
return {
|
|
195
|
+
type: "wuresult",
|
|
196
|
+
id: this.id(),
|
|
197
|
+
url: this._wu.url(),
|
|
198
|
+
wuid: this.wuid(),
|
|
199
|
+
outputs: {
|
|
200
|
+
[this.resultName()]: {
|
|
201
|
+
fields: this.responseFields()
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fromDDL(ddl: DDL2.IWUResult, skipID = false): this {
|
|
208
|
+
if (ddl.outputs[this.resultName()]) {
|
|
209
|
+
return this.responseFields(ddl.outputs[this.resultName()].fields);
|
|
210
|
+
}
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static fromDDL(ec: ElementContainer, ddl: DDL2.IWUResult, wu: WU, resultName: string, skipID = false): WUResult {
|
|
215
|
+
return new WUResult(ec)
|
|
216
|
+
.wu(wu)
|
|
217
|
+
.resultName(resultName)
|
|
218
|
+
.fromDDL(ddl)
|
|
219
|
+
;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_createResult(): Result {
|
|
223
|
+
if (this._wu.url() && this.wuid() && this.resultName()) {
|
|
224
|
+
return Result.attach({ baseUrl: this._wu.url(), hookSend: this._ec.hookSend() }, this.wuid(), this.resultName());
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
sourceHash(): string {
|
|
230
|
+
return super.hash({
|
|
231
|
+
wuid: this.wuid()
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
hash(more: object): string {
|
|
236
|
+
return super.hash({
|
|
237
|
+
ddl: this.toDDL()
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
label(): string {
|
|
242
|
+
return `${this.wuid()}\n${this.resultName()}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
WUResult.prototype._class += " WUResult";
|
|
246
|
+
|
|
247
|
+
export class WU extends Datasource {
|
|
248
|
+
@publish("", "string", "ESP Url (http://x.x.x.x:8010)")
|
|
249
|
+
_url: string;
|
|
250
|
+
url(): string;
|
|
251
|
+
url(_: string): this;
|
|
252
|
+
url(_?: string): this | string {
|
|
253
|
+
if (!arguments.length) return this._url;
|
|
254
|
+
this._url = _;
|
|
255
|
+
this.refreshMeta();
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@publish("", "string", "Workunit ID")
|
|
260
|
+
_wuid: string;
|
|
261
|
+
wuid(): string;
|
|
262
|
+
wuid(_: string): this;
|
|
263
|
+
wuid(_?: string): this | string {
|
|
264
|
+
if (!arguments.length) return this._wuid;
|
|
265
|
+
this._wuid = _;
|
|
266
|
+
this.refreshMeta();
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected _workunit: Workunit;
|
|
271
|
+
protected _outputs: { [id: string]: WUResult } = {};
|
|
272
|
+
|
|
273
|
+
constructor(private _ec: ElementContainer) {
|
|
274
|
+
super();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
toDDL(): DDL2.IWUResult {
|
|
278
|
+
const ddlOutputs: DDL2.OutputDict = {};
|
|
279
|
+
for (const resultName in this._outputs) {
|
|
280
|
+
ddlOutputs[resultName] = {
|
|
281
|
+
fields: this._outputs[resultName].responseFields()
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
type: "wuresult",
|
|
286
|
+
id: this.id(),
|
|
287
|
+
url: this.url(),
|
|
288
|
+
wuid: this.wuid(),
|
|
289
|
+
outputs: ddlOutputs
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
fromDDL(ddl: DDL2.IWUResult, skipID = false): this {
|
|
294
|
+
(skipID ? this : this.id(ddl.id))
|
|
295
|
+
.url(ddl.url)
|
|
296
|
+
.wuid(ddl.wuid)
|
|
297
|
+
;
|
|
298
|
+
const wuResults: { [id: string]: WUResult } = {};
|
|
299
|
+
for (const resultName in ddl.outputs) {
|
|
300
|
+
wuResults[resultName] = WUResult.fromDDL(this._ec, ddl, this, resultName);
|
|
301
|
+
}
|
|
302
|
+
this._outputs = wuResults;
|
|
303
|
+
return this;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static fromDDL(elementContainer: ElementContainer, ddl: DDL2.IWUResult, skipID = false): WU {
|
|
307
|
+
return new WU(elementContainer).fromDDL(ddl, skipID);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
hash(): string {
|
|
311
|
+
return hashSum({
|
|
312
|
+
url: this.url(),
|
|
313
|
+
wuid: this.wuid()
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
label(): string {
|
|
318
|
+
return this.wuid();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
outputs(): WUResult[] {
|
|
322
|
+
const retVal = [];
|
|
323
|
+
for (const resultName in this._outputs) {
|
|
324
|
+
retVal.push(this._outputs[resultName]);
|
|
325
|
+
}
|
|
326
|
+
return retVal;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
outputDDL(): DDL2.OutputDict {
|
|
330
|
+
const retVal: DDL2.OutputDict = {};
|
|
331
|
+
for (const resultName in this._outputs) {
|
|
332
|
+
retVal[resultName] = {
|
|
333
|
+
fields: this._outputs[resultName].outFields() as DDL2.IField[]
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
return retVal;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
output(id: string): WUResult {
|
|
340
|
+
return this._outputs[id];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private _prevSourceHash: string;
|
|
344
|
+
private refreshMetaPromise: Promise<void>;
|
|
345
|
+
private _resultNames: string[] = [];
|
|
346
|
+
refreshMeta(): Promise<void> {
|
|
347
|
+
if (!this.url() || !this.wuid()) {
|
|
348
|
+
return Promise.resolve();
|
|
349
|
+
}
|
|
350
|
+
if (this._prevSourceHash !== this.hash()) {
|
|
351
|
+
this._prevSourceHash = this.hash();
|
|
352
|
+
delete this.refreshMetaPromise;
|
|
353
|
+
}
|
|
354
|
+
if (!this.refreshMetaPromise) {
|
|
355
|
+
this.refreshMetaPromise = super.refreshMeta().then(() => {
|
|
356
|
+
this._workunit = Workunit.attach({ baseUrl: this.url(), hookSend: this._ec.hookSend() }, this.wuid());
|
|
357
|
+
return this._workunit.fetchResults();
|
|
358
|
+
}).then(results => {
|
|
359
|
+
this._resultNames = results.map(r => r.Name);
|
|
360
|
+
}).catch(e => {
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
return this.refreshMetaPromise;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
resultNames(): string[] {
|
|
367
|
+
return this._resultNames;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
WU.prototype._class += " WU";
|
|
371
|
+
|
|
372
|
+
export class WUResultRef extends DatasourceRef {
|
|
373
|
+
|
|
374
|
+
datasource(): WUResult;
|
|
375
|
+
datasource(_: WUResult): this;
|
|
376
|
+
datasource(_?: WUResult): this | WUResult {
|
|
377
|
+
return super.datasource.apply(this, arguments);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
resultName(): string;
|
|
381
|
+
resultName(_: string): this;
|
|
382
|
+
resultName(_?: string): string | this {
|
|
383
|
+
if (!arguments.length) return this.datasource().resultName();
|
|
384
|
+
this.datasource().resultName(_);
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
toDDL(): DDL2.IWUResultRef {
|
|
389
|
+
return {
|
|
390
|
+
id: this.datasource().wu().id(),
|
|
391
|
+
output: this.resultName()
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
WUResultRef.prototype._class += " WUResultRef";
|