@hpcc-js/comms 2.102.2 → 2.102.4

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 (105) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +50 -50
  3. package/dist/index.es6.js +2 -2
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/index.node.js +2 -2
  10. package/dist/index.node.js.map +1 -1
  11. package/dist/index.node.min.js +1 -1
  12. package/dist/index.node.min.js.map +1 -1
  13. package/lib-es6/__package__.js +2 -2
  14. package/lib-es6/__package__.js.map +1 -1
  15. package/package.json +5 -5
  16. package/src/__package__.ts +3 -3
  17. package/src/__tests__/dfuXRef.ts +22 -22
  18. package/src/__tests__/https.ts +69 -69
  19. package/src/__tests__/workunit.ts +35 -35
  20. package/src/clienttools/eclMeta.ts +506 -506
  21. package/src/clienttools/eclcc.ts +628 -628
  22. package/src/connection.ts +295 -295
  23. package/src/ecl/activity.ts +82 -82
  24. package/src/ecl/dfuWorkunit.ts +363 -363
  25. package/src/ecl/graph.ts +196 -196
  26. package/src/ecl/logicalFile.ts +195 -195
  27. package/src/ecl/machine.ts +63 -63
  28. package/src/ecl/query.ts +252 -252
  29. package/src/ecl/queryGraph.ts +813 -813
  30. package/src/ecl/resource.ts +39 -39
  31. package/src/ecl/result.ts +236 -236
  32. package/src/ecl/scope.ts +192 -192
  33. package/src/ecl/sourceFile.ts +34 -34
  34. package/src/ecl/store.ts +154 -154
  35. package/src/ecl/targetCluster.ts +149 -149
  36. package/src/ecl/timer.ts +42 -42
  37. package/src/ecl/topology.ts +131 -131
  38. package/src/ecl/workunit.ts +1314 -1314
  39. package/src/ecl/xsdParser.ts +268 -268
  40. package/src/espConnection.ts +172 -172
  41. package/src/index-common.ts +41 -41
  42. package/src/index.node.ts +68 -68
  43. package/src/index.ts +3 -3
  44. package/src/pem/trustwave.ts +909 -909
  45. package/src/services/fileSpray.ts +48 -48
  46. package/src/services/wsAccess.ts +8 -8
  47. package/src/services/wsAccount.ts +27 -27
  48. package/src/services/wsCloud.ts +73 -73
  49. package/src/services/wsCodesign.ts +94 -94
  50. package/src/services/wsDFU.ts +34 -34
  51. package/src/services/wsDFUXRef.ts +308 -308
  52. package/src/services/wsDali.ts +40 -40
  53. package/src/services/wsEcl.ts +123 -123
  54. package/src/services/wsElk.ts +8 -8
  55. package/src/services/wsLogaccess.ts +263 -263
  56. package/src/services/wsMachine.ts +89 -89
  57. package/src/services/wsPackageProcess.ts +8 -8
  58. package/src/services/wsResources.ts +8 -8
  59. package/src/services/wsSMC.ts +24 -24
  60. package/src/services/wsSasha.ts +7 -7
  61. package/src/services/wsStore.ts +230 -230
  62. package/src/services/wsTopology.ts +45 -45
  63. package/src/services/wsWorkunits.ts +160 -160
  64. package/src/services/wsdl/FileSpray/v1.23/FileSpray.ts +1008 -1008
  65. package/src/services/wsdl/FileSpray/v1.25/FileSpray.ts +1040 -1040
  66. package/src/services/wsdl/FileSpray/v1.26/FileSpray.ts +929 -929
  67. package/src/services/wsdl/WsCloud/v1/WsCloud.ts +38 -38
  68. package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
  69. package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
  70. package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
  71. package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
  72. package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
  73. package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
  74. package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +107 -107
  75. package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
  76. package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
  77. package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
  78. package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +670 -670
  79. package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
  80. package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +885 -885
  81. package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
  82. package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
  83. package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
  84. package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
  85. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
  86. package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
  87. package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
  88. package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3157 -3157
  89. package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
  90. package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
  91. package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
  92. package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
  93. package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +100 -100
  94. package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
  95. package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
  96. package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
  97. package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
  98. package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
  99. package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
  100. package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
  101. package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
  102. package/src/services/wsdl/wsstore/v1.02/wsstore.ts +250 -250
  103. package/types/__package__.d.ts +2 -2
  104. package/types/__package__.d.ts.map +1 -1
  105. package/types-3.4/__package__.d.ts +2 -2
