@ibm/zapp-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,539 @@
1
+ import YAWM from "yawn-yaml/cjs";
2
+ import { ValidateFunction } from "ajv";
3
+ /**
4
+ * A meta-data representation of a schema file
5
+ * providing path and type.
6
+ */
7
+ export interface SchemaFile {
8
+ path: string;
9
+ type: 'json' | 'yaml';
10
+ }
11
+ export abstract class SchemaDocumentInstance {
12
+ protected yawn: YAWM;
13
+ type: string;
14
+ /** If true the document was parsed and validated successfully.
15
+ * If false then pasing or validation failed. Check the errorMessages members then. */
16
+ isValid: boolean;
17
+ /** Provides meta-data for the file used to create the instance using the SchemaFile interface */
18
+ file: SchemaFile | undefined;
19
+ /** Error message resulting from IO errors, parsing, or validations. */
20
+ errorMessages: string | undefined;
21
+ protected static validationFunction: ValidateFunction | undefined;
22
+ /**
23
+ * Creates an instance of SchemaDocumentInstance. Protected, use factory methods instead.
24
+ * @param {string} schemaYamlString String representation of the yaml used to create the instance
25
+ * @param {string} [errorMessages] Optionally provide error messages to be preserved such as IO errors from reading a file
26
+ */
27
+ protected constructor(schemaYamlString: string, errorMessages?: string);
28
+ /**
29
+ * @returns {(Type | undefined)} returns the schema document as an instance of the IBMSchemaDocument interface
30
+ */
31
+ abstract getAsDocument<Type>(): Type | undefined;
32
+ /**
33
+ * @returns {(string | undefined)} returns the schema document as YAML string
34
+ */
35
+ getAsYaml(): string | undefined;
36
+ getAsJson(): string | undefined;
37
+ /**
38
+ * @returns {(Record<string, unknown> | undefined)} returns the schema document as untyped object
39
+ */
40
+ protected getAsObject(): Record<string, unknown> | undefined;
41
+ /**
42
+ * When running ZAPP in an editor then the editor will write file updates in a parallel process
43
+ * than the ZAPP code that runs in an extension host in a parallel node instance. We observed
44
+ * that sometime node's fs.readFile will then return an empty string. The theory is that the file is
45
+ * still locked by the write process because the file contents have not yet been fully flushed to
46
+ * the disk by the other process. As a work around we want to retry reading a file when it returns
47
+ * empty. When an exception is throw then it will not retry.
48
+ *
49
+ * @param filepath Absolute path to the file to read
50
+ * @returns the contents of the file read or throws an exception if multiple attempts failed
51
+ */
52
+ protected static readFileWithRetry(filepath: string): Promise<string>;
53
+ /**
54
+ * If the document instance was read from a file and/or the file is populated with path and type
55
+ * then write it back to the file system replacing the previous file.
56
+ */
57
+ write(): void;
58
+ /**
59
+ * Can be called to check that the document complies with the schema json-schema.
60
+ * If validation errors are found then they will added to the errorMessages member.
61
+ *
62
+ * @returns {boolean} false if validation errors were found
63
+ */
64
+ abstract validate(): boolean;
65
+ protected appendErrorMessage(message: string | undefined): void;
66
+ protected prependErrorMessage(message: string | undefined): void;
67
+ }
68
+ export abstract class SchemaDocumentCache {
69
+ protected type: string;
70
+ /** maps absolute path to a schema file to a cached document instance */
71
+ protected documentsCache: Map<string, SchemaDocumentInstance>;
72
+ /** maps absolute path to a workspace to the absolute path of a schema file */
73
+ protected workspacesMap: Map<string, string>;
74
+ protected constructor(type: string);
75
+ protected addDocument(filePath: string, workspacePath: string, document: SchemaDocumentInstance): void;
76
+ /**
77
+ * Removes a document from the cache.
78
+ * @param filePath absolute path to the schema file
79
+ */
80
+ clearSchemaDocument(filePath: string): void;
81
+ /**
82
+ * Clears the entire document cache.
83
+ * Call when restarting the client and reload all files to cache.
84
+ */
85
+ clearCache(): void;
86
+ protected numberDocsAdded: number;
87
+ protected numberDocsRemoved: number;
88
+ protected numberDocsFound: number;
89
+ /**
90
+ * Report on cache size and stats. Mainly used for testing.
91
+ */
92
+ getCacheStats(): Record<string, unknown>;
93
+ /**
94
+ * Checks for a given filename if it is valid filename that can be used with the
95
+ * currently associated schema. For example, an implementation could allow files
96
+ * with multiple extension such as zapp.yaml as well as zapp.yml and return true
97
+ * for both cases and false for ZAPP.YAML enforcing a case sensitive spelling.
98
+ *
99
+ * @param {string} filename
100
+ * @returns {boolean} true if the filename is matching
101
+ */
102
+ abstract isValidFilename(filename: string): boolean;
103
+ /**
104
+ * Normalization of absolute path names required as VS Code API returns path names
105
+ * with lower case drive letters on Windows, but end users can specify Schema
106
+ * path names with driver letter casing in the way they want. We therefore
107
+ * index the cache on Windows always with all uppercase pathNames.
108
+ * @param {string} absolutePath
109
+ * @returns {string} normalized code and if Window
110
+ * @memberof SchemaDocumentsCache
111
+ */
112
+ protected normalizePath(absolutePath: string): string;
113
+ }
114
+ /**
115
+ * JSON schema for zapp.json and zapp.yaml files. Version 1.0.0 -- Licensed Materials - Property of IBM - (c) Copyright IBM Corporation 2022. All Rights Reserved.
116
+ */
117
+ export type IBMZappDocument = CoreProperties;
118
+ /**
119
+ * A person who has been involved in creating or maintaining this package
120
+ */
121
+ export type Person = {
122
+ name: string;
123
+ url?: string;
124
+ email?: string;
125
+ [k: string]: unknown;
126
+ } | string;
127
+ /**
128
+ * Profiles are additional groups of properties that should only should become valid under specific conditions such as running in a build job or as part of a debug session.
129
+ */
130
+ export type Profile = {
131
+ name: string;
132
+ type: 'dbb';
133
+ settings: DbbSettingsItem;
134
+ } | {
135
+ name: string;
136
+ type: 'rseapi';
137
+ settings: RseapiSettingsItem;
138
+ };
139
+ export interface CoreProperties {
140
+ /**
141
+ * The name of the Z Project.
142
+ */
143
+ name: string;
144
+ /**
145
+ * This helps people understand your project as it would be used by tools.
146
+ */
147
+ description?: string;
148
+ /**
149
+ * Version is a string and it must be parsable for managing dependencies.
150
+ */
151
+ version?: string;
152
+ /**
153
+ * Defines a group name that is shared for each application part in case of applications composed of multiple parts. Allows to uniquely identify the parts by concatenating with the artifact id. For example a groupId `com.ibm.wazi` with an artifactId `service` would create the unique application identifier `com.ibm.wazi.service`.
154
+ */
155
+ groupId?: string;
156
+ /**
157
+ * Define id of the application artifact. Use it in combination with a groupId for multi-part applications.
158
+ */
159
+ artifactId?: string;
160
+ /**
161
+ * In case of a multi-part application defines the name of the parent application part. This zapp will inherit properties such as propertyGroups defined in the parent.
162
+ */
163
+ parentId?: string;
164
+ /**
165
+ * This helps people discover your project.
166
+ */
167
+ keywords?: string[];
168
+ /**
169
+ * The url to the project homepage.
170
+ */
171
+ homepage?: ({
172
+ [k: string]: unknown;
173
+ } | '.') & string;
174
+ /**
175
+ * You should specify a license for your package so that people know how they are permitted to use it and any restrictions you're placing on it.
176
+ */
177
+ license?: string;
178
+ author?: Person;
179
+ /**
180
+ * A list of people who contributed to this package.
181
+ */
182
+ contributors?: [Person, ...Person[]];
183
+ /**
184
+ * A list of people who maintain this package.
185
+ */
186
+ maintainers?: [Person, ...Person[]];
187
+ /**
188
+ * A list properties defining path names for resolving dependencies.
189
+ */
190
+ propertyGroups?: [PropertyGroupItem, ...PropertyGroupItem[]];
191
+ /**
192
+ * Profiles are additional groups of properties that should only should become valid under specific conditions such as running in a build job or as part of a debug session.
193
+ */
194
+ profiles?: [Profile, ...Profile[]];
195
+ }
196
+ export interface PropertyGroupItem {
197
+ /**
198
+ * The name of the property group, which is used in hovers and error messages.
199
+ */
200
+ name: string;
201
+ /**
202
+ * Limits the property group to one specific language.
203
+ */
204
+ language?: 'cobol' | 'pl1' | 'hlasm' | 'rexx' | 'jcl';
205
+ /**
206
+ * Global compiler options separated by a comma that impact the parsing of the programs for the editor. Requires that you specify a language. If there are multiple Property Groups for a language with compiler option then they will be concatenated.
207
+ */
208
+ compilerOptions?: string;
209
+ /**
210
+ * An array of potential library locations defining the search order for include files. Libraries with the name 'syslib' will be handled as default include locations. The list can contain many entries of the type 'local' or 'mvs'. It can contain items of the same type twice in case, for example, you want to search in remote locations first, then some local location, and if still not found more remote locations.
211
+ */
212
+ libraries?: [LibraryItem, ...LibraryItem[]];
213
+ }
214
+ export interface LibraryItem {
215
+ /**
216
+ * Name of the library. The default name should be `syslib` if using unamed libraries.
217
+ */
218
+ name: string;
219
+ /**
220
+ * The type of the property group defining where dependencies should be located. Allowed values are 'local' for using a local workspace and 'mvs' for dependencies located in MVS Datasets.
221
+ */
222
+ type: 'mvs' | 'local';
223
+ /**
224
+ * An array of include file locations. For 'local' libraries values can be absolute and relative filename paths using GLOB patterns. For 'mvs' libraries value can be data set names. GLOB patterns for dat sets are currently not supported.
225
+ */
226
+ locations: [string, ...string[]];
227
+ }
228
+ /**
229
+ * DBB build script properties for running User Build on remote host.
230
+ */
231
+ export interface DbbSettingsItem {
232
+ /**
233
+ * Defines the name of the application to build. Will be used to create a folder on USS to upload all files to.
234
+ */
235
+ application: string;
236
+ /**
237
+ * Command that the build script is executed with such as the path to groovyz and it's parameters.
238
+ */
239
+ command: string;
240
+ /**
241
+ * The full path of build script on the remote host that should be used with the command.
242
+ */
243
+ buildScriptPath?: string;
244
+ /**
245
+ * A list of strings that are the parameters for the build script. Check the documentation for built-in variables, such as the name of the program to build, that can be used here.
246
+ */
247
+ buildScriptArgs?: string[];
248
+ /**
249
+ * Lists of GLOB patterns that define the files that should be uploaded to USS for a build. Relative path names are interpreted relative to the location of the ZAPP file that is being used for the build, which is a ZAPP file in the same workspace as the program to be build.
250
+ */
251
+ additionalDependencies?: string[];
252
+ /**
253
+ * Lists of GLOB patterns that define the files that should be downloaded from USS after the build. Relative path names are interpreted relative to the DBB log directory user setting. If not provided then all files of the user setting location will be downloaded.
254
+ */
255
+ logFilePatterns?: string[];
256
+ }
257
+ /**
258
+ * RSE API client settings for interactions with a z/OS remote host running an RSE API server.
259
+ */
260
+ export interface RseapiSettingsItem {
261
+ /**
262
+ * A list of mapping objects that map local file extensions to transfer modes and encodings to MVS datasets that can be specified using wildcards.
263
+ */
264
+ mappings: RseapiSettingsItemMapping[];
265
+ /**
266
+ * The encoding to be used when no mapping can be found. If not provided then either the user or server default will be used.
267
+ */
268
+ 'default.encoding': string;
269
+ }
270
+ /**
271
+ * One mapping that contains at least transfer and resource values.
272
+ */
273
+ export interface RseapiSettingsItemMapping {
274
+ /**
275
+ * A local file extension such as cbl or pl1.
276
+ */
277
+ extension?: string;
278
+ /**
279
+ * The transfer mode to be used. Can be 'text' or 'binary'.
280
+ */
281
+ transfer?: 'text' | 'binary';
282
+ /**
283
+ * The data set name to be mapped to. Can use a wildcard such as '**CPY'.
284
+ */
285
+ resource?: string;
286
+ /**
287
+ * The encoding to be used for text transfer. See the RSE API documentation for the values allowed.
288
+ */
289
+ encoding?: string;
290
+ /**
291
+ * A nested mappings array with resource mappings to members of the data sets that were mapped by the parent mapping.
292
+ */
293
+ memberMappings?: {
294
+ /**
295
+ * A local file extension such as cbl or pl1.
296
+ */
297
+ extension?: string;
298
+ /**
299
+ * The transfer mode to be used. Can be 'text' or 'binary'.
300
+ */
301
+ transfer?: 'text' | 'binary';
302
+ /**
303
+ * The encoding to be used for text transfer. See the RSE API documentation for the values allowed.
304
+ */
305
+ encoding?: string;
306
+ /**
307
+ * The data set member name to be mapped to. Can use a wildcard such as '**CPY'.
308
+ */
309
+ resource?: string;
310
+ }[];
311
+ }
312
+ /**
313
+ * A meta-data representation of a zapp file
314
+ * providing path and type.
315
+ */
316
+ export interface ZappFile {
317
+ path: string;
318
+ type: 'json' | 'yaml';
319
+ }
320
+ /**
321
+ * Represent ZAPP documents that are stored either as yaml or json files.
322
+ * Features various factory method to create instances for workspace locations or absolute file names.
323
+ */
324
+ export class ZappDocumentInstance extends SchemaDocumentInstance {
325
+ type: string;
326
+ protected static validationFunction: ValidateFunction<unknown>;
327
+ /**
328
+ * Creates a ZappDocumentInstance with a yaml string.
329
+ * @param {string} zappYamlString
330
+ * @returns {ZappDocumentInstance}
331
+ */
332
+ static createFromYamlString(zappYamlString: string): ZappDocumentInstance;
333
+ /**
334
+ * Creates a ZappDocumentInstance with a json string.
335
+ * @param {string} zappJsonString
336
+ * @returns {ZappDocumentInstance}
337
+ */
338
+ static createFromJsonString(zappJsonString: string): ZappDocumentInstance;
339
+ /**
340
+ * Creates a ZappDocumentInstance with a yaml file path
341
+ * @param {string} filepath absolute path name
342
+ * @returns {Promise<ZappDocumentInstance>} promise that will resolve into an instantiated ZappDocumentInstance.
343
+ * If no document was found or it contained errors then these errors will be populated in the object.
344
+ */
345
+ static createFromYamlFile(filepath: string): Promise<ZappDocumentInstance>;
346
+ /**
347
+ * Creates a ZappDocumentInstance with a json file path
348
+ * @param {string} filepath absolute path name
349
+ * @returns {Promise<ZappDocumentInstance>} promise that will resolve into an instantiated ZappDocumentInstance.
350
+ * If no document was found or it contained errors then these errors will be populated in the object.
351
+ */
352
+ static createFromJsonFile(filepath: string): Promise<ZappDocumentInstance>;
353
+ /**
354
+ * Creates a ZappDocumentInstance from a file. Checks the file type automatically.
355
+ * @param {string} filepath absolute path name
356
+ * @returns {Promise<ZappDocumentInstance>} promise that will resolve into an instantiated ZappDocumentInstance.
357
+ * If no document was found or it contained errors then these errors will be populated in the object.
358
+ */
359
+ static createFromFile(filepath: string): Promise<ZappDocumentInstance>;
360
+ /**
361
+ * Creates a ZappDocumentInstance by looking for a zapp file in a directory.
362
+ * Checks the file type automatically. Will always prioritize yaml over json.
363
+ * @param {string} workspacePath absolute path name
364
+ * @returns {Promise<ZappDocumentInstance>} promise that will resolve into an instantiated ZappDocumentInstance.
365
+ * If no document was found or it contained errors then these errors will be populated in the object.
366
+ */
367
+ static loadFromWorkspace(workspacePath: string): Promise<ZappDocumentInstance>;
368
+ /**
369
+ * Looks for zapp files in a directory. Will always prioritize yaml over json.
370
+ * @param {string} workspacePath absolute path name
371
+ * @returns {(ZappFile | undefined)} An instance of ZappFile or undefined if not found
372
+ */
373
+ static findZappFile(workspacePath: string): ZappFile | undefined;
374
+ /**
375
+ * @param {string} filename string that represent a filename; not a path
376
+ * @returns {boolean} true if filename is either zapp.json, zapp.yml, or zapp.yaml
377
+ */
378
+ static isZappFileName(filename: string): boolean;
379
+ /**
380
+ * @returns {(IBMZappDocument | undefined)} returns the ZAPP document as an instance of the IBMZappDocument interface
381
+ */
382
+ getAsDocument<IBMZappDocument>(): IBMZappDocument | undefined;
383
+ /**
384
+ * Can be called to check that the document complies with the schema json-schema.
385
+ * If validation errors are found then they will added to the errorMessages member.
386
+ * @returns {boolean} false if validation errors were found
387
+ */
388
+ validate(): boolean;
389
+ }
390
+ /**
391
+ * Class that finds, loads, and caches instances of zapp files in memory.
392
+ */
393
+ export class ZappDocumentsCache extends SchemaDocumentCache {
394
+ static cacheType: string;
395
+ protected static getInstance(): ZappDocumentsCache;
396
+ protected static resetInstance(): void;
397
+ /**
398
+ * Retrieves a zapp file from the cache. Although the file to retrieve is provided to
399
+ * identify the file, it will not load it into the cache if not found to keep access to the
400
+ * cache synchronous. Undefined will return, which could then be used to call loadZappDocument()
401
+ * to load it an place it in the cache.
402
+ * @param filePath absolute path to the zapp file
403
+ * @returns {(Promise<ZappDocumentInstance | undefined>)} undefined if file was not cached, yet
404
+ */
405
+ static getZappDocument(filePath: string): ZappDocumentInstance | undefined;
406
+ /**
407
+ * Asynchronously loads a zapp file from the path provided.
408
+ * @param {string} filePath absolute path to the zapp file
409
+ * @returns {(Promise<ZappDocumentInstance | undefined>)} undefined if invalid path was provided.
410
+ * In case of loading errors ZappDocumentInstance will contain error messages.
411
+ */
412
+ static loadZappDocument(filePath: string, workspacePath: string): Promise<ZappDocumentInstance | undefined>;
413
+ /**
414
+ * Removes a document from the cache.
415
+ * @param filePath absolute path to the zapp file
416
+ */
417
+ static clearZappDocument(filePath: string): void;
418
+ /**
419
+ * Gets the cached ZAPP document for the workspace path provided.
420
+ * Assumes that the document cache has been updated with the latest file, e.g. by a watcher.
421
+ * @param workspacePath absolute path to the workspace that contains a zapp file
422
+ * @returns {ZappDocumentInstance | undefined} undefined if invalid path was provided.
423
+ */
424
+ static getZappDocumentInWorkspace(workspacePath: string): ZappDocumentInstance | undefined;
425
+ /**
426
+ * Looks for a ZAPP file with various file extensions in the workspace directory and
427
+ * loads the best match into the cache.
428
+ * @param {string} workspacePath path to the workspace in which a zapp file resides
429
+ * @returns {(Promise<ZappDocumentInstance | undefined>)} undefined if invalid path was provided.
430
+ * In case of loading errors ZappDocumentInstance will contain error messages.
431
+ */
432
+ static loadZappDocumentInWorkspace(workspacePath: string): Promise<ZappDocumentInstance | undefined>;
433
+ isValidFilename(filename: string): boolean;
434
+ static getCacheStats(): Record<string, unknown>;
435
+ static clearCache(): void;
436
+ }
437
+ /**
438
+ * A collection of business logic for accessing, manipulating, validating
439
+ * property groups in ZAPP documents.
440
+ */
441
+ export class PropertyGroupsController {
442
+ /**
443
+ * Basic accessor method for reading property groups in a workspace.
444
+ * @param {string} workspacePath absolute path to the workspace that contains zapp.yaml or zapp.json
445
+ * @param {string} [language] optional filter by language which will include property groups without a language property
446
+ * @returns {zapp.PropertyGroupItem[]} an array of property groups found
447
+ */
448
+ static getPropertyGroups(workspacePath: string, language?: string): PropertyGroupItem[];
449
+ }
450
+ /**
451
+ * A collection of business logic for accessing, manipulating, validating
452
+ * user build data in ZAPP documents.
453
+ *
454
+ * Conventions used:
455
+ * - load methods are async and load from disk
456
+ * - get methods are sync as they assume zapp is in cache
457
+ * - workspacePath is the path to the zapp file folder; not the absolute path the file
458
+ */
459
+ export class ZappProfilesController {
460
+ /**
461
+ * Gets all the profiles found in a ZAPP file loaded from the path specified.
462
+ * This call assumes that the ZAPP files was already loaded by the client, i.e.
463
+ * during editor startup or some other asynchronous call to loadZappProfiles().
464
+ *
465
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
466
+ * @returns {(zapp.Profile[] | undefined)}
467
+ */
468
+ static getZappProfiles(workspacePath: string): Profile[] | undefined;
469
+ /**
470
+ * Loads a ZAPP file from the path specified and returns all the profiles found in the doc.
471
+ *
472
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
473
+ * @returns {(Promise<zapp.Profile[] | undefined>)}
474
+ */
475
+ static loadZappProfiles(workspacePath: string): Promise<Profile[] | undefined>;
476
+ }
477
+ export const zappConstants: {
478
+ profileTypeDbb: string;
479
+ profileTypeRseApi: string;
480
+ propertyPropertyGroups: string;
481
+ };
482
+ /**
483
+ * A collection of business logic for accessing, manipulating, validating
484
+ * user build data in ZAPP documents.
485
+ */
486
+ export class UserBuildController extends ZappProfilesController {
487
+ /**
488
+ * @param {string} workspacePath the location of the workspace with a zapp file
489
+ * @returns {(string[] | undefined)} a list of DBB profiles defined in the zapp file
490
+ */
491
+ static getUserBuildProfileNames(workspacePath: string): string[] | undefined;
492
+ /**
493
+ * @param {string} workspacePath the location of the workspace with a zapp file
494
+ * @param {string} [profileName] optional, if multiple DBB profiles are available then qualify by name
495
+ * @returns {(zapp.DbbSettingsItem | undefined)}
496
+ * DbbSettingsItem object of the profile that matches the profileName
497
+ * or if omitted the first one found. Undefined if not available.
498
+ */
499
+ static getUserBuildSettings(workspacePath: string, profileName?: string): DbbSettingsItem | undefined;
500
+ }
501
+ /**
502
+ * A collection of business logic for accessing, manipulating, validating
503
+ * rse api mappings in ZAPP documents.
504
+ *
505
+ * Conventions used:
506
+ * - load methods are async and load from disk
507
+ * - get methods are sync as they assume zapp is in cache
508
+ * - workspacePath is the path to the zapp file folder; not the absolute path the file
509
+ */
510
+ export class RseApiController extends ZappProfilesController {
511
+ /**
512
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
513
+ * @returns {(string[] | undefined)} Returns the list of all the profiles founds in a currently caches ZAPP file
514
+ */
515
+ static getRseApiProfileNames(workspacePath: string): string[] | undefined;
516
+ /**
517
+ * Validation check to test if a ZAPP file only contains only one Mappings profile
518
+ *
519
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
520
+ * @returns {boolean} True if one entry was found
521
+ */
522
+ static onlyOneMappingsEntry(workspacePath: string): boolean;
523
+ /**
524
+ * Requires that the ZAPP file was already cached. If in doubt call loadRseApiSettings()
525
+ *
526
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
527
+ * @returns {(zapp.RseapiSettingsItem | undefined)} Returns the settings specified for an RSE API profile
528
+ */
529
+ static getRseApiSettings(workspacePath: string): RseapiSettingsItem | undefined;
530
+ /**
531
+ * Loads a ZAPP file from the specified path and return RSE API settings.
532
+ *
533
+ * @param {string} workspacePath Path to a folder in which a zapp file can be found
534
+ * @returns {(Promise<zapp.RseapiSettingsItem | undefined>)} Returns the settings specified for an RSE API profile
535
+ */
536
+ static loadRseApiSettings(workspacePath: string): Promise<RseapiSettingsItem | undefined>;
537
+ }
538
+
539
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ var e=require("fs"),t=require("yawn-yaml/cjs"),i=require("path"),s=require("os"),r=require("js-yaml"),a=require("ajv"),n=require("ajv-formats");function o(e,t){return Object.keys(t).forEach((function(i){"default"===i||"__esModule"===i||e.hasOwnProperty(i)||Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[i]}})})),e}function p(e){return e&&e.__esModule?e.default:e}function c(e,t,i,s){Object.defineProperty(e,t,{get:i,set:s,enumerable:!0,configurable:!0})}var l={},d={},h={};c(h,"SchemaDocumentInstance",(()=>m));class m{isValid=!1;constructor(e,i){i&&this.prependErrorMessage(i);try{this.yawn=new(p(t))(e),this.validate()}catch(e){this.prependErrorMessage(e?.message)}}getAsYaml(){return this.yawn?.yaml}getAsJson(){return JSON.stringify(this.yawn?.json)}getAsObject(){return this.yawn?.json}static async readFileWithRetry(t){let i="";for(let s=0;s<10;s++){if(i=await e.promises.readFile(t,"utf8"),i)return i;await new Promise((e=>setTimeout(e,100)))}return i}write(){if(this.isValid){if(this.file?.path){let t="# Undefined "+this.type+" document.";"json"===this.file.type&&(t=JSON.stringify(this.getAsObject())),"yaml"===this.file.type&&(t=this.getAsYaml()||t),e.writeFileSync(this.file.path,t,{encoding:"utf-8"})}}else this.appendErrorMessage(`Tried to write invalid document "${this.file?.path}"`)}appendErrorMessage(e){const t=this.errorMessages?`${this.errorMessages}\n`:"";this.errorMessages=`${t}- ${e||"Unknown Error reading "+this.type+" file."}`}prependErrorMessage(e){const t=this.errorMessages?`\n${this.errorMessages}`:"";this.errorMessages=`- ${e||"Unknown Error reading "+this.type+" file."}${t}`}}var u={};c(u,"SchemaDocumentCache",(()=>f));class f{constructor(e){this.type=e,this.documentsCache=new Map,this.workspacesMap=new Map,this.numberDocsAdded=0,this.numberDocsRemoved=0,this.numberDocsFound=0}addDocument(e,t,i){this.documentsCache.set(e,i),this.workspacesMap.set(t,e)}clearSchemaDocument(e){if(!e)return;const t=this.normalizePath(e),s=i.dirname(t);this.workspacesMap.has(s)&&this.workspacesMap.delete(s),this.documentsCache.has(t)&&(this.documentsCache.delete(t),this.numberDocsRemoved++)}clearCache(){this.workspacesMap.clear(),this.documentsCache.clear()}getCacheStats(){return{documentsCacheSize:this.documentsCache.size,workspacesMapSize:this.workspacesMap.size,numberDocsAdded:this.numberDocsAdded,numberDocsRemoved:this.numberDocsRemoved,numberDocsFound:this.numberDocsFound}}normalizePath(e){if(!e||!i.isAbsolute(e))return e;let t=i.normalize(e);if("win32"===s.platform()){const e=i.basename(t);if(this.isValidFilename(e)){const s=i.dirname(t);t=i.join(s.toUpperCase(),e)}else t=t.toUpperCase()}return t}}o(d,h),o(d,u),o(l,d);var g={},y={},b={};c(b,"PropertyGroupsController",(()=>j));var w={};c(w,"ZappDocumentsCache",(()=>S));var v={};c(v,"ZappDocumentInstance",(()=>P));var I;I=JSON.parse('{"$schema":"http://json-schema.org/draft-07/schema#","title":"IBM Zapp Document","description":"JSON schema for zapp.json and zapp.yaml files. Version 1.0.0 -- Licensed Materials - Property of IBM - (c) Copyright IBM Corporation 2022. All Rights Reserved.","type":"object","definitions":{"coreProperties":{"type":"object","required":["name"],"additionalProperties":false,"properties":{"name":{"description":"The name of the Z Project.","type":"string","maxLength":214,"minLength":1},"description":{"description":"This helps people understand your project as it would be used by tools.","type":"string"},"version":{"description":"Version is a string and it must be parsable for managing dependencies.","type":"string","default":"1.0.0"},"groupId":{"description":"Defines a group name that is shared for each application part in case of applications composed of multiple parts. Allows to uniquely identify the parts by concatenating with the artifact id. For example a groupId `com.ibm.wazi` with an artifactId `service` would create the unique application identifier `com.ibm.wazi.service`.","type":"string","examples":["com.ibm.wazi","payments"]},"artifactId":{"description":"Define id of the application artifact. Use it in combination with a groupId for multi-part applications.","type":"string","default":"","examples":["sam"]},"parentId":{"description":"In case of a multi-part application defines the name of the parent application part. This zapp will inherit properties such as propertyGroups defined in the parent.","type":"string","default":"","examples":["com.ibm.wazi.parent"]},"keywords":{"description":"This helps people discover your project.","type":"array","items":{"type":"string"}},"homepage":{"description":"The url to the project homepage.","type":"string","oneOf":[{"format":"uri"},{"enum":["."]}]},"license":{"type":"string","description":"You should specify a license for your package so that people know how they are permitted to use it and any restrictions you\'re placing on it."},"author":{"$ref":"#/definitions/person"},"contributors":{"description":"A list of people who contributed to this package.","type":"array","items":{"$ref":"#/definitions/person"},"minItems":1},"maintainers":{"description":"A list of people who maintain this package.","type":"array","items":{"$ref":"#/definitions/person"},"minItems":1},"propertyGroups":{"description":"A list properties defining path names for resolving dependencies.","type":"array","items":{"$ref":"#/definitions/propertyGroupItem"},"minItems":1},"profiles":{"description":"Profiles are additional groups of properties that should only should become valid under specific conditions such as running in a build job or as part of a debug session.","type":"array","items":{"$ref":"#/definitions/profile"},"minItems":1}}},"propertyGroupItem":{"type":"object","additionalProperties":false,"required":["name"],"properties":{"name":{"type":"string","description":"The name of the property group, which is used in hovers and error messages.","examples":["sample-local"]},"language":{"type":"string","enum":["cobol","pl1","hlasm","rexx","jcl"],"description":"Limits the property group to one specific language."},"compilerOptions":{"type":"string","description":"Global compiler options separated by a comma that impact the parsing of the programs for the editor. Requires that you specify a language. If there are multiple Property Groups for a language with compiler option then they will be concatenated."},"libraries":{"type":"array","description":"An array of potential library locations defining the search order for include files. Libraries with the name \'syslib\' will be handled as default include locations. The list can contain many entries of the type \'local\' or \'mvs\'. It can contain items of the same type twice in case, for example, you want to search in remote locations first, then some local location, and if still not found more remote locations.","items":{"$ref":"#/definitions/libraryItem"},"minItems":1}}},"libraryItem":{"type":"object","additionalProperties":false,"required":["name","type","locations"],"properties":{"name":{"type":"string","description":"Name of the library. The default name should be `syslib` if using unamed libraries.","default":"syslib","examples":["syslib","currencylib"]},"type":{"type":"string","enum":["mvs","local"],"description":"The type of the property group defining where dependencies should be located. Allowed values are \'local\' for using a local workspace and \'mvs\' for dependencies located in MVS Datasets.","default":"local","examples":["local","mvs"]},"locations":{"type":"array","description":"An array of include file locations. For \'local\' libraries values can be absolute and relative filename paths using GLOB patterns. For \'mvs\' libraries value can be data set names. GLOB patterns for dat sets are currently not supported.","items":{"type":"string"},"minItems":1,"examples":["**/copybook","USER1.SAMPLE.COBCOPY"]}}},"person":{"description":"A person who has been involved in creating or maintaining this package","type":["object","string"],"required":["name"],"properties":{"name":{"type":"string"},"url":{"type":"string","format":"uri"},"email":{"type":"string","format":"email"}}},"profile":{"type":"object","description":"Profiles are additional groups of properties that should only should become valid under specific conditions such as running in a build job or as part of a debug session.","additionalProperties":false,"required":["name","type"],"properties":{"name":{"type":"string","description":"The name of the profile.","examples":["dbb-build"]},"type":{"type":"string","enum":["dbb","rseapi","debug"],"description":"The type of the profile.","default":"dbb","examples":["dbb","rseapi"]},"settings":{"description":"Settings objects specific to the type specified for the profile.","type":"object"}},"anyOf":[{"required":["name","type","settings"],"additionalProperties":false,"properties":{"name":{"type":"string"},"type":{"const":"dbb","type":"string"},"settings":{"$ref":"#/definitions/dbbSettingsItem"}}},{"required":["name","type","settings"],"additionalProperties":false,"properties":{"name":{"type":"string"},"type":{"const":"rseapi","type":"string"},"settings":{"$ref":"#/definitions/rseapiSettingsItem"}}}]},"dbbSettingsItem":{"type":"object","additionalProperties":false,"required":["application","command"],"description":"DBB build script properties for running User Build on remote host.","properties":{"application":{"type":"string","description":"Defines the name of the application to build. Will be used to create a folder on USS to upload all files to."},"command":{"type":"string","description":"Command that the build script is executed with such as the path to groovyz and it\'s parameters."},"buildScriptPath":{"type":"string","description":"The full path of build script on the remote host that should be used with the command."},"buildScriptArgs":{"type":"array","items":{"type":"string"},"description":"A list of strings that are the parameters for the build script. Check the documentation for built-in variables, such as the name of the program to build, that can be used here."},"additionalDependencies":{"type":"array","items":{"type":"string"},"description":"Lists of GLOB patterns that define the files that should be uploaded to USS for a build. Relative path names are interpreted relative to the location of the ZAPP file that is being used for the build, which is a ZAPP file in the same workspace as the program to be build."},"logFilePatterns":{"type":"array","items":{"type":"string"},"description":"Lists of GLOB patterns that define the files that should be downloaded from USS after the build. Relative path names are interpreted relative to the DBB log directory user setting. If not provided then all files of the user setting location will be downloaded."}}},"rseapiSettingsItem":{"type":"object","additionalProperties":false,"description":"RSE API client settings for interactions with a z/OS remote host running an RSE API server.","required":["mappings","default.encoding"],"properties":{"mappings":{"type":"array","description":"A list of mapping objects that map local file extensions to transfer modes and encodings to MVS datasets that can be specified using wildcards.","items":{"$ref":"#/definitions/rseapiSettingsItemMapping"}},"default.encoding":{"type":"string","description":"The encoding to be used when no mapping can be found. If not provided then either the user or server default will be used."}}},"rseapiSettingsItemMapping":{"type":"object","additionalProperties":false,"description":"One mapping that contains at least transfer and resource values.","properties":{"extension":{"type":"string","description":"A local file extension such as cbl or pl1."},"transfer":{"type":"string","enum":["text","binary"],"description":"The transfer mode to be used. Can be \'text\' or \'binary\'."},"resource":{"type":"string","description":"The data set name to be mapped to. Can use a wildcard such as \'**CPY\'."},"encoding":{"type":"string","description":"The encoding to be used for text transfer. See the RSE API documentation for the values allowed."},"memberMappings":{"type":"array","items":{"type":"object","additionalProperties":false,"description":"One member mapping that contains at least transfer and resource values.","properties":{"extension":{"type":"string","description":"A local file extension such as cbl or pl1."},"transfer":{"type":"string","enum":["text","binary"],"description":"The transfer mode to be used. Can be \'text\' or \'binary\'."},"encoding":{"type":"string","description":"The encoding to be used for text transfer. See the RSE API documentation for the values allowed."},"resource":{"type":"string","description":"The data set member name to be mapped to. Can use a wildcard such as \'**CPY\'."}}},"description":"A nested mappings array with resource mappings to members of the data sets that were mapped by the parent mapping."}}}},"anyOf":[{"$ref":"#/definitions/coreProperties"}]}');class P extends m{type="zapp";static validationFunction=P.initAjvValidator();static initAjvValidator(){const e=new(p(a))({allErrors:!0,strictTuples:!1,allowUnionTypes:!0});return p(n)(e),e.compile(I)}static createFromYamlString(e){return new P(e)}static createFromJsonString(e){let t="";try{const i=JSON.parse(e);return t=r.dump(i),this.createFromYamlString(t)}catch(e){return new P(t,e?.message||e)}}static async createFromYamlFile(e){let t="";try{t=await this.readFileWithRetry(e);const i=this.createFromYamlString(t);return i.file={path:e,type:"yaml"},i}catch(e){return new P(t,e?.message||e)}}static async createFromJsonFile(e){let t="";try{t=await this.readFileWithRetry(e);const i=this.createFromJsonString(t);return i.file={path:e,type:"json"},i}catch(e){return new P(t,e?.message||e)}}static async createFromFile(e){return e?.endsWith(".yaml")||e?.endsWith(".yml")?await this.createFromYamlFile(e):e?.endsWith(".json")?await this.createFromJsonFile(e):new P("","Invalid filename for reading a ZAPP file.")}static async loadFromWorkspace(e){const t=this.findZappFile(e);return"yaml"===t?.type?await this.createFromYamlFile(t.path):"json"===t?.type?await this.createFromJsonFile(t.path):new P("",`No ZAPP file was found in "${e}".`)}static findZappFile(t){if(!t)return;const s=i.normalize(t),r=i.join(s,"zapp.yaml");if(e.existsSync(r))return{path:r,type:"yaml"};const a=i.join(s,"zapp.yml");if(e.existsSync(a))return{path:a,type:"yaml"};const n=i.join(s,"zapp.json");return e.existsSync(n)?{path:n,type:"json"}:void 0}static isZappFileName(e){return/^(zapp\.)(yml|yaml|json)$/.test(e)}getAsDocument(){try{const e=this.yawn.json;if(e)return e}catch(e){this.prependErrorMessage(e?.message)}}validate(){if(this.yawn){if(this.isValid=P.validationFunction(this.getAsObject()),!this.isValid){const e=P.validationFunction.errors;return e?e.forEach((e=>{let t=e.message;if(e.params){const i=e.params;t=`${t}(${Object.keys(i).map((e=>`${e}:${i[e]}`))})`}this.appendErrorMessage(t)})):this.appendErrorMessage("Unknown validation error."),!1}return!0}return!1}}class S extends f{static cacheType="zapp";static getInstance(){return this.instance||(this.instance=new S(this.cacheType)),this.instance}static resetInstance(){this.instance=void 0}static getZappDocument(e){if(!e)return;const t=this.getInstance().normalizePath(e);return this.getInstance().documentsCache.has(t)?(this.getInstance().numberDocsFound++,this.getInstance().documentsCache.get(t)):void 0}static async loadZappDocument(e,t){if(!e)return;const i=this.getInstance().normalizePath(e);if(this.getInstance().documentsCache.has(i))return this.getInstance().numberDocsFound++,this.getInstance().documentsCache.get(i);const s=await P.createFromFile(i);return this.getInstance().addDocument(e,t,s),this.getInstance().numberDocsAdded++,s}static clearZappDocument(e){this.getInstance().clearSchemaDocument(e)}static getZappDocumentInWorkspace(e){if(!e)return;const t=this.getInstance().normalizePath(e),i=this.getInstance().workspacesMap.get(t);return i?this.getZappDocument(i):void 0}static async loadZappDocumentInWorkspace(e){const t=this.getInstance().normalizePath(e),i=P.findZappFile(t);if(i){const s=await this.loadZappDocument(i.path,e);return this.getInstance().workspacesMap.set(t,i.path),s}}isValidFilename(e){return P.isZappFileName(e)}static getCacheStats(){return this.getInstance().getCacheStats()}static clearCache(){this.getInstance().clearCache(),this.resetInstance()}}class j{static getPropertyGroups(e,t){let i=[];const s=S.getZappDocumentInWorkspace(e);if(s&&!s.errorMessages){const e=s.getAsDocument();if(e){const s=e.propertyGroups;s&&(i=s,t&&(i=s.filter((e=>!e.language||e.language===t))))}}return i}}var A={};c(A,"UserBuildController",(()=>x));var D={};c(D,"ZappProfilesController",(()=>F));class F{static getZappProfiles(e){const t=S.getZappDocumentInWorkspace(e);if(!t||t.errorMessages)return;const i=t.getAsDocument();return i&&i.profiles&&0!==i.profiles.length?i.profiles:void 0}static async loadZappProfiles(e){if(await S.loadZappDocumentInWorkspace(e))return this.getZappProfiles(e)}}var M={};c(M,"zappConstants",(()=>C));const C={profileTypeDbb:"dbb",profileTypeRseApi:"rseapi",propertyPropertyGroups:"propertyGroups"};class x extends F{static getUserBuildProfileNames(e){const t=this.getZappProfiles(e);if(t&&t.length>0)return t.filter((e=>e.type===C.profileTypeDbb)).map((e=>e.name))}static getUserBuildSettings(e,t){const i=this.getZappProfiles(e);if(i&&i.length>0){if(!t){return i.find((e=>e.type===C.profileTypeDbb))?.settings}{const e=i.find((e=>e.name===t));if(e?.type===C.profileTypeDbb)return e.settings}}}}var T={};c(T,"RseApiController",(()=>Z));class Z extends F{static getRseApiProfileNames(e){const t=this.getZappProfiles(e);if(t&&t.length>0)return t.filter((e=>e.type===C.profileTypeRseApi)).map((e=>e.name))}static onlyOneMappingsEntry(e){return 1===this.getRseApiProfileNames(e)?.length}static getRseApiSettings(e){const t=this.getZappProfiles(e);if(t&&t.length>0){return t.find((e=>e.type===C.profileTypeRseApi))?.settings}}static async loadRseApiSettings(e){if(await this.loadZappProfiles(e))return this.getRseApiSettings(e)}}o(y,b),o(y,A),o(y,T),o(y,D);var k={};o(k,{}),o(k,v),o(k,w),o(k,M),o(g,y),o(g,k),o(module.exports,l),o(module.exports,g);