@sasjs/adapter 6.1.8 → 6.2.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.
@@ -406,12 +406,18 @@ class SASViyaApiClient {
406
406
  logger.info(`Parent folder '${newFolderName}' has been successfully created.`);
407
407
  parentFolderUri = `/folders/folders/${parentFolder.id}`;
408
408
  }
409
- else if (isForced) {
410
- const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
411
- const folderUri = yield this.getFolderUri(folderPath, accessToken);
412
- if (folderUri) {
413
- yield this.deleteFolder(folderPath, accessToken);
414
- }
409
+ }
410
+ // The forced delete of the folder being created is keyed on its path, not on
411
+ // how the parent was found: a caller that supplies the parent's URI (the
412
+ // service pack deploy does, to save a lookup per member) still expects an
413
+ // existing folder of this name to be replaced rather than refused with 409.
414
+ // When the parent itself did not exist there is nothing here to delete, and
415
+ // the lookup is a 404 the caller never sees.
416
+ if (isForced && parentFolderPath) {
417
+ const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
418
+ const folderUri = yield this.getFolderUri(folderPath, accessToken);
419
+ if (folderUri) {
420
+ yield this.deleteFolder(folderPath, accessToken);
415
421
  }
416
422
  }
417
423
  const { result: createFolderResponse } = yield this.requestClient
package/SASjs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SASjsConfig, UploadFile, EditContextInput, PollOptions, VerboseMode, LoginOptions, LoginResult, ExecutionQuery, Tables } from './types';
1
+ import { SASjsConfig, UploadFile, EditContextInput, PollOptions, VerboseMode, LoginOptions, LoginResult, ExecutionQuery, Tables, DeployProgress } from './types';
2
2
  import { SASViyaApiClient } from './SASViyaApiClient';
3
3
  import { SASjsAuthResponse } from './SASjsApiClient';
4
4
  import { OnTokensRefreshed } from './auth/getTokens';
