@hpcc-js/marshaller 2.28.7 → 2.28.8

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 (55) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.es6.js +25 -13
  3. package/dist/index.es6.js.map +1 -1
  4. package/dist/index.js +25 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +2 -2
  7. package/dist/index.min.js.map +1 -1
  8. package/package.json +12 -12
  9. package/src/__package__.ts +3 -3
  10. package/src/dashy.css +239 -239
  11. package/src/dashy.ts +521 -521
  12. package/src/ddl1/DDLApi.ts +229 -229
  13. package/src/ddl1/FlyoutButton.ts +120 -120
  14. package/src/ddl1/Graph.ts +93 -93
  15. package/src/ddl1/HTML.ts +77 -77
  16. package/src/ddl1/HipieDDL.ts +2437 -2437
  17. package/src/ddl1/HipieDDLMixin.ts +380 -380
  18. package/src/ddl1/Tabbed.ts +91 -91
  19. package/src/ddl1/TargetMarshaller.ts +57 -57
  20. package/src/ddl2/PopupManager.ts +89 -89
  21. package/src/ddl2/activities/activity.ts +431 -431
  22. package/src/ddl2/activities/databomb.ts +237 -237
  23. package/src/ddl2/activities/datasource.ts +52 -52
  24. package/src/ddl2/activities/dspicker.ts +106 -106
  25. package/src/ddl2/activities/filter.ts +542 -542
  26. package/src/ddl2/activities/form.ts +153 -153
  27. package/src/ddl2/activities/groupby.ts +439 -439
  28. package/src/ddl2/activities/hipiepipeline.ts +114 -114
  29. package/src/ddl2/activities/limit.ts +49 -49
  30. package/src/ddl2/activities/logicalfile.ts +62 -62
  31. package/src/ddl2/activities/nullview.ts +12 -12
  32. package/src/ddl2/activities/project.ts +764 -764
  33. package/src/ddl2/activities/rest.ts +568 -568
  34. package/src/ddl2/activities/roxie.ts +490 -490
  35. package/src/ddl2/activities/sampledata.json +16264 -16264
  36. package/src/ddl2/activities/sort.ts +176 -176
  37. package/src/ddl2/activities/wuresult.ts +395 -395
  38. package/src/ddl2/dashboard.css +13 -13
  39. package/src/ddl2/dashboard.ts +330 -330
  40. package/src/ddl2/dashboardDockPanel.ts +123 -123
  41. package/src/ddl2/dashboardGrid.ts +202 -202
  42. package/src/ddl2/ddl.ts +410 -410
  43. package/src/ddl2/ddleditor.ts +60 -60
  44. package/src/ddl2/dsTable.ts +238 -238
  45. package/src/ddl2/dvTable.ts +31 -31
  46. package/src/ddl2/graphadapter.ts +297 -297
  47. package/src/ddl2/javascriptadapter.ts +354 -354
  48. package/src/ddl2/model/element.ts +398 -398
  49. package/src/ddl2/model/visualization.ts +351 -351
  50. package/src/ddl2/model/vizChartPanel.ts +149 -149
  51. package/src/ddl2/pipelinePanel.css +4 -4
  52. package/src/ddl2/pipelinePanel.ts +465 -465
  53. package/src/index.ts +26 -26
  54. package/types/__package__.d.ts +2 -2
  55. package/types-3.4/__package__.d.ts +2 -2
