Skip to content

Commit

Permalink
initial pages api support, fix for #3136
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Nov 11, 2024
1 parent 0982b9d commit 90ba34b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions debug/launch/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { Example } from "./sp.js";
// create a settings file using settings.example.js as a template
import(findup("settings.js")).then((settings: { settings: ITestingSettings }) => {

Logger.activeLogLevel = LogLevel.Info;
Logger.activeLogLevel = LogLevel.Info;

// // setup console logger
Logger.subscribe(ConsoleListener("Debug", {
color: "skyblue",
error: "red",
verbose: "lightslategray",
warning: "yellow",
}));
}));

Example(settings.settings);

Expand Down
5 changes: 2 additions & 3 deletions debug/launch/sp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ import { Logger, LogLevel } from "@pnp/logging";
import { spSetup } from "./setup.js";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";

declare var process: { exit(code?: number): void };

export async function Example(settings: ITestingSettings) {

const sp = spSetup(settings);

const w = await sp.web();
const w = await sp.web.lists();

Logger.log({
data: w,
level: LogLevel.Info,
message: "Web Data",
});

process.exit(0);
}
3 changes: 1 addition & 2 deletions packages/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export function combine(...paths: (string | null | undefined)[]): string {

return paths
.filter(path => !stringIsNullOrEmpty(path))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.map(path => path!.replace(/^[\\|/]/, "").replace(/[\\|/]$/, ""))
.map(path => path.replace(/^[\\|/]/, "").replace(/[\\|/]$/, ""))
.join("/")
.replace(/\\/g, "/");
}
Expand Down
14 changes: 4 additions & 10 deletions packages/graph/graphqueryable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, objectDefinedNotNull } from "@pnp/core";
import { isArray } from "@pnp/core";
import { IInvokable, Queryable, queryableFactory, op, get, post, patch, del, put } from "@pnp/queryable";
import { ConsistencyLevel } from "./behaviors/consistency-level.js";
import { IPagedResult, Paged } from "./behaviors/paged.js";
Expand Down Expand Up @@ -164,13 +164,9 @@ export class _GraphCollection<GetType = any[]> extends _GraphQueryable<GetType>

const q = GraphCollection(this).using(Paged(), ConsistencyLevel());

const queryParams = ["$search", "$top", "$select", "$expand", "$filter", "$orderby"];

for (let i = 0; i < queryParams.length; i++) {
const param = this.query.get(queryParams[i]);
if (objectDefinedNotNull(param)) {
q.query.set(queryParams[i], param);
}
// Issue #3136, some APIs take other query params that need to persist through the paging, so we just include everything
for (const [key, value] of this.query) {
q.query.set(key, value);
}

return <AsyncIterator<GetType>>{
Expand All @@ -196,7 +192,6 @@ export class _GraphCollection<GetType = any[]> extends _GraphQueryable<GetType>
};
}
}

export interface IGraphCollection<GetType = any[]> extends _GraphCollection<GetType> { }
export const GraphCollection = graphInvokableFactory<IGraphCollection>(_GraphCollection);

