This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
/
pnp.js
13497 lines (13188 loc) · 502 KB
/
pnp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* sp-pnp-js v3.0.10 - A JavaScript library for SharePoint development.
* MIT (https://github.com/SharePoint/PnP-JS-Core/blob/master/LICENSE)
* Copyright (c) 2017 Microsoft
* docs: http://officedev.github.io/PnP-JS-Core
* source: https://github.com/SharePoint/PnP-JS-Core
* bugs: https://github.com/SharePoint/PnP-JS-Core/issues
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["$pnp"] = factory();
else
root["$pnp"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/assets/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 29);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(global) {
Object.defineProperty(exports, "__esModule", { value: true });
var pnplibconfig_1 = __webpack_require__(4);
function extractWebUrl(candidateUrl) {
if (candidateUrl === null) {
return "";
}
var index = candidateUrl.indexOf("_api/");
if (index > -1) {
return candidateUrl.substr(0, index);
}
// if all else fails just give them what they gave us back
return candidateUrl;
}
exports.extractWebUrl = extractWebUrl;
var Util = /** @class */ (function () {
function Util() {
}
/**
* Gets a callback function which will maintain context across async calls.
* Allows for the calling pattern getCtxCallback(thisobj, method, methodarg1, methodarg2, ...)
*
* @param context The object that will be the 'this' value in the callback
* @param method The method to which we will apply the context and parameters
* @param params Optional, additional arguments to supply to the wrapped method when it is invoked
*/
Util.getCtxCallback = function (context, method) {
var params = [];
for (var _i = 2; _i < arguments.length; _i++) {
params[_i - 2] = arguments[_i];
}
return function () {
method.apply(context, params);
};
};
/**
* Tests if a url param exists
*
* @param name The name of the url paramter to check
*/
Util.urlParamExists = function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
return regex.test(location.search);
};
/**
* Gets a url param value by name
*
* @param name The name of the paramter for which we want the value
*/
Util.getUrlParamByName = function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};
/**
* Gets a url param by name and attempts to parse a bool value
*
* @param name The name of the paramter for which we want the boolean value
*/
Util.getUrlParamBoolByName = function (name) {
var p = this.getUrlParamByName(name);
var isFalse = (p === "" || /false|0/i.test(p));
return !isFalse;
};
/**
* Inserts the string s into the string target as the index specified by index
*
* @param target The string into which we will insert s
* @param index The location in target to insert s (zero based)
* @param s The string to insert into target at position index
*/
Util.stringInsert = function (target, index, s) {
if (index > 0) {
return target.substring(0, index) + s + target.substring(index, target.length);
}
return s + target;
};
/**
* Adds a value to a date
*
* @param date The date to which we will add units, done in local time
* @param interval The name of the interval to add, one of: ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second']
* @param units The amount to add to date of the given interval
*
* http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object
*/
Util.dateAdd = function (date, interval, units) {
var ret = new Date(date); // don't change original date
switch (interval.toLowerCase()) {
case "year":
ret.setFullYear(ret.getFullYear() + units);
break;
case "quarter":
ret.setMonth(ret.getMonth() + 3 * units);
break;
case "month":
ret.setMonth(ret.getMonth() + units);
break;
case "week":
ret.setDate(ret.getDate() + 7 * units);
break;
case "day":
ret.setDate(ret.getDate() + units);
break;
case "hour":
ret.setTime(ret.getTime() + units * 3600000);
break;
case "minute":
ret.setTime(ret.getTime() + units * 60000);
break;
case "second":
ret.setTime(ret.getTime() + units * 1000);
break;
default:
ret = undefined;
break;
}
return ret;
};
/**
* Loads a stylesheet into the current page
*
* @param path The url to the stylesheet
* @param avoidCache If true a value will be appended as a query string to avoid browser caching issues
*/
Util.loadStylesheet = function (path, avoidCache) {
if (avoidCache) {
path += "?" + encodeURIComponent((new Date()).getTime().toString());
}
var head = document.getElementsByTagName("head");
if (head.length > 0) {
var e = document.createElement("link");
head[0].appendChild(e);
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", path);
}
};
/**
* Combines an arbitrary set of paths ensuring that the slashes are normalized
*
* @param paths 0 to n path parts to combine
*/
Util.combinePaths = function () {
var paths = [];
for (var _i = 0; _i < arguments.length; _i++) {
paths[_i] = arguments[_i];
}
return paths
.filter(function (path) { return !Util.stringIsNullOrEmpty(path); })
.map(function (path) { return path.replace(/^[\\|\/]/, "").replace(/[\\|\/]$/, ""); })
.join("/")
.replace(/\\/g, "/");
};
/**
* Gets a random string of chars length
*
* @param chars The length of the random string to generate
*/
Util.getRandomString = function (chars) {
var text = new Array(chars);
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < chars; i++) {
text[i] = possible.charAt(Math.floor(Math.random() * possible.length));
}
return text.join("");
};
/**
* Gets a random GUID value
*
* http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
*/
/* tslint:disable no-bitwise */
Util.getGUID = function () {
var d = new Date().getTime();
var guid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16);
});
return guid;
};
/* tslint:enable */
/**
* Determines if a given value is a function
*
* @param candidateFunction The thing to test for being a function
*/
Util.isFunction = function (candidateFunction) {
return typeof candidateFunction === "function";
};
/**
* @returns whether the provided parameter is a JavaScript Array or not.
*/
Util.isArray = function (array) {
if (Array.isArray) {
return Array.isArray(array);
}
return array && typeof array.length === "number" && array.constructor === Array;
};
/**
* Determines if a string is null or empty or undefined
*
* @param s The string to test
*/
Util.stringIsNullOrEmpty = function (s) {
return typeof s === "undefined" || s === null || s.length < 1;
};
/**
* Provides functionality to extend the given object by doing a shallow copy
*
* @param target The object to which properties will be copied
* @param source The source object from which properties will be copied
* @param noOverwrite If true existing properties on the target are not overwritten from the source
*
*/
Util.extend = function (target, source, noOverwrite) {
if (noOverwrite === void 0) { noOverwrite = false; }
if (source === null || typeof source === "undefined") {
return target;
}
// ensure we don't overwrite things we don't want overwritten
var check = noOverwrite ? function (o, i) { return !(i in o); } : function () { return true; };
return Object.getOwnPropertyNames(source)
.filter(function (v) { return check(target, v); })
.reduce(function (t, v) {
t[v] = source[v];
return t;
}, target);
};
/**
* Determines if a given url is absolute
*
* @param url The url to check to see if it is absolute
*/
Util.isUrlAbsolute = function (url) {
return /^https?:\/\/|^\/\//i.test(url);
};
/**
* Ensures that a given url is absolute for the current web based on context
*
* @param candidateUrl The url to make absolute
*
*/
Util.toAbsoluteUrl = function (candidateUrl) {
return new Promise(function (resolve) {
if (Util.isUrlAbsolute(candidateUrl)) {
// if we are already absolute, then just return the url
return resolve(candidateUrl);
}
if (pnplibconfig_1.RuntimeConfig.spBaseUrl !== null) {
// base url specified either with baseUrl of spfxContext config property
return resolve(Util.combinePaths(pnplibconfig_1.RuntimeConfig.spBaseUrl, candidateUrl));
}
if (typeof global._spPageContextInfo !== "undefined") {
// operating in classic pages
if (global._spPageContextInfo.hasOwnProperty("webAbsoluteUrl")) {
return resolve(Util.combinePaths(global._spPageContextInfo.webAbsoluteUrl, candidateUrl));
}
else if (global._spPageContextInfo.hasOwnProperty("webServerRelativeUrl")) {
return resolve(Util.combinePaths(global._spPageContextInfo.webServerRelativeUrl, candidateUrl));
}
}
// does window.location exist and have a certain path part in it?
if (typeof global.location !== "undefined") {
var baseUrl_1 = global.location.toString().toLowerCase();
["/_layouts/", "/siteassets/"].forEach(function (s) {
var index = baseUrl_1.indexOf(s);
if (index > 0) {
return resolve(Util.combinePaths(baseUrl_1.substr(0, index), candidateUrl));
}
});
}
return resolve(candidateUrl);
});
};
return Util;
}());
exports.Util = Util;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(30)))
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = __webpack_require__(0);
var collections_1 = __webpack_require__(9);
var utils_1 = __webpack_require__(10);
var exceptions_1 = __webpack_require__(2);
var logging_1 = __webpack_require__(5);
var queryable_1 = __webpack_require__(19);
var pipeline_1 = __webpack_require__(20);
var httpclient_1 = __webpack_require__(21);
/**
* SharePointQueryable Base Class
*
*/
var SharePointQueryable = /** @class */ (function (_super) {
__extends(SharePointQueryable, _super);
/**
* Creates a new instance of the SharePointQueryable class
*
* @constructor
* @param baseUrl A string or SharePointQueryable that should form the base part of the url
*
*/
function SharePointQueryable(baseUrl, path) {
var _this = _super.call(this) || this;
_this._options = {};
_this._query = new collections_1.Dictionary();
_this._batch = null;
if (typeof baseUrl === "string") {
// we need to do some extra parsing to get the parent url correct if we are
// being created from just a string.
var urlStr = baseUrl;
if (util_1.Util.isUrlAbsolute(urlStr) || urlStr.lastIndexOf("/") < 0) {
_this._parentUrl = urlStr;
_this._url = util_1.Util.combinePaths(urlStr, path);
}
else if (urlStr.lastIndexOf("/") > urlStr.lastIndexOf("(")) {
// .../items(19)/fields
var index = urlStr.lastIndexOf("/");
_this._parentUrl = urlStr.slice(0, index);
path = util_1.Util.combinePaths(urlStr.slice(index), path);
_this._url = util_1.Util.combinePaths(_this._parentUrl, path);
}
else {
// .../items(19)
var index = urlStr.lastIndexOf("(");
_this._parentUrl = urlStr.slice(0, index);
_this._url = util_1.Util.combinePaths(urlStr, path);
}
}
else {
var q = baseUrl;
_this._parentUrl = q._url;
_this._options = q._options;
var target = q._query.get("@target");
if (target !== null) {
_this._query.add("@target", target);
}
_this._url = util_1.Util.combinePaths(_this._parentUrl, path);
}
return _this;
}
/**
* Blocks a batch call from occuring, MUST be cleared by calling the returned function
*/
SharePointQueryable.prototype.addBatchDependency = function () {
if (this.hasBatch) {
return this._batch.addDependency();
}
return function () { return null; };
};
Object.defineProperty(SharePointQueryable.prototype, "hasBatch", {
/**
* Indicates if the current query has a batch associated
*
*/
get: function () {
return this._batch !== null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SharePointQueryable.prototype, "batch", {
/**
* The batch currently associated with this query or null
*
*/
get: function () {
return this.hasBatch ? this._batch : null;
},
enumerable: true,
configurable: true
});
/**
* Creates a new instance of the supplied factory and extends this into that new instance
*
* @param factory constructor for the new SharePointQueryable
*/
SharePointQueryable.prototype.as = function (factory) {
var o = new factory(this._url, null);
return util_1.Util.extend(o, this, true);
};
/**
* Adds this query to the supplied batch
*
* @example
* ```
*
* let b = pnp.sp.createBatch();
* pnp.sp.web.inBatch(b).get().then(...);
* b.execute().then(...)
* ```
*/
SharePointQueryable.prototype.inBatch = function (batch) {
if (this._batch !== null) {
throw new exceptions_1.AlreadyInBatchException();
}
this._batch = batch;
return this;
};
/**
* Gets the full url with query information
*
*/
SharePointQueryable.prototype.toUrlAndQuery = function () {
var aliasedParams = new collections_1.Dictionary();
var url = this.toUrl().replace(/'!(@.*?)::(.*?)'/ig, function (match, labelName, value) {
logging_1.Logger.write("Rewriting aliased parameter from match " + match + " to label: " + labelName + " value: " + value, logging_1.LogLevel.Verbose);
aliasedParams.add(labelName, "'" + value + "'");
return labelName;
});
// inlude our explicitly set query string params
aliasedParams.merge(this._query);
if (aliasedParams.count() > 0) {
url += "?" + aliasedParams.getKeys().map(function (key) { return key + "=" + aliasedParams.get(key); }).join("&");
}
return url;
};
/**
* Gets a parent for this instance as specified
*
* @param factory The contructor for the class to create
*/
SharePointQueryable.prototype.getParent = function (factory, baseUrl, path, batch) {
if (baseUrl === void 0) { baseUrl = this.parentUrl; }
var parent = new factory(baseUrl, path);
parent.configure(this._options);
var target = this.query.get("@target");
if (target !== null) {
parent.query.add("@target", target);
}
if (typeof batch !== "undefined") {
parent = parent.inBatch(batch);
}
return parent;
};
/**
* Clones this SharePointQueryable into a new SharePointQueryable instance of T
* @param factory Constructor used to create the new instance
* @param additionalPath Any additional path to include in the clone
* @param includeBatch If true this instance's batch will be added to the cloned instance
*/
SharePointQueryable.prototype.clone = function (factory, additionalPath, includeBatch) {
if (includeBatch === void 0) { includeBatch = true; }
var clone = new factory(this, additionalPath);
clone.configure(this._options);
var target = this.query.get("@target");
if (target !== null) {
clone.query.add("@target", target);
}
if (includeBatch && this.hasBatch) {
clone = clone.inBatch(this.batch);
}
return clone;
};
/**
* Converts the current instance to a request context
*
* @param verb The request verb
* @param options The set of supplied request options
* @param parser The supplied ODataParser instance
* @param pipeline Optional request processing pipeline
*/
SharePointQueryable.prototype.toRequestContext = function (verb, options, parser, pipeline) {
var _this = this;
if (options === void 0) { options = {}; }
if (pipeline === void 0) { pipeline = pipeline_1.PipelineMethods.default; }
var dependencyDispose = this.hasBatch ? this.addBatchDependency() : function () { return; };
return util_1.Util.toAbsoluteUrl(this.toUrlAndQuery()).then(function (url) {
utils_1.mergeOptions(options, _this._options);
// build our request context
var context = {
batch: _this._batch,
batchDependency: dependencyDispose,
cachingOptions: _this._cachingOptions,
clientFactory: function () { return new httpclient_1.HttpClient(); },
isBatched: _this.hasBatch,
isCached: _this._useCaching,
options: options,
parser: parser,
pipeline: pipeline,
requestAbsoluteUrl: url,
requestId: util_1.Util.getGUID(),
verb: verb,
};
return context;
});
};
return SharePointQueryable;
}(queryable_1.ODataQueryable));
exports.SharePointQueryable = SharePointQueryable;
/**
* Represents a REST collection which can be filtered, paged, and selected
*
*/
var SharePointQueryableCollection = /** @class */ (function (_super) {
__extends(SharePointQueryableCollection, _super);
function SharePointQueryableCollection() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Filters the returned collection (https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#bk_supported)
*
* @param filter The string representing the filter query
*/
SharePointQueryableCollection.prototype.filter = function (filter) {
this._query.add("$filter", filter);
return this;
};
/**
* Choose which fields to return
*
* @param selects One or more fields to return
*/
SharePointQueryableCollection.prototype.select = function () {
var selects = [];
for (var _i = 0; _i < arguments.length; _i++) {
selects[_i] = arguments[_i];
}
if (selects.length > 0) {
this._query.add("$select", selects.join(","));
}
return this;
};
/**
* Expands fields such as lookups to get additional data
*
* @param expands The Fields for which to expand the values
*/
SharePointQueryableCollection.prototype.expand = function () {
var expands = [];
for (var _i = 0; _i < arguments.length; _i++) {
expands[_i] = arguments[_i];
}
if (expands.length > 0) {
this._query.add("$expand", expands.join(","));
}
return this;
};
/**
* Orders based on the supplied fields ascending
*
* @param orderby The name of the field to sort on
* @param ascending If false DESC is appended, otherwise ASC (default)
*/
SharePointQueryableCollection.prototype.orderBy = function (orderBy, ascending) {
if (ascending === void 0) { ascending = true; }
var keys = this._query.getKeys();
var query = [];
var asc = ascending ? " asc" : " desc";
for (var i = 0; i < keys.length; i++) {
if (keys[i] === "$orderby") {
query.push(this._query.get("$orderby"));
break;
}
}
query.push("" + orderBy + asc);
this._query.add("$orderby", query.join(","));
return this;
};
/**
* Skips the specified number of items
*
* @param skip The number of items to skip
*/
SharePointQueryableCollection.prototype.skip = function (skip) {
this._query.add("$skip", skip.toString());
return this;
};
/**
* Limits the query to only return the specified number of items
*
* @param top The query row limit
*/
SharePointQueryableCollection.prototype.top = function (top) {
this._query.add("$top", top.toString());
return this;
};
return SharePointQueryableCollection;
}(SharePointQueryable));
exports.SharePointQueryableCollection = SharePointQueryableCollection;
/**
* Represents an instance that can be selected
*
*/
var SharePointQueryableInstance = /** @class */ (function (_super) {
__extends(SharePointQueryableInstance, _super);
function SharePointQueryableInstance() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Choose which fields to return
*
* @param selects One or more fields to return
*/
SharePointQueryableInstance.prototype.select = function () {
var selects = [];
for (var _i = 0; _i < arguments.length; _i++) {
selects[_i] = arguments[_i];
}
if (selects.length > 0) {
this._query.add("$select", selects.join(","));
}
return this;
};
/**
* Expands fields such as lookups to get additional data
*
* @param expands The Fields for which to expand the values
*/
SharePointQueryableInstance.prototype.expand = function () {
var expands = [];
for (var _i = 0; _i < arguments.length; _i++) {
expands[_i] = arguments[_i];
}
if (expands.length > 0) {
this._query.add("$expand", expands.join(","));
}
return this;
};
return SharePointQueryableInstance;
}(SharePointQueryable));
exports.SharePointQueryableInstance = SharePointQueryableInstance;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var logging_1 = __webpack_require__(5);
function defaultLog(error) {
logging_1.Logger.log({ data: {}, level: logging_1.LogLevel.Error, message: "[" + error.name + "]::" + error.message });
}
/**
* Represents an exception with an HttpClient request
*
*/
var ProcessHttpClientResponseException = /** @class */ (function (_super) {
__extends(ProcessHttpClientResponseException, _super);
function ProcessHttpClientResponseException(status, statusText, data) {
var _this = _super.call(this, "Error making HttpClient request in queryable: [" + status + "] " + statusText) || this;
_this.status = status;
_this.statusText = statusText;
_this.data = data;
_this.name = "ProcessHttpClientResponseException";
logging_1.Logger.log({ data: _this.data, level: logging_1.LogLevel.Error, message: _this.message });
return _this;
}
return ProcessHttpClientResponseException;
}(Error));
exports.ProcessHttpClientResponseException = ProcessHttpClientResponseException;
var NoCacheAvailableException = /** @class */ (function (_super) {
__extends(NoCacheAvailableException, _super);
function NoCacheAvailableException(msg) {
if (msg === void 0) { msg = "Cannot create a caching configuration provider since cache is not available."; }
var _this = _super.call(this, msg) || this;
_this.name = "NoCacheAvailableException";
defaultLog(_this);
return _this;
}
return NoCacheAvailableException;
}(Error));
exports.NoCacheAvailableException = NoCacheAvailableException;
var APIUrlException = /** @class */ (function (_super) {
__extends(APIUrlException, _super);
function APIUrlException(msg) {
if (msg === void 0) { msg = "Unable to determine API url."; }
var _this = _super.call(this, msg) || this;
_this.name = "APIUrlException";
defaultLog(_this);
return _this;
}
return APIUrlException;
}(Error));
exports.APIUrlException = APIUrlException;
var AuthUrlException = /** @class */ (function (_super) {
__extends(AuthUrlException, _super);
function AuthUrlException(data, msg) {
if (msg === void 0) { msg = "Auth URL Endpoint could not be determined from data. Data logged."; }
var _this = _super.call(this, msg) || this;
_this.name = "APIUrlException";
logging_1.Logger.log({ data: data, level: logging_1.LogLevel.Error, message: _this.message });
return _this;
}
return AuthUrlException;
}(Error));
exports.AuthUrlException = AuthUrlException;
var NodeFetchClientUnsupportedException = /** @class */ (function (_super) {
__extends(NodeFetchClientUnsupportedException, _super);
function NodeFetchClientUnsupportedException(msg) {
if (msg === void 0) { msg = "Using NodeFetchClient in the browser is not supported."; }
var _this = _super.call(this, msg) || this;
_this.name = "NodeFetchClientUnsupportedException";
defaultLog(_this);
return _this;
}
return NodeFetchClientUnsupportedException;
}(Error));
exports.NodeFetchClientUnsupportedException = NodeFetchClientUnsupportedException;
var SPRequestExecutorUndefinedException = /** @class */ (function (_super) {
__extends(SPRequestExecutorUndefinedException, _super);
function SPRequestExecutorUndefinedException() {
var _this = this;
var msg = [
"SP.RequestExecutor is undefined. ",
"Load the SP.RequestExecutor.js library (/_layouts/15/SP.RequestExecutor.js) before loading the PnP JS Core library.",
].join(" ");
_this = _super.call(this, msg) || this;
_this.name = "SPRequestExecutorUndefinedException";
defaultLog(_this);
return _this;
}
return SPRequestExecutorUndefinedException;
}(Error));
exports.SPRequestExecutorUndefinedException = SPRequestExecutorUndefinedException;
var MaxCommentLengthException = /** @class */ (function (_super) {
__extends(MaxCommentLengthException, _super);
function MaxCommentLengthException(msg) {
if (msg === void 0) { msg = "The maximum comment length is 1023 characters."; }
var _this = _super.call(this, msg) || this;
_this.name = "MaxCommentLengthException";
defaultLog(_this);
return _this;
}
return MaxCommentLengthException;
}(Error));
exports.MaxCommentLengthException = MaxCommentLengthException;
var NotSupportedInBatchException = /** @class */ (function (_super) {
__extends(NotSupportedInBatchException, _super);
function NotSupportedInBatchException(operation) {
if (operation === void 0) { operation = "This operation"; }
var _this = _super.call(this, operation + " is not supported as part of a batch.") || this;
_this.name = "NotSupportedInBatchException";
defaultLog(_this);
return _this;
}
return NotSupportedInBatchException;
}(Error));
exports.NotSupportedInBatchException = NotSupportedInBatchException;
var ODataIdException = /** @class */ (function (_super) {
__extends(ODataIdException, _super);
function ODataIdException(data, msg) {
if (msg === void 0) { msg = "Could not extract odata id in object, you may be using nometadata. Object data logged to logger."; }
var _this = _super.call(this, msg) || this;
_this.name = "ODataIdException";
logging_1.Logger.log({ data: data, level: logging_1.LogLevel.Error, message: _this.message });
return _this;
}
return ODataIdException;
}(Error));
exports.ODataIdException = ODataIdException;
var BatchParseException = /** @class */ (function (_super) {
__extends(BatchParseException, _super);
function BatchParseException(msg) {
var _this = _super.call(this, msg) || this;
_this.name = "BatchParseException";
defaultLog(_this);
return _this;
}
return BatchParseException;
}(Error));
exports.BatchParseException = BatchParseException;
var AlreadyInBatchException = /** @class */ (function (_super) {
__extends(AlreadyInBatchException, _super);
function AlreadyInBatchException(msg) {
if (msg === void 0) { msg = "This query is already part of a batch."; }
var _this = _super.call(this, msg) || this;
_this.name = "AlreadyInBatchException";
defaultLog(_this);
return _this;
}
return AlreadyInBatchException;
}(Error));
exports.AlreadyInBatchException = AlreadyInBatchException;
var FunctionExpectedException = /** @class */ (function (_super) {
__extends(FunctionExpectedException, _super);
function FunctionExpectedException(msg) {
if (msg === void 0) { msg = "This query is already part of a batch."; }
var _this = _super.call(this, msg) || this;
_this.name = "FunctionExpectedException";
defaultLog(_this);
return _this;
}
return FunctionExpectedException;
}(Error));
exports.FunctionExpectedException = FunctionExpectedException;
var UrlException = /** @class */ (function (_super) {
__extends(UrlException, _super);
function UrlException(msg) {
var _this = _super.call(this, msg) || this;
_this.name = "UrlException";
defaultLog(_this);
return _this;
}
return UrlException;
}(Error));
exports.UrlException = UrlException;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = __webpack_require__(0);
var logging_1 = __webpack_require__(5);
var exceptions_1 = __webpack_require__(2);
var core_1 = __webpack_require__(14);
function spExtractODataId(candidate) {
if (candidate.hasOwnProperty("odata.id")) {
return candidate["odata.id"];
}
else if (candidate.hasOwnProperty("__metadata") && candidate.__metadata.hasOwnProperty("id")) {
return candidate.__metadata.id;
}
else {
throw new exceptions_1.ODataIdException(candidate);
}
}
exports.spExtractODataId = spExtractODataId;
var SPODataEntityParserImpl = /** @class */ (function (_super) {
__extends(SPODataEntityParserImpl, _super);
function SPODataEntityParserImpl(factory) {
var _this = _super.call(this) || this;
_this.factory = factory;
_this.hydrate = function (d) {
var o = new _this.factory(spGetEntityUrl(d), null);
return util_1.Util.extend(o, d);
};
return _this;
}
SPODataEntityParserImpl.prototype.parse = function (r) {
var _this = this;
return _super.prototype.parse.call(this, r).then(function (d) {
var o = new _this.factory(spGetEntityUrl(d), null);
return util_1.Util.extend(o, d);
});
};
return SPODataEntityParserImpl;
}(core_1.ODataParserBase));
var SPODataEntityArrayParserImpl = /** @class */ (function (_super) {
__extends(SPODataEntityArrayParserImpl, _super);
function SPODataEntityArrayParserImpl(factory) {
var _this = _super.call(this) || this;
_this.factory = factory;
_this.hydrate = function (d) {
return d.map(function (v) {
var o = new _this.factory(spGetEntityUrl(v), null);
return util_1.Util.extend(o, v);
});
};
return _this;
}
SPODataEntityArrayParserImpl.prototype.parse = function (r) {
var _this = this;
return _super.prototype.parse.call(this, r).then(function (d) {
return d.map(function (v) {
var o = new _this.factory(spGetEntityUrl(v), null);
return util_1.Util.extend(o, v);
});
});
};
return SPODataEntityArrayParserImpl;
}(core_1.ODataParserBase));
function spGetEntityUrl(entity) {
if (entity.hasOwnProperty("odata.metadata") && entity.hasOwnProperty("odata.editLink")) {
// we are dealign with minimal metadata (default)
return util_1.Util.combinePaths(util_1.extractWebUrl(entity["odata.metadata"]), "_api", entity["odata.editLink"]);