@pnp/odata
Advanced tools
Comparing version 2.2.0 to 2.3.0
74
batch.js
import { getGUID } from "@pnp/common"; | ||
export class Batch { | ||
constructor(_batchId = getGUID()) { | ||
var Batch = /** @class */ (function () { | ||
function Batch(_batchId) { | ||
if (_batchId === void 0) { _batchId = getGUID(); } | ||
this._batchId = _batchId; | ||
@@ -10,13 +11,21 @@ this._reqs = []; | ||
} | ||
get batchId() { | ||
return this._batchId; | ||
} | ||
Object.defineProperty(Batch.prototype, "batchId", { | ||
get: function () { | ||
return this._batchId; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Batch.prototype, "requests", { | ||
/** | ||
* The requests contained in this batch | ||
*/ | ||
get: function () { | ||
// we sort these each time this is accessed | ||
return this._reqs.sort(function (info1, info2) { return info1.index - info2.index; }); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* The requests contained in this batch | ||
*/ | ||
get requests() { | ||
// we sort these each time this is accessed | ||
return this._reqs.sort((info1, info2) => info1.index - info2.index); | ||
} | ||
/** | ||
* Not meant for use directly | ||
@@ -26,3 +35,3 @@ * | ||
*/ | ||
track(batchee) { | ||
Batch.prototype.track = function (batchee) { | ||
batchee.data.batch = this; | ||
@@ -34,3 +43,3 @@ // we need to track the order requests are added to the batch to ensure we always | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -41,4 +50,4 @@ * Adds the given request context to the batch for execution | ||
*/ | ||
add(context) { | ||
const info = { | ||
Batch.prototype.add = function (context) { | ||
var info = { | ||
id: context.requestId, | ||
@@ -54,3 +63,3 @@ index: context.batchIndex, | ||
// we create a new promise that will be resolved within the batch | ||
const p = new Promise((resolve, reject) => { | ||
var p = new Promise(function (resolve, reject) { | ||
info.resolve = resolve; | ||
@@ -61,3 +70,3 @@ info.reject = reject; | ||
return p; | ||
} | ||
}; | ||
/** | ||
@@ -67,9 +76,9 @@ * Adds a dependency insuring that some set of actions will occur before a batch is processed. | ||
*/ | ||
addDependency() { | ||
let resolver = () => void (0); | ||
this._deps.push(new Promise((resolve) => { | ||
Batch.prototype.addDependency = function () { | ||
var resolver = function () { return void (0); }; | ||
this._deps.push(new Promise(function (resolve) { | ||
resolver = resolve; | ||
})); | ||
return resolver; | ||
} | ||
}; | ||
/** | ||
@@ -80,5 +89,5 @@ * The batch's execute method will not resolve util any promises added here resolve | ||
*/ | ||
addResolveBatchDependency(p) { | ||
Batch.prototype.addResolveBatchDependency = function (p) { | ||
this._rDeps.push(p); | ||
} | ||
}; | ||
/** | ||
@@ -89,12 +98,15 @@ * Execute the current batch and resolve the associated promises | ||
*/ | ||
execute() { | ||
Batch.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._deps) | ||
.then(() => Promise.all(this._deps)) | ||
.then(() => this.executeImpl()) | ||
.then(() => Promise.all(this._rDeps)) | ||
.then(() => void (0)); | ||
} | ||
} | ||
.then(function () { return Promise.all(_this._deps); }) | ||
.then(function () { return _this.executeImpl(); }) | ||
.then(function () { return Promise.all(_this._rDeps); }) | ||
.then(function () { return void (0); }); | ||
}; | ||
return Batch; | ||
}()); | ||
export { Batch }; | ||
//# sourceMappingURL=batch.js.map |
import { PnPClientStorage } from "@pnp/common"; | ||
const storage = new PnPClientStorage(); | ||
export class CachingOptions { | ||
constructor(key, storeName, expiration) { | ||
var storage = new PnPClientStorage(); | ||
var CachingOptions = /** @class */ (function () { | ||
function CachingOptions(key, storeName, expiration) { | ||
this.key = key; | ||
@@ -9,20 +9,27 @@ this.storeName = storeName; | ||
} | ||
get store() { | ||
if (this.storeName === "local") { | ||
return storage.local; | ||
} | ||
else { | ||
return storage.session; | ||
} | ||
} | ||
} | ||
export class CachingParserWrapper { | ||
constructor(parser, cacheOptions) { | ||
Object.defineProperty(CachingOptions.prototype, "store", { | ||
get: function () { | ||
if (this.storeName === "local") { | ||
return storage.local; | ||
} | ||
else { | ||
return storage.session; | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return CachingOptions; | ||
}()); | ||
export { CachingOptions }; | ||
var CachingParserWrapper = /** @class */ (function () { | ||
function CachingParserWrapper(parser, cacheOptions) { | ||
this.parser = parser; | ||
this.cacheOptions = cacheOptions; | ||
} | ||
parse(response) { | ||
return this.parser.parse(response).then(r => this.cacheData(r)); | ||
} | ||
cacheData(data) { | ||
CachingParserWrapper.prototype.parse = function (response) { | ||
var _this = this; | ||
return this.parser.parse(response).then(function (r) { return _this.cacheData(r); }); | ||
}; | ||
CachingParserWrapper.prototype.cacheData = function (data) { | ||
if (this.cacheOptions.store !== null) { | ||
@@ -32,4 +39,6 @@ this.cacheOptions.store.put(this.cacheOptions.key, data, this.cacheOptions.expiration); | ||
return data; | ||
} | ||
} | ||
}; | ||
return CachingParserWrapper; | ||
}()); | ||
export { CachingParserWrapper }; | ||
//# sourceMappingURL=caching.js.map |
28
debug.js
@@ -5,7 +5,11 @@ import { hOP } from "@pnp/common"; | ||
extendGlobal([ | ||
(op, target, ...rest) => { | ||
function (op, target) { | ||
var rest = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
rest[_i - 2] = arguments[_i]; | ||
} | ||
if (target.__deepTrace) { | ||
switch (op) { | ||
case "apply": | ||
Logger.write(`${op} ::> ()`, 1 /* Info */); | ||
Logger.write(op + " ::> ()", 1 /* Info */); | ||
break; | ||
@@ -15,3 +19,3 @@ case "has": | ||
case "set": | ||
Logger.write(`${op} ::> ${rest[0]}`, 1 /* Info */); | ||
Logger.write(op + " ::> " + rest[0], 1 /* Info */); | ||
break; | ||
@@ -23,10 +27,10 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
get: (target, p, _receiver) => { | ||
get: function (target, p, _receiver) { | ||
switch (p) { | ||
case "__enableDeepTrace": | ||
return () => { | ||
return function () { | ||
target.__deepTrace = true; | ||
}; | ||
case "__disableDeepTrace": | ||
return () => { | ||
return function () { | ||
target.__deepTrace = false; | ||
@@ -37,9 +41,9 @@ }; | ||
case "__unwrap": | ||
return () => target; | ||
return function () { return target; }; | ||
case "__json": | ||
return () => { | ||
const o = {}; | ||
for (const name in target) { | ||
if (hOP(target, name)) { | ||
o[name] = target[name]; | ||
return function () { | ||
var o = {}; | ||
for (var name_1 in target) { | ||
if (hOP(target, name_1)) { | ||
o[name_1] = target[name_1]; | ||
} | ||
@@ -46,0 +50,0 @@ } |
@@ -0,9 +1,18 @@ | ||
import { __read, __spreadArray } from "tslib"; | ||
import { DefaultRuntime } from "@pnp/common"; | ||
import { extensionOrDefault, applyFactoryExtensions } from "./invokable-extensions.js"; | ||
const invokableBinder = (invoker) => (constructor) => { | ||
return (...args) => { | ||
const factory = (as) => { | ||
const r = Object.assign(function (...ags) { | ||
return invoker.call(r, ...ags); | ||
}, new constructor(...as)); | ||
var invokableBinder = function (invoker) { return function (constructor) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var factory = function (as) { | ||
var r = Object.assign(function () { | ||
var ags = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
ags[_i] = arguments[_i]; | ||
} | ||
return invoker.call.apply(invoker, __spreadArray([r], __read(ags))); | ||
}, new (constructor.bind.apply(constructor, __spreadArray([void 0], __read(as))))()); | ||
Reflect.setPrototypeOf(r, constructor.prototype); | ||
@@ -18,13 +27,37 @@ return r; | ||
return new Proxy(applyFactoryExtensions(factory, args), { | ||
apply: (target, _thisArg, argArray) => { | ||
return extensionOrDefault("apply", (...a) => Reflect.apply(a[0], a[1], a[2]), target, _thisArg, argArray); | ||
apply: function (target, _thisArg, argArray) { | ||
return extensionOrDefault("apply", function () { | ||
var a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
a[_i] = arguments[_i]; | ||
} | ||
return Reflect.apply(a[0], a[1], a[2]); | ||
}, target, _thisArg, argArray); | ||
}, | ||
get: (target, p, receiver) => { | ||
return extensionOrDefault("get", (...a) => Reflect.get(a[0], a[1], a[2]), target, p, receiver); | ||
get: function (target, p, receiver) { | ||
return extensionOrDefault("get", function () { | ||
var a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
a[_i] = arguments[_i]; | ||
} | ||
return Reflect.get(a[0], a[1], a[2]); | ||
}, target, p, receiver); | ||
}, | ||
has: (target, p) => { | ||
return extensionOrDefault("has", (...a) => Reflect.has(a[0], a[1]), target, p); | ||
has: function (target, p) { | ||
return extensionOrDefault("has", function () { | ||
var a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
a[_i] = arguments[_i]; | ||
} | ||
return Reflect.has(a[0], a[1]); | ||
}, target, p); | ||
}, | ||
set: (target, p, value, receiver) => { | ||
return extensionOrDefault("set", (...a) => Reflect.set(a[0], a[1], a[2], a[3]), target, p, value, receiver); | ||
set: function (target, p, value, receiver) { | ||
return extensionOrDefault("set", function () { | ||
var a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
a[_i] = arguments[_i]; | ||
} | ||
return Reflect.set(a[0], a[1], a[2], a[3]); | ||
}, target, p, value, receiver); | ||
}, | ||
@@ -34,6 +67,6 @@ }); | ||
}; | ||
}; | ||
export const invokableFactory = invokableBinder(function (options) { | ||
}; }; | ||
export var invokableFactory = invokableBinder(function (options) { | ||
return this.defaultAction(options); | ||
}); | ||
//# sourceMappingURL=invokable-binder.js.map |
@@ -0,6 +1,7 @@ | ||
import { __read, __spreadArray } from "tslib"; | ||
import { isFunc, getGUID } from "@pnp/common"; | ||
let _enableExtensions = false; | ||
const globalExtensions = []; | ||
const factoryExtensions = new Map(); | ||
const ObjExtensionsSym = Symbol.for("43f7a601"); | ||
var _enableExtensions = false; | ||
var globalExtensions = []; | ||
var factoryExtensions = new Map(); | ||
var ObjExtensionsSym = Symbol.for("43f7a601"); | ||
/** | ||
@@ -11,3 +12,3 @@ * Creates global extensions across all invokable objects | ||
*/ | ||
export const extendGlobal = (e) => { | ||
export var extendGlobal = function (e) { | ||
_enableExtensions = true; | ||
@@ -23,3 +24,3 @@ extendCol(globalExtensions, e); | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const extendObj = (target, extensions) => { | ||
export var extendObj = function (target, extensions) { | ||
_enableExtensions = true; | ||
@@ -38,6 +39,6 @@ if (!Reflect.has(target, ObjExtensionsSym)) { | ||
*/ | ||
export const extendFactory = (factory, extensions) => { | ||
export var extendFactory = function (factory, extensions) { | ||
_enableExtensions = true; | ||
// factoryExtensions | ||
const proto = Reflect.getPrototypeOf(factory); | ||
var proto = Reflect.getPrototypeOf(factory); | ||
if (!Reflect.has(proto, ObjExtensionsSym)) { | ||
@@ -48,3 +49,3 @@ Reflect.defineProperty(proto, ObjExtensionsSym, { | ||
} | ||
const key = proto[ObjExtensionsSym]; | ||
var key = proto[ObjExtensionsSym]; | ||
if (!factoryExtensions.has(key)) { | ||
@@ -57,3 +58,3 @@ factoryExtensions.set(key, []); | ||
if (Array.isArray(e)) { | ||
a.push(...e); | ||
a.push.apply(a, __spreadArray([], __read(e))); | ||
} | ||
@@ -67,3 +68,3 @@ else { | ||
*/ | ||
export const clearGlobalExtensions = () => { | ||
export var clearGlobalExtensions = function () { | ||
globalExtensions.length = 0; | ||
@@ -74,3 +75,3 @@ }; | ||
*/ | ||
export const disableExtensions = () => { | ||
export var disableExtensions = function () { | ||
_enableExtensions = false; | ||
@@ -81,3 +82,3 @@ }; | ||
*/ | ||
export const enableExtensions = () => { | ||
export var enableExtensions = function () { | ||
_enableExtensions = true; | ||
@@ -92,7 +93,7 @@ }; | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const applyFactoryExtensions = (factory, args) => { | ||
let o = factory(args); | ||
const proto = Reflect.getPrototypeOf(factory); | ||
export var applyFactoryExtensions = function (factory, args) { | ||
var o = factory(args); | ||
var proto = Reflect.getPrototypeOf(factory); | ||
if (Reflect.has(proto, ObjExtensionsSym)) { | ||
const extensions = factoryExtensions.get(Reflect.get(proto, ObjExtensionsSym)); | ||
var extensions = factoryExtensions.get(Reflect.get(proto, ObjExtensionsSym)); | ||
o = extendObj(o, extensions); | ||
@@ -102,17 +103,21 @@ } | ||
}; | ||
export function extensionOrDefault(op, or, target, ...rest) { | ||
export function extensionOrDefault(op, or, target) { | ||
var rest = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
rest[_i - 3] = arguments[_i]; | ||
} | ||
if (_enableExtensions) { | ||
const extensions = []; | ||
var extensions = []; | ||
// we need to first invoke extensions tied to only this object | ||
if (Reflect.has(target, ObjExtensionsSym)) { | ||
extensions.push(...Reflect.get(target, ObjExtensionsSym)); | ||
extensions.push.apply(extensions, __spreadArray([], __read(Reflect.get(target, ObjExtensionsSym)))); | ||
} | ||
// second we need to process any global extensions | ||
extensions.push(...globalExtensions); | ||
for (let i = 0; i < extensions.length; i++) { | ||
const extension = extensions[i]; | ||
let result = undefined; | ||
extensions.push.apply(extensions, __spreadArray([], __read(globalExtensions))); | ||
for (var i = 0; i < extensions.length; i++) { | ||
var extension = extensions[i]; | ||
var result = undefined; | ||
if (isFunc(extension)) { | ||
// this extension is a function which we call | ||
result = extension(op, target, ...rest); | ||
result = extension.apply(void 0, __spreadArray([op, target], __read(rest))); | ||
} | ||
@@ -125,3 +130,3 @@ else if (op === "get" && Reflect.has(extension, rest[0])) { | ||
// this extension is a ProxyHandler that has a handler defined for {op} so we pass control and see if we get a result | ||
result = Reflect.get(extension, op)(target, ...rest); | ||
result = Reflect.get(extension, op).apply(void 0, __spreadArray([target], __read(rest))); | ||
} | ||
@@ -136,4 +141,4 @@ if (typeof result !== "undefined") { | ||
} | ||
return or(target, ...rest); | ||
return or.apply(void 0, __spreadArray([target], __read(rest))); | ||
} | ||
//# sourceMappingURL=invokable-extensions.js.map |
{ | ||
"name": "@pnp/odata", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "pnp - provides shared odata functionality and base classes", | ||
@@ -9,4 +9,4 @@ "main": "./index.js", | ||
"tslib": "2.1.0", | ||
"@pnp/logging": "2.2.0", | ||
"@pnp/common": "2.2.0" | ||
"@pnp/logging": "2.3.0", | ||
"@pnp/common": "2.3.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "author": { |
147
parsers.js
@@ -1,12 +0,16 @@ | ||
import { __awaiter } from "tslib"; | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { isFunc, hOP } from "@pnp/common"; | ||
export class ODataParser { | ||
parse(r) { | ||
return new Promise((resolve, reject) => { | ||
if (this.handleError(r, reject)) { | ||
this.parseImpl(r, resolve, reject); | ||
var ODataParser = /** @class */ (function () { | ||
function ODataParser() { | ||
} | ||
ODataParser.prototype.parse = function (r) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this.handleError(r, reject)) { | ||
_this.parseImpl(r, resolve, reject); | ||
} | ||
}); | ||
} | ||
parseImpl(r, resolve, reject) { | ||
}; | ||
ODataParser.prototype.parseImpl = function (r, resolve, reject) { | ||
var _this = this; | ||
if ((r.headers.has("Content-Length") && parseFloat(r.headers.get("Content-Length")) === 0) || r.status === 204) { | ||
@@ -18,7 +22,7 @@ resolve({}); | ||
r.text() | ||
.then(txt => txt.replace(/\s/ig, "").length > 0 ? JSON.parse(txt) : {}) | ||
.then(json => resolve(this.parseODataJSON(json))) | ||
.catch(e => reject(e)); | ||
.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); }); | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -31,3 +35,3 @@ * Handles a response with ok === false by parsing the body and creating a ProcessHttpClientResponseException | ||
*/ | ||
handleError(r, reject) { | ||
ODataParser.prototype.handleError = function (r, reject) { | ||
if (!r.ok) { | ||
@@ -37,3 +41,3 @@ HttpRequestError.init(r).then(reject); | ||
return r.ok; | ||
} | ||
}; | ||
/** | ||
@@ -44,4 +48,4 @@ * Normalizes the json response by removing the various nested levels | ||
*/ | ||
parseODataJSON(json) { | ||
let result = json; | ||
ODataParser.prototype.parseODataJSON = function (json) { | ||
var result = json; | ||
if (hOP(json, "d")) { | ||
@@ -59,21 +63,45 @@ if (hOP(json.d, "results")) { | ||
return result; | ||
}; | ||
return ODataParser; | ||
}()); | ||
export { ODataParser }; | ||
var TextParser = /** @class */ (function (_super) { | ||
__extends(TextParser, _super); | ||
function TextParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
} | ||
export class TextParser extends ODataParser { | ||
parseImpl(r, resolve) { | ||
TextParser.prototype.parseImpl = function (r, resolve) { | ||
r.text().then(resolve); | ||
}; | ||
return TextParser; | ||
}(ODataParser)); | ||
export { TextParser }; | ||
var BlobParser = /** @class */ (function (_super) { | ||
__extends(BlobParser, _super); | ||
function BlobParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
} | ||
export class BlobParser extends ODataParser { | ||
parseImpl(r, resolve) { | ||
BlobParser.prototype.parseImpl = function (r, resolve) { | ||
r.blob().then(resolve); | ||
}; | ||
return BlobParser; | ||
}(ODataParser)); | ||
export { BlobParser }; | ||
var JSONParser = /** @class */ (function (_super) { | ||
__extends(JSONParser, _super); | ||
function JSONParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
} | ||
export class JSONParser extends ODataParser { | ||
parseImpl(r, resolve) { | ||
JSONParser.prototype.parseImpl = function (r, resolve) { | ||
r.json().then(resolve); | ||
}; | ||
return JSONParser; | ||
}(ODataParser)); | ||
export { JSONParser }; | ||
var BufferParser = /** @class */ (function (_super) { | ||
__extends(BufferParser, _super); | ||
function BufferParser() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
} | ||
export class BufferParser extends ODataParser { | ||
parseImpl(r, resolve) { | ||
BufferParser.prototype.parseImpl = function (r, resolve) { | ||
if (isFunc(r.arrayBuffer)) { | ||
@@ -85,28 +113,47 @@ r.arrayBuffer().then(resolve); | ||
} | ||
}; | ||
return BufferParser; | ||
}(ODataParser)); | ||
export { BufferParser }; | ||
var LambdaParser = /** @class */ (function (_super) { | ||
__extends(LambdaParser, _super); | ||
function LambdaParser(parser) { | ||
var _this = _super.call(this) || this; | ||
_this.parser = parser; | ||
return _this; | ||
} | ||
} | ||
export class LambdaParser extends ODataParser { | ||
constructor(parser) { | ||
super(); | ||
this.parser = parser; | ||
} | ||
parseImpl(r, resolve) { | ||
LambdaParser.prototype.parseImpl = function (r, resolve) { | ||
this.parser(r).then(resolve); | ||
}; | ||
return LambdaParser; | ||
}(ODataParser)); | ||
export { LambdaParser }; | ||
var HttpRequestError = /** @class */ (function (_super) { | ||
__extends(HttpRequestError, _super); | ||
function HttpRequestError(message, response, status, statusText) { | ||
if (status === void 0) { status = response.status; } | ||
if (statusText === void 0) { statusText = response.statusText; } | ||
var _this = _super.call(this, message) || this; | ||
_this.response = response; | ||
_this.status = status; | ||
_this.statusText = statusText; | ||
_this.isHttpRequestError = true; | ||
return _this; | ||
} | ||
} | ||
export class HttpRequestError extends Error { | ||
constructor(message, response, status = response.status, statusText = response.statusText) { | ||
super(message); | ||
this.response = response; | ||
this.status = status; | ||
this.statusText = statusText; | ||
this.isHttpRequestError = true; | ||
} | ||
static init(r) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const t = yield r.clone().text(); | ||
return new HttpRequestError(`Error making HttpClient request in queryable [${r.status}] ${r.statusText} ::> ${t}`, r.clone()); | ||
HttpRequestError.init = function (r) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var t; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, r.clone().text()]; | ||
case 1: | ||
t = _a.sent(); | ||
return [2 /*return*/, new HttpRequestError("Error making HttpClient request in queryable [" + r.status + "] " + r.statusText + " ::> " + t, r.clone())]; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
return HttpRequestError; | ||
}(Error)); | ||
export { HttpRequestError }; | ||
//# sourceMappingURL=parsers.js.map |
@@ -19,3 +19,3 @@ import { ODataParser } from "./parsers.js"; | ||
cachingOptions: null, | ||
clientFactory, | ||
clientFactory: clientFactory, | ||
cloneParentCacheOptions: null, | ||
@@ -25,3 +25,3 @@ cloneParentWasCaching: false, | ||
isBatched: objectDefinedNotNull(o.batch), | ||
method, | ||
method: method, | ||
options: null, | ||
@@ -40,3 +40,3 @@ parentUrl: "", | ||
} | ||
export const defaultPipelineBinder = pipelineBinder(getDefaultPipeline()); | ||
export var defaultPipelineBinder = pipelineBinder(getDefaultPipeline()); | ||
//# sourceMappingURL=pipeline-binder.js.map |
119
pipeline.js
@@ -14,3 +14,3 @@ import { __decorate } from "tslib"; | ||
level: 1 /* Info */, | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) Returning result from pipeline. Set logging to verbose to see data.`, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Returning result from pipeline. Set logging to verbose to see data.", | ||
}); | ||
@@ -23,3 +23,3 @@ return Promise.resolve(context.result); | ||
export function setResult(context, value) { | ||
return new Promise((resolve) => { | ||
return new Promise(function (resolve) { | ||
context.result = value; | ||
@@ -45,6 +45,6 @@ context.hasResult = true; | ||
if (context.pipes.length < 1) { | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Request pipeline contains no methods!`, 3 /* Error */); | ||
Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Request pipeline contains no methods!", 3 /* Error */); | ||
throw Error("Request pipeline contains no methods!"); | ||
} | ||
const promise = next(context).then(ctx => returnResult(ctx)).catch((e) => { | ||
var promise = next(context).then(function (ctx) { return returnResult(ctx); }).catch(function (e) { | ||
Logger.error(e); | ||
@@ -62,15 +62,20 @@ throw e; | ||
*/ | ||
export function requestPipelineMethod(alwaysRun = false) { | ||
return (target, propertyKey, descriptor) => { | ||
const method = descriptor.value; | ||
descriptor.value = function (...args) { | ||
export 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]; | ||
} | ||
// if we have a result already in the pipeline, pass it along and don't call the tagged method | ||
if (!alwaysRun && args.length > 0 && hOP(args[0], "hasResult") && args[0].hasResult) { | ||
Logger.write(`[${args[0].requestId}] (${(new Date()).getTime()}) Skipping request pipeline method ${propertyKey}, existing result in pipeline.`, 0 /* Verbose */); | ||
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 | ||
Logger.write(`[${args[0].requestId}] (${(new Date()).getTime()}) Calling request pipeline method ${propertyKey}.`, 0 /* Verbose */); | ||
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((ctx) => next(ctx)); | ||
return method.apply(target, args).then(function (ctx) { return next(ctx); }); | ||
}; | ||
@@ -82,25 +87,27 @@ }; | ||
*/ | ||
export class PipelineMethods { | ||
var PipelineMethods = /** @class */ (function () { | ||
function PipelineMethods() { | ||
} | ||
/** | ||
* Logs the start of the request | ||
*/ | ||
static logStart(context) { | ||
return new Promise(resolve => { | ||
PipelineMethods.logStart = function (context) { | ||
return new Promise(function (resolve) { | ||
Logger.log({ | ||
data: Logger.activeLogLevel === 1 /* Info */ ? {} : context, | ||
level: 1 /* Info */, | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) Beginning ${context.method} request (${context.url})`, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Beginning " + context.method + " request (" + context.url + ")", | ||
}); | ||
resolve(context); | ||
}); | ||
} | ||
}; | ||
/** | ||
* Handles caching of the request | ||
*/ | ||
static caching(context) { | ||
return new Promise(resolve => { | ||
PipelineMethods.caching = function (context) { | ||
return new Promise(function (resolve) { | ||
// handle caching, if applicable | ||
if (context.useCaching) { | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Caching is enabled for request, checking cache...`, 1 /* Info */); | ||
let cacheOptions = new CachingOptions(context.url.toLowerCase()); | ||
Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Caching is enabled for request, checking cache...", 1 /* Info */); | ||
var cacheOptions = new CachingOptions(context.url.toLowerCase()); | ||
if (context.cachingOptions !== undefined) { | ||
@@ -112,3 +119,3 @@ cacheOptions = assign(cacheOptions, context.cachingOptions); | ||
// check if we have the data in cache and if so resolve the promise and return | ||
let data = cacheOptions.store.get(cacheOptions.key); | ||
var data = cacheOptions.store.get(cacheOptions.key); | ||
if (data !== null) { | ||
@@ -118,3 +125,3 @@ Logger.log({ | ||
level: 1 /* Info */, | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) Value returned from cache.`, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Value returned from cache.", | ||
}); | ||
@@ -129,6 +136,6 @@ // ensure we clear any held batch dependency we are resolving from the cache | ||
} | ||
return setResult(context, data).then(ctx => resolve(ctx)); | ||
return setResult(context, data).then(function (ctx) { return resolve(ctx); }); | ||
} | ||
} | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Value not found in cache.`, 1 /* Info */); | ||
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 | ||
@@ -140,11 +147,11 @@ // and send things on their way | ||
}); | ||
} | ||
}; | ||
/** | ||
* Sends the request | ||
*/ | ||
static send(context) { | ||
return new Promise((resolve, reject) => { | ||
PipelineMethods.send = function (context) { | ||
return new Promise(function (resolve, reject) { | ||
// send or batch the request | ||
if (context.isBatched) { | ||
const p = context.batch.add(context); | ||
var p = context.batch.add(context); | ||
// we release the dependency here to ensure the batch does not execute until the request is added to the batch | ||
@@ -154,3 +161,3 @@ if (isFunc(context.batchDependency)) { | ||
} | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Batching request in batch ${context.batch.batchId}.`, 1 /* Info */); | ||
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 | ||
@@ -160,19 +167,19 @@ resolve(setResult(context, p)); | ||
else { | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Sending request.`, 1 /* Info */); | ||
Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Sending request.", 1 /* Info */); | ||
// we are not part of a batch, so proceed as normal | ||
const client = context.clientFactory(); | ||
const opts = assign(context.options || {}, { method: context.method }); | ||
var client = context.clientFactory(); | ||
var opts = assign(context.options || {}, { method: context.method }); | ||
client.fetch(context.url, opts) | ||
.then(response => context.parser.parse(response)) | ||
.then(result => setResult(context, result)) | ||
.then(ctx => resolve(ctx)) | ||
.catch(e => reject(e)); | ||
.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 | ||
*/ | ||
static logEnd(context) { | ||
return new Promise(resolve => { | ||
PipelineMethods.logEnd = function (context) { | ||
return new Promise(function (resolve) { | ||
if (context.isBatched) { | ||
@@ -182,3 +189,3 @@ Logger.log({ | ||
level: 1 /* Info */, | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) ${context.method} request will complete in batch ${context.batch.batchId}.`, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") " + context.method + " request will complete in batch " + context.batch.batchId + ".", | ||
}); | ||
@@ -190,3 +197,3 @@ } | ||
level: 1 /* Info */, | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) Completing ${context.method} request.`, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Completing " + context.method + " request.", | ||
}); | ||
@@ -196,16 +203,18 @@ } | ||
}); | ||
} | ||
} | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logStart", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "caching", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "send", null); | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logEnd", null); | ||
}; | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logStart", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "caching", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "send", null); | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logEnd", null); | ||
return PipelineMethods; | ||
}()); | ||
export { PipelineMethods }; | ||
export function getDefaultPipeline() { | ||
@@ -212,0 +221,0 @@ return [ |
173
queryable.js
@@ -0,5 +1,6 @@ | ||
import { __read, __spreadArray } from "tslib"; | ||
import { combine, mergeOptions, objectDefinedNotNull, assign, Runtime, DefaultRuntime, dateAdd, stringIsNullOrEmpty, } from "@pnp/common"; | ||
import { ODataParser } from "./parsers.js"; | ||
export function cloneQueryableData(source) { | ||
let body; | ||
var body; | ||
// this handles bodies that cannot be JSON encoded (Blob, etc) | ||
@@ -11,6 +12,6 @@ // Note however, even bodies that can be serialized will not be cloned. | ||
} | ||
const s = JSON.stringify(source, (key, value) => { | ||
var s = JSON.stringify(source, function (key, value) { | ||
switch (key) { | ||
case "query": | ||
return JSON.stringify([...value]); | ||
return JSON.stringify(__spreadArray([], __read(value))); | ||
case "batch": | ||
@@ -26,3 +27,3 @@ case "batchDependency": | ||
}, 0); | ||
const parsed = JSON.parse(s, (key, value) => { | ||
var parsed = JSON.parse(s, function (key, value) { | ||
switch (key) { | ||
@@ -47,4 +48,5 @@ case "query": | ||
} | ||
export class Queryable { | ||
constructor(dataSeed = {}) { | ||
var Queryable = /** @class */ (function () { | ||
function Queryable(dataSeed) { | ||
if (dataSeed === void 0) { dataSeed = {}; } | ||
this._data = Object.assign({}, { | ||
@@ -61,9 +63,13 @@ cloneParentWasCaching: false, | ||
} | ||
get data() { | ||
return this._data; | ||
} | ||
set data(value) { | ||
this._data = Object.assign({}, this.data, cloneQueryableData(value)); | ||
} | ||
getRuntime() { | ||
Object.defineProperty(Queryable.prototype, "data", { | ||
get: function () { | ||
return this._data; | ||
}, | ||
set: function (value) { | ||
this._data = Object.assign({}, this.data, cloneQueryableData(value)); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Queryable.prototype.getRuntime = function () { | ||
if (this._runtime === null) { | ||
@@ -73,5 +79,9 @@ return DefaultRuntime; | ||
return this._runtime; | ||
} | ||
setRuntime(...args) { | ||
}; | ||
Queryable.prototype.setRuntime = function () { | ||
// need to wait for ts update in spfx: [runtime: Runtime] | [cloneGlobal: boolean, additionalConfig?: ITypedHash<any>] | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (args[0] instanceof Runtime) { | ||
@@ -87,3 +97,3 @@ this._runtime = args[0]; | ||
return this; | ||
} | ||
}; | ||
/** | ||
@@ -93,5 +103,5 @@ * Gets the current url | ||
*/ | ||
toUrl() { | ||
Queryable.prototype.toUrl = function () { | ||
return this.data.url; | ||
} | ||
}; | ||
/** | ||
@@ -102,14 +112,18 @@ * Directly concatenates the supplied string to the current url, not normalizing "/" chars | ||
*/ | ||
concat(pathPart) { | ||
Queryable.prototype.concat = function (pathPart) { | ||
this.data.url += pathPart; | ||
return this; | ||
} | ||
}; | ||
Object.defineProperty(Queryable.prototype, "query", { | ||
/** | ||
* Provides access to the query builder for this url | ||
* | ||
*/ | ||
get: function () { | ||
return this.data.query; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Provides access to the query builder for this url | ||
* | ||
*/ | ||
get query() { | ||
return this.data.query; | ||
} | ||
/** | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
@@ -119,6 +133,6 @@ * | ||
*/ | ||
configure(options) { | ||
Queryable.prototype.configure = function (options) { | ||
mergeOptions(this.data.options, options); | ||
return this; | ||
} | ||
}; | ||
/** | ||
@@ -129,5 +143,5 @@ * Configures this instance from the configure options of the supplied instance | ||
*/ | ||
configureFrom(o) { | ||
Queryable.prototype.configureFrom = function (o) { | ||
mergeOptions(this.data.options, o.data.options); | ||
const sourceRuntime = o.getRuntime(); | ||
var sourceRuntime = o.getRuntime(); | ||
if (!sourceRuntime.get("__isDefault__")) { | ||
@@ -137,3 +151,3 @@ this.setRuntime(sourceRuntime); | ||
return this; | ||
} | ||
}; | ||
/** | ||
@@ -144,4 +158,4 @@ * Enables caching for this request | ||
*/ | ||
usingCaching(options) { | ||
const runtime = this.getRuntime(); | ||
Queryable.prototype.usingCaching = function (options) { | ||
var runtime = this.getRuntime(); | ||
if (!runtime.get("globalCacheDisable")) { | ||
@@ -157,3 +171,3 @@ this.data.useCaching = true; | ||
// this uses our local options if they are defined as defaults | ||
const defaultOpts = { | ||
var defaultOpts = { | ||
expiration: dateAdd(new Date(), "second", runtime.get("defaultCachingTimeoutSeconds")), | ||
@@ -165,7 +179,7 @@ storeName: runtime.get("defaultCachingStore"), | ||
return this; | ||
} | ||
usingParser(parser) { | ||
}; | ||
Queryable.prototype.usingParser = function (parser) { | ||
this.data.parser = parser; | ||
return this; | ||
} | ||
}; | ||
/** | ||
@@ -176,6 +190,6 @@ * Allows you to set a request specific processing pipeline | ||
*/ | ||
withPipeline(pipeline) { | ||
Queryable.prototype.withPipeline = function (pipeline) { | ||
this.data.pipes = pipeline.slice(0); | ||
return this; | ||
} | ||
}; | ||
/** | ||
@@ -186,5 +200,5 @@ * Appends the given string and normalizes "/" chars | ||
*/ | ||
append(pathPart) { | ||
Queryable.prototype.append = function (pathPart) { | ||
this.data.url = combine(this.data.url, pathPart); | ||
} | ||
}; | ||
/** | ||
@@ -201,3 +215,3 @@ * Adds this query to the supplied batch | ||
*/ | ||
inBatch(batch) { | ||
Queryable.prototype.inBatch = function (batch) { | ||
if (this.hasBatch) { | ||
@@ -210,34 +224,46 @@ throw Error("This query is already part of a batch."); | ||
return this; | ||
} | ||
}; | ||
/** | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
addBatchDependency() { | ||
Queryable.prototype.addBatchDependency = function () { | ||
if (objectDefinedNotNull(this.data.batch)) { | ||
return this.data.batch.addDependency(); | ||
} | ||
return () => null; | ||
} | ||
return function () { return null; }; | ||
}; | ||
Object.defineProperty(Queryable.prototype, "hasBatch", { | ||
/** | ||
* Indicates if the current query has a batch associated | ||
* | ||
*/ | ||
get: function () { | ||
return objectDefinedNotNull(this.data.batch); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Queryable.prototype, "batch", { | ||
/** | ||
* The batch currently associated with this query or null | ||
* | ||
*/ | ||
get: function () { | ||
return this.hasBatch ? this.data.batch : null; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Queryable.prototype, "parentUrl", { | ||
/** | ||
* Gets the parent url used when creating this instance | ||
* | ||
*/ | ||
get: function () { | ||
return this.data.parentUrl; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Indicates if the current query has a batch associated | ||
* | ||
*/ | ||
get hasBatch() { | ||
return objectDefinedNotNull(this.data.batch); | ||
} | ||
/** | ||
* The batch currently associated with this query or null | ||
* | ||
*/ | ||
get batch() { | ||
return this.hasBatch ? this.data.batch : null; | ||
} | ||
/** | ||
* Gets the parent url used when creating this instance | ||
* | ||
*/ | ||
get parentUrl() { | ||
return this.data.parentUrl; | ||
} | ||
/** | ||
* Clones this instance's data to target | ||
@@ -248,3 +274,4 @@ * | ||
*/ | ||
cloneTo(target, settings = {}) { | ||
Queryable.prototype.cloneTo = function (target, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
// default values for settings | ||
@@ -265,3 +292,3 @@ settings = assign({ | ||
if (settings.includeQuery && this.query.size > 0) { | ||
this.query.forEach((v, k) => target.query.set(k, v)); | ||
this.query.forEach(function (v, k) { return target.query.set(k, v); }); | ||
} | ||
@@ -273,4 +300,6 @@ if (this.data.useCaching) { | ||
return target; | ||
} | ||
} | ||
}; | ||
return Queryable; | ||
}()); | ||
export { Queryable }; | ||
//# sourceMappingURL=queryable.js.map |
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
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
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
106807
1565
+ Added@pnp/common@2.3.0(transitive)
+ Added@pnp/logging@2.3.0(transitive)
- Removed@pnp/common@2.2.0(transitive)
- Removed@pnp/logging@2.2.0(transitive)
Updated@pnp/common@2.3.0
Updated@pnp/logging@2.3.0