Expand All @@ -205,7 +200,6 @@ export const GraphCollection = graphInvokableFactory<IGraphCollection>(_GraphCol
*
*/
export class _GraphInstance<GetType = any> extends _GraphQueryable<GetType> { }

export interface IGraphInstance<GetType = any> extends IInvokable, IGraphQueryable<GetType> { }
export const GraphInstance = graphInvokableFactory<IGraphInstance>(_GraphInstance);

Expand Down
40 changes: 22 additions & 18 deletions packages/graph/pages/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import { combine } from "@pnp/core";
import { body } from "@pnp/queryable";
import { IDeleteable, IGetById, IUpdateable, defaultPath, deleteable, getById, updateable } from "../decorators.js";
import { graphInvokableFactory, _GraphCollection, _GraphInstance, GraphInit, graphPost } from "../graphqueryable.js";
import { body } from "@pnp/queryable";
import { ValidWebpart } from "./webpart-types.js";

/**
Expand Down Expand Up @@ -126,7 +126,6 @@ export class _HorizontalSection extends _GraphInstance<IHorizontalSectionInfo> {
export interface IHorizontalSection extends _HorizontalSection, IUpdateable, IDeleteable { }
export const HorizontalSection = graphInvokableFactory<IHorizontalSection>(_HorizontalSection);

// @getById(HorizontalSection)
@defaultPath("canvasLayout/horizontalSections")
export class _HorizontalSections extends _GraphCollection<IHorizontalSectionInfo[]> {

Expand All @@ -139,7 +138,7 @@ export class _HorizontalSections extends _GraphCollection<IHorizontalSectionInfo
return section.concat(`('${id}')`);
}
}
export interface IHorizontalSections extends _HorizontalSections, IGetById<IHorizontalSection, number> { }
export interface IHorizontalSections extends _HorizontalSections, IGetById<IHorizontalSection, string | number> { }
export const HorizontalSections = graphInvokableFactory<IHorizontalSections>(_HorizontalSections);

export class _HorizontalSectionColumn extends _GraphInstance<IHorizontalSectionColumnInfo> {
Expand All @@ -152,9 +151,14 @@ export interface IHorizontalSectionColumn extends _HorizontalSectionColumn { }
export const HorizontalSectionColumn = graphInvokableFactory<IHorizontalSectionColumn>(_HorizontalSectionColumn);

@defaultPath("columns")
@getById(HorizontalSectionColumn)
export class _HorizontalSectionColumns extends _GraphCollection<IHorizontalSectionColumnInfo[]> { }
export interface IHorizontalSectionColumns extends _HorizontalSectionColumns, IGetById<IHorizontalSectionColumn, number> { }
export class _HorizontalSectionColumns extends _GraphCollection<IHorizontalSectionColumnInfo[]> {

public getById(id: string | number): IHorizontalSectionColumn {
const column = HorizontalSectionColumn(this);
return column.concat(`('${id}')`);
}
}
export interface IHorizontalSectionColumns extends _HorizontalSectionColumns, IGetById<IHorizontalSectionColumn, string | number> { }
export const HorizontalSectionColumns = graphInvokableFactory<IHorizontalSectionColumns>(_HorizontalSectionColumns);

@updateable()
Expand Down Expand Up @@ -189,41 +193,41 @@ export class _Webparts extends _GraphCollection<ValidWebpart[]> {
const base = url.slice(0, url.indexOf(SitePageTypeString) + SitePageTypeString.length);
return Webpart([this, base], `webparts/${id}`);
}

/**
* Gets the webpart information by id from the page's collection
* @param id string id of the webpart
* @returns The IWebpart instance
*/
public getByIndex(index: number): IWebpart {
return Webpart(this, `${index}`);
}
}
export interface IWebparts extends _Webparts, IGetById<IWebpart> { }
export const Webparts = graphInvokableFactory<IWebparts>(_Webparts);



/**
* Contains info representing a vertical section
*/
export interface IVerticalSectionInfo {
emphasis: "none" | "netural" | "soft" | "strong" | "unknownFutureValue";
id: string;
}


/**
* Contains info representing a horizontal section
*/
export interface IHorizontalSectionInfo {
emphasis: "none" | "netural" | "soft" | "strong" | "unknownFutureValue";
id: string;
layout: "none" | "oneColumn" | "twoColumns" | "threeColumns" | "oneThirdLeftColumn" | "oneThirdRightColumn" | "fullWidth" | "unknownFutureValue";
columns: IHorizontalSectionColumnInfo[];
}

/**
* Contains info representing a horizontal section column
*/
export interface IHorizontalSectionColumnInfo {
id: string;
width: string;
webparts: any[];
}


/**
* Contains info representing a path user
*/
export interface IPageUserInfo {
displayName: string;
email?: string;
Expand Down
5 changes: 5 additions & 0 deletions packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export type QueryParams = {

/** Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */
toString(): string;

/**
* Iterator accessor
*/
[Symbol.iterator](): Iterator<[string, string]>;
};

@invokable()
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ES2015",
"dom",
"ES2017.Object",
"ES2015.Iterable"
],
"baseUrl": ".",
"rootDir": ".",
Expand Down

0 comments on commit 90ba34b

Please sign in to comment.