@@ -1,506 +1,506 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
-
4
- import { Dictionary, DictionaryNoCase, find, SAXStackParser, scopedLogger, XMLNode } from "@hpcc-js/util";
5
- import { ClientTools, locateClientTools } from "./eclcc";
6
-
7
- const logger = scopedLogger("clienttools/eclmeta");
8
-
9
- export interface IFilePath {
10
- scope: ECLScope;
11
- }
12
-
13
- const _inspect = false;
14
- function inspect(obj: any, _id: string, known: any) {
15
- if (_inspect) {
16
- for (const key in obj) {
17
- const id = `${_id}.${key}`;
18
- if (key !== "$" && known[key] === undefined && known[key.toLowerCase() + "s"] === undefined) {
19
- logger.debug(id);
20
- }
21
- }
22
- if (obj.$) {
23
- inspect(obj.$, _id + ".$", known);
24
- }
25
- }
26
- }
27
-
28
- export class Attr {
29
- __attrs: { [id: string]: string };
30
- name: string;
31
-
32
- constructor(xmlAttr: XMLNode) {
33
- this.__attrs = xmlAttr.$;
34
- this.name = xmlAttr.$.name;
35
- }
36
- }
37
-
38
- export class Field {
39
- __attrs: { [id: string]: string };
40
- definition: Definition;
41
- get scope(): ECLScope {
42
- return this.definition;
43
- }
44
- name: string;
45
- type: string;
46
-
47
- constructor(definition: Definition, xmlField: XMLNode) {
48
- this.__attrs = xmlField.$;
49
- this.definition = definition;
50
- this.name = xmlField.$.name;
51
- this.type = xmlField.$.type;
52
- }
53
- }
54
-
55
- export interface ECLDefinitionLocation {
56
- filePath: string;
57
- line: number;
58
- charPos: number;
59
- definition?: Definition;
60
- source?: Source;
61
- }
62
-
63
- export interface ISuggestion {
64
- name: string;
65
- type: string;
66
- }
67
-
68
- export class ECLScope implements IFilePath {
69
- get scope(): ECLScope {
70
- return this;
71
- }
72
- name: string;
73
- type: string;
74
- sourcePath: string;
75
- line: number;
76
- start: number;
77
- body: number;
78
- end: number;
79
- definitions: Definition[];
80
-
81
- constructor(name: string, type: string, sourcePath: string, xmlDefinitions: XMLNode[], line: number = 1, start: number = 0, body: number = 0, end: number = Number.MAX_VALUE) {
82
- this.name = name;
83
- this.type = type;
84
- this.sourcePath = path.normalize(sourcePath);
85
- this.line = +line - 1;
86
- this.start = +start;
87
- this.body = +body;
88
- this.end = +end;
89
- this.definitions = this.parseDefinitions(xmlDefinitions);
90
- }
91
-
92
- private parseDefinitions(definitions: XMLNode[] = []): Definition[] {
93
- return definitions.map(definition => {
94
- const retVal = new Definition(this.sourcePath, definition);
95
- inspect(definition, "definition", retVal);
96
- return retVal;
97
- });
98
- }
99
-
100
- contains(charOffset: number) {
101
- return charOffset >= this.start && charOffset <= this.end;
102
- }
103
-
104
- scopeStackAt(charOffset: number): ECLScope[] {
105
- let retVal: ECLScope[] = [];
106
- if (this.contains(charOffset)) {
107
- retVal.push(this);
108
- this.definitions.forEach(def => {
109
- retVal = def.scopeStackAt(charOffset).concat(retVal);
110
- });
111
- }
112
- return retVal;
113
- }
114
-
115
- private _resolve(defs: Definition[] = [], qualifiedID: string): Definition | undefined {
116
- const qualifiedIDParts = qualifiedID.split(".");
117
- const base = qualifiedIDParts.shift();
118
- const retVal = find(defs, def => {
119
- if (typeof def.name === "string" && typeof base === "string" && def.name.toLowerCase() === base.toLowerCase()) {
120
- return true;
121
- }
122
- return false;
123
- });
124
- if (retVal && retVal.definitions.length && qualifiedIDParts.length) {
125
- return this._resolve(retVal.definitions, qualifiedIDParts.join("."));
126
- }
127
- return retVal;
128
- }
129
-
130
- resolve(qualifiedID: string): Definition | undefined {
131
- return this._resolve(this.definitions, qualifiedID);
132
- }
133
-
134
- suggestions(): ISuggestion[] {
135
- return this.definitions.map(def => {
136
- return {
137
- name: def.name,
138
- type: this.type
139
- };
140
- });
141
- }
142
- }
143
-
144
- export class Definition extends ECLScope {
145
- __attrs: { [id: string]: string };
146
- exported: boolean;
147
- shared: boolean;
148
- fullname: string;
149
- inherittype: string;
150
- attrs: Attr[];
151
- fields: Field[];
152
-
153
- constructor(sourcePath: string, xmlDefinition: XMLNode) {
154
- super(xmlDefinition.$.name, xmlDefinition.$.type, sourcePath, xmlDefinition.children("Definition"), xmlDefinition.$.line, xmlDefinition.$.start, xmlDefinition.$.body, xmlDefinition.$.end);
155
- this.__attrs = xmlDefinition.$;
156
- this.exported = !!xmlDefinition.$.exported;
157
- this.shared = !!xmlDefinition.$.shared;
158
- this.fullname = xmlDefinition.$.fullname;
159
- this.inherittype = xmlDefinition.$.inherittype;
160
- this.attrs = this.parseAttrs(xmlDefinition.children("Attr"));
161
- this.fields = this.parseFields(xmlDefinition.children("Field"));
162
- }
163
-
164
- private parseAttrs(attrs: XMLNode[] = []): Attr[] {
165
- return attrs.map(attr => {
166
- const retVal = new Attr(attr);
167
- inspect(attr, "attr", retVal);
168
- return retVal;
169
- });
170
- }
171
-
172
- private parseFields(fields: XMLNode[] = []): Field[] {
173
- return fields.map(field => {
174
- const retVal = new Field(this, field);
175
- inspect(field, "field", retVal);
176
- return retVal;
177
- });
178
- }
179
-
180
- suggestions() {
181
- return super.suggestions().concat(this.fields.map(field => {
182
- return {
183
- name: field.name,
184
- type: field.type
185
- };
186
- }));
187
- }
188
- }
189
-
190
- export class Import {
191
- __attrs: { [id: string]: string };
192
- name: string;
193
- ref: string;
194
- start: number;
195
- end: number;
196
- line: number;
197
-
198
- constructor(xmlImport: XMLNode) {
199
- this.__attrs = xmlImport.$;
200
- this.name = xmlImport.$.name;
201
- this.ref = xmlImport.$.ref;
202
- this.start = xmlImport.$.start;
203
- this.end = xmlImport.$.end;
204
- this.line = xmlImport.$.line;
205
- }
206
- }
207
-
208
- export class Source extends ECLScope {
209
- imports: Import[];
210
- __attrs: { [id: string]: string };
211
-
212
- constructor(xmlSource: XMLNode) {
213
- super(xmlSource.$.name, "source", xmlSource.$.sourcePath, xmlSource.children("Definition"));
214
- this.__attrs = xmlSource.$;
215
- const nameParts = xmlSource.$.name.split(".");
216
- nameParts.pop();
217
- const fakeNode = new XMLNode("");
218
- fakeNode.appendAttribute("name", "$");
219
- fakeNode.appendAttribute("ref", nameParts.join("."));
220
- this.imports = [
221
- new Import(fakeNode),
222
- ...this.parseImports(xmlSource.children("Import"))
223
- ];
224
- }
225
-
226
- private parseImports(imports: XMLNode[] = []): Import[] {
227
- return imports.map(imp => {
228
- const retVal = new Import(imp);
229
- inspect(imp, "import", retVal);
230
- return retVal;
231
- });
232
- }
233
-
234
- resolve(qualifiedID: string, charOffset?: number): Definition | undefined {
235
- let retVal;
236
-
237
- // Check Inner Scopes ---
238
- if (!retVal && charOffset !== undefined) {
239
- const scopes = this.scopeStackAt(charOffset);
240
- scopes.some(scope => {
241
- retVal = scope.resolve(qualifiedID);
242
- return !!retVal;
243
- });
244
- }
245
-
246
- // Check Definitions ---
247
- if (!retVal) {
248
- retVal = super.resolve(qualifiedID);
249
- }
250
- return retVal;
251
- }
252
- }
253
-
254
- const isHiddenDirectory = source => path.basename(source).indexOf(".") === 0;
255
- const isDirectory = source => fs.lstatSync(source).isDirectory() && !isHiddenDirectory(source);
256
- const isEcl = source => [".ecl", ".ecllib"].indexOf(path.extname(source).toLowerCase()) >= 0;
257
- const modAttrs = source => fs.readdirSync(source).map(name => path.join(source, name)).filter(path => isDirectory(path) || isEcl(path));
258
-
259
- export class File extends ECLScope {
260
-
261
- constructor(name: string, sourcePath: string) {
262
- super(name, "file", sourcePath, []);
263
- }
264
-
265
- suggestions(): ISuggestion[] {
266
- return [];
267
- }
268
- }
269
-
270
- export class Folder extends ECLScope {
271
-
272
- constructor(name: string, sourcePath: string) {
273
- super(name, "folder", sourcePath, []);
274
- }
275
-
276
- suggestions(): ISuggestion[] {
277
- return modAttrs(this.sourcePath).map(folder => {
278
- return {
279
- name: path.basename(folder, ".ecl"),
280
- type: "folder"
281
- };
282
- });
283
- }
284
- }
285
-
286
- export class Workspace {
287
- _workspacePath: string;
288
- _eclccPath?: string;
289
- _clientTools: ClientTools;
290
- _sourceByID: DictionaryNoCase<Source> = new DictionaryNoCase<Source>();
291
- _sourceByPath: Dictionary<Source> = new Dictionary<Source>();
292
- private _test: DictionaryNoCase<IFilePath> = new DictionaryNoCase<IFilePath>();
293
-
294
- constructor(workspacePath: string, eclccPath?: string) {
295
- this._workspacePath = workspacePath;
296
- this._eclccPath = eclccPath;
297
- }
298
-
299
- refresh() {
300
- this.primeWorkspace();
301
- this.primeClientTools();
302
- }
303
-
304
- primeClientTools(): Promise<this> {
305
- return locateClientTools(this._eclccPath, "", this._workspacePath).then(clientTools => {
306
- this._clientTools = clientTools;
307
- return clientTools.paths();
308
- }).then(paths => {
309
- for (const knownFolder of ["ECLCC_ECLLIBRARY_PATH", "ECLCC_PLUGIN_PATH"]) {
310
- if (paths[knownFolder] && fs.existsSync(paths[knownFolder])) {
311
- this.walkChildFolders(paths[knownFolder], paths[knownFolder]);
312
- }
313
- }
314
- return this;
315
- });
316
- }
317
-
318
- primeWorkspace() {
319
- if (fs.existsSync(this._workspacePath)) {
320
- this.visitFolder(this._workspacePath, this._workspacePath);
321
- }
322
- }
323
-
324
- walkChildFolders(folderPath: string, refPath: string, force: boolean = false) {
325
- for (const child of modAttrs(folderPath)) {
326
- if (!isDirectory(child)) {
327
- this.visitFile(child, refPath, force);
328
- } else {
329
- this.visitFolder(child, refPath, force);
330
- }
331
- }
332
- }
333
-
334
- visitFile(filePath: string, refPath: string, force: boolean = false) {
335
- const filePathInfo = path.parse(filePath);
336
- const pathNoExt = path.join(filePathInfo.dir, filePathInfo.name);
337
- const name = path.relative(refPath, pathNoExt).split(path.sep).join(".");
338
- if (force || !this._test.has(name)) {
339
- this._test.set(name, new File("", filePath));
340
- }
341
- }
342
-
343
- visitFolder(folderPath: string, refPath: string, force: boolean = false) {
344
- const name = path.relative(refPath, folderPath).split(path.sep).join(".");
345
- if (force || !this._test.has(name)) {
346
- this._test.set(name, new Folder(name, folderPath));
347
- this.walkChildFolders(folderPath, refPath, force);
348
- }
349
- }
350
-
351
- buildStack(parentStack: string[], name: string, removeDupID: boolean): { stack: string[], qid: string } {
352
- const nameStack = name.split(".");
353
- if (removeDupID && parentStack[parentStack.length - 1] === nameStack[0]) {
354
- nameStack.shift();
355
- }
356
- const stack = [...parentStack, ...nameStack];
357
- const qid: string = stack.join(".");
358
- return {
359
- stack,
360
- qid
361
- };
362
- }
363
-
364
- walkECLScope(parentStack: string[], scope: ECLScope) {
365
- const info = this.buildStack(parentStack, scope.name, true);
366
- this._test.set(info.qid, scope);
367
- for (const def of scope.definitions) {
368
- this.walkDefinition(info.stack, def);
369
- }
370
- }
371
-
372
- walkField(parentStack: string[], field: Field) {
373
- const info = this.buildStack(parentStack, field.name, false);
374
- this._test.set(info.qid, field);
375
- }
376
-
377
- walkDefinition(parentStack: string[], definition: Definition) {
378
- const info = this.buildStack(parentStack, definition.name, true);
379
- this.walkECLScope(parentStack, definition);
380
- for (const field of definition.fields) {
381
- this.walkField(info.stack, field);
382
- }
383
- }
384
-
385
- walkSource(source: Source) {
386
- // const dirName = path.dirname(source.sourcePath);
387
- // const relName = path.relative(this._workspacePath, dirName).split(path.sep).join(".");
388
- // const folder = new Folder(relName, dirName);
389
- // this._test.set(folder.name, folder);
390
- this.walkECLScope([], source);
391
- }
392
-
393
- parseSources(sources: XMLNode[] = []): void {
394
- for (const _source of sources) {
395
- if (_source.$.name) { // Plugins have no name...
396
- const source = new Source(_source);
397
- inspect(_source, "source", source);
398
- this._sourceByID.set(source.name, source);
399
- this._sourceByPath.set(source.sourcePath, source);
400
-
401
- // If external source like "std.system.ThorLib" then need to backup to "std" and add its folder
402
- if (source.name) {
403
- const sourceNameParts = source.name.split(".");
404
- let depth = sourceNameParts.length;
405
- if (depth > 1) {
406
- let sourcePath = source.sourcePath;
407
- while (depth > 1) {
408
- sourcePath = path.dirname(sourcePath);
409
- --depth;
410
- }
411
- this.visitFolder(sourcePath, path.dirname(sourcePath));
412
- }
413
- }
414
- this.walkSource(source);
415
- }
416
- }
417
- }
418
-
419
- parseMetaXML(metaXML: string): string[] {
420
- const metaParser = new MetaParser();
421
- metaParser.parse(metaXML);
422
- this.parseSources(metaParser.sources);
423
- return metaParser.sources.map(source => path.normalize(source.$.sourcePath));
424
- }
425
-
426
- resolveQualifiedID(filePath: string, qualifiedID: string, charOffset?: number): ECLScope | undefined {
427
- let retVal: ECLScope | undefined;
428
- if (!retVal && this._test.has(qualifiedID)) {
429
- retVal = this._test.get(qualifiedID).scope;
430
- }
431
- if (!retVal && this._sourceByPath.has(filePath)) {
432
- const eclSource = this._sourceByPath.get(filePath);
433
-
434
- // Resolve Imports ---
435
- const qualifiedIDParts = qualifiedID.split(".");
436
- for (const imp of eclSource.imports) {
437
- if (imp.name.toLowerCase() === qualifiedIDParts[0].toLowerCase()) {
438
- if (imp.ref) {
439
- qualifiedIDParts[0] = imp.ref;
440
- } else {
441
- qualifiedIDParts.shift();
442
- }
443
- break;
444
- }
445
- }
446
- let realQID = qualifiedIDParts.join(".");
447
- if (!retVal && this._test.has(realQID)) {
448
- retVal = this._test.get(realQID).scope;
449
- }
450
- if (!retVal) {
451
- realQID = [...eclSource.name.split("."), ...qualifiedIDParts].join(".");
452
- if (this._test.has(realQID)) {
453
- retVal = this._test.get(realQID).scope;
454
- }
455
- }
456
- }
457
- return retVal;
458
- }
459
-
460
- resolvePartialID(filePath: string, partialID: string, charOffset: number): ECLScope | undefined {
461
- partialID = partialID.toLowerCase();
462
- const partialIDParts = partialID.split(".");
463
- partialIDParts.pop();
464
- const partialIDQualifier = partialIDParts.length === 1 ? partialIDParts[0] : partialIDParts.join(".");
465
- return this.resolveQualifiedID(filePath, partialIDQualifier, charOffset);
466
- }
467
- }
468
-
469
- const workspaceCache = new Dictionary<Workspace>();
470
- export function attachWorkspace(_workspacePath: string, eclccPath?: string): Workspace {
471
- const workspacePath = path.normalize(_workspacePath);
472
- if (!workspaceCache.has(workspacePath)) {
473
- const workspace = new Workspace(workspacePath, eclccPath);
474
- workspaceCache.set(workspacePath, workspace);
475
- workspace.refresh();
476
- }
477
- return workspaceCache.get(workspacePath);
478
- }
479
-
480
- function isQualifiedIDChar(lineText: string, charPos: number, reverse: boolean) {
481
- if (charPos < 0) return false;
482
- const testChar = lineText.charAt(charPos);
483
- return (reverse ? /[a-zA-Z\d_\.$]/ : /[a-zA-Z\d_]/).test(testChar);
484
- }
485
-
486
- export function qualifiedIDBoundary(lineText: string, charPos: number, reverse: boolean) {
487
- while (isQualifiedIDChar(lineText, charPos, reverse)) {
488
- charPos += reverse ? -1 : 1;
489
- }
490
- return charPos + (reverse ? 1 : -1);
491
- }
492
-
493
- class MetaParser extends SAXStackParser {
494
- sources: XMLNode[] = [];
495
-
496
- endXMLNode(e: XMLNode) {
497
- switch (e.name) {
498
- case "Source":
499
- this.sources.push(e);
500
- break;
501
- default:
502
- break;
503
- }
504
- super.endXMLNode(e);
505
- }
506
- }
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+
4
+ import { Dictionary, DictionaryNoCase, find, SAXStackParser, scopedLogger, XMLNode } from "@hpcc-js/util";
5
+ import { ClientTools, locateClientTools } from "./eclcc";
6
+
7
+ const logger = scopedLogger("clienttools/eclmeta");
8
+
9
+ export interface IFilePath {
10
+ scope: ECLScope;
11
+ }
12
+
13
+ const _inspect = false;
14
+ function inspect(obj: any, _id: string, known: any) {
15
+ if (_inspect) {
16
+ for (const key in obj) {
17
+ const id = `${_id}.${key}`;
18
+ if (key !== "$" && known[key] === undefined && known[key.toLowerCase() + "s"] === undefined) {
19
+ logger.debug(id);
20
+ }
21
+ }
22
+ if (obj.$) {
23
+ inspect(obj.$, _id + ".$", known);
24
+ }
25
+ }
26
+ }
27
+
28
+ export class Attr {
29
+ __attrs: { [id: string]: string };
30
+ name: string;
31
+
32
+ constructor(xmlAttr: XMLNode) {
33
+ this.__attrs = xmlAttr.$;
34
+ this.name = xmlAttr.$.name;
35
+ }
36
+ }
37
+
38
+ export class Field {
39
+ __attrs: { [id: string]: string };
40
+ definition: Definition;
41
+ get scope(): ECLScope {
42
+ return this.definition;
43
+ }
44
+ name: string;
45
+ type: string;
46
+
47
+ constructor(definition: Definition, xmlField: XMLNode) {
48
+ this.__attrs = xmlField.$;
49
+ this.definition = definition;
50
+ this.name = xmlField.$.name;
51
+ this.type = xmlField.$.type;
52
+ }
53
+ }
54
+
55
+ export interface ECLDefinitionLocation {
56
+ filePath: string;
57
+ line: number;
58
+ charPos: number;
59
+ definition?: Definition;
60
+ source?: Source;
61
+ }
62
+
63
+ export interface ISuggestion {
64
+ name: string;
65
+ type: string;
66
+ }
67
+
68
+ export class ECLScope implements IFilePath {
69
+ get scope(): ECLScope {
70
+ return this;
71
+ }
72
+ name: string;
73
+ type: string;
74
+ sourcePath: string;
75
+ line: number;
76
+ start: number;
77
+ body: number;
78
+ end: number;
79
+ definitions: Definition[];
80
+
81
+ constructor(name: string, type: string, sourcePath: string, xmlDefinitions: XMLNode[], line: number = 1, start: number = 0, body: number = 0, end: number = Number.MAX_VALUE) {
82
+ this.name = name;
83
+ this.type = type;
84
+ this.sourcePath = path.normalize(sourcePath);
85
+ this.line = +line - 1;
86
+ this.start = +start;
87
+ this.body = +body;
88
+ this.end = +end;
89
+ this.definitions = this.parseDefinitions(xmlDefinitions);
90
+ }
91
+
92
+ private parseDefinitions(definitions: XMLNode[] = []): Definition[] {
93
+ return definitions.map(definition => {
94
+ const retVal = new Definition(this.sourcePath, definition);
95
+ inspect(definition, "definition", retVal);
96
+ return retVal;
97
+ });
98
+ }
99
+
100
+ contains(charOffset: number) {
101
+ return charOffset >= this.start && charOffset <= this.end;
102
+ }
103
+
104
+ scopeStackAt(charOffset: number): ECLScope[] {
105
+ let retVal: ECLScope[] = [];
106
+ if (this.contains(charOffset)) {
107
+ retVal.push(this);
108
+ this.definitions.forEach(def => {
109
+ retVal = def.scopeStackAt(charOffset).concat(retVal);
110
+ });
111
+ }
112
+ return retVal;
113
+ }
114
+
115
+ private _resolve(defs: Definition[] = [], qualifiedID: string): Definition | undefined {
116
+ const qualifiedIDParts = qualifiedID.split(".");
117
+ const base = qualifiedIDParts.shift();
118
+ const retVal = find(defs, def => {
119
+ if (typeof def.name === "string" && typeof base === "string" && def.name.toLowerCase() === base.toLowerCase()) {
120
+ return true;
121
+ }
122
+ return false;
123
+ });
124
+ if (retVal && retVal.definitions.length && qualifiedIDParts.length) {
125
+ return this._resolve(retVal.definitions, qualifiedIDParts.join("."));
126
+ }
127
+ return retVal;
128
+ }
129
+
130
+ resolve(qualifiedID: string): Definition | undefined {
131
+ return this._resolve(this.definitions, qualifiedID);
132
+ }
133
+
134
+ suggestions(): ISuggestion[] {
135
+ return this.definitions.map(def => {
136
+ return {
137
+ name: def.name,
138
+ type: this.type
139
+ };
140
+ });
141
+ }
142
+ }
143
+
144
+ export class Definition extends ECLScope {
145
+ __attrs: { [id: string]: string };
146
+ exported: boolean;
147
+ shared: boolean;
148
+ fullname: string;
149
+ inherittype: string;
150
+ attrs: Attr[];
151
+ fields: Field[];
152
+
153
+ constructor(sourcePath: string, xmlDefinition: XMLNode) {
154
+ super(xmlDefinition.$.name, xmlDefinition.$.type, sourcePath, xmlDefinition.children("Definition"), xmlDefinition.$.line, xmlDefinition.$.start, xmlDefinition.$.body, xmlDefinition.$.end);
155
+ this.__attrs = xmlDefinition.$;
156
+ this.exported = !!xmlDefinition.$.exported;
157
+ this.shared = !!xmlDefinition.$.shared;
158
+ this.fullname = xmlDefinition.$.fullname;
159
+ this.inherittype = xmlDefinition.$.inherittype;
160
+ this.attrs = this.parseAttrs(xmlDefinition.children("Attr"));
161
+ this.fields = this.parseFields(xmlDefinition.children("Field"));
162
+ }
163
+
164
+ private parseAttrs(attrs: XMLNode[] = []): Attr[] {
165
+ return attrs.map(attr => {
166
+ const retVal = new Attr(attr);
167
+ inspect(attr, "attr", retVal);
168
+ return retVal;
169
+ });
170
+ }
171
+
172
+ private parseFields(fields: XMLNode[] = []): Field[] {
173
+ return fields.map(field => {
174
+ const retVal = new Field(this, field);
175
+ inspect(field, "field", retVal);
176
+ return retVal;
177
+ });
178
+ }
179
+
180
+ suggestions() {
181
+ return super.suggestions().concat(this.fields.map(field => {
182
+ return {
183
+ name: field.name,
184
+ type: field.type
185
+ };
186
+ }));
187
+ }
188
+ }
189
+
190
+ export class Import {
191
+ __attrs: { [id: string]: string };
192
+ name: string;
193
+ ref: string;
194
+ start: number;
195
+ end: number;
196
+ line: number;
197
+
198
+ constructor(xmlImport: XMLNode) {
199
+ this.__attrs = xmlImport.$;
200
+ this.name = xmlImport.$.name;
201
+ this.ref = xmlImport.$.ref;
202
+ this.start = xmlImport.$.start;
203
+ this.end = xmlImport.$.end;
204
+ this.line = xmlImport.$.line;
205
+ }
206
+ }
207
+
208
+ export class Source extends ECLScope {
209
+ imports: Import[];
210
+ __attrs: { [id: string]: string };
211
+
212
+ constructor(xmlSource: XMLNode) {
213
+ super(xmlSource.$.name, "source", xmlSource.$.sourcePath, xmlSource.children("Definition"));
214
+ this.__attrs = xmlSource.$;
215
+ const nameParts = xmlSource.$.name.split(".");
216
+ nameParts.pop();
217
+ const fakeNode = new XMLNode("");
218
+ fakeNode.appendAttribute("name", "$");
219
+ fakeNode.appendAttribute("ref", nameParts.join("."));
220
+ this.imports = [
221
+ new Import(fakeNode),
222
+ ...this.parseImports(xmlSource.children("Import"))
223
+ ];
224
+ }
225
+
226
+ private parseImports(imports: XMLNode[] = []): Import[] {
227
+ return imports.map(imp => {
228
+ const retVal = new Import(imp);
229
+ inspect(imp, "import", retVal);
230
+ return retVal;
231
+ });
232
+ }
233
+
234
+ resolve(qualifiedID: string, charOffset?: number): Definition | undefined {
235
+ let retVal;
236
+
237
+ // Check Inner Scopes ---
238
+ if (!retVal && charOffset !== undefined) {
239
+ const scopes = this.scopeStackAt(charOffset);
240
+ scopes.some(scope => {
241
+ retVal = scope.resolve(qualifiedID);
242
+ return !!retVal;
243
+ });
244
+ }
245
+
246
+ // Check Definitions ---
247
+ if (!retVal) {
248
+ retVal = super.resolve(qualifiedID);
249
+ }
250
+ return retVal;
251
+ }
252
+ }
253
+
254
+ const isHiddenDirectory = source => path.basename(source).indexOf(".") === 0;
255
+ const isDirectory = source => fs.lstatSync(source).isDirectory() && !isHiddenDirectory(source);
256
+ const isEcl = source => [".ecl", ".ecllib"].indexOf(path.extname(source).toLowerCase()) >= 0;
257
+ const modAttrs = source => fs.readdirSync(source).map(name => path.join(source, name)).filter(path => isDirectory(path) || isEcl(path));
258
+
259
+ export class File extends ECLScope {
260
+
261
+ constructor(name: string, sourcePath: string) {
262
+ super(name, "file", sourcePath, []);
263
+ }
264
+
265
+ suggestions(): ISuggestion[] {
266
+ return [];
267
+ }
268
+ }
269
+
270
+ export class Folder extends ECLScope {
271
+
272
+ constructor(name: string, sourcePath: string) {
273
+ super(name, "folder", sourcePath, []);
274
+ }
275
+
276
+ suggestions(): ISuggestion[] {
277
+ return modAttrs(this.sourcePath).map(folder => {
278
+ return {
279
+ name: path.basename(folder, ".ecl"),
280
+ type: "folder"
281
+ };
282
+ });
283
+ }
284
+ }
285
+
286
+ export class Workspace {
287
+ _workspacePath: string;
288
+ _eclccPath?: string;
289
+ _clientTools: ClientTools;
290
+ _sourceByID: DictionaryNoCase<Source> = new DictionaryNoCase<Source>();
291
+ _sourceByPath: Dictionary<Source> = new Dictionary<Source>();
292
+ private _test: DictionaryNoCase<IFilePath> = new DictionaryNoCase<IFilePath>();
293
+
294
+ constructor(workspacePath: string, eclccPath?: string) {
295
+ this._workspacePath = workspacePath;
296
+ this._eclccPath = eclccPath;
297
+ }
298
+
299
+ refresh() {
300
+ this.primeWorkspace();
301
+ this.primeClientTools();
302
+ }
303
+
304
+ primeClientTools(): Promise<this> {
305
+ return locateClientTools(this._eclccPath, "", this._workspacePath).then(clientTools => {
306
+ this._clientTools = clientTools;
307
+ return clientTools.paths();
308
+ }).then(paths => {
309
+ for (const knownFolder of ["ECLCC_ECLLIBRARY_PATH", "ECLCC_PLUGIN_PATH"]) {
310
+ if (paths[knownFolder] && fs.existsSync(paths[knownFolder])) {
311
+ this.walkChildFolders(paths[knownFolder], paths[knownFolder]);
312
+ }
313
+ }
314
+ return this;
315
+ });
316
+ }
317
+
318
+ primeWorkspace() {
319
+ if (fs.existsSync(this._workspacePath)) {
320
+ this.visitFolder(this._workspacePath, this._workspacePath);
321
+ }
322
+ }
323
+
324
+ walkChildFolders(folderPath: string, refPath: string, force: boolean = false) {
325
+ for (const child of modAttrs(folderPath)) {
326
+ if (!isDirectory(child)) {
327
+ this.visitFile(child, refPath, force);
328
+ } else {
329
+ this.visitFolder(child, refPath, force);
330
+ }
331
+ }
332
+ }
333
+
334
+ visitFile(filePath: string, refPath: string, force: boolean = false) {
335
+ const filePathInfo = path.parse(filePath);
336
+ const pathNoExt = path.join(filePathInfo.dir, filePathInfo.name);
337
+ const name = path.relative(refPath, pathNoExt).split(path.sep).join(".");
338
+ if (force || !this._test.has(name)) {
339
+ this._test.set(name, new File("", filePath));
340
+ }
341
+ }
342
+
343
+ visitFolder(folderPath: string, refPath: string, force: boolean = false) {
344
+ const name = path.relative(refPath, folderPath).split(path.sep).join(".");
345
+ if (force || !this._test.has(name)) {
346
+ this._test.set(name, new Folder(name, folderPath));
347
+ this.walkChildFolders(folderPath, refPath, force);
348
+ }
349
+ }
350
+
351
+ buildStack(parentStack: string[], name: string, removeDupID: boolean): { stack: string[], qid: string } {
352
+ const nameStack = name.split(".");
353
+ if (removeDupID && parentStack[parentStack.length - 1] === nameStack[0]) {
354
+ nameStack.shift();
355
+ }
356
+ const stack = [...parentStack, ...nameStack];
357
+ const qid: string = stack.join(".");
358
+ return {
359
+ stack,
360
+ qid
361
+ };
362
+ }
363
+
364
+ walkECLScope(parentStack: string[], scope: ECLScope) {
365
+ const info = this.buildStack(parentStack, scope.name, true);
366
+ this._test.set(info.qid, scope);
367
+ for (const def of scope.definitions) {
368
+ this.walkDefinition(info.stack, def);
369
+ }
370
+ }
371
+
372
+ walkField(parentStack: string[], field: Field) {
373
+ const info = this.buildStack(parentStack, field.name, false);
374
+ this._test.set(info.qid, field);
375
+ }
376
+
377
+ walkDefinition(parentStack: string[], definition: Definition) {
378
+ const info = this.buildStack(parentStack, definition.name, true);
379
+ this.walkECLScope(parentStack, definition);
380
+ for (const field of definition.fields) {
381
+ this.walkField(info.stack, field);
382
+ }
383
+ }
384
+
385
+ walkSource(source: Source) {
386
+ // const dirName = path.dirname(source.sourcePath);
387
+ // const relName = path.relative(this._workspacePath, dirName).split(path.sep).join(".");
388
+ // const folder = new Folder(relName, dirName);
389
+ // this._test.set(folder.name, folder);
390
+ this.walkECLScope([], source);
391
+ }
392
+
393
+ parseSources(sources: XMLNode[] = []): void {
394
+ for (const _source of sources) {
395
+ if (_source.$.name) { // Plugins have no name...
396
+ const source = new Source(_source);
397
+ inspect(_source, "source", source);
398
+ this._sourceByID.set(source.name, source);
399
+ this._sourceByPath.set(source.sourcePath, source);
400
+
401
+ // If external source like "std.system.ThorLib" then need to backup to "std" and add its folder
402
+ if (source.name) {
403
+ const sourceNameParts = source.name.split(".");
404
+ let depth = sourceNameParts.length;
405
+ if (depth > 1) {
406
+ let sourcePath = source.sourcePath;
407
+ while (depth > 1) {
408
+ sourcePath = path.dirname(sourcePath);
409
+ --depth;
410
+ }
411
+ this.visitFolder(sourcePath, path.dirname(sourcePath));
412
+ }
413
+ }
414
+ this.walkSource(source);
415
+ }
416
+ }
417
+ }
418
+
419
+ parseMetaXML(metaXML: string): string[] {
420
+ const metaParser = new MetaParser();
421
+ metaParser.parse(metaXML);
422
+ this.parseSources(metaParser.sources);
423
+ return metaParser.sources.map(source => path.normalize(source.$.sourcePath));
424
+ }
425
+
426
+ resolveQualifiedID(filePath: string, qualifiedID: string, charOffset?: number): ECLScope | undefined {
427
+ let retVal: ECLScope | undefined;
428
+ if (!retVal && this._test.has(qualifiedID)) {
429
+ retVal = this._test.get(qualifiedID).scope;
430
+ }
431
+ if (!retVal && this._sourceByPath.has(filePath)) {
432
+ const eclSource = this._sourceByPath.get(filePath);
433
+
434
+ // Resolve Imports ---
435
+ const qualifiedIDParts = qualifiedID.split(".");
436
+ for (const imp of eclSource.imports) {
437
+ if (imp.name.toLowerCase() === qualifiedIDParts[0].toLowerCase()) {
438
+ if (imp.ref) {
439
+ qualifiedIDParts[0] = imp.ref;
440
+ } else {
441
+ qualifiedIDParts.shift();
442
+ }
443
+ break;
444
+ }
445
+ }
446
+ let realQID = qualifiedIDParts.join(".");
447
+ if (!retVal && this._test.has(realQID)) {
448
+ retVal = this._test.get(realQID).scope;
449
+ }
450
+ if (!retVal) {
451
+ realQID = [...eclSource.name.split("."), ...qualifiedIDParts].join(".");
452
+ if (this._test.has(realQID)) {
453
+ retVal = this._test.get(realQID).scope;
454
+ }
455
+ }
456
+ }
457
+ return retVal;
458
+ }
459
+
460
+ resolvePartialID(filePath: string, partialID: string, charOffset: number): ECLScope | undefined {
461
+ partialID = partialID.toLowerCase();
462
+ const partialIDParts = partialID.split(".");
463
+ partialIDParts.pop();
464
+ const partialIDQualifier = partialIDParts.length === 1 ? partialIDParts[0] : partialIDParts.join(".");
465
+ return this.resolveQualifiedID(filePath, partialIDQualifier, charOffset);
466
+ }
467
+ }
468
+
469
+ const workspaceCache = new Dictionary<Workspace>();
470
+ export function attachWorkspace(_workspacePath: string, eclccPath?: string): Workspace {
471
+ const workspacePath = path.normalize(_workspacePath);
472
+ if (!workspaceCache.has(workspacePath)) {
473
+ const workspace = new Workspace(workspacePath, eclccPath);
474
+ workspaceCache.set(workspacePath, workspace);
475
+ workspace.refresh();
476
+ }
477
+ return workspaceCache.get(workspacePath);
478
+ }
479
+
480
+ function isQualifiedIDChar(lineText: string, charPos: number, reverse: boolean) {
481
+ if (charPos < 0) return false;
482
+ const testChar = lineText.charAt(charPos);
483
+ return (reverse ? /[a-zA-Z\d_\.$]/ : /[a-zA-Z\d_]/).test(testChar);
484
+ }
485
+
486
+ export function qualifiedIDBoundary(lineText: string, charPos: number, reverse: boolean) {
487
+ while (isQualifiedIDChar(lineText, charPos, reverse)) {
488
+ charPos += reverse ? -1 : 1;
489
+ }
490
+ return charPos + (reverse ? 1 : -1);
491
+ }
492
+
493
+ class MetaParser extends SAXStackParser {
494
+ sources: XMLNode[] = [];
495
+
496
+ endXMLNode(e: XMLNode) {
497
+ switch (e.name) {
498
+ case "Source":
499
+ this.sources.push(e);
500
+ break;
501
+ default:
502
+ break;
503
+ }
504
+ super.endXMLNode(e);
505
+ }
506
+ }