gd-sprest 7.0.0 → 7.0.3

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.
@@ -18,7 +18,7 @@ export interface IBase<Type = any, Result = Type, QueryResult = Result> extends
18
18
  */
19
19
 
20
20
  /** The batch requests. */
21
- batchRequests: Array<Array<{ callback?: any, response?: IBase, targetInfo: ITargetInfo }>>;
21
+ batchRequests: Array<Array<IBatchRequest>>;
22
22
 
23
23
  /** The index of this object in the responses array. */
24
24
  responseIndex: number;
@@ -0,0 +1,12 @@
1
+ import { IBase } from "./base";
2
+ import { ITargetInfo } from "./targetInfo";
3
+
4
+ /**
5
+ * Batch Request
6
+ */
7
+ export interface IBatchRequest {
8
+ callback?: any;
9
+ changesetId?: string;
10
+ response?: IBase;
11
+ targetInfo: ITargetInfo;
12
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./base";
2
+ export * from "./batch";
2
3
  export * from "./helper";
3
4
  export * from "./request";
4
5
  export * from "./requestType";
@@ -20,7 +20,7 @@ export interface IRequest {
20
20
  parseXML(xml: string): IBase;
21
21
 
22
22
  /** Updates the data object. */
23
- updateDataObject(base: IBase, isBatchRequest: boolean, batchCallback?: (batchResponses: Array<any>) => void);
23
+ updateDataObject(base: IBase, isBatchRequest: boolean, batchIdx: number, batchCallback?: (batchResponses: Array<any>) => void);
24
24
 
25
25
  /** Validates the data collection results. */
26
26
  validateDataCollectionResults(base: IBase): PromiseLike<void>;
@@ -6,6 +6,7 @@ exports.Mapper = {
6
6
  "MS.FileServices.File": {
7
7
  copyTo: {
8
8
  argNames: ["target", "overwrite"],
9
+ requestType: utils_1.RequestType.PostWithArgs
9
10
  },
10
11
  delete: {
11
12
  requestType: utils_1.RequestType.Delete
@@ -69,6 +70,7 @@ exports.Mapper = {
69
70
  "Microsoft.Office.Server.ContentCenter.SPMachineLearningModel": {
70
71
  copy: {
71
72
  argNames: ["copyTo"],
73
+ requestType: utils_1.RequestType.PostWithArgs
72
74
  },
73
75
  delete: {},
74
76
  importMeta: {},
@@ -1466,6 +1468,7 @@ exports.Mapper = {
1466
1468
  "PS.Calendar": {
1467
1469
  copyTo: {
1468
1470
  argNames: ["name"],
1471
+ requestType: utils_1.RequestType.PostWithArgs
1469
1472
  },
1470
1473
  delete: {
1471
1474
  requestType: utils_1.RequestType.Delete
@@ -4427,9 +4430,12 @@ exports.Mapper = {
4427
4430
  },
4428
4431
  checkOut: {},
4429
4432
  checkoutPage: {},
4430
- copy: {},
4433
+ copy: {
4434
+ requestType: utils_1.RequestType.Post
4435
+ },
4431
4436
  copyWithConfiguration: {
4432
4437
  argNames: ["sitePageFlags", "isNews"],
4438
+ requestType: utils_1.RequestType.Post
4433
4439
  },
4434
4440
  createNewsCopy: {},
4435
4441
  demoteFromNews: {},
@@ -4565,9 +4571,12 @@ exports.Mapper = {
4565
4571
  },
4566
4572
  checkOut: {},
4567
4573
  checkoutPage: {},
4568
- copy: {},
4574
+ copy: {
4575
+ requestType: utils_1.RequestType.Post
4576
+ },
4569
4577
  copyWithConfiguration: {
4570
4578
  argNames: ["sitePageFlags", "isNews"],
4579
+ requestType: utils_1.RequestType.Post
4571
4580
  },
4572
4581
  createNewsCopy: {},
4573
4582
  demoteFromNews: {},
@@ -4645,7 +4654,7 @@ exports.Mapper = {
4645
4654
  requestType: utils_1.RequestType.Post
4646
4655
  },
4647
4656
  copy: {
4648
- requestType: utils_1.RequestType.Post
4657
+ requestType: utils_1.RequestType.PostWithArgs
4649
4658
  },
4650
4659
  copyWithConfiguration: {
4651
4660
  argNames: ["sitePageFlags", "isNews"],
@@ -4752,7 +4761,9 @@ exports.Mapper = {
4752
4761
  },
4753
4762
  checkOut: {},
4754
4763
  checkoutPage: {},
4755
- copy: {},
4764
+ copy: {
4765
+ requestType: utils_1.RequestType.Post
4766
+ },
4756
4767
  copyWithConfiguration: {
4757
4768
  argNames: ["sitePageFlags", "isNews"],
4758
4769
  },
@@ -4870,7 +4881,9 @@ exports.Mapper = {
4870
4881
  },
4871
4882
  checkOut: {},
4872
4883
  checkoutPage: {},
4873
- copy: {},
4884
+ copy: {
4885
+ requestType: utils_1.RequestType.Post
4886
+ },
4874
4887
  copyWithConfiguration: {
4875
4888
  argNames: ["sitePageFlags", "isNews"],
4876
4889
  },
package/build/rest.js CHANGED
@@ -8,7 +8,7 @@ var sptypes_1 = require("./sptypes");
8
8
  * SharePoint REST Library
9
9
  */
10
10
  exports.$REST = {
11
- __ver: 7.00,
11
+ __ver: 7.03,
12
12
  AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); },
13
13
  Apps: Lib.Apps,
14
14
  ContextInfo: Lib.ContextInfo,
@@ -11,7 +11,7 @@ var Batch = /** @class */ (function () {
11
11
  }
12
12
  // Method to execute a batch request
13
13
  Batch.execute = function (base, args) {
14
- var appendFl = false;
14
+ var createFl = false;
15
15
  var callback = null;
16
16
  // Parse the arguments
17
17
  for (var i = 0; i < args.length; i++) {
@@ -19,8 +19,8 @@ var Batch = /** @class */ (function () {
19
19
  // Check the type
20
20
  switch (typeof (arg)) {
21
21
  case "boolean":
22
- // Set the append flag
23
- appendFl = arg;
22
+ // Set the create flag
23
+ createFl = arg;
24
24
  break;
25
25
  case "function":
26
26
  // Set the callback method
@@ -30,39 +30,39 @@ var Batch = /** @class */ (function () {
30
30
  }
31
31
  // Set the base
32
32
  base.base = base.base ? base.base : base;
33
- // See if we are appending this request
34
- if (appendFl && base.base.batchRequests) {
35
- // Append the request
36
- base.base.batchRequests[base.base.batchRequests.length - 1].push({
37
- callback: callback,
38
- targetInfo: new _1.TargetInfo(base.targetInfo)
39
- });
40
- }
41
- else {
33
+ // See if we are creating a new request
34
+ if (createFl || base.base.batchRequests == null) {
42
35
  // Ensure the batch requests exist
43
36
  base.base.batchRequests = base.base.batchRequests || [];
44
37
  // Create the request
45
38
  base.base.batchRequests.push([{
46
39
  callback: callback,
40
+ changesetId: lib_1.ContextInfo.generateGUID(),
47
41
  targetInfo: new _1.TargetInfo(base.targetInfo)
48
42
  }]);
49
43
  }
44
+ else {
45
+ // Append the request
46
+ base.base.batchRequests[base.base.batchRequests.length - 1].push({
47
+ callback: callback,
48
+ changesetId: lib_1.ContextInfo.generateGUID(),
49
+ targetInfo: new _1.TargetInfo(base.targetInfo)
50
+ });
51
+ }
50
52
  // Return this object
51
53
  return base;
52
54
  };
53
55
  // Method to generate a batch request
54
- Batch.getTargetInfo = function (requests) {
56
+ Batch.getTargetInfo = function (url, requests) {
55
57
  var batchId = "batch_" + lib_1.ContextInfo.generateGUID();
56
58
  var batchRequests = [];
57
- // Parse the requests
58
- for (var i = 0; i < requests.length; i++) {
59
- // Create the batch request
60
- batchRequests.push(Batch.createBatch(batchId, requests[i]));
61
- }
59
+ // Create the batch request
60
+ batchRequests.push(Batch.createBatch(batchId, requests));
62
61
  // End the batch request
63
62
  batchRequests.push("--" + batchId + "--");
64
- // Return the target info
63
+ // Return the target information
65
64
  return new _1.TargetInfo({
65
+ url: url,
66
66
  endpoint: "$batch",
67
67
  method: "POST",
68
68
  data: batchRequests.join("\r\n"),
@@ -82,11 +82,10 @@ var Batch = /** @class */ (function () {
82
82
  // Determine if the batch requires a change set
83
83
  var requiresChangeset = request_1 && request_1.targetInfo.requestMethod != "GET";
84
84
  if (requiresChangeset) {
85
- var changesetId = "changeset_" + lib_1.ContextInfo.generateGUID();
86
85
  // Create a change set
87
- batch.push("Content-Type: multipart/mixed; boundary=" + changesetId);
86
+ batch.push("Content-Type: multipart/mixed; boundary=" + request_1.changesetId);
88
87
  batch.push("");
89
- batch.push("--" + changesetId);
88
+ batch.push("--" + request_1.changesetId);
90
89
  batch.push("Content-Type: application/http");
91
90
  batch.push("Content-Transfer-Encoding: binary");
92
91
  batch.push("");
@@ -95,7 +94,7 @@ var Batch = /** @class */ (function () {
95
94
  batch.push("");
96
95
  request_1.targetInfo.requestData ? batch.push(request_1.targetInfo.requestData) : null;
97
96
  batch.push("");
98
- batch.push("--" + changesetId + "--");
97
+ batch.push("--" + request_1.changesetId + "--");
99
98
  }
100
99
  else {
101
100
  // Create a change set
@@ -121,19 +120,15 @@ var Batch = /** @class */ (function () {
121
120
  return request.join("\r\n");
122
121
  };
123
122
  // Process the batch request callbacks
124
- Batch.processCallbacks = function (requests) {
125
- if (requests === void 0) { requests = []; }
123
+ Batch.processCallbacks = function (batchRequests) {
124
+ if (batchRequests === void 0) { batchRequests = []; }
126
125
  // Parse the requests
127
- for (var i = 0; i < requests.length; i++) {
128
- var request = requests[i];
129
- // Parse the batch request
130
- for (var j = 0; j < request.length; j++) {
131
- var batchRequest = request[j];
132
- // See if a callback exists
133
- if (batchRequest.callback) {
134
- // Execute the callback
135
- batchRequest.callback(batchRequest.response, batchRequest.targetInfo);
136
- }
126
+ for (var i = 0; i < batchRequests.length; i++) {
127
+ var batchRequest = batchRequests[i];
128
+ // See if a callback exists
129
+ if (batchRequest.callback) {
130
+ // Execute the callback
131
+ batchRequest.callback(batchRequest.response, batchRequest.targetInfo);
137
132
  }
138
133
  }
139
134
  };
@@ -4,6 +4,7 @@ exports.Request = void 0;
4
4
  var base_1 = require("./base");
5
5
  var batch_1 = require("./batch");
6
6
  var lib_1 = require("../lib");
7
+ var executor_1 = require("../helper/executor");
7
8
  var helper_1 = require("./helper");
8
9
  var mapper_1 = require("../mapper");
9
10
  var requestType_1 = require("./requestType");
@@ -288,81 +289,109 @@ exports.Request = {
288
289
  },
289
290
  // Method to execute the request
290
291
  executeRequest: function (base, asyncFl, callback) {
291
- var isBatchRequest = base.base && base.base.batchRequests && base.base.batchRequests.length > 0;
292
- var targetInfo = isBatchRequest ? batch_1.Batch.getTargetInfo(base.base.batchRequests) : new targetInfo_1.TargetInfo(base.targetInfo);
293
- // See if this is an asynchronous request
294
- if (asyncFl) {
295
- // See if the not a batch request, and it already exists
296
- if (base.xhr && !isBatchRequest) {
297
- // Execute the callback
298
- callback ? callback(base, false) : null;
299
- }
300
- else {
301
- // Create the request
302
- base.xhr = new xhrRequest_1.XHRRequest(asyncFl, targetInfo, function () {
303
- // Update the response and status
304
- base.response = base.xhr.response;
305
- base.status = base.xhr.status;
306
- var errorFl = !(base.status >= 200 && base.status < 300);
307
- // See if we are returning a file buffer
308
- if (base.requestType == requestType_1.RequestType.GetBuffer) {
309
- // Execute the callback
310
- callback ? callback(base.response, errorFl) : null;
311
- }
312
- else {
313
- // Update the data object
314
- exports.Request.updateDataObject(base, isBatchRequest, callback);
315
- // Ensure this isn't a batch request
316
- if (!isBatchRequest) {
317
- // See if this is an xml response
318
- if (base.xml) {
319
- // Execute the callback
320
- callback ? callback(base, errorFl) : null;
321
- }
322
- else {
323
- // Validate the data collection
324
- exports.Request.validateDataCollectionResults(base).then(
325
- // Success
326
- function () {
292
+ // Execution method
293
+ var execute = function (targetInfo, batchIdx, onComplete) {
294
+ // See if this is an asynchronous request
295
+ if (asyncFl) {
296
+ // See if the not a batch request, and it already exists
297
+ if (base.xhr && !isBatchRequest) {
298
+ // Execute the callback
299
+ callback ? callback(base, false) : null;
300
+ }
301
+ else {
302
+ // Create the request
303
+ base.xhr = new xhrRequest_1.XHRRequest(asyncFl, targetInfo, function () {
304
+ // Update the response and status
305
+ base.response = base.xhr.response;
306
+ base.status = base.xhr.status;
307
+ var errorFl = !(base.status >= 200 && base.status < 300);
308
+ // See if we are returning a file buffer
309
+ if (base.requestType == requestType_1.RequestType.GetBuffer) {
310
+ // Execute the callback
311
+ callback ? callback(base.response, errorFl) : null;
312
+ }
313
+ else {
314
+ // Update the data object
315
+ exports.Request.updateDataObject(base, isBatchRequest, batchIdx, callback);
316
+ // Ensure this isn't a batch request
317
+ if (!isBatchRequest) {
318
+ // See if this is an xml response
319
+ if (base.xml) {
327
320
  // Execute the callback
328
321
  callback ? callback(base, errorFl) : null;
329
- },
330
- // Error
331
- function () {
332
- // Execute the callback and set the error flag
333
- callback ? callback(base, true) : null;
334
- });
322
+ }
323
+ else {
324
+ // Validate the data collection
325
+ exports.Request.validateDataCollectionResults(base).then(
326
+ // Success
327
+ function () {
328
+ // Execute the callback
329
+ callback ? callback(base, errorFl) : null;
330
+ },
331
+ // Error
332
+ function () {
333
+ // Execute the callback and set the error flag
334
+ callback ? callback(base, true) : null;
335
+ });
336
+ }
335
337
  }
336
338
  }
337
- }
338
- });
339
+ // Call the event
340
+ onComplete ? onComplete() : null;
341
+ });
342
+ }
339
343
  }
340
- }
341
- // Else, see if we already executed this request
342
- else if (base.xhr) {
343
- return base;
344
- }
345
- // Else, we haven't executed this request
346
- else {
347
- // Create the request
348
- base.xhr = new xhrRequest_1.XHRRequest(asyncFl, targetInfo);
349
- // Update the response and status
350
- base.response = base.xhr.response;
351
- base.status = base.xhr.status;
352
- // See if we are returning a file buffer
353
- if (base.requestType == requestType_1.RequestType.GetBuffer) {
354
- // Return the response
355
- return base.response;
344
+ // Else, see if we already executed this request
345
+ else if (base.xhr) {
346
+ return base;
356
347
  }
357
- // Update the base object
358
- exports.Request.updateDataObject(base, isBatchRequest, callback);
359
- // See if the base is a collection and has more results
360
- if (base["d"] && base["d"].__next) {
361
- // Add the "next" method to get the next set of results
362
- base["next"] = new Function("return this.getNextSetOfResults();");
348
+ // Else, we haven't executed this request
349
+ else {
350
+ // Create the request
351
+ base.xhr = new xhrRequest_1.XHRRequest(asyncFl, targetInfo);
352
+ // Update the response and status
353
+ base.response = base.xhr.response;
354
+ base.status = base.xhr.status;
355
+ // See if we are returning a file buffer
356
+ if (base.requestType == requestType_1.RequestType.GetBuffer) {
357
+ // Return the response
358
+ return base.response;
359
+ }
360
+ // Update the base object
361
+ exports.Request.updateDataObject(base, isBatchRequest, batchIdx, callback);
362
+ // See if the base is a collection and has more results
363
+ if (base["d"] && base["d"].__next) {
364
+ // Add the "next" method to get the next set of results
365
+ base["next"] = new Function("return this.getNextSetOfResults();");
366
+ }
367
+ // Call the event
368
+ onComplete ? onComplete() : null;
369
+ // Return the base object
370
+ return base;
363
371
  }
364
- // Return the base object
365
- return base;
372
+ };
373
+ // See if this is a batch request
374
+ var isBatchRequest = base.base && base.base.batchRequests && base.base.batchRequests.length > 0;
375
+ if (isBatchRequest) {
376
+ var batchIdx_1 = 0;
377
+ // Parse the requests
378
+ executor_1.Executor(base.base.batchRequests, function (batchRequest) {
379
+ // Return a promise
380
+ return new Promise(function (resolve) {
381
+ // Execute the request
382
+ execute(batch_1.Batch.getTargetInfo(base.targetInfo.url, batchRequest), batchIdx_1++, function () {
383
+ // Resolve the request
384
+ resolve(null);
385
+ });
386
+ });
387
+ }).then(function () {
388
+ // Clear the batch requests
389
+ base.base.batchRequests = null;
390
+ });
391
+ }
392
+ else {
393
+ // Execute the request
394
+ return execute(new targetInfo_1.TargetInfo(base.targetInfo));
366
395
  }
367
396
  },
368
397
  // Method to parse the xml
@@ -419,8 +448,9 @@ exports.Request = {
419
448
  return objData;
420
449
  },
421
450
  // Method to convert the input arguments into an object
422
- updateDataObject: function (base, isBatchRequest, batchCallback) {
451
+ updateDataObject: function (base, isBatchRequest, batchIdx, batchCallback) {
423
452
  if (isBatchRequest === void 0) { isBatchRequest = false; }
453
+ if (batchIdx === void 0) { batchIdx = 0; }
424
454
  // Ensure the request was successful
425
455
  if (base.status >= 200 && base.status < 300) {
426
456
  // Return if we are expecting a buffer
@@ -428,7 +458,6 @@ exports.Request = {
428
458
  return;
429
459
  }
430
460
  // Parse the responses
431
- var batchIdx = 0;
432
461
  var batchRequestIdx = 0;
433
462
  var responses = isBatchRequest ? base.response.split("\n") : [base.response];
434
463
  for (var i = 0; i < responses.length; i++) {
@@ -532,11 +561,9 @@ exports.Request = {
532
561
  // See if this was a batch request
533
562
  if (isBatchRequest) {
534
563
  // Process the callbacks
535
- batch_1.Batch.processCallbacks(base.base.batchRequests);
564
+ batch_1.Batch.processCallbacks(base.base.batchRequests[batchIdx]);
536
565
  // Execute the callback if it exists
537
566
  batchCallback ? batchCallback(base.base.batchRequests) : null;
538
- // Clear the batch requests
539
- base.base.batchRequests = null;
540
567
  }
541
568
  }
542
569
  },
@@ -5672,6 +5672,7 @@ declare module 'gd-sprest/intellisense/webTemplateExtensions' {
5672
5672
 
5673
5673
  declare module 'gd-sprest/utils' {
5674
5674
  export * from "gd-sprest/utils/base";
5675
+ export * from "gd-sprest/utils/batch";
5675
5676
  export * from "gd-sprest/utils/helper";
5676
5677
  export * from "gd-sprest/utils/request";
5677
5678
  export * from "gd-sprest/utils/requestType";
@@ -6254,7 +6255,7 @@ declare module 'gd-sprest/utils/base' {
6254
6255
 
6255
6256
 
6256
6257
  /** The batch requests. */
6257
- batchRequests: Array<Array<{ callback?: any, response?: IBase, targetInfo: ITargetInfo }>>;
6258
+ batchRequests: Array<Array<IBatchRequest>>;
6258
6259
 
6259
6260
  /** The index of this object in the responses array. */
6260
6261
  responseIndex: number;
@@ -6313,6 +6314,21 @@ declare module 'gd-sprest/utils/base' {
6313
6314
  }
6314
6315
  }
6315
6316
 
6317
+ declare module 'gd-sprest/utils/batch' {
6318
+ import { IBase } from "gd-sprest/utils/base";
6319
+ import { ITargetInfo } from "gd-sprest/utils/targetInfo";
6320
+
6321
+ /**
6322
+ * Batch Request
6323
+ */
6324
+ export interface IBatchRequest {
6325
+ callback?: any;
6326
+ changesetId?: string;
6327
+ response?: IBase;
6328
+ targetInfo: ITargetInfo;
6329
+ }
6330
+ }
6331
+
6316
6332
  declare module 'gd-sprest/utils/helper' {
6317
6333
  import { IMethodInfo, IRequestInfo } from "gd-sprest-def/lib/base";
6318
6334
  import { IBase } from "gd-sprest/utils/base";
@@ -6386,7 +6402,7 @@ declare module 'gd-sprest/utils/request' {
6386
6402
  parseXML(xml: string): IBase;
6387
6403
 
6388
6404
  /** Updates the data object. */
6389
- updateDataObject(base: IBase, isBatchRequest: boolean, batchCallback?: (batchResponses: Array<any>) => void);
6405
+ updateDataObject(base: IBase, isBatchRequest: boolean, batchIdx: number, batchCallback?: (batchResponses: Array<any>) => void);
6390
6406
 
6391
6407
  /** Validates the data collection results. */
6392
6408
  validateDataCollectionResults(base: IBase): PromiseLike<void>;