@pnp/odata
Advanced tools
Comparing version 1.0.4-4 to 1.0.4
/** | ||
@license | ||
* @pnp/odata v1.0.4-4 - pnp - provides shared odata functionality and base classes | ||
* @pnp/odata v1.0.4 - pnp - provides shared odata functionality and base classes | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -10,4 +10,4 @@ * Copyright (c) 2018 Microsoft | ||
*/ | ||
import { Dictionary, PnPClientStorage, RuntimeConfig, combinePaths, dateAdd, extend, getGUID, isFunc, mergeOptions, objectDefinedNotNull } from '@pnp/common'; | ||
import { __decorate, __extends } from 'tslib'; | ||
import { RuntimeConfig, dateAdd, PnPClientStorage, isFunc, extend, combinePaths, Dictionary, mergeOptions, objectDefinedNotNull, getGUID } from '@pnp/common'; | ||
import { __extends, __decorate } from 'tslib'; | ||
import { Logger } from '@pnp/logging'; | ||
@@ -14,0 +14,0 @@ |
/** | ||
@license | ||
* @pnp/odata v1.0.4-4 - pnp - provides shared odata functionality and base classes | ||
* @pnp/odata v1.0.4 - pnp - provides shared odata functionality and base classes | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -12,3 +12,3 @@ * Copyright (c) 2018 Microsoft | ||
@license | ||
* @pnp/common v1.0.4-4 - pnp - provides shared functionality across all pnp libraries | ||
* @pnp/common v1.0.4 - pnp - provides shared functionality across all pnp libraries | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -36,3 +36,3 @@ * Copyright (c) 2018 Microsoft | ||
@license | ||
* @pnp/logging v1.0.4-4 - pnp - light-weight, subscribable logging framework | ||
* @pnp/logging v1.0.4 - pnp - light-weight, subscribable logging framework | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -39,0 +39,0 @@ * Copyright (c) 2018 Microsoft |
/** | ||
@license | ||
* @pnp/odata v1.0.4-4 - pnp - provides shared odata functionality and base classes | ||
* @pnp/odata v1.0.4 - pnp - provides shared odata functionality and base classes | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -11,734 +11,734 @@ * Copyright (c) 2018 Microsoft | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pnp/common'), require('tslib'), require('@pnp/logging')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@pnp/common', 'tslib', '@pnp/logging'], factory) : | ||
(factory((global.pnp = global.pnp || {}, global.pnp.odata = {}),global.pnp.common,global.tslib_1,global.pnp.logging)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pnp/common'), require('tslib'), require('@pnp/logging')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@pnp/common', 'tslib', '@pnp/logging'], factory) : | ||
(factory((global.pnp = global.pnp || {}, global.pnp.odata = {}),global.pnp.common,global.tslib_1,global.pnp.logging)); | ||
}(this, (function (exports,common,tslib_1,logging) { 'use strict'; | ||
var CachingOptions = /** @class */ (function () { | ||
function CachingOptions(key) { | ||
this.key = key; | ||
this.expiration = common.dateAdd(new Date(), "second", common.RuntimeConfig.defaultCachingTimeoutSeconds); | ||
this.storeName = common.RuntimeConfig.defaultCachingStore; | ||
} | ||
Object.defineProperty(CachingOptions.prototype, "store", { | ||
get: function () { | ||
if (this.storeName === "local") { | ||
return CachingOptions.storage.local; | ||
} | ||
else { | ||
return CachingOptions.storage.session; | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
CachingOptions.storage = new common.PnPClientStorage(); | ||
return CachingOptions; | ||
}()); | ||
var CachingParserWrapper = /** @class */ (function () { | ||
function CachingParserWrapper(_parser, _cacheOptions) { | ||
this._parser = _parser; | ||
this._cacheOptions = _cacheOptions; | ||
} | ||
CachingParserWrapper.prototype.parse = function (response) { | ||
var _this = this; | ||
// add this to the cache based on the options | ||
return this._parser.parse(response).then(function (data) { | ||
if (_this._cacheOptions.store !== null) { | ||
_this._cacheOptions.store.put(_this._cacheOptions.key, data, _this._cacheOptions.expiration); | ||
} | ||
return data; | ||
var CachingOptions = /** @class */ (function () { | ||
function CachingOptions(key) { | ||
this.key = key; | ||
this.expiration = common.dateAdd(new Date(), "second", common.RuntimeConfig.defaultCachingTimeoutSeconds); | ||
this.storeName = common.RuntimeConfig.defaultCachingStore; | ||
} | ||
Object.defineProperty(CachingOptions.prototype, "store", { | ||
get: function () { | ||
if (this.storeName === "local") { | ||
return CachingOptions.storage.local; | ||
} | ||
else { | ||
return CachingOptions.storage.session; | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
}; | ||
return CachingParserWrapper; | ||
}()); | ||
CachingOptions.storage = new common.PnPClientStorage(); | ||
return CachingOptions; | ||
}()); | ||
var CachingParserWrapper = /** @class */ (function () { | ||
function CachingParserWrapper(_parser, _cacheOptions) { | ||
this._parser = _parser; | ||
this._cacheOptions = _cacheOptions; | ||
} | ||
CachingParserWrapper.prototype.parse = function (response) { | ||
var _this = this; | ||
// add this to the cache based on the options | ||
return this._parser.parse(response).then(function (data) { | ||
if (_this._cacheOptions.store !== null) { | ||
_this._cacheOptions.store.put(_this._cacheOptions.key, data, _this._cacheOptions.expiration); | ||
} | ||
return data; | ||
}); | ||
}; | ||
return CachingParserWrapper; | ||
}()); | ||
/** | ||
* Represents an exception with an HttpClient request | ||
* | ||
*/ | ||
var ProcessHttpClientResponseException = /** @class */ (function (_super) { | ||
tslib_1.__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.Logger.log({ data: _this.data, level: 3 /* Error */, message: _this.message }); | ||
return _this; | ||
} | ||
return ProcessHttpClientResponseException; | ||
}(Error)); | ||
var ODataParserBase = /** @class */ (function () { | ||
function ODataParserBase() { | ||
} | ||
ODataParserBase.prototype.parse = function (r) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this.handleError(r, reject)) { | ||
// handle all requests as text, then parse if they are not empty | ||
r.text() | ||
.then(function (txt) { return txt.replace(/\s/ig, "").length > 0 ? JSON.parse(txt) : {}; }) | ||
.then(function (json) { return resolve(_this.parseODataJSON(json)); }) | ||
.catch(function (e) { return reject(e); }); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Handles a response with ok === false by parsing the body and creating a ProcessHttpClientResponseException | ||
* which is passed to the reject delegate. This method returns true if there is no error, otherwise false | ||
* Represents an exception with an HttpClient request | ||
* | ||
* @param r Current response object | ||
* @param reject reject delegate for the surrounding promise | ||
*/ | ||
ODataParserBase.prototype.handleError = function (r, reject) { | ||
if (!r.ok) { | ||
// read the response as text, it may not be valid json | ||
r.json().then(function (json) { | ||
// include the headers as they contain diagnostic information | ||
var data = { | ||
responseBody: json, | ||
responseHeaders: r.headers, | ||
}; | ||
reject(new ProcessHttpClientResponseException(r.status, r.statusText, data)); | ||
}).catch(function (e) { | ||
// we failed to read the body - possibly it is empty. Let's report the original status that caused | ||
// the request to fail and log the error without parsing the body if anyone needs it for debugging | ||
logging.Logger.log({ | ||
data: e, | ||
level: 2 /* Warning */, | ||
message: "There was an error parsing the error response body. See data for details.", | ||
var ProcessHttpClientResponseException = /** @class */ (function (_super) { | ||
tslib_1.__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.Logger.log({ data: _this.data, level: 3 /* Error */, message: _this.message }); | ||
return _this; | ||
} | ||
return ProcessHttpClientResponseException; | ||
}(Error)); | ||
var ODataParserBase = /** @class */ (function () { | ||
function ODataParserBase() { | ||
} | ||
ODataParserBase.prototype.parse = function (r) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this.handleError(r, reject)) { | ||
// handle all requests as text, then parse if they are not empty | ||
r.text() | ||
.then(function (txt) { return txt.replace(/\s/ig, "").length > 0 ? JSON.parse(txt) : {}; }) | ||
.then(function (json) { return resolve(_this.parseODataJSON(json)); }) | ||
.catch(function (e) { return reject(e); }); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Handles a response with ok === false by parsing the body and creating a ProcessHttpClientResponseException | ||
* which is passed to the reject delegate. This method returns true if there is no error, otherwise false | ||
* | ||
* @param r Current response object | ||
* @param reject reject delegate for the surrounding promise | ||
*/ | ||
ODataParserBase.prototype.handleError = function (r, reject) { | ||
if (!r.ok) { | ||
// read the response as text, it may not be valid json | ||
r.json().then(function (json) { | ||
// include the headers as they contain diagnostic information | ||
var data = { | ||
responseBody: json, | ||
responseHeaders: r.headers, | ||
}; | ||
reject(new ProcessHttpClientResponseException(r.status, r.statusText, data)); | ||
}).catch(function (e) { | ||
// we failed to read the body - possibly it is empty. Let's report the original status that caused | ||
// the request to fail and log the error without parsing the body if anyone needs it for debugging | ||
logging.Logger.log({ | ||
data: e, | ||
level: 2 /* Warning */, | ||
message: "There was an error parsing the error response body. See data for details.", | ||
}); | ||
// include the headers as they contain diagnostic information | ||
var data = { | ||
responseBody: "[[body not available]]", | ||
responseHeaders: r.headers, | ||
}; | ||
reject(new ProcessHttpClientResponseException(r.status, r.statusText, data)); | ||
}); | ||
// include the headers as they contain diagnostic information | ||
var data = { | ||
responseBody: "[[body not available]]", | ||
responseHeaders: r.headers, | ||
}; | ||
reject(new ProcessHttpClientResponseException(r.status, r.statusText, data)); | ||
}); | ||
} | ||
return r.ok; | ||
}; | ||
/** | ||
* Normalizes the json response by removing the various nested levels | ||
* | ||
* @param json json object to parse | ||
*/ | ||
ODataParserBase.prototype.parseODataJSON = function (json) { | ||
var result = json; | ||
if (json.hasOwnProperty("d")) { | ||
if (json.d.hasOwnProperty("results")) { | ||
result = json.d.results; | ||
} | ||
else { | ||
result = json.d; | ||
return r.ok; | ||
}; | ||
/** | ||
* Normalizes the json response by removing the various nested levels | ||
* | ||
* @param json json object to parse | ||
*/ | ||
ODataParserBase.prototype.parseODataJSON = function (json) { | ||
var result = json; | ||
if (json.hasOwnProperty("d")) { | ||
if (json.d.hasOwnProperty("results")) { | ||
result = json.d.results; | ||
} | ||
else { | ||
result = json.d; | ||
} | ||
} | ||
else if (json.hasOwnProperty("value")) { | ||
result = json.value; | ||
} | ||
return result; | ||
}; | ||
return ODataParserBase; | ||
}()); | ||
var ODataDefaultParser = /** @class */ (function (_super) { | ||
tslib_1.__extends(ODataDefaultParser, _super); | ||
function ODataDefaultParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
else if (json.hasOwnProperty("value")) { | ||
result = json.value; | ||
return ODataDefaultParser; | ||
}(ODataParserBase)); | ||
var TextParser = /** @class */ (function () { | ||
function TextParser() { | ||
} | ||
return result; | ||
}; | ||
return ODataParserBase; | ||
}()); | ||
var ODataDefaultParser = /** @class */ (function (_super) { | ||
tslib_1.__extends(ODataDefaultParser, _super); | ||
function ODataDefaultParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return ODataDefaultParser; | ||
}(ODataParserBase)); | ||
var TextParser = /** @class */ (function () { | ||
function TextParser() { | ||
} | ||
TextParser.prototype.parse = function (r) { | ||
return r.text(); | ||
}; | ||
return TextParser; | ||
}()); | ||
var BlobParser = /** @class */ (function () { | ||
function BlobParser() { | ||
} | ||
BlobParser.prototype.parse = function (r) { | ||
return r.blob(); | ||
}; | ||
return BlobParser; | ||
}()); | ||
var JSONParser = /** @class */ (function () { | ||
function JSONParser() { | ||
} | ||
JSONParser.prototype.parse = function (r) { | ||
return r.json(); | ||
}; | ||
return JSONParser; | ||
}()); | ||
var BufferParser = /** @class */ (function () { | ||
function BufferParser() { | ||
} | ||
BufferParser.prototype.parse = function (r) { | ||
if (common.isFunc(r.arrayBuffer)) { | ||
return r.arrayBuffer(); | ||
TextParser.prototype.parse = function (r) { | ||
return r.text(); | ||
}; | ||
return TextParser; | ||
}()); | ||
var BlobParser = /** @class */ (function () { | ||
function BlobParser() { | ||
} | ||
return r.buffer(); | ||
}; | ||
return BufferParser; | ||
}()); | ||
/** | ||
* Resolves the context's result value | ||
* | ||
* @param context The current context | ||
*/ | ||
function returnResult(context) { | ||
logging.Logger.log({ | ||
data: context.result, | ||
level: 0 /* Verbose */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Returning result, see data property for value.", | ||
}); | ||
return Promise.resolve(context.result || null); | ||
} | ||
/** | ||
* Sets the result on the context | ||
*/ | ||
function setResult(context, value) { | ||
return new Promise(function (resolve) { | ||
context.result = value; | ||
context.hasResult = true; | ||
resolve(context); | ||
}); | ||
} | ||
/** | ||
* Invokes the next method in the provided context's pipeline | ||
* | ||
* @param c The current request context | ||
*/ | ||
function next(c) { | ||
if (c.pipeline.length > 0) { | ||
return c.pipeline.shift()(c); | ||
} | ||
else { | ||
return Promise.resolve(c); | ||
} | ||
} | ||
/** | ||
* Executes the current request context's pipeline | ||
* | ||
* @param context Current context | ||
*/ | ||
function pipe(context) { | ||
if (context.pipeline.length < 1) { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Request pipeline contains no methods!", 2 /* Warning */); | ||
} | ||
return next(context) | ||
.then(function (ctx) { return returnResult(ctx); }) | ||
.catch(function (e) { | ||
logging.Logger.error(e); | ||
throw e; | ||
}); | ||
} | ||
/** | ||
* decorator factory applied to methods in the pipeline to control behavior | ||
*/ | ||
function requestPipelineMethod(alwaysRun) { | ||
if (alwaysRun === void 0) { alwaysRun = false; } | ||
return function (target, propertyKey, descriptor) { | ||
var method = descriptor.value; | ||
descriptor.value = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
BlobParser.prototype.parse = function (r) { | ||
return r.blob(); | ||
}; | ||
return BlobParser; | ||
}()); | ||
var JSONParser = /** @class */ (function () { | ||
function JSONParser() { | ||
} | ||
JSONParser.prototype.parse = function (r) { | ||
return r.json(); | ||
}; | ||
return JSONParser; | ||
}()); | ||
var BufferParser = /** @class */ (function () { | ||
function BufferParser() { | ||
} | ||
BufferParser.prototype.parse = function (r) { | ||
if (common.isFunc(r.arrayBuffer)) { | ||
return r.arrayBuffer(); | ||
} | ||
// if we have a result already in the pipeline, pass it along and don't call the tagged method | ||
if (!alwaysRun && args.length > 0 && args[0].hasOwnProperty("hasResult") && args[0].hasResult) { | ||
logging.Logger.write("[" + args[0].requestId + "] (" + (new Date()).getTime() + ") Skipping request pipeline method " + propertyKey + ", existing result in pipeline.", 0 /* Verbose */); | ||
return Promise.resolve(args[0]); | ||
} | ||
// apply the tagged method | ||
logging.Logger.write("[" + args[0].requestId + "] (" + (new Date()).getTime() + ") Calling request pipeline method " + propertyKey + ".", 0 /* Verbose */); | ||
// then chain the next method in the context's pipeline - allows for dynamic pipeline | ||
return method.apply(target, args).then(function (ctx) { return next(ctx); }); | ||
return r.buffer(); | ||
}; | ||
}; | ||
} | ||
/** | ||
* Contains the methods used within the request pipeline | ||
*/ | ||
var PipelineMethods = /** @class */ (function () { | ||
function PipelineMethods() { | ||
return BufferParser; | ||
}()); | ||
/** | ||
* Resolves the context's result value | ||
* | ||
* @param context The current context | ||
*/ | ||
function returnResult(context) { | ||
logging.Logger.log({ | ||
data: context.result, | ||
level: 0 /* Verbose */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Returning result, see data property for value.", | ||
}); | ||
return Promise.resolve(context.result || null); | ||
} | ||
/** | ||
* Logs the start of the request | ||
* Sets the result on the context | ||
*/ | ||
PipelineMethods.logStart = function (context) { | ||
function setResult(context, value) { | ||
return new Promise(function (resolve) { | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Beginning " + context.verb + " request (" + context.requestAbsoluteUrl + ")", | ||
}); | ||
context.result = value; | ||
context.hasResult = true; | ||
resolve(context); | ||
}); | ||
}; | ||
} | ||
/** | ||
* Handles caching of the request | ||
* Invokes the next method in the provided context's pipeline | ||
* | ||
* @param c The current request context | ||
*/ | ||
PipelineMethods.caching = function (context) { | ||
return new Promise(function (resolve) { | ||
// handle caching, if applicable | ||
if (context.verb === "GET" && context.isCached) { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Caching is enabled for request, checking cache...", 1 /* Info */); | ||
var cacheOptions = new CachingOptions(context.requestAbsoluteUrl.toLowerCase()); | ||
if (typeof context.cachingOptions !== "undefined") { | ||
cacheOptions = common.extend(cacheOptions, context.cachingOptions); | ||
} | ||
// we may not have a valid store | ||
if (cacheOptions.store !== null) { | ||
// check if we have the data in cache and if so resolve the promise and return | ||
var data = cacheOptions.store.get(cacheOptions.key); | ||
if (data !== null) { | ||
// ensure we clear any help batch dependency we are resolving from the cache | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : data, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Value returned from cache.", | ||
}); | ||
if (common.isFunc(context.batchDependency)) { | ||
context.batchDependency(); | ||
} | ||
// handle the case where a parser needs to take special actions with a cached result (such as getAs) | ||
if (context.parser.hasOwnProperty("hydrate")) { | ||
data = context.parser.hydrate(data); | ||
} | ||
return setResult(context, data).then(function (ctx) { return resolve(ctx); }); | ||
} | ||
} | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Value not found in cache.", 1 /* Info */); | ||
// if we don't then wrap the supplied parser in the caching parser wrapper | ||
// and send things on their way | ||
context.parser = new CachingParserWrapper(context.parser, cacheOptions); | ||
} | ||
return resolve(context); | ||
function next(c) { | ||
if (c.pipeline.length > 0) { | ||
return c.pipeline.shift()(c); | ||
} | ||
else { | ||
return Promise.resolve(c); | ||
} | ||
} | ||
/** | ||
* Executes the current request context's pipeline | ||
* | ||
* @param context Current context | ||
*/ | ||
function pipe(context) { | ||
if (context.pipeline.length < 1) { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Request pipeline contains no methods!", 2 /* Warning */); | ||
} | ||
return next(context) | ||
.then(function (ctx) { return returnResult(ctx); }) | ||
.catch(function (e) { | ||
logging.Logger.error(e); | ||
throw e; | ||
}); | ||
}; | ||
} | ||
/** | ||
* Sends the request | ||
* decorator factory applied to methods in the pipeline to control behavior | ||
*/ | ||
PipelineMethods.send = function (context) { | ||
return new Promise(function (resolve, reject) { | ||
// send or batch the request | ||
if (context.isBatched) { | ||
// we are in a batch, so add to batch, remove dependency, and resolve with the batch's promise | ||
var p = context.batch.add(context.requestAbsoluteUrl, context.verb, context.options, context.parser); | ||
// we release the dependency here to ensure the batch does not execute until the request is added to the batch | ||
if (common.isFunc(context.batchDependency)) { | ||
context.batchDependency(); | ||
function requestPipelineMethod(alwaysRun) { | ||
if (alwaysRun === void 0) { alwaysRun = false; } | ||
return function (target, propertyKey, descriptor) { | ||
var method = descriptor.value; | ||
descriptor.value = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Batching request in batch " + context.batch.batchId + ".", 1 /* Info */); | ||
// we set the result as the promise which will be resolved by the batch's execution | ||
resolve(setResult(context, p)); | ||
} | ||
else { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Sending request.", 1 /* Info */); | ||
// we are not part of a batch, so proceed as normal | ||
var client = context.clientFactory(); | ||
var opts = common.extend(context.options || {}, { method: context.verb }); | ||
client.fetch(context.requestAbsoluteUrl, opts) | ||
.then(function (response) { return context.parser.parse(response); }) | ||
.then(function (result) { return setResult(context, result); }) | ||
.then(function (ctx) { return resolve(ctx); }) | ||
.catch(function (e) { return reject(e); }); | ||
} | ||
}); | ||
}; | ||
// if we have a result already in the pipeline, pass it along and don't call the tagged method | ||
if (!alwaysRun && args.length > 0 && args[0].hasOwnProperty("hasResult") && args[0].hasResult) { | ||
logging.Logger.write("[" + args[0].requestId + "] (" + (new Date()).getTime() + ") Skipping request pipeline method " + propertyKey + ", existing result in pipeline.", 0 /* Verbose */); | ||
return Promise.resolve(args[0]); | ||
} | ||
// apply the tagged method | ||
logging.Logger.write("[" + args[0].requestId + "] (" + (new Date()).getTime() + ") Calling request pipeline method " + propertyKey + ".", 0 /* Verbose */); | ||
// then chain the next method in the context's pipeline - allows for dynamic pipeline | ||
return method.apply(target, args).then(function (ctx) { return next(ctx); }); | ||
}; | ||
}; | ||
} | ||
/** | ||
* Logs the end of the request | ||
* Contains the methods used within the request pipeline | ||
*/ | ||
PipelineMethods.logEnd = function (context) { | ||
return new Promise(function (resolve) { | ||
if (context.isBatched) { | ||
var PipelineMethods = /** @class */ (function () { | ||
function PipelineMethods() { | ||
} | ||
/** | ||
* Logs the start of the request | ||
*/ | ||
PipelineMethods.logStart = function (context) { | ||
return new Promise(function (resolve) { | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") " + context.verb + " request will complete in batch " + context.batch.batchId + ".", | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Beginning " + context.verb + " request (" + context.requestAbsoluteUrl + ")", | ||
}); | ||
} | ||
else { | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Completing " + context.verb + " request.", | ||
}); | ||
} | ||
resolve(context); | ||
}); | ||
}; | ||
tslib_1.__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logStart", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "caching", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "send", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logEnd", null); | ||
return PipelineMethods; | ||
}()); | ||
function getDefaultPipeline() { | ||
return [ | ||
PipelineMethods.logStart, | ||
PipelineMethods.caching, | ||
PipelineMethods.send, | ||
PipelineMethods.logEnd, | ||
].slice(0); | ||
} | ||
resolve(context); | ||
}); | ||
}; | ||
/** | ||
* Handles caching of the request | ||
*/ | ||
PipelineMethods.caching = function (context) { | ||
return new Promise(function (resolve) { | ||
// handle caching, if applicable | ||
if (context.verb === "GET" && context.isCached) { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Caching is enabled for request, checking cache...", 1 /* Info */); | ||
var cacheOptions = new CachingOptions(context.requestAbsoluteUrl.toLowerCase()); | ||
if (typeof context.cachingOptions !== "undefined") { | ||
cacheOptions = common.extend(cacheOptions, context.cachingOptions); | ||
} | ||
// we may not have a valid store | ||
if (cacheOptions.store !== null) { | ||
// check if we have the data in cache and if so resolve the promise and return | ||
var data = cacheOptions.store.get(cacheOptions.key); | ||
if (data !== null) { | ||
// ensure we clear any help batch dependency we are resolving from the cache | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : data, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Value returned from cache.", | ||
}); | ||
if (common.isFunc(context.batchDependency)) { | ||
context.batchDependency(); | ||
} | ||
// handle the case where a parser needs to take special actions with a cached result (such as getAs) | ||
if (context.parser.hasOwnProperty("hydrate")) { | ||
data = context.parser.hydrate(data); | ||
} | ||
return setResult(context, data).then(function (ctx) { return resolve(ctx); }); | ||
} | ||
} | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Value not found in cache.", 1 /* Info */); | ||
// if we don't then wrap the supplied parser in the caching parser wrapper | ||
// and send things on their way | ||
context.parser = new CachingParserWrapper(context.parser, cacheOptions); | ||
} | ||
return resolve(context); | ||
}); | ||
}; | ||
/** | ||
* Sends the request | ||
*/ | ||
PipelineMethods.send = function (context) { | ||
return new Promise(function (resolve, reject) { | ||
// send or batch the request | ||
if (context.isBatched) { | ||
// we are in a batch, so add to batch, remove dependency, and resolve with the batch's promise | ||
var p = context.batch.add(context.requestAbsoluteUrl, context.verb, context.options, context.parser); | ||
// we release the dependency here to ensure the batch does not execute until the request is added to the batch | ||
if (common.isFunc(context.batchDependency)) { | ||
context.batchDependency(); | ||
} | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Batching request in batch " + context.batch.batchId + ".", 1 /* Info */); | ||
// we set the result as the promise which will be resolved by the batch's execution | ||
resolve(setResult(context, p)); | ||
} | ||
else { | ||
logging.Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Sending request.", 1 /* Info */); | ||
// we are not part of a batch, so proceed as normal | ||
var client = context.clientFactory(); | ||
var opts = common.extend(context.options || {}, { method: context.verb }); | ||
client.fetch(context.requestAbsoluteUrl, opts) | ||
.then(function (response) { return context.parser.parse(response); }) | ||
.then(function (result) { return setResult(context, result); }) | ||
.then(function (ctx) { return resolve(ctx); }) | ||
.catch(function (e) { return reject(e); }); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Logs the end of the request | ||
*/ | ||
PipelineMethods.logEnd = function (context) { | ||
return new Promise(function (resolve) { | ||
if (context.isBatched) { | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") " + context.verb + " request will complete in batch " + context.batch.batchId + ".", | ||
}); | ||
} | ||
else { | ||
logging.Logger.log({ | ||
data: logging.Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Completing " + context.verb + " request.", | ||
}); | ||
} | ||
resolve(context); | ||
}); | ||
}; | ||
tslib_1.__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logStart", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "caching", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "send", null); | ||
tslib_1.__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logEnd", null); | ||
return PipelineMethods; | ||
}()); | ||
function getDefaultPipeline() { | ||
return [ | ||
PipelineMethods.logStart, | ||
PipelineMethods.caching, | ||
PipelineMethods.send, | ||
PipelineMethods.logEnd, | ||
].slice(0); | ||
} | ||
var AlreadyInBatchException = /** @class */ (function (_super) { | ||
tslib_1.__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"; | ||
logging.Logger.error(_this); | ||
return _this; | ||
} | ||
return AlreadyInBatchException; | ||
}(Error)); | ||
var Queryable = /** @class */ (function () { | ||
function Queryable() { | ||
this._query = new common.Dictionary(); | ||
this._options = {}; | ||
this._url = ""; | ||
this._parentUrl = ""; | ||
this._useCaching = false; | ||
this._cachingOptions = null; | ||
} | ||
/** | ||
* Gets the currentl url | ||
* | ||
*/ | ||
Queryable.prototype.toUrl = function () { | ||
return this._url; | ||
}; | ||
/** | ||
* Directly concatonates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatonate to the url | ||
*/ | ||
Queryable.prototype.concat = function (pathPart) { | ||
this._url += pathPart; | ||
return this; | ||
}; | ||
Object.defineProperty(Queryable.prototype, "query", { | ||
var AlreadyInBatchException = /** @class */ (function (_super) { | ||
tslib_1.__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"; | ||
logging.Logger.error(_this); | ||
return _this; | ||
} | ||
return AlreadyInBatchException; | ||
}(Error)); | ||
var Queryable = /** @class */ (function () { | ||
function Queryable() { | ||
this._query = new common.Dictionary(); | ||
this._options = {}; | ||
this._url = ""; | ||
this._parentUrl = ""; | ||
this._useCaching = false; | ||
this._cachingOptions = null; | ||
} | ||
/** | ||
* Provides access to the query builder for this url | ||
* Gets the currentl url | ||
* | ||
*/ | ||
Queryable.prototype.toUrl = function () { | ||
return this._url; | ||
}; | ||
/** | ||
* Directly concatonates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatonate to the url | ||
*/ | ||
get: function () { | ||
return this._query; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
* | ||
* @param options custom options | ||
*/ | ||
Queryable.prototype.configure = function (options) { | ||
common.mergeOptions(this._options, options); | ||
return this; | ||
}; | ||
/** | ||
* Configures this instance from the configure options of the supplied instance | ||
* | ||
* @param o Instance from which options should be taken | ||
*/ | ||
Queryable.prototype.configureFrom = function (o) { | ||
common.mergeOptions(this._options, o._options); | ||
return this; | ||
}; | ||
/** | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
Queryable.prototype.usingCaching = function (options) { | ||
if (!common.RuntimeConfig.globalCacheDisable) { | ||
this._useCaching = true; | ||
if (typeof options !== "undefined") { | ||
this._cachingOptions = options; | ||
Queryable.prototype.concat = function (pathPart) { | ||
this._url += pathPart; | ||
return this; | ||
}; | ||
Object.defineProperty(Queryable.prototype, "query", { | ||
/** | ||
* Provides access to the query builder for this url | ||
* | ||
*/ | ||
get: function () { | ||
return this._query; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
* | ||
* @param options custom options | ||
*/ | ||
Queryable.prototype.configure = function (options) { | ||
common.mergeOptions(this._options, options); | ||
return this; | ||
}; | ||
/** | ||
* Configures this instance from the configure options of the supplied instance | ||
* | ||
* @param o Instance from which options should be taken | ||
*/ | ||
Queryable.prototype.configureFrom = function (o) { | ||
common.mergeOptions(this._options, o._options); | ||
return this; | ||
}; | ||
/** | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
Queryable.prototype.usingCaching = function (options) { | ||
if (!common.RuntimeConfig.globalCacheDisable) { | ||
this._useCaching = true; | ||
if (typeof options !== "undefined") { | ||
this._cachingOptions = options; | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Executes the currently built request | ||
* | ||
* @param parser Allows you to specify a parser to handle the result | ||
* @param getOptions The options used for this request | ||
*/ | ||
Queryable.prototype.get = function (parser, options) { | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.getCore(parser, options); | ||
}; | ||
Queryable.prototype.getCore = function (parser, options) { | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.toRequestContext("GET", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.postCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("POST", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.patchCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("PATCH", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.deleteCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("DELETE", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.putCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("PUT", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
/** | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
Queryable.prototype.append = function (pathPart) { | ||
this._url = common.combinePaths(this._url, pathPart); | ||
}; | ||
Object.defineProperty(Queryable.prototype, "parentUrl", { | ||
return this; | ||
}; | ||
/** | ||
* Gets the parent url used when creating this instance | ||
* Executes the currently built request | ||
* | ||
* @param parser Allows you to specify a parser to handle the result | ||
* @param getOptions The options used for this request | ||
*/ | ||
get: function () { | ||
return this._parentUrl; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Extends this queryable from | ||
* | ||
* @param parent Parent queryable from which we will derive a base url | ||
* @param path Additional path | ||
*/ | ||
Queryable.prototype.extend = function (parent, path) { | ||
this._parentUrl = parent._url; | ||
this._url = common.combinePaths(this._parentUrl, path); | ||
this.configureFrom(parent); | ||
}; | ||
return Queryable; | ||
}()); | ||
var ODataQueryable = /** @class */ (function (_super) { | ||
tslib_1.__extends(ODataQueryable, _super); | ||
function ODataQueryable() { | ||
var _this = _super.call(this) || this; | ||
_this._batch = null; | ||
return _this; | ||
} | ||
/** | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
ODataQueryable.prototype.inBatch = function (batch) { | ||
if (this.batch !== null) { | ||
throw new AlreadyInBatchException(); | ||
Queryable.prototype.get = function (parser, options) { | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.getCore(parser, options); | ||
}; | ||
Queryable.prototype.getCore = function (parser, options) { | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.toRequestContext("GET", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.postCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("POST", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.patchCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("PATCH", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.deleteCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("DELETE", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
Queryable.prototype.putCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new JSONParser(); } | ||
return this.toRequestContext("PUT", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
/** | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
Queryable.prototype.append = function (pathPart) { | ||
this._url = common.combinePaths(this._url, pathPart); | ||
}; | ||
Object.defineProperty(Queryable.prototype, "parentUrl", { | ||
/** | ||
* Gets the parent url used when creating this instance | ||
* | ||
*/ | ||
get: function () { | ||
return this._parentUrl; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Extends this queryable from | ||
* | ||
* @param parent Parent queryable from which we will derive a base url | ||
* @param path Additional path | ||
*/ | ||
Queryable.prototype.extend = function (parent, path) { | ||
this._parentUrl = parent._url; | ||
this._url = common.combinePaths(this._parentUrl, path); | ||
this.configureFrom(parent); | ||
}; | ||
return Queryable; | ||
}()); | ||
var ODataQueryable = /** @class */ (function (_super) { | ||
tslib_1.__extends(ODataQueryable, _super); | ||
function ODataQueryable() { | ||
var _this = _super.call(this) || this; | ||
_this._batch = null; | ||
return _this; | ||
} | ||
this._batch = batch; | ||
return this; | ||
}; | ||
/** | ||
* Gets the currentl url | ||
* | ||
*/ | ||
ODataQueryable.prototype.toUrl = function () { | ||
return this._url; | ||
}; | ||
/** | ||
* Executes the currently built request | ||
* | ||
* @param parser Allows you to specify a parser to handle the result | ||
* @param getOptions The options used for this request | ||
*/ | ||
ODataQueryable.prototype.get = function (parser, options) { | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.getCore(parser, options); | ||
}; | ||
ODataQueryable.prototype.getCore = function (parser, options) { | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.toRequestContext("GET", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.postCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("POST", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.patchCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("PATCH", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.deleteCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("DELETE", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.putCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("PUT", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
/** | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
ODataQueryable.prototype.addBatchDependency = function () { | ||
if (this._batch !== null) { | ||
return this._batch.addDependency(); | ||
} | ||
return function () { return null; }; | ||
}; | ||
Object.defineProperty(ODataQueryable.prototype, "hasBatch", { | ||
/** | ||
* Indicates if the current query has a batch associated | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
get: function () { | ||
return common.objectDefinedNotNull(this._batch); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ODataQueryable.prototype, "batch", { | ||
ODataQueryable.prototype.inBatch = function (batch) { | ||
if (this.batch !== null) { | ||
throw new AlreadyInBatchException(); | ||
} | ||
this._batch = batch; | ||
return this; | ||
}; | ||
/** | ||
* The batch currently associated with this query or null | ||
* Gets the currentl url | ||
* | ||
*/ | ||
get: function () { | ||
return this.hasBatch ? this._batch : null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ODataQueryable; | ||
}(Queryable)); | ||
var ODataBatch = /** @class */ (function () { | ||
function ODataBatch(_batchId) { | ||
if (_batchId === void 0) { _batchId = common.getGUID(); } | ||
this._batchId = _batchId; | ||
this._requests = []; | ||
this._dependencies = []; | ||
} | ||
Object.defineProperty(ODataBatch.prototype, "batchId", { | ||
get: function () { | ||
return this._batchId; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ODataBatch.prototype, "requests", { | ||
ODataQueryable.prototype.toUrl = function () { | ||
return this._url; | ||
}; | ||
/** | ||
* The requests contained in this batch | ||
* Executes the currently built request | ||
* | ||
* @param parser Allows you to specify a parser to handle the result | ||
* @param getOptions The options used for this request | ||
*/ | ||
get: function () { | ||
return this._requests; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* | ||
* @param url Request url | ||
* @param method Request method (GET, POST, etc) | ||
* @param options Any request options | ||
* @param parser The parser used to handle the eventual return from the query | ||
*/ | ||
ODataBatch.prototype.add = function (url, method, options, parser) { | ||
var info = { | ||
method: method.toUpperCase(), | ||
options: options, | ||
parser: parser, | ||
reject: null, | ||
resolve: null, | ||
url: url, | ||
ODataQueryable.prototype.get = function (parser, options) { | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.getCore(parser, options); | ||
}; | ||
var p = new Promise(function (resolve, reject) { | ||
info.resolve = resolve; | ||
info.reject = reject; | ||
ODataQueryable.prototype.getCore = function (parser, options) { | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
if (options === void 0) { options = {}; } | ||
return this.toRequestContext("GET", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.postCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("POST", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.patchCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("PATCH", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.deleteCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("DELETE", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
ODataQueryable.prototype.putCore = function (options, parser) { | ||
if (options === void 0) { options = {}; } | ||
if (parser === void 0) { parser = new ODataDefaultParser(); } | ||
return this.toRequestContext("PUT", options, parser, getDefaultPipeline()).then(function (context) { return pipe(context); }); | ||
}; | ||
/** | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
ODataQueryable.prototype.addBatchDependency = function () { | ||
if (this._batch !== null) { | ||
return this._batch.addDependency(); | ||
} | ||
return function () { return null; }; | ||
}; | ||
Object.defineProperty(ODataQueryable.prototype, "hasBatch", { | ||
/** | ||
* Indicates if the current query has a batch associated | ||
* | ||
*/ | ||
get: function () { | ||
return common.objectDefinedNotNull(this._batch); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
this._requests.push(info); | ||
return p; | ||
}; | ||
/** | ||
* Adds a dependency insuring that some set of actions will occur before a batch is processed. | ||
* MUST be cleared using the returned resolve delegate to allow batches to run | ||
*/ | ||
ODataBatch.prototype.addDependency = function () { | ||
var resolver = function () { return void (0); }; | ||
var promise = new Promise(function (resolve) { | ||
resolver = resolve; | ||
Object.defineProperty(ODataQueryable.prototype, "batch", { | ||
/** | ||
* The batch currently associated with this query or null | ||
* | ||
*/ | ||
get: function () { | ||
return this.hasBatch ? this._batch : null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
this._dependencies.push(promise); | ||
return resolver; | ||
}; | ||
/** | ||
* Execute the current batch and resolve the associated promises | ||
* | ||
* @returns A promise which will be resolved once all of the batch's child promises have resolved | ||
*/ | ||
ODataBatch.prototype.execute = function () { | ||
var _this = this; | ||
// we need to check the dependencies twice due to how different engines handle things. | ||
// We can get a second set of promises added during the first set resolving | ||
return Promise.all(this._dependencies).then(function () { return Promise.all(_this._dependencies); }).then(function () { return _this.executeImpl(); }); | ||
}; | ||
return ODataBatch; | ||
}()); | ||
return ODataQueryable; | ||
}(Queryable)); | ||
exports.CachingOptions = CachingOptions; | ||
exports.CachingParserWrapper = CachingParserWrapper; | ||
exports.ProcessHttpClientResponseException = ProcessHttpClientResponseException; | ||
exports.ODataParserBase = ODataParserBase; | ||
exports.ODataDefaultParser = ODataDefaultParser; | ||
exports.TextParser = TextParser; | ||
exports.BlobParser = BlobParser; | ||
exports.JSONParser = JSONParser; | ||
exports.BufferParser = BufferParser; | ||
exports.setResult = setResult; | ||
exports.pipe = pipe; | ||
exports.requestPipelineMethod = requestPipelineMethod; | ||
exports.PipelineMethods = PipelineMethods; | ||
exports.getDefaultPipeline = getDefaultPipeline; | ||
exports.AlreadyInBatchException = AlreadyInBatchException; | ||
exports.Queryable = Queryable; | ||
exports.ODataQueryable = ODataQueryable; | ||
exports.ODataBatch = ODataBatch; | ||
var ODataBatch = /** @class */ (function () { | ||
function ODataBatch(_batchId) { | ||
if (_batchId === void 0) { _batchId = common.getGUID(); } | ||
this._batchId = _batchId; | ||
this._requests = []; | ||
this._dependencies = []; | ||
} | ||
Object.defineProperty(ODataBatch.prototype, "batchId", { | ||
get: function () { | ||
return this._batchId; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ODataBatch.prototype, "requests", { | ||
/** | ||
* The requests contained in this batch | ||
*/ | ||
get: function () { | ||
return this._requests; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* | ||
* @param url Request url | ||
* @param method Request method (GET, POST, etc) | ||
* @param options Any request options | ||
* @param parser The parser used to handle the eventual return from the query | ||
*/ | ||
ODataBatch.prototype.add = function (url, method, options, parser) { | ||
var info = { | ||
method: method.toUpperCase(), | ||
options: options, | ||
parser: parser, | ||
reject: null, | ||
resolve: null, | ||
url: url, | ||
}; | ||
var p = new Promise(function (resolve, reject) { | ||
info.resolve = resolve; | ||
info.reject = reject; | ||
}); | ||
this._requests.push(info); | ||
return p; | ||
}; | ||
/** | ||
* Adds a dependency insuring that some set of actions will occur before a batch is processed. | ||
* MUST be cleared using the returned resolve delegate to allow batches to run | ||
*/ | ||
ODataBatch.prototype.addDependency = function () { | ||
var resolver = function () { return void (0); }; | ||
var promise = new Promise(function (resolve) { | ||
resolver = resolve; | ||
}); | ||
this._dependencies.push(promise); | ||
return resolver; | ||
}; | ||
/** | ||
* Execute the current batch and resolve the associated promises | ||
* | ||
* @returns A promise which will be resolved once all of the batch's child promises have resolved | ||
*/ | ||
ODataBatch.prototype.execute = function () { | ||
var _this = this; | ||
// we need to check the dependencies twice due to how different engines handle things. | ||
// We can get a second set of promises added during the first set resolving | ||
return Promise.all(this._dependencies).then(function () { return Promise.all(_this._dependencies); }).then(function () { return _this.executeImpl(); }); | ||
}; | ||
return ODataBatch; | ||
}()); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.CachingOptions = CachingOptions; | ||
exports.CachingParserWrapper = CachingParserWrapper; | ||
exports.ProcessHttpClientResponseException = ProcessHttpClientResponseException; | ||
exports.ODataParserBase = ODataParserBase; | ||
exports.ODataDefaultParser = ODataDefaultParser; | ||
exports.TextParser = TextParser; | ||
exports.BlobParser = BlobParser; | ||
exports.JSONParser = JSONParser; | ||
exports.BufferParser = BufferParser; | ||
exports.setResult = setResult; | ||
exports.pipe = pipe; | ||
exports.requestPipelineMethod = requestPipelineMethod; | ||
exports.PipelineMethods = PipelineMethods; | ||
exports.getDefaultPipeline = getDefaultPipeline; | ||
exports.AlreadyInBatchException = AlreadyInBatchException; | ||
exports.Queryable = Queryable; | ||
exports.ODataQueryable = ODataQueryable; | ||
exports.ODataBatch = ODataBatch; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=odata.es5.umd.js.map |
/** | ||
@license | ||
* @pnp/odata v1.0.4-4 - pnp - provides shared odata functionality and base classes | ||
* @pnp/odata v1.0.4 - pnp - provides shared odata functionality and base classes | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -10,2 +10,2 @@ * Copyright (c) 2018 Microsoft | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@pnp/common"),require("tslib"),require("@pnp/logging")):"function"==typeof define&&define.amd?define(["exports","@pnp/common","tslib","@pnp/logging"],t):t((e.pnp=e.pnp||{},e.pnp.odata={}),e.pnp.common,e.tslib_1,e.pnp.logging)}(this,function(e,t,n,r){"use strict";var o=function(){function e(e){this.key=e,this.expiration=t.dateAdd(new Date,"second",t.RuntimeConfig.defaultCachingTimeoutSeconds),this.storeName=t.RuntimeConfig.defaultCachingStore}return Object.defineProperty(e.prototype,"store",{get:function(){return"local"===this.storeName?e.storage.local:e.storage.session},enumerable:!0,configurable:!0}),e.storage=new t.PnPClientStorage,e}(),i=function(){function e(e,t){this._parser=e,this._cacheOptions=t}return e.prototype.parse=function(e){var t=this;return this._parser.parse(e).then(function(e){return null!==t._cacheOptions.store&&t._cacheOptions.store.put(t._cacheOptions.key,e,t._cacheOptions.expiration),e})},e}(),u=function(e){function t(t,n,o){var i=e.call(this,"Error making HttpClient request in queryable: ["+t+"] "+n)||this;return i.status=t,i.statusText=n,i.data=o,i.name="ProcessHttpClientResponseException",r.Logger.log({data:i.data,level:3,message:i.message}),i}return n.__extends(t,e),t}(Error),s=function(){function e(){}return e.prototype.parse=function(e){var t=this;return new Promise(function(n,r){t.handleError(e,r)&&e.text().then(function(e){return e.replace(/\s/gi,"").length>0?JSON.parse(e):{}}).then(function(e){return n(t.parseODataJSON(e))}).catch(function(e){return r(e)})})},e.prototype.handleError=function(e,t){return e.ok||e.json().then(function(n){var r={responseBody:n,responseHeaders:e.headers};t(new u(e.status,e.statusText,r))}).catch(function(n){r.Logger.log({data:n,level:2,message:"There was an error parsing the error response body. See data for details."});var o={responseBody:"[[body not available]]",responseHeaders:e.headers};t(new u(e.status,e.statusText,o))}),e.ok},e.prototype.parseODataJSON=function(e){var t=e;return e.hasOwnProperty("d")?t=e.d.hasOwnProperty("results")?e.d.results:e.d:e.hasOwnProperty("value")&&(t=e.value),t},e}(),a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n.__extends(t,e),t}(s),c=function(){function e(){}return e.prototype.parse=function(e){return e.text()},e}(),p=function(){function e(){}return e.prototype.parse=function(e){return e.blob()},e}(),l=function(){function e(){}return e.prototype.parse=function(e){return e.json()},e}(),h=function(){function e(){}return e.prototype.parse=function(e){return t.isFunc(e.arrayBuffer)?e.arrayBuffer():e.buffer()},e}();function f(e,t){return new Promise(function(n){e.result=t,e.hasResult=!0,n(e)})}function d(e){return e.pipeline.length>0?e.pipeline.shift()(e):Promise.resolve(e)}function g(e){return e.pipeline.length<1&&r.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Request pipeline contains no methods!",2),d(e).then(function(e){return t=e,r.Logger.log({data:t.result,level:0,message:"["+t.requestId+"] ("+(new Date).getTime()+") Returning result, see data property for value."}),Promise.resolve(t.result||null);var t}).catch(function(e){throw r.Logger.error(e),e})}function y(e){return void 0===e&&(e=!1),function(t,n,o){var i=o.value;o.value=function(){for(var o=[],u=0;u<arguments.length;u++)o[u]=arguments[u];return!e&&o.length>0&&o[0].hasOwnProperty("hasResult")&&o[0].hasResult?(r.Logger.write("["+o[0].requestId+"] ("+(new Date).getTime()+") Skipping request pipeline method "+n+", existing result in pipeline.",0),Promise.resolve(o[0])):(r.Logger.write("["+o[0].requestId+"] ("+(new Date).getTime()+") Calling request pipeline method "+n+".",0),i.apply(t,o).then(function(e){return d(e)}))}}}var v=function(){function e(){}return e.logStart=function(e){return new Promise(function(t){r.Logger.log({data:1===r.Logger.activeLogLevel?{}:e,level:1,message:"["+e.requestId+"] ("+(new Date).getTime()+") Beginning "+e.verb+" request ("+e.requestAbsoluteUrl+")"}),t(e)})},e.caching=function(e){return new Promise(function(n){if("GET"===e.verb&&e.isCached){r.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Caching is enabled for request, checking cache...",1);var u=new o(e.requestAbsoluteUrl.toLowerCase());if(void 0!==e.cachingOptions&&(u=t.extend(u,e.cachingOptions)),null!==u.store){var s=u.store.get(u.key);if(null!==s)return r.Logger.log({data:1===r.Logger.activeLogLevel?{}:s,level:1,message:"["+e.requestId+"] ("+(new Date).getTime()+") Value returned from cache."}),t.isFunc(e.batchDependency)&&e.batchDependency(),e.parser.hasOwnProperty("hydrate")&&(s=e.parser.hydrate(s)),f(e,s).then(function(e){return n(e)})}r.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Value not found in cache.",1),e.parser=new i(e.parser,u)}return n(e)})},e.send=function(e){return new Promise(function(n,o){if(e.isBatched){var i=e.batch.add(e.requestAbsoluteUrl,e.verb,e.options,e.parser);t.isFunc(e.batchDependency)&&e.batchDependency(),r.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Batching request in batch "+e.batch.batchId+".",1),n(f(e,i))}else{r.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Sending request.",1);var u=e.clientFactory(),s=t.extend(e.options||{},{method:e.verb});u.fetch(e.requestAbsoluteUrl,s).then(function(t){return e.parser.parse(t)}).then(function(t){return f(e,t)}).then(function(e){return n(e)}).catch(function(e){return o(e)})}})},e.logEnd=function(e){return new Promise(function(t){e.isBatched?r.Logger.log({data:1===r.Logger.activeLogLevel?{}:e,level:1,message:"["+e.requestId+"] ("+(new Date).getTime()+") "+e.verb+" request will complete in batch "+e.batch.batchId+"."}):r.Logger.log({data:1===r.Logger.activeLogLevel?{}:e,level:1,message:"["+e.requestId+"] ("+(new Date).getTime()+") Completing "+e.verb+" request."}),t(e)})},n.__decorate([y(!0)],e,"logStart",null),n.__decorate([y()],e,"caching",null),n.__decorate([y()],e,"send",null),n.__decorate([y(!0)],e,"logEnd",null),e}();function b(){return[v.logStart,v.caching,v.send,v.logEnd].slice(0)}var m=function(e){function t(t){void 0===t&&(t="This query is already part of a batch.");var n=e.call(this,t)||this;return n.name="AlreadyInBatchException",r.Logger.error(n),n}return n.__extends(t,e),t}(Error),_=function(){function e(){this._query=new t.Dictionary,this._options={},this._url="",this._parentUrl="",this._useCaching=!1,this._cachingOptions=null}return e.prototype.toUrl=function(){return this._url},e.prototype.concat=function(e){return this._url+=e,this},Object.defineProperty(e.prototype,"query",{get:function(){return this._query},enumerable:!0,configurable:!0}),e.prototype.configure=function(e){return t.mergeOptions(this._options,e),this},e.prototype.configureFrom=function(e){return t.mergeOptions(this._options,e._options),this},e.prototype.usingCaching=function(e){return t.RuntimeConfig.globalCacheDisable||(this._useCaching=!0,void 0!==e&&(this._cachingOptions=e)),this},e.prototype.get=function(e,t){return void 0===e&&(e=new l),void 0===t&&(t={}),this.getCore(e,t)},e.prototype.getCore=function(e,t){return void 0===e&&(e=new l),void 0===t&&(t={}),this.toRequestContext("GET",t,e,b()).then(function(e){return g(e)})},e.prototype.postCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("POST",e,t,b()).then(function(e){return g(e)})},e.prototype.patchCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("PATCH",e,t,b()).then(function(e){return g(e)})},e.prototype.deleteCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("DELETE",e,t,b()).then(function(e){return g(e)})},e.prototype.putCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("PUT",e,t,b()).then(function(e){return g(e)})},e.prototype.append=function(e){this._url=t.combinePaths(this._url,e)},Object.defineProperty(e.prototype,"parentUrl",{get:function(){return this._parentUrl},enumerable:!0,configurable:!0}),e.prototype.extend=function(e,n){this._parentUrl=e._url,this._url=t.combinePaths(this._parentUrl,n),this.configureFrom(e)},e}(),w=function(e){function r(){var t=e.call(this)||this;return t._batch=null,t}return n.__extends(r,e),r.prototype.inBatch=function(e){if(null!==this.batch)throw new m;return this._batch=e,this},r.prototype.toUrl=function(){return this._url},r.prototype.get=function(e,t){return void 0===e&&(e=new a),void 0===t&&(t={}),this.getCore(e,t)},r.prototype.getCore=function(e,t){return void 0===e&&(e=new a),void 0===t&&(t={}),this.toRequestContext("GET",t,e,b()).then(function(e){return g(e)})},r.prototype.postCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new a),this.toRequestContext("POST",e,t,b()).then(function(e){return g(e)})},r.prototype.patchCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new a),this.toRequestContext("PATCH",e,t,b()).then(function(e){return g(e)})},r.prototype.deleteCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new a),this.toRequestContext("DELETE",e,t,b()).then(function(e){return g(e)})},r.prototype.putCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new a),this.toRequestContext("PUT",e,t,b()).then(function(e){return g(e)})},r.prototype.addBatchDependency=function(){return null!==this._batch?this._batch.addDependency():function(){return null}},Object.defineProperty(r.prototype,"hasBatch",{get:function(){return t.objectDefinedNotNull(this._batch)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"batch",{get:function(){return this.hasBatch?this._batch:null},enumerable:!0,configurable:!0}),r}(_),q=function(){function e(e){void 0===e&&(e=t.getGUID()),this._batchId=e,this._requests=[],this._dependencies=[]}return Object.defineProperty(e.prototype,"batchId",{get:function(){return this._batchId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"requests",{get:function(){return this._requests},enumerable:!0,configurable:!0}),e.prototype.add=function(e,t,n,r){var o={method:t.toUpperCase(),options:n,parser:r,reject:null,resolve:null,url:e},i=new Promise(function(e,t){o.resolve=e,o.reject=t});return this._requests.push(o),i},e.prototype.addDependency=function(){var e=function(){},t=new Promise(function(t){e=t});return this._dependencies.push(t),e},e.prototype.execute=function(){var e=this;return Promise.all(this._dependencies).then(function(){return Promise.all(e._dependencies)}).then(function(){return e.executeImpl()})},e}();e.CachingOptions=o,e.CachingParserWrapper=i,e.ProcessHttpClientResponseException=u,e.ODataParserBase=s,e.ODataDefaultParser=a,e.TextParser=c,e.BlobParser=p,e.JSONParser=l,e.BufferParser=h,e.setResult=f,e.pipe=g,e.requestPipelineMethod=y,e.PipelineMethods=v,e.getDefaultPipeline=b,e.AlreadyInBatchException=m,e.Queryable=_,e.ODataQueryable=w,e.ODataBatch=q,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@pnp/common"),require("tslib"),require("@pnp/logging")):"function"==typeof define&&define.amd?define(["exports","@pnp/common","tslib","@pnp/logging"],t):t((e.pnp=e.pnp||{},e.pnp.odata={}),e.pnp.common,e.tslib_1,e.pnp.logging)}(this,function(e,u,r,s){"use strict";var o=function(){function e(e){this.key=e,this.expiration=u.dateAdd(new Date,"second",u.RuntimeConfig.defaultCachingTimeoutSeconds),this.storeName=u.RuntimeConfig.defaultCachingStore}return Object.defineProperty(e.prototype,"store",{get:function(){return"local"===this.storeName?e.storage.local:e.storage.session},enumerable:!0,configurable:!0}),e.storage=new u.PnPClientStorage,e}(),i=function(){function e(e,t){this._parser=e,this._cacheOptions=t}return e.prototype.parse=function(e){var t=this;return this._parser.parse(e).then(function(e){return null!==t._cacheOptions.store&&t._cacheOptions.store.put(t._cacheOptions.key,e,t._cacheOptions.expiration),e})},e}(),a=function(o){function e(e,t,n){var r=o.call(this,"Error making HttpClient request in queryable: ["+e+"] "+t)||this;return r.status=e,r.statusText=t,r.data=n,r.name="ProcessHttpClientResponseException",s.Logger.log({data:r.data,level:3,message:r.message}),r}return r.__extends(e,o),e}(Error),t=function(){function e(){}return e.prototype.parse=function(e){var r=this;return new Promise(function(t,n){r.handleError(e,n)&&e.text().then(function(e){return 0<e.replace(/\s/gi,"").length?JSON.parse(e):{}}).then(function(e){return t(r.parseODataJSON(e))}).catch(function(e){return n(e)})})},e.prototype.handleError=function(n,r){return n.ok||n.json().then(function(e){var t={responseBody:e,responseHeaders:n.headers};r(new a(n.status,n.statusText,t))}).catch(function(e){s.Logger.log({data:e,level:2,message:"There was an error parsing the error response body. See data for details."});var t={responseBody:"[[body not available]]",responseHeaders:n.headers};r(new a(n.status,n.statusText,t))}),n.ok},e.prototype.parseODataJSON=function(e){var t=e;return e.hasOwnProperty("d")?t=e.d.hasOwnProperty("results")?e.d.results:e.d:e.hasOwnProperty("value")&&(t=e.value),t},e}(),n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r.__extends(t,e),t}(t),c=function(){function e(){}return e.prototype.parse=function(e){return e.text()},e}(),p=function(){function e(){}return e.prototype.parse=function(e){return e.blob()},e}(),l=function(){function e(){}return e.prototype.parse=function(e){return e.json()},e}(),h=function(){function e(){}return e.prototype.parse=function(e){return u.isFunc(e.arrayBuffer)?e.arrayBuffer():e.buffer()},e}();function f(t,n){return new Promise(function(e){t.result=n,t.hasResult=!0,e(t)})}function d(e){return 0<e.pipeline.length?e.pipeline.shift()(e):Promise.resolve(e)}function g(e){return e.pipeline.length<1&&s.Logger.write("["+e.requestId+"] ("+(new Date).getTime()+") Request pipeline contains no methods!",2),d(e).then(function(e){return t=e,s.Logger.log({data:t.result,level:0,message:"["+t.requestId+"] ("+(new Date).getTime()+") Returning result, see data property for value."}),Promise.resolve(t.result||null);var t}).catch(function(e){throw s.Logger.error(e),e})}function y(i){return void 0===i&&(i=!1),function(n,r,e){var o=e.value;e.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return!i&&0<e.length&&e[0].hasOwnProperty("hasResult")&&e[0].hasResult?(s.Logger.write("["+e[0].requestId+"] ("+(new Date).getTime()+") Skipping request pipeline method "+r+", existing result in pipeline.",0),Promise.resolve(e[0])):(s.Logger.write("["+e[0].requestId+"] ("+(new Date).getTime()+") Calling request pipeline method "+r+".",0),o.apply(n,e).then(function(e){return d(e)}))}}}var v=function(){function e(){}return e.logStart=function(t){return new Promise(function(e){s.Logger.log({data:1===s.Logger.activeLogLevel?{}:t,level:1,message:"["+t.requestId+"] ("+(new Date).getTime()+") Beginning "+t.verb+" request ("+t.requestAbsoluteUrl+")"}),e(t)})},e.caching=function(r){return new Promise(function(t){if("GET"===r.verb&&r.isCached){s.Logger.write("["+r.requestId+"] ("+(new Date).getTime()+") Caching is enabled for request, checking cache...",1);var e=new o(r.requestAbsoluteUrl.toLowerCase());if(void 0!==r.cachingOptions&&(e=u.extend(e,r.cachingOptions)),null!==e.store){var n=e.store.get(e.key);if(null!==n)return s.Logger.log({data:1===s.Logger.activeLogLevel?{}:n,level:1,message:"["+r.requestId+"] ("+(new Date).getTime()+") Value returned from cache."}),u.isFunc(r.batchDependency)&&r.batchDependency(),r.parser.hasOwnProperty("hydrate")&&(n=r.parser.hydrate(n)),f(r,n).then(function(e){return t(e)})}s.Logger.write("["+r.requestId+"] ("+(new Date).getTime()+") Value not found in cache.",1),r.parser=new i(r.parser,e)}return t(r)})},e.send=function(i){return new Promise(function(t,n){if(i.isBatched){var e=i.batch.add(i.requestAbsoluteUrl,i.verb,i.options,i.parser);u.isFunc(i.batchDependency)&&i.batchDependency(),s.Logger.write("["+i.requestId+"] ("+(new Date).getTime()+") Batching request in batch "+i.batch.batchId+".",1),t(f(i,e))}else{s.Logger.write("["+i.requestId+"] ("+(new Date).getTime()+") Sending request.",1);var r=i.clientFactory(),o=u.extend(i.options||{},{method:i.verb});r.fetch(i.requestAbsoluteUrl,o).then(function(e){return i.parser.parse(e)}).then(function(e){return f(i,e)}).then(function(e){return t(e)}).catch(function(e){return n(e)})}})},e.logEnd=function(t){return new Promise(function(e){t.isBatched?s.Logger.log({data:1===s.Logger.activeLogLevel?{}:t,level:1,message:"["+t.requestId+"] ("+(new Date).getTime()+") "+t.verb+" request will complete in batch "+t.batch.batchId+"."}):s.Logger.log({data:1===s.Logger.activeLogLevel?{}:t,level:1,message:"["+t.requestId+"] ("+(new Date).getTime()+") Completing "+t.verb+" request."}),e(t)})},r.__decorate([y(!0)],e,"logStart",null),r.__decorate([y()],e,"caching",null),r.__decorate([y()],e,"send",null),r.__decorate([y(!0)],e,"logEnd",null),e}();function b(){return[v.logStart,v.caching,v.send,v.logEnd].slice(0)}var m=function(n){function e(e){void 0===e&&(e="This query is already part of a batch.");var t=n.call(this,e)||this;return t.name="AlreadyInBatchException",s.Logger.error(t),t}return r.__extends(e,n),e}(Error),_=function(){function e(){this._query=new u.Dictionary,this._options={},this._url="",this._parentUrl="",this._useCaching=!1,this._cachingOptions=null}return e.prototype.toUrl=function(){return this._url},e.prototype.concat=function(e){return this._url+=e,this},Object.defineProperty(e.prototype,"query",{get:function(){return this._query},enumerable:!0,configurable:!0}),e.prototype.configure=function(e){return u.mergeOptions(this._options,e),this},e.prototype.configureFrom=function(e){return u.mergeOptions(this._options,e._options),this},e.prototype.usingCaching=function(e){return u.RuntimeConfig.globalCacheDisable||(this._useCaching=!0,void 0!==e&&(this._cachingOptions=e)),this},e.prototype.get=function(e,t){return void 0===e&&(e=new l),void 0===t&&(t={}),this.getCore(e,t)},e.prototype.getCore=function(e,t){return void 0===e&&(e=new l),void 0===t&&(t={}),this.toRequestContext("GET",t,e,b()).then(function(e){return g(e)})},e.prototype.postCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("POST",e,t,b()).then(function(e){return g(e)})},e.prototype.patchCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("PATCH",e,t,b()).then(function(e){return g(e)})},e.prototype.deleteCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("DELETE",e,t,b()).then(function(e){return g(e)})},e.prototype.putCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new l),this.toRequestContext("PUT",e,t,b()).then(function(e){return g(e)})},e.prototype.append=function(e){this._url=u.combinePaths(this._url,e)},Object.defineProperty(e.prototype,"parentUrl",{get:function(){return this._parentUrl},enumerable:!0,configurable:!0}),e.prototype.extend=function(e,t){this._parentUrl=e._url,this._url=u.combinePaths(this._parentUrl,t),this.configureFrom(e)},e}(),w=function(t){function e(){var e=t.call(this)||this;return e._batch=null,e}return r.__extends(e,t),e.prototype.inBatch=function(e){if(null!==this.batch)throw new m;return this._batch=e,this},e.prototype.toUrl=function(){return this._url},e.prototype.get=function(e,t){return void 0===e&&(e=new n),void 0===t&&(t={}),this.getCore(e,t)},e.prototype.getCore=function(e,t){return void 0===e&&(e=new n),void 0===t&&(t={}),this.toRequestContext("GET",t,e,b()).then(function(e){return g(e)})},e.prototype.postCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new n),this.toRequestContext("POST",e,t,b()).then(function(e){return g(e)})},e.prototype.patchCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new n),this.toRequestContext("PATCH",e,t,b()).then(function(e){return g(e)})},e.prototype.deleteCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new n),this.toRequestContext("DELETE",e,t,b()).then(function(e){return g(e)})},e.prototype.putCore=function(e,t){return void 0===e&&(e={}),void 0===t&&(t=new n),this.toRequestContext("PUT",e,t,b()).then(function(e){return g(e)})},e.prototype.addBatchDependency=function(){return null!==this._batch?this._batch.addDependency():function(){return null}},Object.defineProperty(e.prototype,"hasBatch",{get:function(){return u.objectDefinedNotNull(this._batch)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"batch",{get:function(){return this.hasBatch?this._batch:null},enumerable:!0,configurable:!0}),e}(_),q=function(){function e(e){void 0===e&&(e=u.getGUID()),this._batchId=e,this._requests=[],this._dependencies=[]}return Object.defineProperty(e.prototype,"batchId",{get:function(){return this._batchId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"requests",{get:function(){return this._requests},enumerable:!0,configurable:!0}),e.prototype.add=function(e,t,n,r){var o={method:t.toUpperCase(),options:n,parser:r,reject:null,resolve:null,url:e},i=new Promise(function(e,t){o.resolve=e,o.reject=t});return this._requests.push(o),i},e.prototype.addDependency=function(){var t=function(){},e=new Promise(function(e){t=e});return this._dependencies.push(e),t},e.prototype.execute=function(){var e=this;return Promise.all(this._dependencies).then(function(){return Promise.all(e._dependencies)}).then(function(){return e.executeImpl()})},e}();e.CachingOptions=o,e.CachingParserWrapper=i,e.ProcessHttpClientResponseException=a,e.ODataParserBase=t,e.ODataDefaultParser=n,e.TextParser=c,e.BlobParser=p,e.JSONParser=l,e.BufferParser=h,e.setResult=f,e.pipe=g,e.requestPipelineMethod=y,e.PipelineMethods=v,e.getDefaultPipeline=b,e.AlreadyInBatchException=m,e.Queryable=_,e.ODataQueryable=w,e.ODataBatch=q,Object.defineProperty(e,"__esModule",{value:!0})}); |
/** | ||
@license | ||
* @pnp/odata v1.0.4-4 - pnp - provides shared odata functionality and base classes | ||
* @pnp/odata v1.0.4 - pnp - provides shared odata functionality and base classes | ||
* MIT (https://github.com/pnp/pnpjs/blob/master/LICENSE) | ||
@@ -10,3 +10,3 @@ * Copyright (c) 2018 Microsoft | ||
*/ | ||
import { Dictionary, PnPClientStorage, RuntimeConfig, combinePaths, dateAdd, extend, getGUID, isFunc, mergeOptions, objectDefinedNotNull } from '@pnp/common'; | ||
import { RuntimeConfig, dateAdd, PnPClientStorage, isFunc, extend, combinePaths, Dictionary, mergeOptions, objectDefinedNotNull, getGUID } from '@pnp/common'; | ||
import { Logger } from '@pnp/logging'; | ||
@@ -13,0 +13,0 @@ import { __decorate } from 'tslib'; |
{ | ||
"name": "@pnp/odata", | ||
"version": "1.0.4-4", | ||
"version": "1.0.4", | ||
"description": "pnp - provides shared odata functionality and base classes", | ||
@@ -8,7 +8,7 @@ "main": "./dist/odata.es5.umd.js", | ||
"dependencies": { | ||
"tslib": "1.8.1" | ||
"tslib": "1.9.0" | ||
}, | ||
"peerDependencies": { | ||
"@pnp/logging": "1.0.4-4", | ||
"@pnp/common": "1.0.4-4" | ||
"@pnp/logging": "1.0.4", | ||
"@pnp/common": "1.0.4" | ||
}, | ||
@@ -15,0 +15,0 @@ "author": { |
@@ -59,2 +59,2 @@ import { ODataParser } from "./core"; | ||
} | ||
export declare function getDefaultPipeline(): (<T>(context: RequestContext<T>) => Promise<RequestContext<T>>)[]; | ||
export declare function getDefaultPipeline(): (typeof PipelineMethods.logStart)[]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1173558
6690
1
+ Added@pnp/common@1.0.4(transitive)
+ Added@pnp/logging@1.0.4(transitive)
+ Addedtslib@1.9.0(transitive)
- Removed@pnp/common@1.0.4-4(transitive)
- Removed@pnp/logging@1.0.4-4(transitive)
- Removedtslib@1.8.1(transitive)
Updatedtslib@1.9.0