@@ -361,8 +361,13 @@ export default class SASjs {
361
361
  * @param accessToken - an optional access token to be passed in when
362
362
  * using this function from the command line.
363
363
  * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
364
+ * @param onProgress - optional callback invoked once per member, immediately
365
+ * before the member is written, with its name, folder, type and position. A
366
+ * Viya deploy is one REST call per folder, file and job definition, run in
367
+ * sequence, so this is the only signal a caller has that a large pack is
368
+ * still moving rather than hung.
364
369
  */
365
- deployServicePack(serviceJson: any, appLoc?: string, serverUrl?: string, accessToken?: string, isForced?: boolean): Promise<void>;
370
+ deployServicePack(serviceJson: any, appLoc?: string, serverUrl?: string, accessToken?: string, isForced?: boolean, onProgress?: (progress: DeployProgress) => void): Promise<void>;
366
371
  /**
367
372
  * Kicks off execution of the given job via the compute API.
368
373
  * @returns an object representing the compute session created for the given job.
package/SASjs.js CHANGED
@@ -615,9 +615,14 @@ class SASjs {
615
615
  * @param accessToken - an optional access token to be passed in when
616
616
  * using this function from the command line.
617
617
  * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
618
+ * @param onProgress - optional callback invoked once per member, immediately
619
+ * before the member is written, with its name, folder, type and position. A
620
+ * Viya deploy is one REST call per folder, file and job definition, run in
621
+ * sequence, so this is the only signal a caller has that a large pack is
622
+ * still moving rather than hung.
618
623
  */
619
624
  deployServicePack(serviceJson_1, appLoc_1, serverUrl_1, accessToken_1) {
620
- return __awaiter(this, arguments, void 0, function* (serviceJson, appLoc, serverUrl, accessToken, isForced = false) {
625
+ return __awaiter(this, arguments, void 0, function* (serviceJson, appLoc, serverUrl, accessToken, isForced = false, onProgress) {
621
626
  this.isMethodSupported('deployServicePack', [types_2.ServerType.SasViya]);
622
627
  let sasApiClient = null;
623
628
  if (serverUrl || appLoc) {
@@ -649,7 +654,11 @@ class SASjs {
649
654
  serviceJson.members[0].members.sort((member) => member.type === 'folder' ? -1 : 1);
650
655
  }
651
656
  const members = serviceJson.members;
652
- yield this.createFoldersAndServices(appLoc, members, accessToken, sasApiClient, isForced);
657
+ yield this.createFoldersAndServices(appLoc, members, accessToken, sasApiClient, isForced, {
658
+ onProgress,
659
+ index: 0,
660
+ total: countMembers(members)
661
+ });
653
662
  });
654
663
  }
655
664
  /**
@@ -797,24 +806,36 @@ class SASjs {
797
806
  this.computeJobExecutor = new job_execution_1.ComputeJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
798
807
  this.jesJobExecutor = new job_execution_1.JesJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
799
808
  }
800
- createFoldersAndServices(parentFolder, membersJson, accessToken, sasApiClient, isForced) {
801
- return __awaiter(this, void 0, void 0, function* () {
809
+ createFoldersAndServices(parentFolder_1, membersJson_1, accessToken_1, sasApiClient_1, isForced_1) {
810
+ return __awaiter(this, arguments, void 0, function* (parentFolder, membersJson, accessToken, sasApiClient, isForced, progress = {
811
+ index: 0,
812
+ total: countMembers(membersJson)
813
+ }, parentFolderUri) {
802
814
  yield (0, utils_1.asyncForEach)(membersJson, (member) => __awaiter(this, void 0, void 0, function* () {
803
815
  switch (member.type) {
804
- case 'folder':
805
- yield this.createFolder(member.name, parentFolder, undefined, accessToken, sasApiClient, isForced);
816
+ case 'folder': {
817
+ reportMember(progress, 'folder', member.name, parentFolder);
818
+ const folder = yield this.createFolder(member.name, parentFolder, parentFolderUri, accessToken, sasApiClient, isForced);
819
+ if (member.members && member.members.length) {
820
+ const folderPath = `${parentFolder}/${member.name}`;
821
+ yield this.createFoldersAndServices(folderPath, member.members, accessToken, sasApiClient, isForced, progress,
822
+ // the folder the deploy has just created, so its children do not
823
+ // each resolve the same path back to a URI
824
+ (folder === null || folder === void 0 ? void 0 : folder.id) ? `/folders/folders/${folder.id}` : undefined);
825
+ }
806
826
  break;
827
+ }
807
828
  case 'file':
808
- yield this.createFile(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
829
+ reportMember(progress, 'file', member.name, parentFolder);
830
+ yield this.createFile(member.name, member.code, parentFolder, parentFolderUri, accessToken, sasApiClient);
809
831
  break;
810
832
  case 'service':
811
- yield this.createJobDefinition(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
833
+ reportMember(progress, 'service', member.name, parentFolder);
834
+ yield this.createJobDefinition(member.name, member.code, parentFolder, parentFolderUri, accessToken, sasApiClient);
812
835
  break;
813
836
  default:
814
837
  throw new Error(`Unidentified member '${member.name}' provided.`);
815
838
  }
816
- if (member.type === 'folder' && member.members && member.members.length)
817
- yield this.createFoldersAndServices(`${parentFolder}/${member.name}`, member.members, accessToken, sasApiClient, isForced);
818
839
  }));
819
840
  });
820
841
  }
@@ -852,3 +873,28 @@ class SASjs {
852
873
  }
853
874
  }
854
875
  exports.default = SASjs;
876
+ /**
877
+ * Counts every member of a service pack, at every depth.
878
+ *
879
+ * Folders are counted as well as their children, because the deploy writes the
880
+ * folder itself before recursing - one `onProgress` call per member, so the
881
+ * total is exactly the number of calls the deploy will make.
882
+ */
883
+ const countMembers = (members = []) => members.reduce((count, member) => count + 1 + (member.members ? countMembers(member.members) : 0), 0);
884
+ /**
885
+ * Reports one member immediately before it is written.
886
+ *
887
+ * Emitted per case rather than before the switch so an unidentified member
888
+ * throws without first announcing a write that will not happen.
889
+ */
890
+ const reportMember = (progress, type, name, parentFolder) => {
891
+ var _a;
892
+ const index = ++progress.index;
893
+ (_a = progress.onProgress) === null || _a === void 0 ? void 0 : _a.call(progress, {
894
+ type,
895
+ name,
896
+ parentFolder,
897
+ index,
898
+ total: progress.total
899
+ });
900
+ };
@@ -3567,6 +3567,16 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3567
3567
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3568
3568
 
3569
3569
 
3570
+ /***/ },
3571
+
3572
+ /***/ 5284
3573
+ (__unused_webpack_module, exports) {
3574
+
3575
+ "use strict";
3576
+
3577
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3578
+
3579
+
3570
3580
  /***/ },
3571
3581
 
3572
3582
  /***/ 3438
@@ -4389,6 +4399,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
4389
4399
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4390
4400
  __exportStar(__webpack_require__(5777), exports);
4391
4401
  __exportStar(__webpack_require__(1353), exports);
4402
+ __exportStar(__webpack_require__(5284), exports);
4392
4403
  __exportStar(__webpack_require__(8912), exports);
4393
4404
  __exportStar(__webpack_require__(4006), exports);
4394
4405
  __exportStar(__webpack_require__(5873), exports);
@@ -3374,12 +3374,18 @@ class SASViyaApiClient {
3374
3374
  logger.info(`Parent folder '${newFolderName}' has been successfully created.`);
3375
3375
  parentFolderUri = `/folders/folders/${parentFolder.id}`;
3376
3376
  }
3377
- else if (isForced) {
3378
- const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
3379
- const folderUri = yield this.getFolderUri(folderPath, accessToken);
3380
- if (folderUri) {
3381
- yield this.deleteFolder(folderPath, accessToken);
3382
- }
3377
+ }
3378
+ // The forced delete of the folder being created is keyed on its path, not on
3379
+ // how the parent was found: a caller that supplies the parent's URI (the
3380
+ // service pack deploy does, to save a lookup per member) still expects an
3381
+ // existing folder of this name to be replaced rather than refused with 409.
3382
+ // When the parent itself did not exist there is nothing here to delete, and
3383
+ // the lookup is a 404 the caller never sees.
3384
+ if (isForced && parentFolderPath) {
3385
+ const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
3386
+ const folderUri = yield this.getFolderUri(folderPath, accessToken);
3387
+ if (folderUri) {
3388
+ yield this.deleteFolder(folderPath, accessToken);
3383
3389
  }
3384
3390
  }
3385
3391
  const { result: createFolderResponse } = yield this.requestClient
@@ -4543,9 +4549,14 @@ class SASjs {
4543
4549
  * @param accessToken - an optional access token to be passed in when
4544
4550
  * using this function from the command line.
4545
4551
  * @param isForced - flag that indicates if target folder already exists, it and all subfolders have to be deleted.
4552
+ * @param onProgress - optional callback invoked once per member, immediately
4553
+ * before the member is written, with its name, folder, type and position. A
4554
+ * Viya deploy is one REST call per folder, file and job definition, run in
4555
+ * sequence, so this is the only signal a caller has that a large pack is
4556
+ * still moving rather than hung.
4546
4557
  */
4547
4558
  deployServicePack(serviceJson_1, appLoc_1, serverUrl_1, accessToken_1) {
4548
- return __awaiter(this, arguments, void 0, function* (serviceJson, appLoc, serverUrl, accessToken, isForced = false) {
4559
+ return __awaiter(this, arguments, void 0, function* (serviceJson, appLoc, serverUrl, accessToken, isForced = false, onProgress) {
4549
4560
  this.isMethodSupported('deployServicePack', [types_2.ServerType.SasViya]);
4550
4561
  let sasApiClient = null;
4551
4562
  if (serverUrl || appLoc) {
@@ -4577,7 +4588,11 @@ class SASjs {
4577
4588
  serviceJson.members[0].members.sort((member) => member.type === 'folder' ? -1 : 1);
4578
4589
  }
4579
4590
  const members = serviceJson.members;
4580
- yield this.createFoldersAndServices(appLoc, members, accessToken, sasApiClient, isForced);
4591
+ yield this.createFoldersAndServices(appLoc, members, accessToken, sasApiClient, isForced, {
4592
+ onProgress,
4593
+ index: 0,
4594
+ total: countMembers(members)
4595
+ });
4581
4596
  });
4582
4597
  }
4583
4598
  /**
@@ -4725,24 +4740,36 @@ class SASjs {
4725
4740
  this.computeJobExecutor = new job_execution_1.ComputeJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
4726
4741
  this.jesJobExecutor = new job_execution_1.JesJobExecutor(this.sasjsConfig.serverUrl, this.sasViyaApiClient);
4727
4742
  }
4728
- createFoldersAndServices(parentFolder, membersJson, accessToken, sasApiClient, isForced) {
4729
- return __awaiter(this, void 0, void 0, function* () {
4743
+ createFoldersAndServices(parentFolder_1, membersJson_1, accessToken_1, sasApiClient_1, isForced_1) {
4744
+ return __awaiter(this, arguments, void 0, function* (parentFolder, membersJson, accessToken, sasApiClient, isForced, progress = {
4745
+ index: 0,
4746
+ total: countMembers(membersJson)
4747
+ }, parentFolderUri) {
4730
4748
  yield (0, utils_1.asyncForEach)(membersJson, (member) => __awaiter(this, void 0, void 0, function* () {
4731
4749
  switch (member.type) {
4732
- case 'folder':
4733
- yield this.createFolder(member.name, parentFolder, undefined, accessToken, sasApiClient, isForced);
4750
+ case 'folder': {
4751
+ reportMember(progress, 'folder', member.name, parentFolder);
4752
+ const folder = yield this.createFolder(member.name, parentFolder, parentFolderUri, accessToken, sasApiClient, isForced);
4753
+ if (member.members && member.members.length) {
4754
+ const folderPath = `${parentFolder}/${member.name}`;
4755
+ yield this.createFoldersAndServices(folderPath, member.members, accessToken, sasApiClient, isForced, progress,
4756
+ // the folder the deploy has just created, so its children do not
4757
+ // each resolve the same path back to a URI
4758
+ (folder === null || folder === void 0 ? void 0 : folder.id) ? `/folders/folders/${folder.id}` : undefined);
4759
+ }
4734
4760
  break;
4761
+ }
4735
4762
  case 'file':
4736
- yield this.createFile(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
4763
+ reportMember(progress, 'file', member.name, parentFolder);
4764
+ yield this.createFile(member.name, member.code, parentFolder, parentFolderUri, accessToken, sasApiClient);
4737
4765
  break;
4738
4766
  case 'service':
4739
- yield this.createJobDefinition(member.name, member.code, parentFolder, undefined, accessToken, sasApiClient);
4767
+ reportMember(progress, 'service', member.name, parentFolder);
4768
+ yield this.createJobDefinition(member.name, member.code, parentFolder, parentFolderUri, accessToken, sasApiClient);
4740
4769
  break;
4741
4770
  default:
4742
4771
  throw new Error(`Unidentified member '${member.name}' provided.`);
4743
4772
  }
4744
- if (member.type === 'folder' && member.members && member.members.length)
4745
- yield this.createFoldersAndServices(`${parentFolder}/${member.name}`, member.members, accessToken, sasApiClient, isForced);
4746
4773
  }));
4747
4774
  });
4748
4775
  }
@@ -4780,6 +4807,31 @@ class SASjs {
4780
4807
  }
4781
4808
  }
4782
4809
  exports["default"] = SASjs;
4810
+ /**
4811
+ * Counts every member of a service pack, at every depth.
4812
+ *
4813
+ * Folders are counted as well as their children, because the deploy writes the
4814
+ * folder itself before recursing - one `onProgress` call per member, so the
4815
+ * total is exactly the number of calls the deploy will make.
4816
+ */
4817
+ const countMembers = (members = []) => members.reduce((count, member) => count + 1 + (member.members ? countMembers(member.members) : 0), 0);
4818
+ /**
4819
+ * Reports one member immediately before it is written.
4820
+ *
4821
+ * Emitted per case rather than before the switch so an unidentified member
4822
+ * throws without first announcing a write that will not happen.
4823
+ */
4824
+ const reportMember = (progress, type, name, parentFolder) => {
4825
+ var _a;
4826
+ const index = ++progress.index;
4827
+ (_a = progress.onProgress) === null || _a === void 0 ? void 0 : _a.call(progress, {
4828
+ type,
4829
+ name,
4830
+ parentFolder,
4831
+ index,
4832
+ total: progress.total
4833
+ });
4834
+ };
4783
4835
 
4784
4836
 
4785
4837
  /***/ },
@@ -9862,6 +9914,16 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
9862
9914
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9863
9915
 
9864
9916
 
9917
+ /***/ },
9918
+
9919
+ /***/ 5284
9920
+ (__unused_webpack_module, exports) {
9921
+
9922
+ "use strict";
9923
+
9924
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9925
+
9926
+
9865
9927
  /***/ },
9866
9928
 
9867
9929
  /***/ 3438
@@ -10684,6 +10746,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10684
10746
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10685
10747
  __exportStar(__webpack_require__(5777), exports);
10686
10748
  __exportStar(__webpack_require__(1353), exports);
10749
+ __exportStar(__webpack_require__(5284), exports);
10687
10750
  __exportStar(__webpack_require__(8912), exports);
10688
10751
  __exportStar(__webpack_require__(4006), exports);
10689
10752
  __exportStar(__webpack_require__(5873), exports);
package/package.json CHANGED
@@ -120,7 +120,7 @@
120
120
  "safer-buffer": "npm:@socketregistry/safer-buffer@1.0.10",
121
121
  "side-channel": "npm:@socketregistry/side-channel@1.0.10"
122
122
  },
123
- "version": "6.1.8",
123
+ "version": "6.2.0",
124
124
  "engines": {
125
125
  "node": ">=22"
126
126
  },
@@ -0,0 +1,27 @@
1
+ /**
2
+ * One member of a service pack, reported as the deploy writes it.
3
+ *
4
+ * A deploy is a sequential series of REST calls - one folder, one file, one job
5
+ * definition at a time - and on a real server that is long enough that a caller
6
+ * with no progress reporting looks hung. `deployServicePack` accepts an
7
+ * `onProgress` callback and calls it once per member, immediately before the
8
+ * member is written, so a caller can report position without knowing how the
9
+ * pack is structured.
10
+ */
11
+ export interface DeployProgress {
12
+ /** What is being written: a folder, a file, or a service (a Viya job definition). */
13
+ type: 'folder' | 'file' | 'service';
14
+ /** The member name - a folder name, a file name, or a job name. */
15
+ name: string;
16
+ /** Full path of the folder the member is written into. */
17
+ parentFolder: string;
18
+ /** 1-based position of this member in deployment order. */
19
+ index: number;
20
+ /**
21
+ * Total members in the whole deployment, so a caller can render `12/88`.
22
+ *
23
+ * Every member is counted, at every depth, including folders: it is the
24
+ * number of `onProgress` calls the deploy will make.
25
+ */
26
+ total: number;
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './Context';
2
2
  export * from './CsrfToken';
3
+ export * from './DeployProgress';
3
4
  export * from './Folder';
4
5
  export * from './File';
5
6
  export * from './Job';
package/types/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Context"), exports);
18
18
  __exportStar(require("./CsrfToken"), exports);
19
+ __exportStar(require("./DeployProgress"), exports);
19
20
  __exportStar(require("./Folder"), exports);
20
21
  __exportStar(require("./File"), exports);
21
22
  __exportStar(require("./Job"), exports);