Skip to content

Commit

Permalink
Merge pull request #2953 from patrick-rodgers/version-4
Browse files Browse the repository at this point in the history
Moves stream support into sp/files, updates sp telemetry to remove v for v2.1 apis.
  • Loading branch information
patrick-rodgers authored Mar 6, 2024
2 parents 4384f18 + b0c167b commit 8b0f7ea
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 259 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- sp
- explict error thrown if SPFx context is null or undefined when needed
- getStream method on all readable files
- addChunked updated to accept stream as content, new signature with props object

### Removed

Expand All @@ -35,6 +37,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- PagedItemCollection removed from library
- removed /items/get-all import, unneeded, use async iterator patterns
- ./operations.ts methods moved to ./spqueryable.ts
- startUpload, continueUpload, finishUpload File protected methods removed

- nodejs
- removed stream extensions, moved into sp

### Changed

Expand All @@ -55,3 +61,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- sp
- _Items and IItems now supports async iterator pattern
- chunked upload/add progress object shape changed to : { uploadId: string; stage: "starting" | "continue" | "finishing"; offset: number; }
7 changes: 0 additions & 7 deletions packages/nodejs/behaviors/stream-parse.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/nodejs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@ import * as NodeFetch from "node-fetch";

})(global);

// auto populate all extensions
import "./sp-extensions/stream.js";

// export extension types as a namespace
import * as SPNS from "./sp-extensions/stream.js";

export {
SPNS,
};

export * from "./behaviors/msal.js";
export * from "./behaviors/fetch.js";
export * from "./behaviors/stream-parse.js";
export * from "./behaviors/spdefault.js";
export * from "./behaviors/graphdefault.js";
136 changes: 0 additions & 136 deletions packages/nodejs/sp-extensions/stream.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/sp/behaviors/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TimelinePipe } from "@pnp/core";
import { TimelinePipe, stringIsNullOrEmpty } from "@pnp/core";
import { Queryable } from "@pnp/queryable";

export function Telemetry(): TimelinePipe<Queryable> {
Expand All @@ -14,10 +14,10 @@ export function Telemetry(): TimelinePipe<Queryable> {

// remove anything before the _api as that is potentially PII and we don't care, just want to get the called path to the REST API
// and we want to modify any (*) calls at the end such as items(3) and items(344) so we just track "items()"
clientTag += pathname
.substring(pathname.indexOf("_api/") + 5)
.split("/")
.map((value, index, arr) => index === arr.length - 1 ? value.replace(/\(.*?$/i, "()") : value[0]).join(".");
clientTag = pathname.split("/")
.filter((v) => !stringIsNullOrEmpty(v) && ["_api", "v2.1", "v2.0"].indexOf(v) < 0)
.map((value, index, arr) => index === arr.length - 1 ? value.replace(/\(.*?$/i, "()") : value[0])
.join(".");

if (clientTag.length > 32) {
clientTag = clientTag.substring(0, 32);
Expand Down
29 changes: 28 additions & 1 deletion packages/sp/files/readable-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { TimelinePipe } from "@pnp/core";
import { BlobParse, BufferParse, CacheNever, JSONParse, TextParse } from "@pnp/queryable/index.js";
import {
BlobParse,
BufferParse,
CacheNever,
JSONParse,
Queryable,
TextParse,
headers,
parseBinderWithErrorCheck,
} from "@pnp/queryable";
import { _SPInstance, SPQueryable } from "../spqueryable.js";

export interface IResponseBodyStream {
body: ReadableStream;
knownLength: number;
}

export function StreamParse(): TimelinePipe<Queryable> {

return parseBinderWithErrorCheck(async r => ({ body: r.body, knownLength: parseInt(r?.headers?.get("content-length") || "-1", 10) }));
}

export class ReadableFile<T = any> extends _SPInstance<T> {

/**
Expand Down Expand Up @@ -34,6 +53,14 @@ export class ReadableFile<T = any> extends _SPInstance<T> {
return this.getParsed(JSONParse());
}

/**
* Gets the content of a file as a ReadableStream
*
*/
public getStream(): Promise<IResponseBodyStream> {
return SPQueryable(this, "$value").using(StreamParse(), CacheNever())(headers({ "binaryStringResponseBody": "true" }));
}

private getParsed<T>(parser: TimelinePipe): Promise<T> {
return SPQueryable(this, "$value").using(parser, CacheNever())();
}
Expand Down
Loading

0 comments on commit 8b0f7ea

Please sign in to comment.