@pnp/odata
Advanced tools
Comparing version 2.1.0-beta1 to 2.1.0-beta10
import { IFetchOptions } from "@pnp/common"; | ||
import { IODataParser } from "./parsers"; | ||
import { IQueryable } from "./queryable"; | ||
import { IRequestContext } from "./pipeline"; | ||
import { IODataParser } from "./parsers.js"; | ||
import { IQueryable } from "./queryable.js"; | ||
import { IRequestContext } from "./pipeline.js"; | ||
export interface IODataBatchRequestInfo { | ||
@@ -6,0 +6,0 @@ url: string; |
74
batch.js
import { getGUID } from "@pnp/common"; | ||
var Batch = /** @class */ (function () { | ||
function Batch(_batchId) { | ||
if (_batchId === void 0) { _batchId = getGUID(); } | ||
export class Batch { | ||
constructor(_batchId = getGUID()) { | ||
this._batchId = _batchId; | ||
@@ -11,21 +10,13 @@ this._reqs = []; | ||
} | ||
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 | ||
}); | ||
get batchId() { | ||
return this._batchId; | ||
} | ||
/** | ||
* 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 | ||
@@ -35,3 +26,3 @@ * | ||
*/ | ||
Batch.prototype.track = function (batchee) { | ||
track(batchee) { | ||
batchee.data.batch = this; | ||
@@ -43,3 +34,3 @@ // we need to track the order requests are added to the batch to ensure we always | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -50,4 +41,4 @@ * Adds the given request context to the batch for execution | ||
*/ | ||
Batch.prototype.add = function (context) { | ||
var info = { | ||
add(context) { | ||
const info = { | ||
id: context.requestId, | ||
@@ -63,3 +54,3 @@ index: context.batchIndex, | ||
// we create a new promise that will be resolved within the batch | ||
var p = new Promise(function (resolve, reject) { | ||
const p = new Promise((resolve, reject) => { | ||
info.resolve = resolve; | ||
@@ -70,3 +61,3 @@ info.reject = reject; | ||
return p; | ||
}; | ||
} | ||
/** | ||
@@ -76,9 +67,9 @@ * Adds a dependency insuring that some set of actions will occur before a batch is processed. | ||
*/ | ||
Batch.prototype.addDependency = function () { | ||
var resolver = function () { return void (0); }; | ||
this._deps.push(new Promise(function (resolve) { | ||
addDependency() { | ||
let resolver = () => void (0); | ||
this._deps.push(new Promise((resolve) => { | ||
resolver = resolve; | ||
})); | ||
return resolver; | ||
}; | ||
} | ||
/** | ||
@@ -89,5 +80,5 @@ * The batch's execute method will not resolve util any promises added here resolve | ||
*/ | ||
Batch.prototype.addResolveBatchDependency = function (p) { | ||
addResolveBatchDependency(p) { | ||
this._rDeps.push(p); | ||
}; | ||
} | ||
/** | ||
@@ -98,15 +89,12 @@ * Execute the current batch and resolve the associated promises | ||
*/ | ||
Batch.prototype.execute = function () { | ||
var _this = this; | ||
execute() { | ||
// 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(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 }; | ||
.then(() => Promise.all(this._deps)) | ||
.then(() => this.executeImpl()) | ||
.then(() => Promise.all(this._rDeps)) | ||
.then(() => void (0)); | ||
} | ||
} | ||
//# sourceMappingURL=batch.js.map |
@@ -1,2 +0,2 @@ | ||
import { IODataParser } from "./parsers"; | ||
import { IODataParser } from "./parsers.js"; | ||
import { IPnPClientStore, PnPClientStorage } from "@pnp/common"; | ||
@@ -3,0 +3,0 @@ export interface ICachingOptions { |
import { PnPClientStorage } from "@pnp/common"; | ||
var CachingOptions = /** @class */ (function () { | ||
function CachingOptions(key, storeName, expiration) { | ||
export class CachingOptions { | ||
constructor(key, storeName, expiration) { | ||
this.key = key; | ||
@@ -8,28 +8,21 @@ this.storeName = storeName; | ||
} | ||
Object.defineProperty(CachingOptions.prototype, "store", { | ||
get: function () { | ||
if (this.storeName === "local") { | ||
return CachingOptions.storage.local; | ||
} | ||
else { | ||
return CachingOptions.storage.session; | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
CachingOptions.storage = new PnPClientStorage(); | ||
return CachingOptions; | ||
}()); | ||
export { CachingOptions }; | ||
var CachingParserWrapper = /** @class */ (function () { | ||
function CachingParserWrapper(parser, cacheOptions) { | ||
get store() { | ||
if (this.storeName === "local") { | ||
return CachingOptions.storage.local; | ||
} | ||
else { | ||
return CachingOptions.storage.session; | ||
} | ||
} | ||
} | ||
CachingOptions.storage = new PnPClientStorage(); | ||
export class CachingParserWrapper { | ||
constructor(parser, cacheOptions) { | ||
this.parser = parser; | ||
this.cacheOptions = cacheOptions; | ||
} | ||
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) { | ||
parse(response) { | ||
return this.parser.parse(response).then(r => this.cacheData(r)); | ||
} | ||
cacheData(data) { | ||
if (this.cacheOptions.store !== null) { | ||
@@ -39,6 +32,4 @@ this.cacheOptions.store.put(this.cacheOptions.key, data, this.cacheOptions.expiration); | ||
return data; | ||
}; | ||
return CachingParserWrapper; | ||
}()); | ||
export { CachingParserWrapper }; | ||
} | ||
} | ||
//# sourceMappingURL=caching.js.map |
36
debug.js
@@ -0,13 +1,10 @@ | ||
import { hOP } from "@pnp/common"; | ||
import { Logger } from "@pnp/logging"; | ||
import { extendGlobal } from "./invokable-extensions"; | ||
import { extendGlobal } from "./invokable-extensions.js"; | ||
extendGlobal([ | ||
function (op, target) { | ||
var rest = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
rest[_i - 2] = arguments[_i]; | ||
} | ||
(op, target, ...rest) => { | ||
if (target.__deepTrace) { | ||
switch (op) { | ||
case "apply": | ||
Logger.write(op + " ::> ()", 1 /* Info */); | ||
Logger.write(`${op} ::> ()`, 1 /* Info */); | ||
break; | ||
@@ -17,3 +14,3 @@ case "has": | ||
case "set": | ||
Logger.write(op + " ::> " + rest[0], 1 /* Info */); | ||
Logger.write(`${op} ::> ${rest[0]}`, 1 /* Info */); | ||
break; | ||
@@ -24,18 +21,23 @@ } | ||
{ | ||
get: function (target, p, _receiver) { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
get: (target, p, _receiver) => { | ||
switch (p) { | ||
case "__enableDeepTrace": | ||
return function () { target.__deepTrace = true; }; | ||
return () => { | ||
target.__deepTrace = true; | ||
}; | ||
case "__disableDeepTrace": | ||
return function () { target.__deepTrace = false; }; | ||
return () => { | ||
target.__deepTrace = false; | ||
}; | ||
case "__data": | ||
return target.data; | ||
case "__unwrap": | ||
return function () { return target; }; | ||
return () => target; | ||
case "__json": | ||
return function () { | ||
var o = {}; | ||
for (var name_1 in target) { | ||
if (target.hasOwnProperty(name_1)) { | ||
o[name_1] = target[name_1]; | ||
return () => { | ||
const o = {}; | ||
for (const name in target) { | ||
if (hOP(target, name)) { | ||
o[name] = target[name]; | ||
} | ||
@@ -42,0 +44,0 @@ } |
@@ -1,11 +0,11 @@ | ||
export * from "./batch"; | ||
export * from "./caching"; | ||
export * from "./add-prop"; | ||
export * from "./invokable-binder"; | ||
export * from "./pipeline-binder"; | ||
export * from "./parsers"; | ||
export * from "./pipeline"; | ||
export * from "./queryable"; | ||
export * from "./request-builders"; | ||
export { extendGlobal, extendObj, extendFactory, ExtensionType, clearGlobalExtensions, enableExtensions, disableExtensions, } from "./invokable-extensions"; | ||
export * from "./batch.js"; | ||
export * from "./caching.js"; | ||
export * from "./add-prop.js"; | ||
export * from "./invokable-binder.js"; | ||
export * from "./pipeline-binder.js"; | ||
export * from "./parsers.js"; | ||
export * from "./pipeline.js"; | ||
export * from "./queryable.js"; | ||
export * from "./request-builders.js"; | ||
export { extendGlobal, extendObj, extendFactory, ExtensionType, clearGlobalExtensions, enableExtensions, disableExtensions, } from "./invokable-extensions.js"; | ||
//# sourceMappingURL=index.d.ts.map |
20
index.js
@@ -1,11 +0,11 @@ | ||
export * from "./batch"; | ||
export * from "./caching"; | ||
export * from "./add-prop"; | ||
export * from "./invokable-binder"; | ||
export * from "./pipeline-binder"; | ||
export * from "./parsers"; | ||
export * from "./pipeline"; | ||
export * from "./queryable"; | ||
export * from "./request-builders"; | ||
export { extendGlobal, extendObj, extendFactory, clearGlobalExtensions, enableExtensions, disableExtensions, } from "./invokable-extensions"; | ||
export * from "./batch.js"; | ||
export * from "./caching.js"; | ||
export * from "./add-prop.js"; | ||
export * from "./invokable-binder.js"; | ||
export * from "./pipeline-binder.js"; | ||
export * from "./parsers.js"; | ||
export * from "./pipeline.js"; | ||
export * from "./queryable.js"; | ||
export * from "./request-builders.js"; | ||
export { extendGlobal, extendObj, extendFactory, clearGlobalExtensions, enableExtensions, disableExtensions, } from "./invokable-extensions.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,3 @@ | ||
import { IQueryable } from "./queryable"; | ||
import { IRequestContext } from "./pipeline"; | ||
import { IQueryable } from "./queryable.js"; | ||
import { IRequestContext } from "./pipeline.js"; | ||
export declare type IHybrid<R = any, T = any> = T & { | ||
@@ -7,3 +7,3 @@ (this: T, ...args: any[]): Promise<R>; | ||
export declare type IInvoker<R> = (this: IQueryable<any>, ...args: any[]) => Promise<R>; | ||
export declare const invokableFactory: <R>(constructor: new (...args: any[]) => any) => (...args: any[]) => R; | ||
export declare const invokableFactory: <R>(constructor: new (...args: any[]) => any) => (...args: any[]) => R & IInvokable<any>; | ||
export interface IInvokable<R = any> { | ||
@@ -10,0 +10,0 @@ <T = R>(options?: Partial<IRequestContext<T>>): Promise<T>; |
@@ -1,18 +0,9 @@ | ||
import { __read, __spread } from "tslib"; | ||
import { DefaultRuntime } from "@pnp/common"; | ||
import { extensionOrDefault, applyFactoryExtensions } from "./invokable-extensions"; | ||
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.apply(r, ags); | ||
}, new (constructor.bind.apply(constructor, __spread([void 0], as)))()); | ||
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)); | ||
Reflect.setPrototypeOf(r, constructor.prototype); | ||
@@ -27,37 +18,13 @@ return r; | ||
return new Proxy(applyFactoryExtensions(factory, args), { | ||
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); | ||
apply: (target, _thisArg, argArray) => { | ||
return extensionOrDefault("apply", (...a) => Reflect.apply(a[0], a[1], a[2]), target, _thisArg, argArray); | ||
}, | ||
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); | ||
get: (target, p, receiver) => { | ||
return extensionOrDefault("get", (...a) => Reflect.get(a[0], a[1], a[2]), target, p, receiver); | ||
}, | ||
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); | ||
has: (target, p) => { | ||
return extensionOrDefault("has", (...a) => Reflect.has(a[0], a[1]), target, p); | ||
}, | ||
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); | ||
set: (target, p, value, receiver) => { | ||
return extensionOrDefault("set", (...a) => Reflect.set(a[0], a[1], a[2], a[3]), target, p, value, receiver); | ||
}, | ||
@@ -67,6 +34,6 @@ }); | ||
}; | ||
}; }; | ||
export var invokableFactory = invokableBinder(function (options) { | ||
}; | ||
export const invokableFactory = invokableBinder(function (options) { | ||
return this.defaultAction(options); | ||
}); | ||
//# sourceMappingURL=invokable-binder.js.map |
import { ITypedHash } from "@pnp/common"; | ||
export declare type ValidProxyMethods = "apply" | "get" | "has" | "set"; | ||
export declare type ExtensionDelegateType<T extends object> = { | ||
export declare type ExtensionDelegateType<T extends Record<string, unknown>> = { | ||
(op: string, target: T, ...rest: any[]): void; | ||
}; | ||
export declare type ExtensionType<T extends object = {}> = Pick<ProxyHandler<T>, ValidProxyMethods> | ExtensionDelegateType<T> | ITypedHash<any>; | ||
export declare type ExtensionType<T extends Record<string, unknown> = {}> = Pick<ProxyHandler<T>, ValidProxyMethods> | ExtensionDelegateType<T> | ITypedHash<any>; | ||
/** | ||
@@ -8,0 +8,0 @@ * Creates global extensions across all invokable objects |
@@ -1,7 +0,6 @@ | ||
import { __read, __spread } from "tslib"; | ||
import { isFunc, isArray, getGUID } from "@pnp/common"; | ||
var _enableExtensions = false; | ||
var globalExtensions = []; | ||
var factoryExtensions = new Map(); | ||
var ObjExtensionsSym = Symbol.for("43f7a601"); | ||
import { isFunc, getGUID } from "@pnp/common"; | ||
let _enableExtensions = false; | ||
const globalExtensions = []; | ||
const factoryExtensions = new Map(); | ||
const ObjExtensionsSym = Symbol.for("43f7a601"); | ||
/** | ||
@@ -12,3 +11,3 @@ * Creates global extensions across all invokable objects | ||
*/ | ||
export var extendGlobal = function (e) { | ||
export const extendGlobal = (e) => { | ||
_enableExtensions = true; | ||
@@ -23,3 +22,4 @@ extendCol(globalExtensions, e); | ||
*/ | ||
export var extendObj = function (target, extensions) { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const extendObj = (target, extensions) => { | ||
_enableExtensions = true; | ||
@@ -38,6 +38,6 @@ if (!Reflect.has(target, ObjExtensionsSym)) { | ||
*/ | ||
export var extendFactory = function (factory, extensions) { | ||
export const extendFactory = (factory, extensions) => { | ||
_enableExtensions = true; | ||
// factoryExtensions | ||
var proto = Reflect.getPrototypeOf(factory); | ||
const proto = Reflect.getPrototypeOf(factory); | ||
if (!Reflect.has(proto, ObjExtensionsSym)) { | ||
@@ -48,3 +48,3 @@ Reflect.defineProperty(proto, ObjExtensionsSym, { | ||
} | ||
var key = proto[ObjExtensionsSym]; | ||
const key = proto[ObjExtensionsSym]; | ||
if (!factoryExtensions.has(key)) { | ||
@@ -56,8 +56,6 @@ factoryExtensions.set(key, []); | ||
function extendCol(a, e) { | ||
if (isArray(e)) { | ||
// @ts-ignore | ||
a.push.apply(a, __spread(e)); | ||
if (Array.isArray(e)) { | ||
a.push(...e); | ||
} | ||
else { | ||
// @ts-ignore | ||
a.push(e); | ||
@@ -69,3 +67,3 @@ } | ||
*/ | ||
export var clearGlobalExtensions = function () { | ||
export const clearGlobalExtensions = () => { | ||
globalExtensions.length = 0; | ||
@@ -76,3 +74,3 @@ }; | ||
*/ | ||
export var disableExtensions = function () { | ||
export const disableExtensions = () => { | ||
_enableExtensions = false; | ||
@@ -83,3 +81,3 @@ }; | ||
*/ | ||
export var enableExtensions = function () { | ||
export const enableExtensions = () => { | ||
_enableExtensions = true; | ||
@@ -93,7 +91,8 @@ }; | ||
*/ | ||
export var applyFactoryExtensions = function (factory, args) { | ||
var o = factory(args); | ||
var proto = Reflect.getPrototypeOf(factory); | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const applyFactoryExtensions = (factory, args) => { | ||
let o = factory(args); | ||
const proto = Reflect.getPrototypeOf(factory); | ||
if (Reflect.has(proto, ObjExtensionsSym)) { | ||
var extensions = factoryExtensions.get(Reflect.get(proto, ObjExtensionsSym)); | ||
const extensions = factoryExtensions.get(Reflect.get(proto, ObjExtensionsSym)); | ||
o = extendObj(o, extensions); | ||
@@ -103,21 +102,17 @@ } | ||
}; | ||
export function extensionOrDefault(op, or, target) { | ||
var rest = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
rest[_i - 3] = arguments[_i]; | ||
} | ||
export function extensionOrDefault(op, or, target, ...rest) { | ||
if (_enableExtensions) { | ||
var extensions = []; | ||
const extensions = []; | ||
// we need to first invoke extensions tied to only this object | ||
if (Reflect.has(target, ObjExtensionsSym)) { | ||
extensions.push.apply(extensions, __spread(Reflect.get(target, ObjExtensionsSym))); | ||
extensions.push(...Reflect.get(target, ObjExtensionsSym)); | ||
} | ||
// second we need to process any global extensions | ||
extensions.push.apply(extensions, __spread(globalExtensions)); | ||
for (var i = 0; i < extensions.length; i++) { | ||
var extension = extensions[i]; | ||
var result = undefined; | ||
extensions.push(...globalExtensions); | ||
for (let i = 0; i < extensions.length; i++) { | ||
const extension = extensions[i]; | ||
let result = undefined; | ||
if (isFunc(extension)) { | ||
// this extension is a function which we call | ||
result = extension.apply(void 0, __spread([op, target], rest)); | ||
result = extension(op, target, ...rest); | ||
} | ||
@@ -130,3 +125,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).apply(void 0, __spread([target], rest)); | ||
result = Reflect.get(extension, op)(target, ...rest); | ||
} | ||
@@ -141,4 +136,4 @@ if (typeof result !== "undefined") { | ||
} | ||
return or.apply(void 0, __spread([target], rest)); | ||
return or(target, ...rest); | ||
} | ||
//# sourceMappingURL=invokable-extensions.js.map |
{ | ||
"name": "@pnp/odata", | ||
"version": "2.1.0-beta1", | ||
"version": "2.1.0-beta10", | ||
"description": "pnp - provides shared odata functionality and base classes", | ||
@@ -8,5 +8,5 @@ "main": "./index.js", | ||
"dependencies": { | ||
"tslib": "2.0.0", | ||
"@pnp/logging": "2.1.0-beta1", | ||
"@pnp/common": "2.1.0-beta1" | ||
"tslib": "2.0.3", | ||
"@pnp/logging": "2.1.0-beta10", | ||
"@pnp/common": "2.1.0-beta10" | ||
}, | ||
@@ -13,0 +13,0 @@ "author": { |
147
parsers.js
@@ -1,16 +0,12 @@ | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { __awaiter } from "tslib"; | ||
import { isFunc, hOP } from "@pnp/common"; | ||
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); | ||
export class ODataParser { | ||
parse(r) { | ||
return new Promise((resolve, reject) => { | ||
if (this.handleError(r, reject)) { | ||
this.parseImpl(r, resolve, reject); | ||
} | ||
}); | ||
}; | ||
ODataParser.prototype.parseImpl = function (r, resolve, reject) { | ||
var _this = this; | ||
} | ||
parseImpl(r, resolve, reject) { | ||
if ((r.headers.has("Content-Length") && parseFloat(r.headers.get("Content-Length")) === 0) || r.status === 204) { | ||
@@ -22,7 +18,7 @@ resolve({}); | ||
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); }); | ||
.then(txt => txt.replace(/\s/ig, "").length > 0 ? JSON.parse(txt) : {}) | ||
.then(json => resolve(this.parseODataJSON(json))) | ||
.catch(e => reject(e)); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -35,3 +31,3 @@ * Handles a response with ok === false by parsing the body and creating a ProcessHttpClientResponseException | ||
*/ | ||
ODataParser.prototype.handleError = function (r, reject) { | ||
handleError(r, reject) { | ||
if (!r.ok) { | ||
@@ -41,3 +37,3 @@ HttpRequestError.init(r).then(reject); | ||
return r.ok; | ||
}; | ||
} | ||
/** | ||
@@ -48,4 +44,4 @@ * Normalizes the json response by removing the various nested levels | ||
*/ | ||
ODataParser.prototype.parseODataJSON = function (json) { | ||
var result = json; | ||
parseODataJSON(json) { | ||
let result = json; | ||
if (hOP(json, "d")) { | ||
@@ -63,45 +59,21 @@ 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; | ||
} | ||
TextParser.prototype.parseImpl = function (r, resolve) { | ||
} | ||
export class TextParser extends ODataParser { | ||
parseImpl(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; | ||
} | ||
BlobParser.prototype.parseImpl = function (r, resolve) { | ||
} | ||
export class BlobParser extends ODataParser { | ||
parseImpl(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; | ||
} | ||
JSONParser.prototype.parseImpl = function (r, resolve) { | ||
} | ||
export class JSONParser extends ODataParser { | ||
parseImpl(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; | ||
} | ||
BufferParser.prototype.parseImpl = function (r, resolve) { | ||
} | ||
export class BufferParser extends ODataParser { | ||
parseImpl(r, resolve) { | ||
if (isFunc(r.arrayBuffer)) { | ||
@@ -113,47 +85,28 @@ 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; | ||
} | ||
LambdaParser.prototype.parseImpl = function (r, resolve) { | ||
} | ||
export class LambdaParser extends ODataParser { | ||
constructor(parser) { | ||
super(); | ||
this.parser = parser; | ||
} | ||
parseImpl(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; | ||
} | ||
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())]; | ||
} | ||
}); | ||
} | ||
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()); | ||
}); | ||
}; | ||
return HttpRequestError; | ||
}(Error)); | ||
export { HttpRequestError }; | ||
} | ||
} | ||
//# sourceMappingURL=parsers.js.map |
@@ -1,5 +0,5 @@ | ||
import { IODataParser } from "./parsers"; | ||
import { IODataParser } from "./parsers.js"; | ||
import { IFetchOptions, IRequestClient } from "@pnp/common"; | ||
import { IQueryableData } from "./queryable"; | ||
import { PipelineMethod } from "./pipeline"; | ||
import { IQueryableData } from "./queryable.js"; | ||
import { PipelineMethod } from "./pipeline.js"; | ||
export interface IRequestOptions<T> extends IFetchOptions { | ||
@@ -6,0 +6,0 @@ parser: IODataParser<T>; |
@@ -1,5 +0,5 @@ | ||
import { ODataParser } from "./parsers"; | ||
import { ODataParser } from "./parsers.js"; | ||
import { getGUID, objectDefinedNotNull } from "@pnp/common"; | ||
import { cloneQueryableData } from "./queryable"; | ||
import { pipe, getDefaultPipeline } from "./pipeline"; | ||
import { cloneQueryableData } from "./queryable.js"; | ||
import { pipe, getDefaultPipeline } from "./pipeline.js"; | ||
// first we bind the pipeline we will use for all requests within this closure | ||
@@ -19,3 +19,3 @@ export function pipelineBinder(pipes) { | ||
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 var defaultPipelineBinder = pipelineBinder(getDefaultPipeline()); | ||
export const defaultPipelineBinder = pipelineBinder(getDefaultPipeline()); | ||
//# sourceMappingURL=pipeline-binder.js.map |
import { IRequestClient } from "@pnp/common"; | ||
import { IQueryableData } from "./queryable"; | ||
import { IQueryableData } from "./queryable.js"; | ||
/** | ||
@@ -4,0 +4,0 @@ * Defines the context for a given request to be processed in the pipeline |
121
pipeline.js
import { __decorate } from "tslib"; | ||
import { assign, isFunc, hOP } from "@pnp/common"; | ||
import { Logger } from "@pnp/logging"; | ||
import { CachingOptions, CachingParserWrapper } from "./caching"; | ||
import { CachingOptions, CachingParserWrapper } from "./caching.js"; | ||
/** | ||
@@ -14,3 +14,3 @@ * Resolves the context's result value | ||
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(function (resolve) { | ||
return new Promise((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!"); | ||
} | ||
var promise = next(context).then(function (ctx) { return returnResult(ctx); }).catch(function (e) { | ||
const promise = next(context).then(ctx => returnResult(ctx)).catch((e) => { | ||
Logger.error(e); | ||
@@ -62,20 +62,15 @@ throw e; | ||
*/ | ||
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]; | ||
} | ||
export function requestPipelineMethod(alwaysRun = false) { | ||
return (target, propertyKey, descriptor) => { | ||
const method = descriptor.value; | ||
descriptor.value = function (...args) { | ||
// 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(function (ctx) { return next(ctx); }); | ||
return method.apply(target, args).then((ctx) => next(ctx)); | ||
}; | ||
@@ -87,27 +82,25 @@ }; | ||
*/ | ||
var PipelineMethods = /** @class */ (function () { | ||
function PipelineMethods() { | ||
} | ||
export class PipelineMethods { | ||
/** | ||
* Logs the start of the request | ||
*/ | ||
PipelineMethods.logStart = function (context) { | ||
return new Promise(function (resolve) { | ||
static logStart(context) { | ||
return new Promise(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 | ||
*/ | ||
PipelineMethods.caching = function (context) { | ||
return new Promise(function (resolve) { | ||
static caching(context) { | ||
return new Promise(resolve => { | ||
// handle caching, if applicable | ||
if (context.useCaching) { | ||
Logger.write("[" + context.requestId + "] (" + (new Date()).getTime() + ") Caching is enabled for request, checking cache...", 1 /* Info */); | ||
var cacheOptions = new CachingOptions(context.url.toLowerCase()); | ||
Logger.write(`[${context.requestId}] (${(new Date()).getTime()}) Caching is enabled for request, checking cache...`, 1 /* Info */); | ||
let cacheOptions = new CachingOptions(context.url.toLowerCase()); | ||
if (context.cachingOptions !== undefined) { | ||
@@ -119,3 +112,3 @@ cacheOptions = assign(cacheOptions, context.cachingOptions); | ||
// check if we have the data in cache and if so resolve the promise and return | ||
var data = cacheOptions.store.get(cacheOptions.key); | ||
let data = cacheOptions.store.get(cacheOptions.key); | ||
if (data !== null) { | ||
@@ -125,3 +118,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.`, | ||
}); | ||
@@ -136,6 +129,6 @@ // ensure we clear any held batch dependency we are resolving from the cache | ||
} | ||
return setResult(context, data).then(function (ctx) { return resolve(ctx); }); | ||
return setResult(context, data).then(ctx => 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 | ||
@@ -147,11 +140,11 @@ // and send things on their way | ||
}); | ||
}; | ||
} | ||
/** | ||
* Sends the request | ||
*/ | ||
PipelineMethods.send = function (context) { | ||
return new Promise(function (resolve, reject) { | ||
static send(context) { | ||
return new Promise((resolve, reject) => { | ||
// send or batch the request | ||
if (context.isBatched) { | ||
var p = context.batch.add(context); | ||
const 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 | ||
@@ -161,3 +154,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 | ||
@@ -167,19 +160,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 | ||
var client = context.clientFactory(); | ||
var opts = assign(context.options || {}, { method: context.method }); | ||
const client = context.clientFactory(); | ||
const opts = assign(context.options || {}, { method: context.method }); | ||
client.fetch(context.url, 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); }); | ||
.then(response => context.parser.parse(response)) | ||
.then(result => setResult(context, result)) | ||
.then(ctx => resolve(ctx)) | ||
.catch(e => reject(e)); | ||
} | ||
}); | ||
}; | ||
} | ||
/** | ||
* Logs the end of the request | ||
*/ | ||
PipelineMethods.logEnd = function (context) { | ||
return new Promise(function (resolve) { | ||
static logEnd(context) { | ||
return new Promise(resolve => { | ||
if (context.isBatched) { | ||
@@ -189,3 +182,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}.`, | ||
}); | ||
@@ -197,3 +190,3 @@ } | ||
level: 1 /* Info */, | ||
message: "[" + context.requestId + "] (" + (new Date()).getTime() + ") Completing " + context.method + " request.", | ||
message: `[${context.requestId}] (${(new Date()).getTime()}) Completing ${context.method} request.`, | ||
}); | ||
@@ -203,18 +196,16 @@ } | ||
}); | ||
}; | ||
__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 }; | ||
} | ||
} | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logStart", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "caching", null); | ||
__decorate([ | ||
requestPipelineMethod() | ||
], PipelineMethods, "send", null); | ||
__decorate([ | ||
requestPipelineMethod(true) | ||
], PipelineMethods, "logEnd", null); | ||
export function getDefaultPipeline() { | ||
@@ -221,0 +212,0 @@ return [ |
import { IFetchOptions, IConfigOptions, IRequestClient, ITypedHash, Runtime } from "@pnp/common"; | ||
import { ICachingOptions } from "./caching"; | ||
import { Batch } from "./batch"; | ||
import { PipelineMethod } from "./pipeline"; | ||
import { IODataParser } from "./parsers"; | ||
import { ICachingOptions } from "./caching.js"; | ||
import { Batch } from "./batch.js"; | ||
import { PipelineMethod } from "./pipeline.js"; | ||
import { IODataParser } from "./parsers.js"; | ||
export declare function cloneQueryableData(source: Partial<IQueryableData>): Partial<IQueryableData>; | ||
@@ -53,94 +53,94 @@ export interface IQueryableData<DefaultActionType = any> { | ||
/** | ||
* Gets the full url with query information | ||
* | ||
*/ | ||
* Gets the full url with query information | ||
* | ||
*/ | ||
abstract toUrlAndQuery(): string; | ||
/** | ||
* The default action for this | ||
*/ | ||
* The default action for this | ||
*/ | ||
abstract defaultAction(options?: IFetchOptions): Promise<DefaultActionType>; | ||
/** | ||
* Gets the current url | ||
* | ||
*/ | ||
* Gets the current url | ||
* | ||
*/ | ||
toUrl(): string; | ||
/** | ||
* Directly concatenates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatenate to the url | ||
*/ | ||
* Directly concatenates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatenate to the url | ||
*/ | ||
concat(pathPart: string): this; | ||
/** | ||
* Provides access to the query builder for this url | ||
* | ||
*/ | ||
* Provides access to the query builder for this url | ||
* | ||
*/ | ||
get query(): Map<string, string>; | ||
/** | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
* | ||
* @param options custom options | ||
*/ | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
* | ||
* @param options custom options | ||
*/ | ||
configure(options: IConfigOptions): this; | ||
/** | ||
* Configures this instance from the configure options of the supplied instance | ||
* | ||
* @param o Instance from which options should be taken | ||
*/ | ||
* Configures this instance from the configure options of the supplied instance | ||
* | ||
* @param o Instance from which options should be taken | ||
*/ | ||
configureFrom(o: IQueryable<any>): this; | ||
/** | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
usingCaching(options?: string | ICachingOptions): this; | ||
usingParser(parser: IODataParser<any>): this; | ||
/** | ||
* Allows you to set a request specific processing pipeline | ||
* | ||
* @param pipeline The set of methods, in order, to execute a given request | ||
*/ | ||
* Allows you to set a request specific processing pipeline | ||
* | ||
* @param pipeline The set of methods, in order, to execute a given request | ||
*/ | ||
withPipeline(pipeline: PipelineMethod<DefaultActionType>[]): this; | ||
/** | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
append(pathPart: string): void; | ||
/** | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
inBatch(batch: Batch): this; | ||
/** | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
addBatchDependency(): () => void; | ||
/** | ||
* Indicates if the current query has a batch associated | ||
* | ||
*/ | ||
* Indicates if the current query has a batch associated | ||
* | ||
*/ | ||
protected get hasBatch(): boolean; | ||
/** | ||
* The batch currently associated with this query or null | ||
* | ||
*/ | ||
* The batch currently associated with this query or null | ||
* | ||
*/ | ||
protected get batch(): Batch | null; | ||
/** | ||
* Gets the parent url used when creating this instance | ||
* | ||
*/ | ||
* Gets the parent url used when creating this instance | ||
* | ||
*/ | ||
protected get parentUrl(): string; | ||
/** | ||
* Clones this instance's data to target | ||
* | ||
* @param target Instance to which data is written | ||
* @param settings [Optional] Settings controlling how clone is applied | ||
*/ | ||
* Clones this instance's data to target | ||
* | ||
* @param target Instance to which data is written | ||
* @param settings [Optional] Settings controlling how clone is applied | ||
*/ | ||
protected cloneTo<T extends IQueryable<any>>(target: T, settings?: { | ||
@@ -147,0 +147,0 @@ includeBatch?: boolean; |
263
queryable.js
@@ -1,6 +0,5 @@ | ||
import { __read, __spread } from "tslib"; | ||
import { combine, mergeOptions, objectDefinedNotNull, assign, Runtime, DefaultRuntime, dateAdd, stringIsNullOrEmpty, } from "@pnp/common"; | ||
import { ODataParser } from "./parsers"; | ||
import { ODataParser } from "./parsers.js"; | ||
export function cloneQueryableData(source) { | ||
var body; | ||
let body; | ||
// this handles bodies that cannot be JSON encoded (Blob, etc) | ||
@@ -12,6 +11,6 @@ // Note however, even bodies that can be serialized will not be cloned. | ||
} | ||
var s = JSON.stringify(source, function (key, value) { | ||
const s = JSON.stringify(source, (key, value) => { | ||
switch (key) { | ||
case "query": | ||
return JSON.stringify(__spread(value)); | ||
return JSON.stringify([...value]); | ||
case "batch": | ||
@@ -27,3 +26,3 @@ case "batchDependency": | ||
}, 0); | ||
var parsed = JSON.parse(s, function (key, value) { | ||
const parsed = JSON.parse(s, (key, value) => { | ||
switch (key) { | ||
@@ -48,5 +47,4 @@ case "query": | ||
} | ||
var Queryable = /** @class */ (function () { | ||
function Queryable(dataSeed) { | ||
if (dataSeed === void 0) { dataSeed = {}; } | ||
export class Queryable { | ||
constructor(dataSeed = {}) { | ||
this._data = Object.assign({}, { | ||
@@ -63,13 +61,9 @@ cloneParentWasCaching: false, | ||
} | ||
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 () { | ||
get data() { | ||
return this._data; | ||
} | ||
set data(value) { | ||
this._data = Object.assign({}, this.data, cloneQueryableData(value)); | ||
} | ||
getRuntime() { | ||
if (this._runtime === null) { | ||
@@ -79,9 +73,5 @@ return DefaultRuntime; | ||
return this._runtime; | ||
}; | ||
Queryable.prototype.setRuntime = function () { | ||
} | ||
setRuntime(...args) { | ||
// 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) { | ||
@@ -97,47 +87,43 @@ this._runtime = args[0]; | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Gets the current url | ||
* | ||
*/ | ||
Queryable.prototype.toUrl = function () { | ||
* Gets the current url | ||
* | ||
*/ | ||
toUrl() { | ||
return this.data.url; | ||
}; | ||
} | ||
/** | ||
* Directly concatenates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatenate to the url | ||
*/ | ||
Queryable.prototype.concat = function (pathPart) { | ||
* Directly concatenates the supplied string to the current url, not normalizing "/" chars | ||
* | ||
* @param pathPart The string to concatenate to the url | ||
*/ | ||
concat(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 | ||
}); | ||
} | ||
/** | ||
* Sets custom options for current object and all derived objects accessible via chaining | ||
* | ||
* @param options custom options | ||
*/ | ||
Queryable.prototype.configure = function (options) { | ||
* 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 | ||
* | ||
* @param options custom options | ||
*/ | ||
configure(options) { | ||
mergeOptions(this.data.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) { | ||
* Configures this instance from the configure options of the supplied instance | ||
* | ||
* @param o Instance from which options should be taken | ||
*/ | ||
configureFrom(o) { | ||
mergeOptions(this.data.options, o.data.options); | ||
var sourceRuntime = o.getRuntime(); | ||
const sourceRuntime = o.getRuntime(); | ||
if (!sourceRuntime.get("__isDefault__")) { | ||
@@ -147,10 +133,10 @@ this.setRuntime(sourceRuntime); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
Queryable.prototype.usingCaching = function (options) { | ||
var runtime = this.getRuntime(); | ||
* Enables caching for this request | ||
* | ||
* @param options Defines the options used when caching this request | ||
*/ | ||
usingCaching(options) { | ||
const runtime = this.getRuntime(); | ||
if (!runtime.get("globalCacheDisable")) { | ||
@@ -166,3 +152,3 @@ this.data.useCaching = true; | ||
// this uses our local options if they are defined as defaults | ||
var defaultOpts = { | ||
const defaultOpts = { | ||
expiration: dateAdd(new Date(), "second", runtime.get("defaultCachingTimeoutSeconds")), | ||
@@ -174,36 +160,36 @@ storeName: runtime.get("defaultCachingStore"), | ||
return this; | ||
}; | ||
Queryable.prototype.usingParser = function (parser) { | ||
} | ||
usingParser(parser) { | ||
this.data.parser = parser; | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Allows you to set a request specific processing pipeline | ||
* | ||
* @param pipeline The set of methods, in order, to execute a given request | ||
*/ | ||
Queryable.prototype.withPipeline = function (pipeline) { | ||
* Allows you to set a request specific processing pipeline | ||
* | ||
* @param pipeline The set of methods, in order, to execute a given request | ||
*/ | ||
withPipeline(pipeline) { | ||
this.data.pipes = pipeline.slice(0); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
Queryable.prototype.append = function (pathPart) { | ||
* Appends the given string and normalizes "/" chars | ||
* | ||
* @param pathPart The string to append | ||
*/ | ||
append(pathPart) { | ||
this.data.url = combine(this.data.url, pathPart); | ||
}; | ||
} | ||
/** | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
Queryable.prototype.inBatch = function (batch) { | ||
* Adds this query to the supplied batch | ||
* | ||
* @example | ||
* ``` | ||
* | ||
* let b = pnp.sp.createBatch(); | ||
* pnp.sp.web.inBatch(b).get().then(...); | ||
* b.execute().then(...) | ||
* ``` | ||
*/ | ||
inBatch(batch) { | ||
if (this.hasBatch) { | ||
@@ -216,53 +202,40 @@ 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 | ||
*/ | ||
Queryable.prototype.addBatchDependency = function () { | ||
* Blocks a batch call from occuring, MUST be cleared by calling the returned function | ||
*/ | ||
addBatchDependency() { | ||
if (objectDefinedNotNull(this.data.batch)) { | ||
return this.data.batch.addDependency(); | ||
} | ||
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 | ||
}); | ||
return () => null; | ||
} | ||
/** | ||
* Clones this instance's data to target | ||
* | ||
* @param target Instance to which data is written | ||
* @param settings [Optional] Settings controlling how clone is applied | ||
*/ | ||
Queryable.prototype.cloneTo = function (target, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
* 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 | ||
* | ||
* @param target Instance to which data is written | ||
* @param settings [Optional] Settings controlling how clone is applied | ||
*/ | ||
cloneTo(target, settings = {}) { | ||
// default values for settings | ||
@@ -283,3 +256,3 @@ settings = assign({ | ||
if (settings.includeQuery && this.query.size > 0) { | ||
this.query.forEach(function (v, k) { return target.query.set(k, v); }); | ||
this.query.forEach((v, k) => target.query.set(k, v)); | ||
} | ||
@@ -291,6 +264,4 @@ if (this.data.useCaching) { | ||
return target; | ||
}; | ||
return Queryable; | ||
}()); | ||
export { Queryable }; | ||
} | ||
} | ||
//# sourceMappingURL=queryable.js.map |
@@ -0,0 +0,0 @@ ![SharePoint Patterns and Practices](https://devofficecdn.azureedge.net/media/Default/PnP/sppnp.png) |
@@ -5,2 +5,3 @@ import { jsS } from "@pnp/common"; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export function headers(o, previous) { | ||
@@ -7,0 +8,0 @@ return Object.assign({ headers: o }, previous); |
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
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
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
98026
1418
+ Added@pnp/common@2.1.0-beta10(transitive)
+ Added@pnp/logging@2.1.0-beta10(transitive)
+ Addedtslib@2.0.3(transitive)
- Removed@pnp/common@2.1.0-beta1(transitive)
- Removed@pnp/logging@2.1.0-beta1(transitive)
- Removedtslib@2.0.0(transitive)
Updated@pnp/common@2.1.0-beta10
Updated@pnp/logging@2.1.0-beta10
Updatedtslib@2.0.3