UNPKG

1.85 kBJavaScriptView Raw
1import { ODataParser } from "./parsers.js";
2import { getGUID, objectDefinedNotNull } from "@pnp/common";
3import { cloneQueryableData } from "./queryable.js";
4import { pipe, getDefaultPipeline } from "./pipeline.js";
5// first we bind the pipeline we will use for all requests within this closure
6export function pipelineBinder(pipes) {
7 // then we bind the client factory we'll use (typically done in an implementing library such as sp)
8 return function (clientFactory) {
9 // then we create a binder we can apply for each type of method (GET, POST, etc.)
10 return function (method) {
11 // finally we get a function back to which we can pass an IQueryableData instance and execute the request it defines
12 return function (o) {
13 // send the IQueryableData down the pipeline
14 return pipe(Object.assign({}, {
15 batch: null,
16 batchDependency: null,
17 batchIndex: -1,
18 cachingOptions: null,
19 clientFactory: clientFactory,
20 cloneParentCacheOptions: null,
21 cloneParentWasCaching: false,
22 hasResult: false,
23 isBatched: objectDefinedNotNull(o.batch),
24 method: method,
25 options: null,
26 parentUrl: "",
27 parser: new ODataParser(),
28 pipes: pipes.slice(0),
29 query: new Map(),
30 requestId: getGUID(),
31 url: "",
32 useCaching: /^get$/i.test(o.method) && o.useCaching,
33 }, cloneQueryableData(o)));
34 };
35 };
36 };
37}
38export var defaultPipelineBinder = pipelineBinder(getDefaultPipeline());
39//# sourceMappingURL=pipeline-binder.js.map
\No newline at end of file