@@ -1,490 +1,490 @@
1
- import { publish } from "@hpcc-js/common";
2
- import { Query as CommsQuery } from "@hpcc-js/comms";
3
- import { DDL2 } from "@hpcc-js/ddl-shim";
4
- import { AsyncOrderedQueue, compare, hashSum } from "@hpcc-js/util";
5
- import { ElementContainer } from "../model/element";
6
- import { IActivityError, ReferencedFields } from "./activity";
7
- import { Datasource, DatasourceRef } from "./datasource";
8
- import { Param } from "./rest";
9
-
10
- function parseUrl(_: string): { url: string, querySet: string, queryID: string } {
11
- // "http://10.241.100.157:8002/WsEcl/submit/query/roxie/carmigjx_govbisgsavi.Ins4621360_Service_00000006/json",
12
- const parts = _.split("/WsEcl/submit/query/");
13
- if (parts.length < 2) throw new Error(`Invalid roxie URL: ${_}`);
14
- const urlParts = parts[0].split(":");
15
- if (urlParts.length < 3) throw new Error(`Invalid roxie URL: ${_}`);
16
- const roxieParts = parts[1].split("/");
17
- if (roxieParts.length < 2) throw new Error(`Invalid roxie URL: ${_}`);
18
- return {
19
- url: `${urlParts[0]}:${urlParts[1]}:${urlParts[2] === "18002" ? "18010" : "8010"}`,
20
- querySet: roxieParts[0],
21
- queryID: roxieParts[1]
22
- };
23
- }
24
-
25
- function isHipieRequest(requestField: string): boolean {
26
- return requestField.length >= 8 && requestField.indexOf("_changed") === requestField.length - 8;
27
- }
28
-
29
- function isHipieResponse(resultName: string): boolean {
30
- return (resultName.length >= 8 && resultName.indexOf("_changed") === resultName.length - 8) ||
31
- (["HIPIE_DDL", "HIPIE_DDLGLOBALS", "hipieversion"].indexOf(resultName) >= 0)
32
- ;
33
- }
34
-
35
- export class RoxieService extends Datasource {
36
- private _query: CommsQuery;
37
- private _requestFields: DDL2.IField[];
38
- private _responseFields: { [outputID: string]: DDL2.IField[] } = {};
39
- private _type: "roxie" | "hipie" = "roxie";
40
-
41
- @publish("", "string", "ESP Url (http://x.x.x.x:8002)")
42
- url: publish<this, string>;
43
- @publish("", "string", "Query Set")
44
- querySet: publish<this, string>;
45
- @publish("", "string", "Query ID")
46
- queryID: publish<this, string>;
47
- @publish(false, "boolean", "Ignore provided DDL request")
48
- ignoreHipieRequest: publish<this, boolean>;
49
- @publish(false, "boolean", "Ignore provided DDL response")
50
- ignoreHipieResponse: publish<this, boolean>;
51
-
52
- constructor(private _ec: ElementContainer) {
53
- super();
54
- }
55
-
56
- toDDL(): DDL2.IRoxieService | DDL2.IHipieService {
57
- return {
58
- type: this._type,
59
- id: this.id(),
60
- url: this.url(),
61
- querySet: this.querySet(),
62
- queryID: this.queryID(),
63
- inputs: this.requestFields(),
64
- outputs: this.outputDDL()
65
- };
66
- }
67
-
68
- fromDDL(ddl: DDL2.IRoxieService | DDL2.IHipieService, skipID = false): this {
69
- this._type = ddl.type;
70
- (skipID ? this : this.id(ddl.id))
71
- .url(ddl.url)
72
- .querySet(ddl.querySet)
73
- .queryID(ddl.queryID)
74
- ;
75
- if (ddl.inputs && ddl.inputs.length) {
76
- this.requestFields(ddl.inputs);
77
- }
78
- for (const key in ddl.outputs) {
79
- this.responseFields(key, ddl.outputs[key].fields);
80
- }
81
- return this;
82
- }
83
-
84
- static fromDDL(ec: ElementContainer, ddl: DDL2.IRoxieService | DDL2.IHipieService, skipID = false): RoxieService {
85
- return new RoxieService(ec).fromDDL(ddl, skipID);
86
- }
87
-
88
- hash(more: object = {}): string {
89
- return hashSum({
90
- url: this.url(),
91
- querySet: this.querySet(),
92
- queryId: this.queryID(),
93
- ignoreHipieRequest: this.ignoreHipieRequest(),
94
- ignoreHipieResponse: this.ignoreHipieResponse(),
95
- ...more
96
- });
97
- }
98
-
99
- label(): string {
100
- return this.queryID();
101
- }
102
-
103
- private _prevSourceHash: string;
104
- private refreshMetaPromise: Promise<void>;
105
- refreshMeta(): Promise<void> {
106
- if (this._prevSourceHash !== this.hash()) {
107
- this._prevSourceHash = this.hash();
108
- delete this.refreshMetaPromise;
109
- }
110
- if (!this.refreshMetaPromise) {
111
- const hasMeta = !!this._requestFields;
112
- this.refreshMetaPromise = new Promise<CommsQuery>((resolve, reject) => {
113
- const query = CommsQuery.attach({ baseUrl: this.url(), hookSend: this._ec.hookSend() }, this.querySet(), this.queryID());
114
- if (!hasMeta || this.ignoreHipieRequest() || this.ignoreHipieResponse()) {
115
- resolve(query.refresh());
116
- }
117
- resolve(query);
118
- }).then((query) => {
119
- this._query = query;
120
- if (!hasMeta || this.ignoreHipieRequest()) {
121
- this._requestFields = query.requestFields().filter(row => this._type === "roxie" || !isHipieRequest(row.id));
122
- }
123
- if (!hasMeta || this.ignoreHipieResponse()) {
124
- query.resultNames().filter(resultName => this._type === "roxie" || !isHipieResponse(resultName)).forEach(resultName => {
125
- this._responseFields[resultName] = query.resultFields(resultName);
126
- });
127
- }
128
- });
129
- }
130
- return this.refreshMetaPromise;
131
- }
132
-
133
- requestFields(): DDL2.IField[];
134
- requestFields(_: DDL2.IField[]): this;
135
- requestFields(_?: DDL2.IField[]): DDL2.IField[] | this {
136
- if (!arguments.length) return this._requestFields || [];
137
- this._requestFields = _;
138
- return this;
139
- }
140
-
141
- responseFields(resultName: string): DDL2.IField[];
142
- responseFields(resultName: string, _: DDL2.IField[]): this;
143
- responseFields(resultName: string, _?: DDL2.IField[]): DDL2.IField[] | this {
144
- if (arguments.length === 1) return this._responseFields[resultName] || [];
145
- this._responseFields[resultName] = _;
146
- return this;
147
- }
148
-
149
- private _prevRequestHash;
150
- private _prevPromise;
151
- private _submitQ = new AsyncOrderedQueue();
152
- submit(request: { [key: string]: any }): Promise<{ [key: string]: any }> {
153
- const requestHash = hashSum(request);
154
- if (!this._prevPromise || this._prevRequestHash !== requestHash) {
155
- this._prevRequestHash = requestHash;
156
- this._prevPromise = this._submitQ.push(this._query.submit(request));
157
- }
158
- return this._prevPromise;
159
- }
160
-
161
- resultNames(): string[] {
162
- const retVal: string[] = [];
163
- for (const key in this._responseFields) {
164
- retVal.push(key);
165
- }
166
- return retVal;
167
- }
168
-
169
- outputDDL(): DDL2.OutputDict {
170
- const retVal: DDL2.OutputDict = {};
171
- this.resultNames().forEach(resultName => {
172
- retVal[resultName] = {
173
- fields: this._responseFields[resultName]
174
- };
175
- });
176
- return retVal;
177
- }
178
- }
179
- RoxieService.prototype._class += " RoxieService";
180
-
181
- export class RoxieResult extends Datasource {
182
-
183
- @publish(null, "widget", "Roxie service")
184
- _service: RoxieService = new RoxieService(this._ec);
185
- service(): RoxieService;
186
- service(_: RoxieService): this;
187
- service(_?: RoxieService): this | RoxieService {
188
- if (!arguments.length) return this._service;
189
- this._service = _;
190
- this._service.refreshMeta();
191
- return this;
192
- }
193
-
194
- @publish("", "set", "Result Name", function (this: RoxieResult): string[] {
195
- return this._service !== undefined ? this._service.resultNames() : [];
196
- })
197
- resultName: publish<this, string>;
198
-
199
- constructor(private _ec: ElementContainer) {
200
- super();
201
- }
202
-
203
- toDDL(): DDL2.IRoxieService | DDL2.IHipieService {
204
- return this.service().toDDL();
205
- }
206
-
207
- fromDDL(ddl: DDL2.IRoxieService): this {
208
- this.service().fromDDL(ddl);
209
- return this;
210
- }
211
-
212
- static fromDDL(ec: ElementContainer, rs: RoxieService, resultName: string): RoxieResult {
213
- return new RoxieResult(ec)
214
- .id(`${rs.id()}_${resultName}`)
215
- .service(rs)
216
- .resultName(resultName)
217
- ;
218
- }
219
-
220
- serviceID(): string {
221
- return `${this.service().url()}/${this.service().querySet()}/${this.service().queryID()}`;
222
- }
223
-
224
- sourceHash(): string {
225
- return this.service().hash();
226
- }
227
-
228
- requestFields(): DDL2.IField[] {
229
- return this.service().requestFields();
230
- }
231
-
232
- responseFields(): DDL2.IField[];
233
- responseFields(_: DDL2.IField[]): this;
234
- responseFields(_?: DDL2.IField[]): this | DDL2.IField[] {
235
- if (!arguments.length) return this.service().responseFields(this.resultName());
236
- this.service().responseFields(this.resultName(), _);
237
- return this;
238
- }
239
-
240
- hash(more: object = {}): string {
241
- return hashSum({
242
- source: this.sourceHash(),
243
- resultName: this.resultName(),
244
- ...more
245
- });
246
- }
247
-
248
- label(): string {
249
- return `${this.service().label()}\n${this.resultName()}`;
250
- }
251
-
252
- computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
253
- return () => this.service().responseFields(this.resultName());
254
- }
255
-
256
- refreshMeta(): Promise<void> {
257
- return this.service().refreshMeta();
258
- }
259
-
260
- submit(request: { [key: string]: any }): Promise<{ [key: string]: any }> {
261
- return this.service().submit(request);
262
- }
263
- }
264
- RoxieResult.prototype._class += " RoxieResult";
265
-
266
- export class RoxieResultRef extends DatasourceRef {
267
-
268
- serviceID(): string {
269
- return this.datasource().serviceID();
270
- }
271
-
272
- private _data: ReadonlyArray<object> = [];
273
-
274
- datasource(): RoxieResult;
275
- datasource(_: RoxieResult): this;
276
- datasource(_?: RoxieResult): this | RoxieResult {
277
- return super.datasource.apply(this, arguments);
278
- }
279
-
280
- url(): string {
281
- return this.datasource().service().url();
282
- }
283
-
284
- querySet(): string {
285
- return this.datasource().service().querySet();
286
- }
287
-
288
- queryID(): string {
289
- return this.datasource().service().queryID();
290
- }
291
-
292
- resultName(): string {
293
- return this.datasource().resultName();
294
- }
295
-
296
- @publish([], "propertyArray", "Request Fields")
297
- _request: Param[];
298
- request(): Param[];
299
- request(_: Param[]): this;
300
- request(_?: Param[]): Param[] | this {
301
- if (!arguments.length) return this._request;
302
- this._request = _;
303
- return this;
304
- }
305
-
306
- validate(): IActivityError[] {
307
- let retVal: IActivityError[] = [];
308
- for (const filter of this.validParams()) {
309
- retVal = retVal.concat(filter.validate("request"));
310
- }
311
- return retVal;
312
- }
313
-
314
- constructor(private _ec: ElementContainer) {
315
- super();
316
- }
317
-
318
- toDDL(): DDL2.IRoxieServiceRef {
319
- return {
320
- id: this.datasource().service().id(),
321
- output: this.resultName(),
322
- request: this.validParams().map((vp): DDL2.IRequestField => {
323
- return {
324
- source: vp.source(),
325
- remoteFieldID: vp.remoteField(),
326
- localFieldID: vp.localField(),
327
- value: vp.value()
328
- };
329
- })
330
- };
331
- }
332
-
333
- sourceHash(): string {
334
- return this.datasource().hash();
335
- }
336
-
337
- requestFieldRefs(): DDL2.IRequestField[];
338
- requestFieldRefs(_: DDL2.IRequestField[]): this;
339
- requestFieldRefs(_?: DDL2.IRequestField[]): DDL2.IRequestField[] | this {
340
- if (!arguments.length) return this.validParams().map(param => param.toDDL());
341
- this.request(_.map(fc => Param.fromDDL(this._ec, fc)));
342
- return this;
343
- }
344
-
345
- requestFields(): DDL2.IField[] {
346
- return this.datasource().requestFields();
347
- }
348
-
349
- responseFields(): DDL2.IField[] {
350
- return this.datasource().responseFields();
351
- }
352
-
353
- hash(): string {
354
- return this.datasource().hash({
355
- resultName: this.resultName(),
356
- params: this.request().map(param => param.hash()),
357
- request: this.formatRequest()
358
- });
359
- }
360
-
361
- label(): string {
362
- return `${this.datasource().label()}\n${this.datasource().resultName()}`;
363
- }
364
-
365
- elementIDs() {
366
- return this._ec.elementIDs();
367
- }
368
-
369
- element(source) {
370
- return this._ec.element(source);
371
- }
372
-
373
- referencedFields(refs: ReferencedFields): void {
374
- super.referencedFields(refs);
375
- const localFieldIDs: string[] = [];
376
- for (const param of this.validParams()) {
377
- localFieldIDs.push(param.localField());
378
- const filterSource = param.sourceViz().hipiePipeline();
379
- if (!refs.inputs[this.id()]) {
380
- refs.inputs[this.id()] = [];
381
- }
382
- refs.inputs[this.id()].push(param.localField());
383
- filterSource.resolveFields(refs, [param.remoteField()]);
384
- }
385
- super.resolveFields(refs, localFieldIDs);
386
- }
387
-
388
- validParams() {
389
- return this.request().filter(param => param.exists());
390
- }
391
-
392
- refreshMeta(): Promise<void> {
393
- return this.datasource().refreshMeta().then(() => {
394
- const oldParams = this.request();
395
- const diffs = compare(oldParams.map(p => p.localField()), this.datasource().requestFields().map(ff => ff.id));
396
- const newParams = oldParams.filter(op => diffs.update.indexOf(op.localField()) >= 0);
397
- this.request(newParams.concat(diffs.enter.map(label => new Param(this._ec).localField(label))));
398
- });
399
- }
400
-
401
- updatedBy(): string[] {
402
- return this.validParams().map(param => param.source());
403
- }
404
-
405
- computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
406
- return () => this.datasource().responseFields();
407
- }
408
-
409
- formatRequest(): { [key: string]: any } {
410
- const request: { [key: string]: any } = {};
411
- let hasRequest = false;
412
- const fields = this.datasource().requestFields();
413
- for (const param of this.validParams()) {
414
- const _value = param.calcValue();
415
- const field = fields.filter(row => row.id === param.localField())[0];
416
- let value;
417
- if (field.type === "set") {
418
- value = {
419
- Item: _value
420
- };
421
- } else {
422
- value = _value[0];
423
- }
424
- if (value !== undefined) {
425
- request[param.localField()] = value;
426
- }
427
- hasRequest = true;
428
- }
429
- if (!hasRequest) {
430
- request.refresh = true;
431
- }
432
- return request;
433
- }
434
-
435
- private _prevRequestHash;
436
- private _prevRequestPromise;
437
- exec(): Promise<void> {
438
- return super.exec().then(() => {
439
- const request = this.formatRequest();
440
- const requestHash = hashSum({ hash: this.hash(), request });
441
- if (this._prevRequestHash !== requestHash) {
442
- this._prevRequestHash = requestHash;
443
- this._prevRequestPromise = this.datasource().submit(request).then((response: { [key: string]: any }) => {
444
- const resultName = this.datasource().resultName();
445
- let result = response[resultName];
446
- if (!result) {
447
- // See: https://track.hpccsystems.com/browse/HPCC-21176 ---
448
- // "Result 1" => "result_1"
449
- result = response[resultName.toLowerCase().replace(/ /g, "_")];
450
- }
451
- return this.fixInt64(result);
452
- });
453
- }
454
- return this._prevRequestPromise;
455
- }).then(data => {
456
- this._data = data;
457
- });
458
- }
459
-
460
- inData(): ReadonlyArray<object> {
461
- return this._data;
462
- }
463
-
464
- computeData(): ReadonlyArray<object> {
465
- return this._data;
466
- }
467
- }
468
- RoxieResultRef.prototype._class += " RoxieResultRef";
469
-
470
- export class HipieResultRef extends RoxieResultRef {
471
-
472
- fullUrl(_: string): this {
473
- const info = parseUrl(_);
474
- this.datasource().service().url(info.url);
475
- this.datasource().service().querySet(info.querySet);
476
- this.datasource().service().queryID(info.queryID);
477
- return this;
478
- }
479
-
480
- formatRequest(): { [key: string]: any } {
481
- const _request = super.formatRequest();
482
- const request: { [key: string]: any } = {};
483
- for (const key in _request) {
484
- request[key] = _request[key];
485
- request[`${key}_changed`] = true;
486
- }
487
- return request;
488
- }
489
- }
490
- HipieResultRef.prototype._class += " HipieResultRef";
1
+ import { publish } from "@hpcc-js/common";
2
+ import { Query as CommsQuery } from "@hpcc-js/comms";
3
+ import { DDL2 } from "@hpcc-js/ddl-shim";
4
+ import { AsyncOrderedQueue, compare, hashSum } from "@hpcc-js/util";
5
+ import { ElementContainer } from "../model/element";
6
+ import { IActivityError, ReferencedFields } from "./activity";
7
+ import { Datasource, DatasourceRef } from "./datasource";
8
+ import { Param } from "./rest";
9
+
10
+ function parseUrl(_: string): { url: string, querySet: string, queryID: string } {
11
+ // "http://10.241.100.157:8002/WsEcl/submit/query/roxie/carmigjx_govbisgsavi.Ins4621360_Service_00000006/json",
12
+ const parts = _.split("/WsEcl/submit/query/");
13
+ if (parts.length < 2) throw new Error(`Invalid roxie URL: ${_}`);
14
+ const urlParts = parts[0].split(":");
15
+ if (urlParts.length < 3) throw new Error(`Invalid roxie URL: ${_}`);
16
+ const roxieParts = parts[1].split("/");
17
+ if (roxieParts.length < 2) throw new Error(`Invalid roxie URL: ${_}`);
18
+ return {
19
+ url: `${urlParts[0]}:${urlParts[1]}:${urlParts[2] === "18002" ? "18010" : "8010"}`,
20
+ querySet: roxieParts[0],
21
+ queryID: roxieParts[1]
22
+ };
23
+ }
24
+
25
+ function isHipieRequest(requestField: string): boolean {
26
+ return requestField.length >= 8 && requestField.indexOf("_changed") === requestField.length - 8;
27
+ }
28
+
29
+ function isHipieResponse(resultName: string): boolean {
30
+ return (resultName.length >= 8 && resultName.indexOf("_changed") === resultName.length - 8) ||
31
+ (["HIPIE_DDL", "HIPIE_DDLGLOBALS", "hipieversion"].indexOf(resultName) >= 0)
32
+ ;
33
+ }
34
+
35
+ export class RoxieService extends Datasource {
36
+ private _query: CommsQuery;
37
+ private _requestFields: DDL2.IField[];
38
+ private _responseFields: { [outputID: string]: DDL2.IField[] } = {};
39
+ private _type: "roxie" | "hipie" = "roxie";
40
+
41
+ @publish("", "string", "ESP Url (http://x.x.x.x:8002)")
42
+ url: publish<this, string>;
43
+ @publish("", "string", "Query Set")
44
+ querySet: publish<this, string>;
45
+ @publish("", "string", "Query ID")
46
+ queryID: publish<this, string>;
47
+ @publish(false, "boolean", "Ignore provided DDL request")
48
+ ignoreHipieRequest: publish<this, boolean>;
49
+ @publish(false, "boolean", "Ignore provided DDL response")
50
+ ignoreHipieResponse: publish<this, boolean>;
51
+
52
+ constructor(private _ec: ElementContainer) {
53
+ super();
54
+ }
55
+
56
+ toDDL(): DDL2.IRoxieService | DDL2.IHipieService {
57
+ return {
58
+ type: this._type,
59
+ id: this.id(),
60
+ url: this.url(),
61
+ querySet: this.querySet(),
62
+ queryID: this.queryID(),
63
+ inputs: this.requestFields(),
64
+ outputs: this.outputDDL()
65
+ };
66
+ }
67
+
68
+ fromDDL(ddl: DDL2.IRoxieService | DDL2.IHipieService, skipID = false): this {
69
+ this._type = ddl.type;
70
+ (skipID ? this : this.id(ddl.id))
71
+ .url(ddl.url)
72
+ .querySet(ddl.querySet)
73
+ .queryID(ddl.queryID)
74
+ ;
75
+ if (ddl.inputs && ddl.inputs.length) {
76
+ this.requestFields(ddl.inputs);
77
+ }
78
+ for (const key in ddl.outputs) {
79
+ this.responseFields(key, ddl.outputs[key].fields);
80
+ }
81
+ return this;
82
+ }
83
+
84
+ static fromDDL(ec: ElementContainer, ddl: DDL2.IRoxieService | DDL2.IHipieService, skipID = false): RoxieService {
85
+ return new RoxieService(ec).fromDDL(ddl, skipID);
86
+ }
87
+
88
+ hash(more: object = {}): string {
89
+ return hashSum({
90
+ url: this.url(),
91
+ querySet: this.querySet(),
92
+ queryId: this.queryID(),
93
+ ignoreHipieRequest: this.ignoreHipieRequest(),
94
+ ignoreHipieResponse: this.ignoreHipieResponse(),
95
+ ...more
96
+ });
97
+ }
98
+
99
+ label(): string {
100
+ return this.queryID();
101
+ }
102
+
103
+ private _prevSourceHash: string;
104
+ private refreshMetaPromise: Promise<void>;
105
+ refreshMeta(): Promise<void> {
106
+ if (this._prevSourceHash !== this.hash()) {
107
+ this._prevSourceHash = this.hash();
108
+ delete this.refreshMetaPromise;
109
+ }
110
+ if (!this.refreshMetaPromise) {
111
+ const hasMeta = !!this._requestFields;
112
+ this.refreshMetaPromise = new Promise<CommsQuery>((resolve, reject) => {
113
+ const query = CommsQuery.attach({ baseUrl: this.url(), hookSend: this._ec.hookSend() }, this.querySet(), this.queryID());
114
+ if (!hasMeta || this.ignoreHipieRequest() || this.ignoreHipieResponse()) {
115
+ resolve(query.refresh());
116
+ }
117
+ resolve(query);
118
+ }).then((query) => {
119
+ this._query = query;
120
+ if (!hasMeta || this.ignoreHipieRequest()) {
121
+ this._requestFields = query.requestFields().filter(row => this._type === "roxie" || !isHipieRequest(row.id));
122
+ }
123
+ if (!hasMeta || this.ignoreHipieResponse()) {
124
+ query.resultNames().filter(resultName => this._type === "roxie" || !isHipieResponse(resultName)).forEach(resultName => {
125
+ this._responseFields[resultName] = query.resultFields(resultName);
126
+ });
127
+ }
128
+ });
129
+ }
130
+ return this.refreshMetaPromise;
131
+ }
132
+
133
+ requestFields(): DDL2.IField[];
134
+ requestFields(_: DDL2.IField[]): this;
135
+ requestFields(_?: DDL2.IField[]): DDL2.IField[] | this {
136
+ if (!arguments.length) return this._requestFields || [];
137
+ this._requestFields = _;
138
+ return this;
139
+ }
140
+
141
+ responseFields(resultName: string): DDL2.IField[];
142
+ responseFields(resultName: string, _: DDL2.IField[]): this;
143
+ responseFields(resultName: string, _?: DDL2.IField[]): DDL2.IField[] | this {
144
+ if (arguments.length === 1) return this._responseFields[resultName] || [];
145
+ this._responseFields[resultName] = _;
146
+ return this;
147
+ }
148
+
149
+ private _prevRequestHash;
150
+ private _prevPromise;
151
+ private _submitQ = new AsyncOrderedQueue();
152
+ submit(request: { [key: string]: any }): Promise<{ [key: string]: any }> {
153
+ const requestHash = hashSum(request);
154
+ if (!this._prevPromise || this._prevRequestHash !== requestHash) {
155
+ this._prevRequestHash = requestHash;
156
+ this._prevPromise = this._submitQ.push(this._query.submit(request));
157
+ }
158
+ return this._prevPromise;
159
+ }
160
+
161
+ resultNames(): string[] {
162
+ const retVal: string[] = [];
163
+ for (const key in this._responseFields) {
164
+ retVal.push(key);
165
+ }
166
+ return retVal;
167
+ }
168
+
169
+ outputDDL(): DDL2.OutputDict {
170
+ const retVal: DDL2.OutputDict = {};
171
+ this.resultNames().forEach(resultName => {
172
+ retVal[resultName] = {
173
+ fields: this._responseFields[resultName]
174
+ };
175
+ });
176
+ return retVal;
177
+ }
178
+ }
179
+ RoxieService.prototype._class += " RoxieService";
180
+
181
+ export class RoxieResult extends Datasource {
182
+
183
+ @publish(null, "widget", "Roxie service")
184
+ _service: RoxieService = new RoxieService(this._ec);
185
+ service(): RoxieService;
186
+ service(_: RoxieService): this;
187
+ service(_?: RoxieService): this | RoxieService {
188
+ if (!arguments.length) return this._service;
189
+ this._service = _;
190
+ this._service.refreshMeta();
191
+ return this;
192
+ }
193
+
194
+ @publish("", "set", "Result Name", function (this: RoxieResult): string[] {
195
+ return this._service !== undefined ? this._service.resultNames() : [];
196
+ })
197
+ resultName: publish<this, string>;
198
+
199
+ constructor(private _ec: ElementContainer) {
200
+ super();
201
+ }
202
+
203
+ toDDL(): DDL2.IRoxieService | DDL2.IHipieService {
204
+ return this.service().toDDL();
205
+ }
206
+
207
+ fromDDL(ddl: DDL2.IRoxieService): this {
208
+ this.service().fromDDL(ddl);
209
+ return this;
210
+ }
211
+
212
+ static fromDDL(ec: ElementContainer, rs: RoxieService, resultName: string): RoxieResult {
213
+ return new RoxieResult(ec)
214
+ .id(`${rs.id()}_${resultName}`)
215
+ .service(rs)
216
+ .resultName(resultName)
217
+ ;
218
+ }
219
+
220
+ serviceID(): string {
221
+ return `${this.service().url()}/${this.service().querySet()}/${this.service().queryID()}`;
222
+ }
223
+
224
+ sourceHash(): string {
225
+ return this.service().hash();
226
+ }
227
+
228
+ requestFields(): DDL2.IField[] {
229
+ return this.service().requestFields();
230
+ }
231
+
232
+ responseFields(): DDL2.IField[];
233
+ responseFields(_: DDL2.IField[]): this;
234
+ responseFields(_?: DDL2.IField[]): this | DDL2.IField[] {
235
+ if (!arguments.length) return this.service().responseFields(this.resultName());
236
+ this.service().responseFields(this.resultName(), _);
237
+ return this;
238
+ }
239
+
240
+ hash(more: object = {}): string {
241
+ return hashSum({
242
+ source: this.sourceHash(),
243
+ resultName: this.resultName(),
244
+ ...more
245
+ });
246
+ }
247
+
248
+ label(): string {
249
+ return `${this.service().label()}\n${this.resultName()}`;
250
+ }
251
+
252
+ computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
253
+ return () => this.service().responseFields(this.resultName());
254
+ }
255
+
256
+ refreshMeta(): Promise<void> {
257
+ return this.service().refreshMeta();
258
+ }
259
+
260
+ submit(request: { [key: string]: any }): Promise<{ [key: string]: any }> {
261
+ return this.service().submit(request);
262
+ }
263
+ }
264
+ RoxieResult.prototype._class += " RoxieResult";
265
+
266
+ export class RoxieResultRef extends DatasourceRef {
267
+
268
+ serviceID(): string {
269
+ return this.datasource().serviceID();
270
+ }
271
+
272
+ private _data: ReadonlyArray<object> = [];
273
+
274
+ datasource(): RoxieResult;
275
+ datasource(_: RoxieResult): this;
276
+ datasource(_?: RoxieResult): this | RoxieResult {
277
+ return super.datasource.apply(this, arguments);
278
+ }
279
+
280
+ url(): string {
281
+ return this.datasource().service().url();
282
+ }
283
+
284
+ querySet(): string {
285
+ return this.datasource().service().querySet();
286
+ }
287
+
288
+ queryID(): string {
289
+ return this.datasource().service().queryID();
290
+ }
291
+
292
+ resultName(): string {
293
+ return this.datasource().resultName();
294
+ }
295
+
296
+ @publish([], "propertyArray", "Request Fields")
297
+ _request: Param[];
298
+ request(): Param[];
299
+ request(_: Param[]): this;
300
+ request(_?: Param[]): Param[] | this {
301
+ if (!arguments.length) return this._request;
302
+ this._request = _;
303
+ return this;
304
+ }
305
+
306
+ validate(): IActivityError[] {
307
+ let retVal: IActivityError[] = [];
308
+ for (const filter of this.validParams()) {
309
+ retVal = retVal.concat(filter.validate("request"));
310
+ }
311
+ return retVal;
312
+ }
313
+
314
+ constructor(private _ec: ElementContainer) {
315
+ super();
316
+ }
317
+
318
+ toDDL(): DDL2.IRoxieServiceRef {
319
+ return {
320
+ id: this.datasource().service().id(),
321
+ output: this.resultName(),
322
+ request: this.validParams().map((vp): DDL2.IRequestField => {
323
+ return {
324
+ source: vp.source(),
325
+ remoteFieldID: vp.remoteField(),
326
+ localFieldID: vp.localField(),
327
+ value: vp.value()
328
+ };
329
+ })
330
+ };
331
+ }
332
+
333
+ sourceHash(): string {
334
+ return this.datasource().hash();
335
+ }
336
+
337
+ requestFieldRefs(): DDL2.IRequestField[];
338
+ requestFieldRefs(_: DDL2.IRequestField[]): this;
339
+ requestFieldRefs(_?: DDL2.IRequestField[]): DDL2.IRequestField[] | this {
340
+ if (!arguments.length) return this.validParams().map(param => param.toDDL());
341
+ this.request(_.map(fc => Param.fromDDL(this._ec, fc)));
342
+ return this;
343
+ }
344
+
345
+ requestFields(): DDL2.IField[] {
346
+ return this.datasource().requestFields();
347
+ }
348
+
349
+ responseFields(): DDL2.IField[] {
350
+ return this.datasource().responseFields();
351
+ }
352
+
353
+ hash(): string {
354
+ return this.datasource().hash({
355
+ resultName: this.resultName(),
356
+ params: this.request().map(param => param.hash()),
357
+ request: this.formatRequest()
358
+ });
359
+ }
360
+
361
+ label(): string {
362
+ return `${this.datasource().label()}\n${this.datasource().resultName()}`;
363
+ }
364
+
365
+ elementIDs() {
366
+ return this._ec.elementIDs();
367
+ }
368
+
369
+ element(source) {
370
+ return this._ec.element(source);
371
+ }
372
+
373
+ referencedFields(refs: ReferencedFields): void {
374
+ super.referencedFields(refs);
375
+ const localFieldIDs: string[] = [];
376
+ for (const param of this.validParams()) {
377
+ localFieldIDs.push(param.localField());
378
+ const filterSource = param.sourceViz().hipiePipeline();
379
+ if (!refs.inputs[this.id()]) {
380
+ refs.inputs[this.id()] = [];
381
+ }
382
+ refs.inputs[this.id()].push(param.localField());
383
+ filterSource.resolveFields(refs, [param.remoteField()]);
384
+ }
385
+ super.resolveFields(refs, localFieldIDs);
386
+ }
387
+
388
+ validParams() {
389
+ return this.request().filter(param => param.exists());
390
+ }
391
+
392
+ refreshMeta(): Promise<void> {
393
+ return this.datasource().refreshMeta().then(() => {
394
+ const oldParams = this.request();
395
+ const diffs = compare(oldParams.map(p => p.localField()), this.datasource().requestFields().map(ff => ff.id));
396
+ const newParams = oldParams.filter(op => diffs.update.indexOf(op.localField()) >= 0);
397
+ this.request(newParams.concat(diffs.enter.map(label => new Param(this._ec).localField(label))));
398
+ });
399
+ }
400
+
401
+ updatedBy(): string[] {
402
+ return this.validParams().map(param => param.source());
403
+ }
404
+
405
+ computeFields(inFields: ReadonlyArray<DDL2.IField>): () => ReadonlyArray<DDL2.IField> {
406
+ return () => this.datasource().responseFields();
407
+ }
408
+
409
+ formatRequest(): { [key: string]: any } {
410
+ const request: { [key: string]: any } = {};
411
+ let hasRequest = false;
412
+ const fields = this.datasource().requestFields();
413
+ for (const param of this.validParams()) {
414
+ const _value = param.calcValue();
415
+ const field = fields.filter(row => row.id === param.localField())[0];
416
+ let value;
417
+ if (field.type === "set") {
418
+ value = {
419
+ Item: _value
420
+ };
421
+ } else {
422
+ value = _value[0];
423
+ }
424
+ if (value !== undefined) {
425
+ request[param.localField()] = value;
426
+ }
427
+ hasRequest = true;
428
+ }
429
+ if (!hasRequest) {
430
+ request.refresh = true;
431
+ }
432
+ return request;
433
+ }
434
+
435
+ private _prevRequestHash;
436
+ private _prevRequestPromise;
437
+ exec(): Promise<void> {
438
+ return super.exec().then(() => {
439
+ const request = this.formatRequest();
440
+ const requestHash = hashSum({ hash: this.hash(), request });
441
+ if (this._prevRequestHash !== requestHash) {
442
+ this._prevRequestHash = requestHash;
443
+ this._prevRequestPromise = this.datasource().submit(request).then((response: { [key: string]: any }) => {
444
+ const resultName = this.datasource().resultName();
445
+ let result = response[resultName];
446
+ if (!result) {
447
+ // See: https://track.hpccsystems.com/browse/HPCC-21176 ---
448
+ // "Result 1" => "result_1"
449
+ result = response[resultName.toLowerCase().replace(/ /g, "_")];
450
+ }
451
+ return this.fixInt64(result);
452
+ });
453
+ }
454
+ return this._prevRequestPromise;
455
+ }).then(data => {
456
+ this._data = data;
457
+ });
458
+ }
459
+
460
+ inData(): ReadonlyArray<object> {
461
+ return this._data;
462
+ }
463
+
464
+ computeData(): ReadonlyArray<object> {
465
+ return this._data;
466
+ }
467
+ }
468
+ RoxieResultRef.prototype._class += " RoxieResultRef";
469
+
470
+ export class HipieResultRef extends RoxieResultRef {
471
+
472
+ fullUrl(_: string): this {
473
+ const info = parseUrl(_);
474
+ this.datasource().service().url(info.url);
475
+ this.datasource().service().querySet(info.querySet);
476
+ this.datasource().service().queryID(info.queryID);
477
+ return this;
478
+ }
479
+
480
+ formatRequest(): { [key: string]: any } {
481
+ const _request = super.formatRequest();
482
+ const request: { [key: string]: any } = {};
483
+ for (const key in _request) {
484
+ request[key] = _request[key];
485
+ request[`${key}_changed`] = true;
486
+ }
487
+ return request;
488
+ }
489
+ }
490
+ HipieResultRef.prototype._class += " HipieResultRef";