diff --git a/docs/concepts/batching.md b/docs/concepts/batching.md index ade964c84..c6d657954 100644 --- a/docs/concepts/batching.md +++ b/docs/concepts/batching.md @@ -251,7 +251,7 @@ let newItems: IItem[] = []; for(let i=0; i(); + const newItem = await res[i].select("Title")<{Title: string}>(); newItems.push(newItem); } ``` diff --git a/docs/contributing/debug-tests.md b/docs/contributing/debug-tests.md index a9d1e97be..9f4394095 100644 --- a/docs/contributing/debug-tests.md +++ b/docs/contributing/debug-tests.md @@ -30,7 +30,7 @@ describe("Items", () => { // execute a request to ensure we have a list const ler = await sp.web.lists.ensure("ItemTestList", "Used to test item operations"); - list = ler.list; + list = sp.web.lists.getById(ler.Id); // in this case we want to have some items in the list for testing so we add those // only if the list was just created diff --git a/docs/graph/calendars.md b/docs/graph/calendars.md index e292d4206..287e74fa3 100644 --- a/docs/graph/calendars.md +++ b/docs/graph/calendars.md @@ -5,7 +5,7 @@ More information can be found in the official Graph documentation: - [Calendar Resource Type](https://docs.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0) - [Event Resource Type](https://docs.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0) -## ICalendar, ICalendars, ICalendarGroup, ICalendarGroups, ICalendarPermission, ICalendarPermissions, ICalendarView, IEvent, IEvents, IEventAddResult, IForwardEvent, IGetScheduleRequest +## ICalendar, ICalendars, ICalendarGroup, ICalendarGroups, ICalendarPermission, ICalendarPermissions, ICalendarView, IEvent, IEvents, IForwardEvent, IGetScheduleRequest [![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) diff --git a/docs/graph/items.md b/docs/graph/items.md index 20114a06a..e13a5e0b8 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -4,7 +4,7 @@ More information can be found in the official Graph documentation: - [List Item Resource Type](https://docs.microsoft.com/en-us/graph/api/resources/listitem?view=graph-rest-1.0) -## IListItems, IListItem, IListItemAddResult, IDocumentSetVersion, IDocumentSetVersions IDocumentSetVersionAddResult, +## IListItems, IListItem, IDocumentSetVersion, IDocumentSetVersions IDocumentSetVersionAddResult, [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) ### Get list items diff --git a/docs/sp/clientside-pages.md b/docs/sp/clientside-pages.md index 7b94d011d..224adcf7e 100644 --- a/docs/sp/clientside-pages.md +++ b/docs/sp/clientside-pages.md @@ -927,7 +927,7 @@ const far = await sp.web.getFolderByServerRelativePath("/sites/dev/Shared Docume const page = await sp.web.addClientsidePage("MyPage", "Page Title"); // set the banner image -page.setBannerImage(far.data.ServerRelativeUrl); +page.setBannerImage(far.ServerRelativeUrl); // publish the page await page.save(); diff --git a/docs/sp/fields.md b/docs/sp/fields.md index 8ec6ce5f8..5af47c73b 100644 --- a/docs/sp/fields.md +++ b/docs/sp/fields.md @@ -85,7 +85,7 @@ Create a new field by defining an XML schema that assigns all the properties for ```TypeScript import { spfi } from "@pnp/sp"; -import { IField, IFieldAddResult } from "@pnp/sp/fields/types"; +import { IField, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; @@ -97,15 +97,13 @@ const sp = spfi(...); const fieldSchema = `[today]`; // create the new field in the web -const field: IFieldAddResult = await sp.web.fields.createFieldAsXml(fieldSchema); +const field:IFieldInfo = await sp.web.fields.createFieldAsXml(fieldSchema); // create the new field in the list 'My List' -const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml(fieldSchema); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml(fieldSchema); -// we can use this 'field' variable to run more queries on the list: -const r = await field.field.select("Id")(); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a New Field @@ -114,7 +112,7 @@ Use the add method to create a new field where you define the field type ```TypeScript import { spfi } from "@pnp/sp"; -import { IField, IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; +import { IField, FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -122,15 +120,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new field called 'My Field' in web. -const field: IFieldAddResult = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); // create a new field called 'My Field' in the list 'My List' -const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Site Field to a List @@ -139,7 +134,7 @@ Use the createFieldAsXml method to add a site field to a list. ```TypeScript import { spfi } from "@pnp/sp"; -import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -147,12 +142,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new field called 'My Field' in web. -const field: IFieldAddResult = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); // add the site field 'My Field' to the list 'My List' -const r = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml(field.data.SchemaXml as string); +const r:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml(field.SchemaXml as string); // log the field Id to console -console.log(r.data.Id); +console.log(r.Id); ``` ### Add a Text Field @@ -161,7 +156,7 @@ Use the addText method to create a new text field. ```TypeScript import { spfi } from "@pnp/sp"; -import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -169,15 +164,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new text field called 'My Field' in web. -const field: IFieldAddResult = await sp.web.fields.addText("My Field", { MaxLength: 255, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addText("My Field", { MaxLength: 255, Group: "My Group" }); // create a new text field called 'My Field' in the list 'My List'. -const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.addText("My Field", { MaxLength: 255, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addText("My Field", { MaxLength: 255, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Calculated Field @@ -186,7 +178,7 @@ Use the addCalculated method to create a new calculated field. ```TypeScript import { spfi } from "@pnp/sp"; -import { DateTimeFieldFormatType, FieldTypes } from "@pnp/sp/fields/types"; +import { DateTimeFieldFormatType, FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -194,15 +186,13 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new calculated field called 'My Field' in web -const field = await sp.web.fields.addCalculated("My Field", { Formula: "=Modified+1", DateFormat: DateTimeFieldFormatType.DateOnly, FieldTypeKind: FieldTypes.Calculated, Group: "MyGroup" }); +const field:IFieldInfo = await sp.web.fields.addCalculated("My Field", { Formula: "=Modified+1", DateFormat: DateTimeFieldFormatType.DateOnly, FieldTypeKind: FieldTypes.Calculated, Group: "MyGroup" }); // create a new calculated field called 'My Field' in the list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addCalculated("My Field", { Formula: "=Modified+1", DateFormat: DateTimeFieldFormatType.DateOnly, FieldTypeKind: FieldTypes.Calculated, Group: "MyGroup" }); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addCalculated("My Field", { Formula: "=Modified+1", DateFormat: DateTimeFieldFormatType.DateOnly, FieldTypeKind: FieldTypes.Calculated, Group: "MyGroup" }); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Date/Time Field @@ -211,7 +201,7 @@ Use the addDateTime method to create a new date/time field. ```TypeScript import { spfi } from "@pnp/sp"; -import { DateTimeFieldFormatType, CalendarType, DateTimeFieldFriendlyFormatType } from "@pnp/sp/fields/types"; +import { DateTimeFieldFormatType, CalendarType, DateTimeFieldFriendlyFormatType, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -219,15 +209,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new date/time field called 'My Field' in web -const field = await sp.web.fields.addDateTime("My Field", { DisplayFormat: DateTimeFieldFormatType.DateOnly, DateTimeCalendarType: CalendarType.Gregorian, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Disabled, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addDateTime("My Field", { DisplayFormat: DateTimeFieldFormatType.DateOnly, DateTimeCalendarType: CalendarType.Gregorian, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Disabled, Group: "My Group" }); // create a new date/time field called 'My Field' in the list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addDateTime("My Field", { DisplayFormat: DateTimeFieldFormatType.DateOnly, DateTimeCalendarType: CalendarType.Gregorian, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Disabled, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addDateTime("My Field", { DisplayFormat: DateTimeFieldFormatType.DateOnly, DateTimeCalendarType: CalendarType.Gregorian, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Disabled, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Currency Field @@ -236,6 +223,7 @@ Use the addCurrency method to create a new currency field. ```TypeScript import { spfi } from "@pnp/sp"; +import { IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -243,15 +231,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new currency field called 'My Field' in web -const field = await sp.web.fields.addCurrency("My Field", { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addCurrency("My Field", { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: "My Group" }); // create a new currency field called 'My Field' in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addCurrency("My Field", { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addCurrency("My Field", { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add an Image Field @@ -260,7 +245,7 @@ Use the addImageField method to create a new image field. ```TypeScript import { spfi } from "@pnp/sp"; -import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -268,15 +253,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new image field called 'My Field' in web. -const field: IFieldAddResult = await sp.web.fields.addImageField("My Field"); +const field:IFieldInfo = await sp.web.fields.addImageField("My Field"); // create a new image field called 'My Field' in the list 'My List'. -const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.addImageField("My Field"); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addImageField("My Field"); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Multi-line Text Field @@ -286,6 +268,7 @@ Use the addMultilineText method to create a new multi-line text field. ```TypeScript import { spfi } from "@pnp/sp"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -293,15 +276,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new multi-line text field called 'My Field' in web -const field = await sp.web.fields.addMultilineText("My Field", { NumberOfLines: 6, RichText: true, RestrictedMode: false, AppendOnly: false, AllowHyperlink: true, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addMultilineText("My Field", { NumberOfLines: 6, RichText: true, RestrictedMode: false, AppendOnly: false, AllowHyperlink: true, Group: "My Group" }); // create a new multi-line text field called 'My Field' in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addMultilineText("My Field", { NumberOfLines: 6, RichText: true, RestrictedMode: false, AppendOnly: false, AllowHyperlink: true, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addMultilineText("My Field", { NumberOfLines: 6, RichText: true, RestrictedMode: false, AppendOnly: false, AllowHyperlink: true, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Multi-line Text Field with Enhanced Rich Text @@ -310,6 +290,7 @@ The REST endpoint doesn't support setting the `RichTextMode` field therefore you ```TypeScript import { spfi } from "@pnp/sp"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -317,15 +298,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); //Create a new multi-line text field called 'My Field' in web -const field = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml( +const field:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml( `` ); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); - // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Number Field @@ -334,6 +312,7 @@ Use the addNumber method to create a new number field. ```TypeScript import { spfi } from "@pnp/sp"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -341,15 +320,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new number field called 'My Field' in web -const field = await sp.web.fields.addNumber("My Field", { MinimumValue: 1, MaximumValue: 100, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addNumber("My Field", { MinimumValue: 1, MaximumValue: 100, Group: "My Group" }); // create a new number field called 'My Field' in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addNumber("My Field", { MinimumValue: 1, MaximumValue: 100, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addNumber("My Field", { MinimumValue: 1, MaximumValue: 100, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a URL Field @@ -358,7 +334,7 @@ Use the addUrl method to create a new url field. ```TypeScript import { spfi } from "@pnp/sp"; -import { UrlFieldFormatType } from "@pnp/sp/fields/types"; +import { UrlFieldFormatType, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -366,15 +342,12 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new url field called 'My Field' in web -const field = await sp.web.fields.addUrl("My Field", { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addUrl("My Field", { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: "My Group" }); // create a new url field called 'My Field' in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addUrl("My Field", { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addUrl("My Field", { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field); ``` ### Add a User Field @@ -383,7 +356,7 @@ Use the addUser method to create a new user field. ```TypeScript import { spfi } from "@pnp/sp"; -import { FieldUserSelectionMode } from "@pnp/sp/fields/types"; +import { FieldUserSelectionMode, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; @@ -391,20 +364,17 @@ import "@pnp/sp/fields"; const sp = spfi(...); // create a new user field called 'My Field' in web -const field = await sp.web.fields.addUser("My Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: "My Group" }); +const field:IFieldInfo = await sp.web.fields.addUser("My Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: "My Group" }); // create a new user field called 'My Field' in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addUser("My Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: "My Group" }); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2:IFieldInfo = await sp.web.lists.getByTitle("My List").fields.addUser("My Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: "My Group" }); // log the field Id to console -console.log(r.Id); +console.log(field.Id); // ** // Adding a lookup that supports multiple values takes two calls: -const fieldAddResult = await sp.web.fields.addUser("Multi User Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly }); -await fieldAddResult.field.update({ AllowMultipleValues: true }, "SP.FieldUser"); +const fieldAdd = await sp.web.fields.addUser("Multi User Field", { SelectionMode: FieldUserSelectionMode.PeopleOnly }); +await sp.web.fields.getById(fieldAdd.Id).update({ AllowMultipleValues: true }, "SP.FieldUser"); ``` ### Add a Lookup Field @@ -413,7 +383,7 @@ Use the addLookup method to create a new lookup field. ```TypeScript import { spfi } from "@pnp/sp"; -import { FieldTypes } from "@pnp/sp/fields/types"; +import { FieldTypes, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; @@ -423,20 +393,17 @@ const sp = spfi(...); const list = await sp.web.lists.getByTitle("My Lookup List")(); // create a new lookup field called 'My Field' based on an existing list 'My Lookup List' showing 'Title' field in web. -const field = await sp.web.fields.addLookup("My Field", { LookupListId: list.data.Id, LookupFieldName: "Title" }); +const field = await sp.web.fields.addLookup("My Field", { LookupListId: list.Id, LookupFieldName: "Title" }); // create a new lookup field called 'My Field' based on an existing list 'My Lookup List' showing 'Title' field in list 'My List' -const field2 = await sp.web.lists.getByTitle("My List").fields.addLookup("My Field", {LookupListId: list.data.Id, LookupFieldName: "Title"}); - -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); +const field2 = await sp.web.lists.getByTitle("My List").fields.addLookup("My Field", {LookupListId: list.Id, LookupFieldName: "Title"}); // log the field Id to console -console.log(r.Id); +console.log(field.Id); // ** // Adding a lookup that supports multiple values takes two calls: -const fieldAddResult = await sp.web.fields.addLookup("Multi Lookup Field", { LookupListId: list.data.Id, LookupFieldName: "Title" }); -await fieldAddResult.field.update({ AllowMultipleValues: true }, "SP.FieldLookup"); +const fieldAdd = await sp.web.fields.addLookup("Multi Lookup Field", { LookupListId: list.Id, LookupFieldName: "Title" }); +await sp.web.fields.getById(fieldAdd.Id).update({ AllowMultipleValues: true }, "SP.FieldLookup"); ``` ### Add a Choice Field @@ -458,11 +425,8 @@ const field = await sp.web.fields.addChoice("My Field", { Choices: choices, Edit // create a new choice field called 'My Field' in list 'My List' const field2 = await sp.web.lists.getByTitle("My List").fields.addChoice("My Field", { Choices: choices, EditFormat: ChoiceFieldFormatType.Dropdown, FillInChoice: false, Group: "My Group" }); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); - // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Multi-Choice Field @@ -484,11 +448,8 @@ const field = await sp.web.fields.addMultiChoice("My Field", { Choices: choices, // create a new multi-choice field called 'My Field' in list 'My List' const field2 = await sp.web.lists.getByTitle("My List").fields.addMultiChoice("My Field", { Choices: choices, FillInChoice: false, Group: "My Group" }); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); - // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Boolean Field @@ -508,11 +469,8 @@ const field = await sp.web.fields.addBoolean("My Field", { Group: "My Group" }); // create a new boolean field called 'My Field' in list 'My List' const field2 = await sp.web.lists.getByTitle("My List").fields.addBoolean("My Field", { Group: "My Group" }); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); - // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Add a Dependent Lookup Field @@ -529,16 +487,13 @@ const sp = spfi(...); const field = await sp.web.fields.addLookup("My Field", { LookupListId: list.Id, LookupFieldName: "Title" }); // create a new dependent lookup field called 'My Dep Field' showing 'Description' based on an existing 'My Field' lookup field in web. -const fieldDep = await sp.web.fields.addDependentLookupField("My Dep Field", field.data.Id as string, "Description"); +const fieldDep = await sp.web.fields.addDependentLookupField("My Dep Field", field.Id as string, "Description"); // create a new dependent lookup field called 'My Dep Field' showing 'Description' based on an existing 'My Field' lookup field in list 'My List' const field2 = await sp.web.lists.getByTitle("My List").fields.addLookup("My Field", { LookupListId: list.Id, LookupFieldName: "Title" }); -const fieldDep2 = await sp.web.lists.getByTitle("My List").fields.addDependentLookupField("My Dep Field", field2.data.Id as string, "Description"); +const fieldDep2 = await sp.web.lists.getByTitle("My List").fields.addDependentLookupField("My Dep Field", field2.Id as string, "Description"); -// we can use this 'fieldDep' variable to run more queries on the field: -const r = await fieldDep.field.select("Id")(); - -// log the field Id to console -console.log(r.Id); +// log the fieldDep Id to console +console.log(fieldDep.Id); ``` ### Add a Location Field @@ -558,11 +513,8 @@ const field = await sp.web.fields.addLocation("My Field", { Group: "My Group" }) // create a new location field called 'My Field' in list 'My List' const field2 = await sp.web.lists.getByTitle("My List").fields.addLocation("My Field", { Group: "My Group" }); -// we can use this 'field' variable to run more queries on the field: -const r = await field.field.select("Id")(); - // log the field Id to console -console.log(r.Id); +console.log(field.Id); ``` ### Delete a Field @@ -603,9 +555,9 @@ import "@pnp/sp/fields"; const sp = spfi(...); -// update the field called 'My Field' with a description in web, returns FieldUpdateResult +// update the field called 'My Field' with a description in web, returns IFieldInfo const fieldUpdate = await sp.web.fields.getByTitle("My Field").update({ Description: "My Description" }); -// update the field called 'My Field' with a description in list 'My List', returns FieldUpdateResult +// update the field called 'My Field' with a description in list 'My List', returns IFieldInfo const fieldUpdate2 = await sp.web.lists.getByTitle("My List").fields.getByTitle("My Field").update({ Description: "My Description" }); // if you need to update a field with properties for a specific field type you can optionally include the field type as a second param diff --git a/docs/sp/folders.md b/docs/sp/folders.md index 3f016c059..88df71f50 100644 --- a/docs/sp/folders.md +++ b/docs/sp/folders.md @@ -476,7 +476,7 @@ import "@pnp/sp/lists"; const sp = spfi(...); const newFolderResult = await sp.web.rootFolder.folders.getByUrl("Shared Documents").folders.addUsingPath("My New Folder"); -const item = await newFolderResult.folder.listItemAllFields(); +const item = await sp.web.rootFolder.folders.getByUrl("Shared Documents").folders.getByUrl(newFolderResult.Name).listItemAllFields(); await sp.web.lists.getByTitle("Documents").items.getById(item.ID).update({ ContentTypeId: "0x0120001E76ED75A3E3F3408811F0BF56C4CDDD", diff --git a/docs/sp/items.md b/docs/sp/items.md index cac7920e6..252d90a02 100644 --- a/docs/sp/items.md +++ b/docs/sp/items.md @@ -480,7 +480,7 @@ const newItem = await sp.web.lists.getByTitle("TestList").items.add({ const updateVal = {}; updateVal[fields[0].InternalName] = "-1;#New Term|bb046161-49cc-41bd-a459-5667175920d4;#-1;#New 2|0069972e-67f1-4c5e-99b6-24ac5c90b7c9"; // execute the update call -await newItem.item.update(updateVal); +await sp.web.lists.getByTitle("TestList").items.getById(newItem.Id).update(updateVal); ``` ### Update BCS Field diff --git a/docs/sp/lists.md b/docs/sp/lists.md index d33755245..286c2fd87 100644 --- a/docs/sp/lists.md +++ b/docs/sp/lists.md @@ -63,7 +63,7 @@ const sp = spfi(...); const listAddResult = await sp.web.lists.add("My new list"); // we can work with the list created using the IListAddResult.list property: -const r = await listAddResult.list.select("Title")(); +const r = await sp.web.lists.getByTitle(listAddResult.list.select("Title")(); // log newly created list title to console console.log(r.Title); @@ -457,7 +457,7 @@ import "@pnp/sp/lists"; const sp = spfi(...); const fld = await sp.site.rootWeb.fields.addText("MyField"); -await sp.web.lists.getByTitle("MyList").fields.createFieldAsXml(fld.data.SchemaXml); +await sp.web.lists.getByTitle("MyList").fields.createFieldAsXml(fld.SchemaXml); ``` ### folders diff --git a/docs/sp/navigation.md b/docs/sp/navigation.md index ac3a2cb80..79bedf013 100644 --- a/docs/sp/navigation.md +++ b/docs/sp/navigation.md @@ -98,10 +98,6 @@ import "@pnp/sp/navigation"; const result = await nav.add("Node Title", "/sites/dev/pages/mypage.aspx", true); -const nodeDataRaw = result.data; - -// request the data from the created node -const nodeData = result.node(); ``` ### moveAfter @@ -113,10 +109,8 @@ import "@pnp/sp/navigation"; const node1result = await nav.add(`Testing - ${getRandomString(4)} (1)`, url, true); const node2result = await nav.add(`Testing - ${getRandomString(4)} (2)`, url, true); -const node1 = await node1result.node(); -const node2 = await node2result.node(); -await nav.moveAfter(node1.Id, node2.Id); +await nav.moveAfter(node1result.Id, node2result.Id); ``` ### Delete @@ -129,14 +123,14 @@ import "@pnp/sp/navigation"; const node1result = await nav.add(`Testing - ${getRandomString(4)}`, url, true); let nodes = await nav(); // check we added a node -let index = nodes.findIndex(n => n.Id === node1result.data.Id) +let index = nodes.findIndex(n => n.Id === node1result.Id) // index >= 0 // delete a node -await nav.getById(node1result.data.Id).delete(); +await nav.getById(node1result.Id).delete(); nodes = await nav(); -index = nodes.findIndex(n => n.Id === node1result.data.Id) +index = nodes.findIndex(n => n.Id === node1result.Id) // index = -1 ``` diff --git a/docs/sp/security.md b/docs/sp/security.md index 9d6bbc0e2..e3e57f4a3 100644 --- a/docs/sp/security.md +++ b/docs/sp/security.md @@ -35,7 +35,7 @@ const sp = spfi(...); // ensure we have a list const ler = await sp.web.lists.ensure("SecurityTestingList"); -const list: IList = ler.list; +const list: IList = sp.web.lists.getById(ler.Id); // role assignments (see section below) await list.roleAssignments(); @@ -97,7 +97,7 @@ const sp = spfi(...); // ensure we have a list const ler = await sp.web.lists.ensure("SecurityTestingList"); -const list: IList = ler.list; +const list: IList = sp.web.lists.getById(ler.Id); // list role assignments const assignments = await list.roleAssignments(); diff --git a/docs/sp/site-users.md b/docs/sp/site-users.md index ae7b2c63a..61c07683c 100644 --- a/docs/sp/site-users.md +++ b/docs/sp/site-users.md @@ -90,7 +90,7 @@ const sp = spfi(...); const user = await sp.web.ensureUser("userLoginname") const users = await sp.web.siteUsers; -await users.add(user.data.LoginName); +await users.add(user.LoginName); ``` ### Get user by Id, Email, or LoginName diff --git a/packages/core/timeline.ts b/packages/core/timeline.ts index 48052bc83..6dacbafb6 100644 --- a/packages/core/timeline.ts +++ b/packages/core/timeline.ts @@ -358,7 +358,6 @@ function addObserver(target: Record, moment: string, observer: Vali if (!isFunc(observer)) { throw Error("Observers must be functions."); } - if (!Reflect.has(target, moment)) { // if we don't have a registration for this moment, then we just add a new prop diff --git a/packages/graph/calendars/index.ts b/packages/graph/calendars/index.ts index 1d721bbfc..0a42608bf 100644 --- a/packages/graph/calendars/index.ts +++ b/packages/graph/calendars/index.ts @@ -20,7 +20,6 @@ export { ICalendarView, IEvent, IEvents, - IEventAddResult, IForwardEvent, IGetScheduleRequest, } from "./types.js"; diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index e11a09617..23ce5d0a2 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -167,14 +167,6 @@ export class _CalendarPermissions extends _GraphCollection, IAddable { } export const CalendarPermissions = graphInvokableFactory(_CalendarPermissions); -/** - * EventAddResult - */ -export interface IEventAddResult { - data: IEventType; - event: IEvent; -} - export interface IForwardEvent { Comment?: string; ToRecipients: Recipient[]; diff --git a/packages/graph/columns/addColumns.ts b/packages/graph/columns/addColumns.ts index 8edb6a224..75536dfde 100644 --- a/packages/graph/columns/addColumns.ts +++ b/packages/graph/columns/addColumns.ts @@ -1,4 +1,3 @@ -import { IColumn } from "./types.js"; import { graphPost } from "../graphqueryable.js"; import { body } from "@pnp/queryable"; import { @@ -10,19 +9,6 @@ import { * * @param column a JSON representation of a Column object. */ -export const addColumn = async function(column: IColumnDefinition): Promise { - const data = await graphPost(this, body(column)); - - return { - data, - column: (this).getById(data.id), - }; +export const addColumn = async function(column: IColumnDefinition): Promise { + return graphPost(this, body(column)); }; - -/** -* IColumnAddResult -*/ -export interface IColumnAddResult { - column: IColumn; - data: IColumnDefinition; -} diff --git a/packages/graph/columns/content-types.ts b/packages/graph/columns/content-types.ts index b6d094ed9..32d759ef5 100644 --- a/packages/graph/columns/content-types.ts +++ b/packages/graph/columns/content-types.ts @@ -2,15 +2,17 @@ import { addProp, body } from "@pnp/queryable"; import { graphPost } from "../graphqueryable.js"; import { _ContentType } from "../content-types/types.js"; import { Columns, IColumns,IColumn, _Columns } from "./types.js"; -import { IColumnAddResult } from "./addColumns.js"; +import { + ColumnDefinition as IColumnDefinition, +} from "@microsoft/microsoft-graph-types"; declare module "./types" { interface _Columns { - addRef(siteColumn: IColumn): Promise; + addRef(siteColumn: IColumn): Promise; } interface IColumns { - addRef(siteColumn: IColumn): Promise; + addRef(siteColumn: IColumn): Promise; } } @@ -20,14 +22,9 @@ declare module "./types" { * * @param siteColumn the site column to add. */ -_Columns.prototype.addRef = async function(siteColumn: IColumn): Promise { +_Columns.prototype.addRef = async function(siteColumn: IColumn): Promise { const postBody = { "sourceColumn@odata.bind": `https://graph.microsoft.com/v1.0/${siteColumn.toUrl()}`}; - const data = await graphPost(this, body(postBody)); - - return { - data, - column: (this).getById(data.id), - }; + return graphPost(this, body(postBody)); }; declare module "../content-types/types" { diff --git a/packages/graph/columns/index.ts b/packages/graph/columns/index.ts index 5965e10bc..463ef1bb9 100644 --- a/packages/graph/columns/index.ts +++ b/packages/graph/columns/index.ts @@ -2,10 +2,6 @@ import "./lists.js"; import "./sites.js"; import "./content-types.js"; -export { - IColumnAddResult, -} from "./addColumns.js"; - export { Columns, IColumns, diff --git a/packages/graph/columns/lists.ts b/packages/graph/columns/lists.ts index 5b379bf0b..ee21b4228 100644 --- a/packages/graph/columns/lists.ts +++ b/packages/graph/columns/lists.ts @@ -1,6 +1,6 @@ import { addProp } from "@pnp/queryable"; import { _List } from "../lists/types.js"; -import { addColumn, IColumnAddResult } from "./addColumns.js"; +import { addColumn } from "./addColumns.js"; import { Columns, IColumns, _Columns } from "./types.js"; import { ColumnDefinition as IColumnDefinition, @@ -9,11 +9,11 @@ import { declare module "./types" { interface _Columns { - add(column: IColumnDefinition): Promise; + add(column: IColumnDefinition): Promise; } interface IColumns { - add(column: IColumnDefinition): Promise; + add(column: IColumnDefinition): Promise; } } diff --git a/packages/graph/columns/sites.ts b/packages/graph/columns/sites.ts index 9b30464d7..dcff9db6c 100644 --- a/packages/graph/columns/sites.ts +++ b/packages/graph/columns/sites.ts @@ -1,5 +1,5 @@ import { addProp } from "@pnp/queryable"; -import { addColumn, IColumnAddResult } from "./addColumns.js"; +import { addColumn } from "./addColumns.js"; import { Columns, IColumns, _Columns } from "./types.js"; import { ColumnDefinition as IColumnDefinition, @@ -8,11 +8,11 @@ import { _Site } from "../sites/types.js"; declare module "./types" { interface _Columns { - add(column: IColumnDefinition): Promise; + add(column: IColumnDefinition): Promise; } interface IColumns { - add(column: IColumnDefinition): Promise; + add(column: IColumnDefinition): Promise; } } diff --git a/packages/graph/contacts/index.ts b/packages/graph/contacts/index.ts index 911d39a98..80e70a28e 100644 --- a/packages/graph/contacts/index.ts +++ b/packages/graph/contacts/index.ts @@ -2,9 +2,7 @@ import "./users.js"; export { Contact, - IContactAddResult, ContactFolder, - IContactFolderAddResult, ContactFolders, Contacts, IContact, diff --git a/packages/graph/contacts/types.ts b/packages/graph/contacts/types.ts index b8d14e20b..dd3c5f700 100644 --- a/packages/graph/contacts/types.ts +++ b/packages/graph/contacts/types.ts @@ -33,7 +33,7 @@ export class _Contacts extends _GraphCollection { surName: string, emailAddresses: IEmailAddressType[], businessPhones: string[], - additionalProperties: Record = {}): Promise { + additionalProperties: Record = {}): Promise { const postBody = { businessPhones, @@ -43,12 +43,7 @@ export class _Contacts extends _GraphCollection { ...additionalProperties, }; - const data = await graphPost(this, body(postBody)); - - return { - contact: (this).getById(data.id), - data, - }; + return graphPost(this, body(postBody)); } } export interface IContacts extends _Contacts, IGetById { } @@ -90,36 +85,15 @@ export class _ContactFolders extends _GraphCollection { * @param displayName The folder's display name. * @param parentFolderId The ID of the folder's parent folder. */ - public async add(displayName: string, parentFolderId?: string): Promise { + public async add(displayName: string, parentFolderId?: string): Promise { const postBody = { displayName: displayName, parentFolderId: parentFolderId, }; - const data = await graphPost(this, body(postBody)); - - return { - contactFolder: (this).getById(data.id), - data, - }; + return graphPost(this, body(postBody)); } } export interface IContactFolders extends _ContactFolders, IGetById { } export const ContactFolders = graphInvokableFactory(_ContactFolders); - -/** - * IContactFolderAddResult - */ -export interface IContactFolderAddResult { - data: IContactFolderType; - contactFolder: IContactFolder; -} - -/** - * IContactAddResult - */ -export interface IContactAddResult { - data: IContactType; - contact: IContact; -} diff --git a/packages/graph/groups/index.ts b/packages/graph/groups/index.ts index b8ee14b29..4a5bcdd43 100644 --- a/packages/graph/groups/index.ts +++ b/packages/graph/groups/index.ts @@ -6,7 +6,6 @@ export { GroupType, Groups, IGroup, - IGroupAddResult, IGroups, } from "./types.js"; diff --git a/packages/graph/groups/types.ts b/packages/graph/groups/types.ts index f8d7810af..0387f4c7c 100644 --- a/packages/graph/groups/types.ts +++ b/packages/graph/groups/types.ts @@ -90,7 +90,7 @@ export class _Groups extends _DirectoryObjects { * @param groupType Type of group being created * @param additionalProperties A plain object collection of additional properties you want to set on the new group */ - public async add(name: string, mailNickname: string, groupType: GroupType, additionalProperties: Record = {}): Promise { + public async add(name: string, mailNickname: string, groupType: GroupType, additionalProperties: Record = {}): Promise { let postBody = { displayName: name, @@ -109,21 +109,9 @@ export class _Groups extends _DirectoryObjects { }; } - const data = await graphPost(this, body(postBody)); + return graphPost(this, body(postBody)); - return { - data, - group: (this).getById(data.id), - }; } } export interface IGroups extends _Groups, IGetById { } export const Groups = graphInvokableFactory(_Groups); - -/** - * IGroupAddResult - */ -export interface IGroupAddResult { - group: IGroup; - data: any; -} diff --git a/packages/graph/list-item/index.ts b/packages/graph/list-item/index.ts index f85c30980..8c488971c 100644 --- a/packages/graph/list-item/index.ts +++ b/packages/graph/list-item/index.ts @@ -6,10 +6,8 @@ export { IListItems, ListItem, IListItem, - IListItemAddResult, IDocumentSetVersion, DocumentSetVersion, DocumentSetVersions, IDocumentSetVersions, - IDocumentSetVersionAddResult, } from "./types.js"; diff --git a/packages/graph/list-item/types.ts b/packages/graph/list-item/types.ts index 101734540..26787c015 100644 --- a/packages/graph/list-item/types.ts +++ b/packages/graph/list-item/types.ts @@ -57,19 +57,3 @@ export const DocumentSetVersion = graphInvokableFactory(_Do export class _DocumentSetVersions extends _GraphCollection{} export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById, IAddable {} export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); - -/** - * IDocumentSetVersionAddResult - */ -export interface IDocumentSetVersionAddResult { - item: IDocumentSetVersion; - data: IDocumentSetVersionEntity; -} - -/** - * IListAddResult - */ -export interface IListItemAddResult { - list: IListItem; - data: IListItemEntity; -} diff --git a/packages/graph/lists/index.ts b/packages/graph/lists/index.ts index 615a4e719..025129437 100644 --- a/packages/graph/lists/index.ts +++ b/packages/graph/lists/index.ts @@ -6,5 +6,4 @@ export { ILists, List, IList, - IListAddResult, } from "./types.js"; diff --git a/packages/graph/lists/types.ts b/packages/graph/lists/types.ts index 48b5cb1fd..82033d921 100644 --- a/packages/graph/lists/types.ts +++ b/packages/graph/lists/types.ts @@ -1,7 +1,6 @@ import { List as IListEntity } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js"; -import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { body } from "@pnp/queryable"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; +import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById, addable, IAddable } from "../decorators.js"; /** * Represents a list entity @@ -18,29 +17,8 @@ export const List = graphInvokableFactory(_List); */ @defaultPath("lists") @getById(List) -export class _Lists extends _GraphCollection{ - /** - * Create a new list as specified in the request body. - * - * @param list a JSON representation of a List object. - */ - public async add(list: IListEntity): Promise { - const data = await graphPost(this, body(list)); +@addable() +export class _Lists extends _GraphCollection{ } - return { - data, - list: (this).getById(data.id), - }; - } -} - -export interface ILists extends _Lists, IGetById { } +export interface ILists extends _Lists, IGetById, IAddable { } export const Lists = graphInvokableFactory(_Lists); - -/** - * IListAddResult - */ -export interface IListAddResult { - list: IList; - data: IListEntity; -} diff --git a/packages/sp/appcatalog/index.ts b/packages/sp/appcatalog/index.ts index 301fc4877..cb280c215 100644 --- a/packages/sp/appcatalog/index.ts +++ b/packages/sp/appcatalog/index.ts @@ -5,7 +5,6 @@ import { AppCatalog, IAppCatalog } from "./types.js"; import "./web.js"; export { - IAppAddResult, IApp, IAppCatalog, App, diff --git a/packages/sp/appcatalog/types.ts b/packages/sp/appcatalog/types.ts index d40a27443..285907a8f 100644 --- a/packages/sp/appcatalog/types.ts +++ b/packages/sp/appcatalog/types.ts @@ -6,9 +6,7 @@ import { SPCollection, spPost, } from "../spqueryable.js"; -import { odataUrlFrom } from "../utils/odata-url-from.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; -import { File, IFile } from "../files/types.js"; import { combine } from "@pnp/core"; import { defaultPath } from "../decorators.js"; @@ -84,21 +82,16 @@ export class _AppCatalog extends _SPCollection { * @param shouldOverWrite Should an app with the same name in the same location be overwritten? (default: true) * @returns Promise */ - public async add(filename: string, content: string | ArrayBuffer | Blob, shouldOverWrite = true): Promise { + public async add(filename: string, content: string | ArrayBuffer | Blob, shouldOverWrite = true): Promise { // you don't add to the availableapps collection const adder = AppCatalog(this, getAppCatalogPath(this.toUrl(), `add(overwrite=${shouldOverWrite},url='${filename}')`)); - const r = await spPost(adder, { + return spPost(adder, { body: content, headers: { "binaryStringRequestBody": "true", }, }); - - return { - data: r, - file: File([this, odataUrlFrom(r)]), - }; } } export interface IAppCatalog extends _AppCatalog { } @@ -160,17 +153,3 @@ export class _App extends _SPInstance { } export interface IApp extends _App { } export const App = spInvokableFactory(_App); - -/** - * Result object after adding an app - */ -export interface IAppAddResult { - /** - * Contains metadata of the added app - */ - data: any; - /** - * A File instance to the item in SharePoint - */ - file: IFile; -} diff --git a/packages/sp/comments/clientside-page.ts b/packages/sp/comments/clientside-page.ts index b2db9d5e7..16895f96c 100644 --- a/packages/sp/comments/clientside-page.ts +++ b/packages/sp/comments/clientside-page.ts @@ -1,6 +1,6 @@ import { _ClientsidePage } from "../clientside-pages/types.js"; import { ICommentInfo, IComment, ILikedByInformation } from "./types.js"; -import { IItemUpdateResult, Item } from "../items/index.js"; +import { IItem, Item } from "../items/index.js"; import { SPQueryable, spPost } from "../spqueryable.js"; declare module "../clientside-pages/types" { @@ -12,9 +12,9 @@ declare module "../clientside-pages/types" { like(): Promise; unlike(): Promise; getLikedByInformation(): Promise; - enableComments(): Promise; - disableComments(): Promise; - setCommentsOn(on: boolean): Promise; + enableComments(): Promise; + disableComments(): Promise; + setCommentsOn(on: boolean): Promise; } interface IClientsidePage { /** @@ -51,11 +51,11 @@ declare module "../clientside-pages/types" { /** * Enables comments for this page */ - enableComments(): Promise; + enableComments(): Promise; /** * Disables comments for this page */ - disableComments(): Promise; + disableComments(): Promise; } } @@ -99,21 +99,21 @@ _ClientsidePage.prototype.getLikedByInformation = async function (this: _Clients return item.getLikedByInformation(); }; -_ClientsidePage.prototype.enableComments = async function (this: _ClientsidePage): Promise { +_ClientsidePage.prototype.enableComments = async function (this: _ClientsidePage): Promise { return this.setCommentsOn(true).then(r => { this.commentsDisabled = false; return r; }); }; -_ClientsidePage.prototype.disableComments = async function (this: _ClientsidePage): Promise { +_ClientsidePage.prototype.disableComments = async function (this: _ClientsidePage): Promise { return this.setCommentsOn(false).then(r => { this.commentsDisabled = true; return r; }); }; -_ClientsidePage.prototype.setCommentsOn = async function (this: _ClientsidePage, on: boolean): Promise { +_ClientsidePage.prototype.setCommentsOn = async function (this: _ClientsidePage, on: boolean): Promise { const item = await this.getItem(); return Item(item, `SetCommentsDisabled(${!on})`).update({}); }; diff --git a/packages/sp/fields/index.ts b/packages/sp/fields/index.ts index 5bdee4df2..0aef96306 100644 --- a/packages/sp/fields/index.ts +++ b/packages/sp/fields/index.ts @@ -6,8 +6,6 @@ export { Fields, IField, Field, - IFieldAddResult, - IFieldUpdateResult, AddFieldOptions, CalendarType, ChoiceFieldFormatType, diff --git a/packages/sp/fields/types.ts b/packages/sp/fields/types.ts index 8a7f23e9e..ea5ea5811 100644 --- a/packages/sp/fields/types.ts +++ b/packages/sp/fields/types.ts @@ -19,18 +19,14 @@ export class _Fields extends _SPCollection { * * @param xml A string or XmlSchemaFieldCreationInformation instance descrbing the field to create */ - public async createFieldAsXml(xml: string | IXmlSchemaFieldCreationInformation): Promise { + public async createFieldAsXml(xml: string | IXmlSchemaFieldCreationInformation): Promise> { if (typeof xml === "string") { xml = { SchemaXml: xml }; } - const data = await spPost<{ Id: string }>(Fields(this, "createfieldasxml"), body({ parameters: xml })); + return spPost<{ Id: string }>(Fields(this, "createfieldasxml"), body({ parameters: xml })); - return { - data, - field: this.getById(data.Id), - }; } /** @@ -66,9 +62,9 @@ export class _Fields extends _SPCollection { * @param title The new field's title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public async add(title: string, fieldTypeKind: number, properties?: IFieldCreationProperties): Promise { + public async add(title: string, fieldTypeKind: number, properties?: IFieldCreationProperties): Promise> { - const data = await spPost<{Id: string }>(Fields(this,null), body(Object.assign(metadata(mapFieldTypeEnumToString(fieldTypeKind)),{ + return spPost(Fields(this,null), body(Object.assign(metadata(mapFieldTypeEnumToString(fieldTypeKind)),{ Title: title, FieldTypeKind: fieldTypeKind, ...properties, @@ -76,11 +72,6 @@ export class _Fields extends _SPCollection { "Accept":"application/json;odata=verbose", "Content-Type":"application/json;odata=verbose", }))); - - return { - data, - field:this.getById(data.Id), - }; } /** @@ -89,20 +80,15 @@ export class _Fields extends _SPCollection { * @param title The new field's title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public async addField(title: string, fieldTypeKind: number, properties?: IAddFieldProperties): Promise { + public async addField(title: string, fieldTypeKind: number, properties?: IAddFieldProperties): Promise> { - const data = await spPost<{ Id: string }>(Fields(this, "AddField"), body({ + return spPost<{ Id: string }>(Fields(this, "AddField"), body({ parameters: { Title: title, FieldTypeKind: fieldTypeKind, ...properties, }, })); - - return { - data, - field: this.getById(data.Id), - }; } /** @@ -111,7 +97,7 @@ export class _Fields extends _SPCollection { * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addText(title: string, properties?: IFieldCreationProperties & AddTextProps): Promise { + public addText(title: string, properties?: IFieldCreationProperties & AddTextProps): Promise> { return this.add(title, 2, { MaxLength: 255, @@ -125,7 +111,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addCalculated(title: string, properties?: IFieldCreationProperties & AddCalculatedProps): Promise { + public addCalculated(title: string, properties?: IFieldCreationProperties & AddCalculatedProps): Promise> { return this.add(title, 17, { OutputType: FieldTypes.Text, @@ -139,7 +125,7 @@ export class _Fields extends _SPCollection { * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addDateTime(title: string, properties?: IFieldCreationProperties & AddDateTimeProps): Promise { + public addDateTime(title: string, properties?: IFieldCreationProperties & AddDateTimeProps): Promise> { return this.add(title, 4, { DateTimeCalendarType: CalendarType.Gregorian, @@ -155,7 +141,7 @@ export class _Fields extends _SPCollection { * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addNumber(title: string, properties?: IFieldCreationProperties & AddNumberProps): Promise { + public addNumber(title: string, properties?: IFieldCreationProperties & AddNumberProps): Promise> { return this.add(title, 9, properties); } @@ -166,7 +152,7 @@ export class _Fields extends _SPCollection { * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addCurrency(title: string, properties?: IFieldCreationProperties & AddCurrencyProps): Promise { + public addCurrency(title: string, properties?: IFieldCreationProperties & AddCurrencyProps): Promise> { return this.add(title, 10, { CurrencyLocaleId: 1033, @@ -181,7 +167,7 @@ export class _Fields extends _SPCollection { * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) * */ - public addMultilineText(title: string, properties?: IFieldCreationProperties & AddMultilineTextProps): Promise { + public addMultilineText(title: string, properties?: IFieldCreationProperties & AddMultilineTextProps): Promise> { return this.add(title, 3, { AllowHyperlink: true, @@ -198,7 +184,7 @@ export class _Fields extends _SPCollection { * * @param title The field title */ - public addUrl(title: string, properties?: IFieldCreationProperties & AddUrlProps): Promise { + public addUrl(title: string, properties?: IFieldCreationProperties & AddUrlProps): Promise> { return this.add(title, 11, { DisplayFormat: UrlFieldFormatType.Hyperlink, @@ -211,7 +197,7 @@ export class _Fields extends _SPCollection { * @param title The new field's title * @param properties */ - public addUser(title: string, properties?: IFieldCreationProperties & AddUserProps): Promise { + public addUser(title: string, properties?: IFieldCreationProperties & AddUserProps): Promise> { return this.add(title, 20, { SelectionMode: FieldUserSelectionMode.PeopleAndGroups, @@ -225,7 +211,7 @@ export class _Fields extends _SPCollection { * @param title The new field's title * @param properties Set of additional properties to set on the new field */ - public async addLookup(title: string, properties?: IAddFieldProperties): Promise { + public async addLookup(title: string, properties?: IAddFieldProperties): Promise> { return this.addField(title, 7, properties); } @@ -236,7 +222,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addChoice(title: string, properties?: IFieldCreationProperties & AddChoiceProps): Promise { + public addChoice(title: string, properties?: IFieldCreationProperties & AddChoiceProps): Promise> { const props = { ...properties, @@ -254,7 +240,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addMultiChoice(title: string, properties?: IFieldCreationProperties & AddMultiChoiceProps): Promise { + public addMultiChoice(title: string, properties?: IFieldCreationProperties & AddMultiChoiceProps): Promise> { const props = { ...properties, @@ -272,7 +258,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addBoolean(title: string, properties?: IFieldCreationProperties): Promise { + public addBoolean(title: string, properties?: IFieldCreationProperties): Promise> { return this.add(title, 8, properties); } @@ -284,16 +270,11 @@ export class _Fields extends _SPCollection { * @param primaryLookupFieldId The guid of the primary Lookup Field. * @param showField Which field to show from the lookup list. */ - public async addDependentLookupField(displayName: string, primaryLookupFieldId: string, showField: string): Promise { + public async addDependentLookupField(displayName: string, primaryLookupFieldId: string, showField: string): Promise> { const path = `adddependentlookupfield(displayName='${displayName}', primarylookupfieldid='${primaryLookupFieldId}', showfield='${showField}')`; - const data = await spPost(Fields(this, path)); - - return { - data, - field: this.getById(data.Id), - }; + return spPost(Fields(this, path)); } /** @@ -302,7 +283,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addLocation(title: string, properties?: IFieldCreationProperties): Promise { + public addLocation(title: string, properties?: IFieldCreationProperties): Promise> { return this.add(title, 33, properties); } @@ -313,7 +294,7 @@ export class _Fields extends _SPCollection { * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ - public addImageField(title: string, properties?: IFieldCreationProperties): Promise { + public addImageField(title: string, properties?: IFieldCreationProperties): Promise> { return this.add(title, 34, properties); } @@ -331,19 +312,14 @@ export class _Field extends _SPInstance { * @param properties A plain object hash of values to update for the list * @param fieldType The type value such as SP.FieldLookup. Optional, looked up from the field if not provided */ - public async update(properties: any, fieldType?: string): Promise { + public async update(properties: any, fieldType?: string): Promise> { if (typeof fieldType === "undefined" || fieldType === null) { const info = await Field(this).select("FieldTypeKind")(); fieldType = info["odata.type"]; } - const data = await spPostMerge(this, body(properties)); - - return { - data, - field: this, - }; + return spPostMerge(this, body(properties)); } /** @@ -370,22 +346,6 @@ export class _Field extends _SPInstance { export interface IField extends _Field, IDeleteable { } export const Field = spInvokableFactory(_Field); -/** - * This interface defines the result of adding a field - */ -export interface IFieldAddResult { - data: Partial; - field: IField; -} - -/** - * This interface defines the result of updating a field - */ -export interface IFieldUpdateResult { - data: Partial; - field: IField; -} - export type AddTextProps = { MaxLength?: number; }; diff --git a/packages/sp/files/index.ts b/packages/sp/files/index.ts index 6239e97c8..f94c04e79 100644 --- a/packages/sp/files/index.ts +++ b/packages/sp/files/index.ts @@ -7,7 +7,6 @@ export { IFile, Files, IFiles, - IFileAddResult, IFileUploadProgressData, CheckinType, MoveOperations, diff --git a/packages/sp/files/types.ts b/packages/sp/files/types.ts index 3a50d27cb..d8f624659 100644 --- a/packages/sp/files/types.ts +++ b/packages/sp/files/types.ts @@ -53,7 +53,7 @@ export class _Files extends _SPCollection { * @param parameters Additional parameters to control method behavior */ @cancelableScope - public async addUsingPath(url: string, content: string | ArrayBuffer | Blob, parameters: IAddUsingPathProps = { Overwrite: false }): Promise { + public async addUsingPath(url: string, content: string | ArrayBuffer | Blob, parameters: IAddUsingPathProps = { Overwrite: false }): Promise { const path = [`AddUsingPath(decodedurl='${encodePath(url)}'`]; @@ -74,12 +74,7 @@ export class _Files extends _SPCollection { path.push(")"); - const resp: IFileInfo = await spPost(Files(this, path.join("")), { body: content }); - - return { - data: resp, - file: fileFromServerRelativePath(this, resp.ServerRelativeUrl), - }; + return spPost(Files(this, path.join("")), { body: content }); } /** @@ -91,12 +86,12 @@ export class _Files extends _SPCollection { * @returns The new File and the raw response. */ @cancelableScope - public async addChunked(url: string, content: ValidFileContentSource, props?: Partial & Partial): Promise { + public async addChunked(url: string, content: ValidFileContentSource, props?: Partial & Partial): Promise { // add an empty stub const response = await this.addUsingPath(url, null, props); - const file = fileFromServerRelativePath(this, response.data.ServerRelativeUrl); + const file = fileFromServerRelativePath(this, response.ServerRelativeUrl); file.using(CancelAction(() => { return File(file).delete(); @@ -113,12 +108,8 @@ export class _Files extends _SPCollection { * @returns The template file that was added and the raw response. */ @cancelableScope - public async addTemplateFile(fileUrl: string, templateFileType: TemplateFileType): Promise { - const response: IFileInfo = await spPost(Files(this, `addTemplateFile(urloffile='${encodePath(fileUrl)}',templatefiletype=${templateFileType})`)); - return { - data: response, - file: fileFromServerRelativePath(this, response.ServerRelativeUrl), - }; + public async addTemplateFile(fileUrl: string, templateFileType: TemplateFileType): Promise { + return spPost(Files(this, `addTemplateFile(urloffile='${encodePath(fileUrl)}',templatefiletype=${templateFileType})`)); } } export interface IFiles extends _Files { } @@ -404,7 +395,7 @@ export class _File extends ReadableFile { * @param chunkSize The size of each file slice, in bytes (default: 10485760) */ @cancelableScope - public async setContentChunked(file: ValidFileContentSource, props: Partial): Promise { + public async setContentChunked(file: ValidFileContentSource, props: Partial): Promise { const { progress } = applyChunckedOperationDefaults(props); @@ -425,12 +416,7 @@ export class _File extends ReadableFile { if (chunk.done) { progress({ offset, stage: "finishing", uploadId }); - const data = await spPost(File(fileRef, `finishUpload(uploadId=guid'${uploadId}',fileOffset=${offset})`), { body: chunk?.value || "" }); - - return { - data, - file: fileFromServerRelativePath(this, data.ServerRelativeUrl), - }; + return spPost(File(fileRef, `finishUpload(uploadId=guid'${uploadId}',fileOffset=${offset})`), { body: chunk?.value || "" }); } else if (first) { @@ -604,14 +590,6 @@ export enum CheckinType { Major = 1, Overwrite = 2, } -/** - * Describes file and result - */ -export interface IFileAddResult { - file: IFile; - data: IFileInfo; -} - /** * File move opertions */ diff --git a/packages/sp/folders/index.ts b/packages/sp/folders/index.ts index 8a953316c..cebe44852 100644 --- a/packages/sp/folders/index.ts +++ b/packages/sp/folders/index.ts @@ -4,8 +4,6 @@ import "./web.js"; export { Folder, - IFolderAddResult, - IFolderUpdateResult, Folders, IFolder, IFolders, diff --git a/packages/sp/folders/types.ts b/packages/sp/folders/types.ts index 4967f6ef7..a3a6a769b 100644 --- a/packages/sp/folders/types.ts +++ b/packages/sp/folders/types.ts @@ -40,14 +40,10 @@ export class _Folders extends _SPCollection { * @param serverRelativeUrl The server relative url of the new folder to create * @param overwrite True to overwrite an existing folder, default false */ - public async addUsingPath(serverRelativeUrl: string, overwrite = false): Promise { + public async addUsingPath(serverRelativeUrl: string, overwrite = false): Promise { - const data: IFolderInfo = await spPost(Folders(this, `addUsingPath(DecodedUrl='${encodePath(serverRelativeUrl)}',overwrite=${overwrite})`)); + return spPost(Folders(this, `addUsingPath(DecodedUrl='${encodePath(serverRelativeUrl)}',overwrite=${overwrite})`)); - return { - data, - folder: folderFromServerRelativePath(this, data.ServerRelativeUrl), - }; } } export interface IFolders extends _Folders { } @@ -102,14 +98,9 @@ export class _Folder extends _SPInstance { * Updates folder's properties * @param props Folder's properties to update */ - public async update(props: Partial): Promise { + public async update(props: Partial): Promise { - const data = await spPostMerge(this, body(props)); - - return { - data, - folder: this, - }; + return spPostMerge(this, body(props)); } /** @@ -339,38 +330,6 @@ export async function folderFromPath(base: ISPQueryable, path: string): Promise< return (isUrlAbsolute(path) ? folderFromAbsolutePath : folderFromServerRelativePath)(base, path); } -/** - * Describes result of adding a folder - */ -export interface IFolderAddResult { - - /** - * A folder's instance - */ - folder: IFolder; - - /** - * Additional data from the server - */ - data: any; -} - -/** - * Describes result of updating a folder - */ -export interface IFolderUpdateResult { - - /** - * A folder's instance - */ - folder: IFolder; - - /** - * Additional data from the server - */ - data: any; -} - export interface IFolderInfo { readonly "odata.id": string; Exists: boolean; diff --git a/packages/sp/items/index.ts b/packages/sp/items/index.ts index d878c1601..47e1d6c60 100644 --- a/packages/sp/items/index.ts +++ b/packages/sp/items/index.ts @@ -9,9 +9,6 @@ export { ItemVersions, IItemVersion, IItemVersions, - IItemAddResult, - IItemUpdateResult, - IItemUpdateResultData, IItemDeleteParams, IItemParentInfos, } from "./types.js"; diff --git a/packages/sp/items/types.ts b/packages/sp/items/types.ts index e0c062905..c8e51cda4 100644 --- a/packages/sp/items/types.ts +++ b/packages/sp/items/types.ts @@ -112,12 +112,8 @@ export class _Items extends _SPCollection { * @param properties The new items's properties * @param listItemEntityTypeFullName The type name of the list's entities */ - public async add(properties: Record = {}): Promise { - - return spPost<{ Id: number }>(this, body(properties)).then((data) => ({ - data: data, - item: this.getById(data.Id), - })); + public async add(properties: Record = {}): Promise { + return spPost(this, body(properties)); } } export interface IItems extends _Items { } @@ -191,19 +187,15 @@ export class _Item extends _SPInstance { * @param properties A plain object hash of values to update for the list * @param eTag Value used in the IF-Match header, by default "*" */ - public async update(properties: Record, eTag = "*"): Promise { + public async update(properties: Record, eTag = "*"): Promise { const postBody = body(properties, headers({ "IF-Match": eTag, "X-HTTP-Method": "MERGE", })); - const data = await spPost(Item(this).using(ItemUpdatedParser()), postBody); + return spPost(Item(this).using(ItemUpdatedParser()), postBody); - return { - data, - item: this, - }; } /** @@ -362,16 +354,6 @@ function ItemUpdatedParser() { })); } -export interface IItemAddResult { - item: IItem; - data: any; -} - -export interface IItemUpdateResult { - item: IItem; - data: IItemUpdateResultData; -} - export interface IItemUpdateResultData { etag: string; } diff --git a/packages/sp/lists/index.ts b/packages/sp/lists/index.ts index 4d2776ff2..719a1e7a1 100644 --- a/packages/sp/lists/index.ts +++ b/packages/sp/lists/index.ts @@ -5,9 +5,6 @@ export { IList, Lists, ILists, - IListAddResult, - IListUpdateResult, - IListEnsureResult, ControlMode, ICamlQuery, IChangeLogItemQuery, diff --git a/packages/sp/lists/types.ts b/packages/sp/lists/types.ts index 5ca217593..8153b456a 100644 --- a/packages/sp/lists/types.ts +++ b/packages/sp/lists/types.ts @@ -55,7 +55,7 @@ export class _Lists extends _SPCollection { * @param enableContentTypes If true content types will be allowed and enabled, otherwise they will be disallowed and not enabled * @param additionalSettings Will be passed as part of the list creation body */ - public async add(title: string, desc = "", template = 100, enableContentTypes = false, additionalSettings: Partial = {}): Promise { + public async add(title: string, desc = "", template = 100, enableContentTypes = false, additionalSettings: Partial = {}): Promise { const addSettings = { "AllowContentTypes": enableContentTypes, @@ -66,9 +66,8 @@ export class _Lists extends _SPCollection { ...additionalSettings, }; - const data = await spPost(this, body(addSettings)); + return spPost(this, body(addSettings)); - return { data, list: this.getByTitle(addSettings.Title) }; } /** @@ -85,7 +84,7 @@ export class _Lists extends _SPCollection { desc = "", template = 100, enableContentTypes = false, - additionalSettings: Partial = {}): Promise { + additionalSettings: Partial = {}): Promise { const addOrUpdateSettings = { Title: title, Description: desc, ContentTypesEnabled: enableContentTypes, ...additionalSettings }; @@ -95,14 +94,13 @@ export class _Lists extends _SPCollection { await list.select("Title")(); - const data = await list.update(addOrUpdateSettings).then(r => r.data); + const data = await list.update(addOrUpdateSettings); - return { created: false, data, list: this.getByTitle(addOrUpdateSettings.Title) }; + return data; } catch (e) { - const data = await this.add(title, desc, template, enableContentTypes, addOrUpdateSettings).then(r => r.data); - return { created: true, data, list: this.getByTitle(addOrUpdateSettings.Title) }; + return this.add(title, desc, template, enableContentTypes, addOrUpdateSettings).then(r => r); } } @@ -167,16 +165,10 @@ export class _List extends _SPInstance { * @param properties A plain object hash of values to update for the list * @param eTag Value used in the IF-Match header, by default "*" */ - public async update(properties: Partial, eTag = "*"): Promise { + public async update(properties: Partial, eTag = "*"): Promise { - const data = await spPostMerge(this, body(properties, headers({ "IF-Match": eTag }))); + return spPostMerge(this, body(properties, headers({ "IF-Match": eTag }))); - const list: IList = hOP(properties, "Title") ? this.getParent(List, `getByTitle('${properties.Title}')`) : List(this); - - return { - data, - list, - }; } /** @@ -356,31 +348,6 @@ export class _List extends _SPInstance { export interface IList extends _List, IDeleteableWithETag { } export const List = spInvokableFactory(_List); -/** - * Represents the output of the add method - */ -export interface IListAddResult { - list: IList; - data: IListInfo; -} - -/** - * Represents the output of the update method - */ -export interface IListUpdateResult { - list: IList; - data: IListInfo; -} - -/** - * Represents the output of the ensure method - */ -export interface IListEnsureResult { - list: IList; - created: boolean; - data: IListInfo; -} - /** * Specifies a Collaborative Application Markup Language (CAML) query on a list or joined lists. */ diff --git a/packages/sp/navigation/index.ts b/packages/sp/navigation/index.ts index d294d9c60..a1f1edb07 100644 --- a/packages/sp/navigation/index.ts +++ b/packages/sp/navigation/index.ts @@ -7,7 +7,6 @@ export { INavNodeUpdateResult, INavigation, INavigationNode, - INavigationNodeAddResult, INavigationNodes, INavigationService, Navigation, diff --git a/packages/sp/navigation/types.ts b/packages/sp/navigation/types.ts index d6355eb5d..ffac8c2cd 100644 --- a/packages/sp/navigation/types.ts +++ b/packages/sp/navigation/types.ts @@ -36,7 +36,7 @@ export class _NavigationNodes extends _SPCollection { * @param url The url of the node * @param visible If true the node is visible, otherwise it is hidden (default: true) */ - public async add(title: string, url: string, visible = true): Promise { + public async add(title: string, url: string, visible = true): Promise { const postBody = body({ IsVisible: visible, @@ -44,12 +44,7 @@ export class _NavigationNodes extends _SPCollection { Url: url, }); - const data = await spPost(NavigationNodes(this, null), postBody); - - return { - data, - node: this.getById(data.Id), - }; + return spPost(NavigationNodes(this, null), postBody); } /** @@ -220,15 +215,6 @@ export interface ISerializableNavigationNode { Children: ISerializableNavigationNode[]; } -/** - * Result from adding a navigation node - * - */ -export interface INavigationNodeAddResult { - data: INavNodeInfo; - node: INavigationNode; -} - /** * Represents the information describing a navigation node */ diff --git a/packages/sp/site-groups/index.ts b/packages/sp/site-groups/index.ts index a1f9369ea..f62152410 100644 --- a/packages/sp/site-groups/index.ts +++ b/packages/sp/site-groups/index.ts @@ -2,8 +2,6 @@ import "./web.js"; export { ISiteGroup, - IGroupAddResult, - IGroupUpdateResult, ISiteGroups, SiteGroup, SiteGroups, diff --git a/packages/sp/site-groups/types.ts b/packages/sp/site-groups/types.ts index a3ed9f964..38770f63b 100644 --- a/packages/sp/site-groups/types.ts +++ b/packages/sp/site-groups/types.ts @@ -26,14 +26,9 @@ export class _SiteGroups extends _SPCollection { * * @param properties The group properties object of property names and values to be set for the group */ - public async add(properties: Partial): Promise { + public async add(properties: Partial): Promise { - const data = await spPost(this, body(properties)); - - return { - data, - group: this.getById(data.Id), - }; + return spPost(this, body(properties)); } /** @@ -79,14 +74,9 @@ export class _SiteGroup extends _SPInstance { /** * @param props Group properties to update */ - public async update(props: Partial): Promise { - - const data = await spPostMerge(this, body(props)); + public async update(props: Partial): Promise { - return { - data, - group: this, - }; + return spPostMerge(this, body(props)); } /** @@ -100,24 +90,6 @@ export class _SiteGroup extends _SPInstance { export interface ISiteGroup extends _SiteGroup { } export const SiteGroup = spInvokableFactory(_SiteGroup); -/** - * Result from updating a group - * - */ -export interface IGroupUpdateResult { - group: ISiteGroup; - data: any; -} - -/** - * Results from adding a group - * - */ -export interface IGroupAddResult { - group: ISiteGroup; - data: any; -} - export interface ISiteGroupInfo { AllowMembersEditMembership: boolean; AllowRequestToJoinLeave: boolean; diff --git a/packages/sp/site-users/index.ts b/packages/sp/site-users/index.ts index f0cbdb8a1..84ef29a4f 100644 --- a/packages/sp/site-users/index.ts +++ b/packages/sp/site-users/index.ts @@ -2,11 +2,9 @@ import "./web.js"; export { ISiteUser, - IWebEnsureUserResult, SiteUser, SiteUsers, ISiteUsers, ISiteUserProps, - IUserUpdateResult, ISiteUserInfo, } from "./types.js"; diff --git a/packages/sp/site-users/types.ts b/packages/sp/site-users/types.ts index 283b313f7..3f79bbcb5 100644 --- a/packages/sp/site-users/types.ts +++ b/packages/sp/site-users/types.ts @@ -98,24 +98,28 @@ export class _SiteUser extends _SPInstance { * * @param props Group properties to update */ - public async update(props: Partial): Promise { + public async update(props: Partial): Promise { - const data = await spPostMerge(this, body(props)); + return spPostMerge(this, body(props)); - return { - data, - user: this, - }; } } export interface ISiteUser extends _SiteUser, IDeleteable { } export const SiteUser = spInvokableFactory(_SiteUser); -export interface ISiteUserInfo extends ISiteUserProps { +export interface ISiteUserInfo { + Id: number; + IsHiddenInUI: boolean; + LoginName: string; + Title: string; + PrincipalType: number; + Email: string; Expiration: string; IsEmailAuthenticationGuestUser: boolean; + IsShareByEmailGuestUser: boolean; + IsSiteAdmin: boolean; UserId: { NameId: string; NameIdIssuer: string; @@ -177,21 +181,3 @@ export interface ISiteUserProps { */ Title: string; } - -/** - * Properties that provide both a getter, and a setter. - * - */ -export interface IUserUpdateResult { - user: ISiteUser; - data: any; -} - -/** - * Result from ensuring a user - * - */ -export interface IWebEnsureUserResult { - data: ISiteUserProps; - user: ISiteUser; -} diff --git a/packages/sp/site-users/web.ts b/packages/sp/site-users/web.ts index 97be709ca..0699e75ba 100644 --- a/packages/sp/site-users/web.ts +++ b/packages/sp/site-users/web.ts @@ -1,14 +1,13 @@ import { addProp, body } from "@pnp/queryable"; import { _Web, Web } from "../webs/types.js"; -import { ISiteUsers, SiteUsers, ISiteUser, SiteUser, IWebEnsureUserResult } from "./types.js"; -import { odataUrlFrom } from "../utils/odata-url-from.js"; +import { ISiteUsers, SiteUsers, ISiteUser, SiteUser, ISiteUserInfo } from "./types.js"; import { spPost } from "../spqueryable.js"; declare module "../webs/types" { interface _Web { readonly siteUsers: ISiteUsers; readonly currentUser: ISiteUser; - ensureUser(loginName: string): Promise; + ensureUser(loginName: string): Promise; getUserById(id: number): ISiteUser; } interface IWeb { @@ -28,7 +27,7 @@ declare module "../webs/types" { * * @param loginName The login name of the user (ex: i:0#.f|membership|user@domain.onmicrosoft.com) */ - ensureUser(loginName: string): Promise; + ensureUser(loginName: string): Promise; /** * Returns the user corresponding to the specified member identifier for the current site @@ -42,13 +41,9 @@ declare module "../webs/types" { addProp(_Web, "siteUsers", SiteUsers); addProp(_Web, "currentUser", SiteUser); -_Web.prototype.ensureUser = async function (this: _Web, logonName: string): Promise { +_Web.prototype.ensureUser = async function (this: _Web, logonName: string): Promise { - const data = await spPost(Web(this, "ensureuser"), body({ logonName })); - return { - data, - user: SiteUser([this, odataUrlFrom(data)]), - }; + return spPost(Web(this, "ensureuser"), body({ logonName })); }; _Web.prototype.getUserById = function (id: number): ISiteUser { diff --git a/packages/sp/subscriptions/index.ts b/packages/sp/subscriptions/index.ts index 37fe82a58..b1b041895 100644 --- a/packages/sp/subscriptions/index.ts +++ b/packages/sp/subscriptions/index.ts @@ -2,8 +2,6 @@ import "./list.js"; export { ISubscription, - ISubscriptionAddResult, - ISubscriptionUpdateResult, ISubscriptions, Subscription, Subscriptions, diff --git a/packages/sp/subscriptions/types.ts b/packages/sp/subscriptions/types.ts index 066265368..a40d6ae31 100644 --- a/packages/sp/subscriptions/types.ts +++ b/packages/sp/subscriptions/types.ts @@ -29,7 +29,7 @@ export class _Subscriptions extends _SPCollection { * @param expirationDate The date and time to expire the subscription in the form YYYY-MM-ddTHH:mm:ss+00:00 (maximum of 6 months) * @param clientState A client specific string (optional) */ - public async add(notificationUrl: string, expirationDate: string, clientState?: string): Promise { + public async add(notificationUrl: string, expirationDate: string, clientState?: string): Promise { const postBody: any = { "expirationDateTime": expirationDate, @@ -41,9 +41,7 @@ export class _Subscriptions extends _SPCollection { postBody.clientState = clientState; } - const data = await spPost(this, body(postBody)); - - return { data, subscription: this.getById(data.id) }; + return spPost(this, body(postBody)); } } export interface ISubscriptions extends _Subscriptions { } @@ -58,7 +56,7 @@ export class _Subscription extends _SPInstance { * @param notificationUrl The url to receive the notifications (optional) * @param clientState A client specific string (optional) */ - public async update(expirationDate?: string, notificationUrl?: string, clientState?: string): Promise { + public async update(expirationDate?: string, notificationUrl?: string, clientState?: string): Promise { const postBody: any = {}; @@ -74,9 +72,7 @@ export class _Subscription extends _SPInstance { postBody.clientState = clientState; } - const data = await spPatch(this, body(postBody)); - - return { data, subscription: this }; + return spPatch(this, body(postBody)); } /** @@ -89,21 +85,3 @@ export class _Subscription extends _SPInstance { } export interface ISubscription extends _Subscription { } export const Subscription = spInvokableFactory(_Subscription); - -/** - * Result from adding a new subscription - * - */ -export interface ISubscriptionAddResult { - subscription: ISubscription; - data: any; -} - -/** - * Result from updating a subscription - * - */ -export interface ISubscriptionUpdateResult { - subscription: ISubscription; - data: any; -} diff --git a/packages/sp/views/index.ts b/packages/sp/views/index.ts index ef3f9a1df..e9578ebaf 100644 --- a/packages/sp/views/index.ts +++ b/packages/sp/views/index.ts @@ -7,8 +7,6 @@ export { View, ViewFields, Views, - IViewAddResult, - IViewUpdateResult, IViewInfo, ViewScope, } from "./types.js"; diff --git a/packages/sp/views/types.ts b/packages/sp/views/types.ts index e240cdfbd..607ac50f6 100644 --- a/packages/sp/views/types.ts +++ b/packages/sp/views/types.ts @@ -21,18 +21,13 @@ export class _Views extends _SPCollection { * @param personalView True if this is a personal view, otherwise false, default = false * @param additionalSettings Will be passed as part of the view creation body */ - public async add(Title: string, PersonalView = false, additionalSettings: Record = {}): Promise { + public async add(Title: string, PersonalView = false, additionalSettings: Record = {}): Promise { - const data = await spPost(this, body({ + return spPost(this, body({ PersonalView, Title, ...additionalSettings, })); - - return { - data, - view: this.getById(data.Id), - }; } /** @@ -69,14 +64,10 @@ export class _View extends _SPInstance { * * @param properties A plain object hash of values to update for the view */ - public async update(props: Partial): Promise { + public async update(props: Partial): Promise { - const data = await spPostMerge(this, body(props)); + return await spPostMerge(this, body(props)); - return { - data, - view: this, - }; } // : any = this._update>("SP.View", data => ({ data, view: this })); @@ -149,16 +140,6 @@ export class _ViewFields extends _SPCollection<{ Items: string[]; SchemaXml: str export interface IViewFields extends _ViewFields { } export const ViewFields = spInvokableFactory(_ViewFields); -export interface IViewAddResult { - view: IView; - data: IViewInfo; -} - -export interface IViewUpdateResult { - view: IView; - data: IViewInfo; -} - export enum ViewScope { DefaultValue, Recursive, diff --git a/packages/sp/webs/index.ts b/packages/sp/webs/index.ts index cc1f5efae..419776ef8 100644 --- a/packages/sp/webs/index.ts +++ b/packages/sp/webs/index.ts @@ -5,8 +5,6 @@ export { IWeb, IWebs, Web, - IWebAddResult, - IWebUpdateResult, Webs, IWebInfo, IStorageEntity, diff --git a/packages/sp/webs/types.ts b/packages/sp/webs/types.ts index 86a341765..0aa571804 100644 --- a/packages/sp/webs/types.ts +++ b/packages/sp/webs/types.ts @@ -16,7 +16,6 @@ import { } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { IChangeQuery } from "../types.js"; -import { odataUrlFrom } from "../utils/odata-url-from.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine, isArray } from "@pnp/core"; import { encodePath } from "../utils/encode-path-str.js"; @@ -34,7 +33,7 @@ export class _Webs extends _SPCollection { * @param language The locale id that specifies the new web's language (default = 1033 [English, US]) * @param inheritPermissions When true, permissions will be inherited from the new web's parent (default = true) */ - public async add(Title: string, Url: string, Description = "", WebTemplate = "STS", Language = 1033, UseSamePermissionsAsParentSite = true): Promise { + public async add(Title: string, Url: string, Description = "", WebTemplate = "STS", Language = 1033, UseSamePermissionsAsParentSite = true): Promise { const postBody = body({ "parameters": { @@ -47,12 +46,7 @@ export class _Webs extends _SPCollection { }, }); - const data = await spPost(Webs(this, "add"), postBody); - - return { - data, - web: Web([this, odataUrlFrom(data).replace(/_api\/web\/?/i, "")]), - }; + return spPost(Webs(this, "add"), postBody); } } export interface IWebs extends _Webs { } @@ -264,24 +258,6 @@ export class _Web extends _SPInstance { export interface IWeb extends _Web, IDeleteable { } export const Web = spInvokableFactory(_Web); -/** - * Result from adding a web - * - */ -export interface IWebAddResult { - data: IWebInfo; - web: IWeb; -} - -/** - * Result from updating a web - * - */ -export interface IWebUpdateResult { - data: any; - web: IWeb; -} - export interface IWebInfosData { Configuration: number; Created: string; diff --git a/samples/project-preset/src/pnpjs-preset.ts b/samples/project-preset/src/pnpjs-preset.ts index 16ab73be2..88f534ec7 100644 --- a/samples/project-preset/src/pnpjs-preset.ts +++ b/samples/project-preset/src/pnpjs-preset.ts @@ -49,7 +49,7 @@ extendFactory(Web, { if (r.created) { const [batchedWeb, execute] = this.batched(); - const list = batchedWeb.lists.getById(r.data.Id); + const list = batchedWeb.lists.getById(r.Id); list.fields.addText("TextField"); list.fields.addUrl("UrlField", { DisplayFormat: UrlFieldFormatType.Hyperlink }); await execute(); diff --git a/test/graph/columns.ts b/test/graph/columns.ts index effb013b8..8e95a0409 100644 --- a/test/graph/columns.ts +++ b/test/graph/columns.ts @@ -72,7 +72,7 @@ describe("Columns", function () { list: { "template": "genericList" }, }); - list = addList.list; + list = site.lists.getById(addList.id); })); after(async function () { @@ -114,8 +114,8 @@ describe("Columns", function () { columnTemplate.name += "Add"; columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); - await site.columns.getById(c.data.id).delete(); - return expect((c.data.name === columnTemplate.name)).to.be.true; + await site.columns.getById(c.id).delete(); + return expect((c.name === columnTemplate.name)).to.be.true; })); it("update", pnpTest("8ce610b0-3139-4e2b-9d90-47ad43247250", async function () { @@ -130,9 +130,9 @@ describe("Columns", function () { columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await site.columns.add(columnTemplate); - await site.columns.getById(c.data.id).update({ displayName: newColumnName }); - const updateColumn = await site.columns.getById(c.data.id)(); - await site.columns.getById(c.data.id).delete(); + await site.columns.getById(c.id).update({ displayName: newColumnName }); + const updateColumn = await site.columns.getById(c.id)(); + await site.columns.getById(c.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; })); @@ -147,10 +147,10 @@ describe("Columns", function () { columnTemplate.name += props.name; columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); - await site.columns.getById(c.data.id).delete(); + await site.columns.getById(c.id).delete(); let deletedColumn: ColumnDefinition = null; try { - deletedColumn = await site.columns.getById(c.data.id)(); + deletedColumn = await site.columns.getById(c.id)(); } catch (err) { // do nothing } @@ -177,7 +177,7 @@ describe("Columns", function () { columnTemplate.name = columnTemplateName; columnTemplate.displayName = columnTemplateName; const addSiteCT = await site.columns.add(columnTemplate); - siteColumn = addSiteCT.column; + siteColumn = site.columns.getById(addSiteCT.id); })); after(async function () { @@ -203,24 +203,24 @@ describe("Columns", function () { it("addRef", pnpTest("9dd8c09e-9e07-42e2-ac2d-5685966d2aa0", async function () { const c = await contentType.columns.addRef(siteColumn); - await contentType.columns.getById(c.data.id).delete(); - return expect((c.data.name === columnTemplateName)).to.be.true; + await contentType.columns.getById(c.id).delete(); + return expect((c.name === columnTemplateName)).to.be.true; })); // Site column properties cannot be updated in content type. it.skip("update", pnpTest("c3afb14e-3f42-48e8-9ea6-43be8d231762", async function () { const c = await contentType.columns.addRef(siteColumn); - const updateColumnResults = await contentType.columns.getById(c.data.id).update({ propagateChanges: true }); - await contentType.columns.getById(c.data.id).delete(); + const updateColumnResults = await contentType.columns.getById(c.id).update({ propagateChanges: true }); + await contentType.columns.getById(c.id).delete(); return expect((updateColumnResults.propagateChanges)).to.be.true; })); it("delete", pnpTest("4d6e18c1-abe7-4cd4-a90e-1c1715d5e1ce", async function () { const c = await contentType.columns.addRef(siteColumn); - await contentType.columns.getById(c.data.id).delete(); + await contentType.columns.getById(c.id).delete(); let deletedColumn: ColumnDefinition = null; try { - deletedColumn = await contentType.columns.getById(c.data.id)(); + deletedColumn = await contentType.columns.getById(c.id)(); } catch (err) { // do nothing } @@ -254,8 +254,8 @@ describe("Columns", function () { columnTemplate.name += "Add"; columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); - await list.columns.getById(c.data.id).delete(); - return expect((c.data.name === columnTemplate.name)).to.be.true; + await list.columns.getById(c.id).delete(); + return expect((c.name === columnTemplate.name)).to.be.true; })); it("update", pnpTest("3827a66a-2f8b-4cd7-addb-b49eac258f45", async function () { @@ -270,9 +270,9 @@ describe("Columns", function () { columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await list.columns.add(columnTemplate); - await list.columns.getById(c.data.id).update({ displayName: newColumnName }); - const updateColumn = await list.columns.getById(c.data.id)(); - await list.columns.getById(c.data.id).delete(); + await list.columns.getById(c.id).update({ displayName: newColumnName }); + const updateColumn = await list.columns.getById(c.id)(); + await list.columns.getById(c.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; })); @@ -287,10 +287,10 @@ describe("Columns", function () { columnTemplate.name += props.name; columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); - await list.columns.getById(c.data.id).delete(); + await list.columns.getById(c.id).delete(); let deletedColumn: ColumnDefinition = null; try { - deletedColumn = await list.columns.getById(c.data.id)(); + deletedColumn = await list.columns.getById(c.id)(); } catch (err) { // do nothing } diff --git a/test/graph/contacts.ts b/test/graph/contacts.ts index 817f41f9e..28189905a 100644 --- a/test/graph/contacts.ts +++ b/test/graph/contacts.ts @@ -33,20 +33,20 @@ describe("Contacts", function () { name: `Pavel ${testContactName}}`, }], ["+1 732 555 1111"]); - testContactID = contact.data.id; - rootFolderID = contact.data.parentFolderId; + testContactID = contact.id; + rootFolderID = contact.parentFolderId; // Create a test folder const folder = await this.pnp.graph.users.getById(testUserName).contactFolders.add(testFolderName, rootFolderID); - testFolderID = folder.data.id; + testFolderID = folder.id; const subFolder = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).childFolders.add(testSubFolderName, testFolderID); - subFolderID = subFolder.data.id; + subFolderID = subFolder.id; // Add a test user in the new folder const contact2 = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).contacts.add("Jane", testContactName, [{ address: "janeb@contoso.onmicrosoft.com", name: `Pavel ${testContactName}}`, }], ["+1 732 555 1111"]); - testContact2ID = contact2.data.id; + testContact2ID = contact2.id; }); it("Get Contacts", async function () { @@ -68,7 +68,7 @@ describe("Contacts", function () { address: "tmctester@contoso.onmicrosoft.com", name: `Test ${testContactName}`, }], ["+1 732 555 0102"]); - contactId = contact.data.id; + contactId = contact.id; contactAfterAdd = await this.pnp.graph.users.getById(testUserName).contacts.getById(contactId)(); } catch (err) { console.log(err.message); @@ -87,10 +87,10 @@ describe("Contacts", function () { address: "tmctester@contoso.onmicrosoft.com", name: `Test ${testContactName}`, }], ["+1 732 555 0102"]); - await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.data.id).update({ birthday: "1986-05-30" }); - const contact2 = await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.data.id)(); + await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).update({ birthday: "1986-05-30" }); + const contact2 = await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id)(); // Clean up the added contact - await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.data.id).delete(); + await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).delete(); return expect(contact2.birthday).equals("1986-05-30T11:59:00Z"); }); @@ -101,13 +101,13 @@ describe("Contacts", function () { address: "tmctester@contoso.onmicrosoft.com", name: `Test ${testContactName}`, }], ["+1 732 555 0102"]); - await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.data.id).delete(); + await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).delete(); let deletedUserFound = false; try { // If we try to find a user that doesn"t exist this returns a 404 - await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.data.id)(); + await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id)(); deletedUserFound = true; } catch (e) { @@ -140,7 +140,7 @@ describe("Contacts", function () { try { const testFolderName = `TestFolder_${getRandomString(4)}`; const folder = await this.pnp.graph.users.getById(testUserName).contactFolders.add(testFolderName, rootFolderID); - folderId = folder.data.id; + folderId = folder.id; folderAfterAdd = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folderId)(); } catch (err) { console.log(err.message); @@ -160,7 +160,7 @@ describe("Contacts", function () { try { const testFolderName = `TestFolder_${getRandomString(4)}`; const folder = await this.pnp.graph.users.getById(testUserName).contactFolders.add(testFolderName, rootFolderID); - folderId = folder.data.id; + folderId = folder.id; await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folderId).update({ displayName: folderDisplayName }); folderAfterUpdate = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folderId)(); } catch (err) { @@ -178,13 +178,13 @@ describe("Contacts", function () { // Add a folder that we can then delete const testFolderName = `TestFolder_${getRandomString(4)}`; const folder = await this.pnp.graph.users.getById(testUserName).contactFolders.add(testFolderName, rootFolderID); - await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folder.data.id).delete(); + await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folder.id).delete(); let deletedFolderFound = false; try { // If we try to find a folder that doesn"t exist this returns a 404 - await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folder.data.id)(); + await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folder.id)(); deletedFolderFound = true; } catch (e) { @@ -220,9 +220,9 @@ describe("Contacts", function () { const contact = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).childFolders.getById(subFolderID) .contacts.add("Test", testContactName, [{ address: "tmctester@contoso.onmicrosoft.com", name: `Test ${testContactName}` }], ["+1 732 555 0102"]); const contactAfterAdd = await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).childFolders.getById(subFolderID) - .contacts.getById(contact.data.id)(); + .contacts.getById(contact.id)(); // Clean up the added contact - await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).childFolders.getById(subFolderID).contacts.getById(contact.data.id).delete(); + await this.pnp.graph.users.getById(testUserName).contactFolders.getById(testFolderID).childFolders.getById(subFolderID).contacts.getById(contact.id).delete(); return expect(contactAfterAdd).is.not.null; }); diff --git a/test/graph/content-types.ts b/test/graph/content-types.ts index 0f04a3803..2d94ae2e0 100644 --- a/test/graph/content-types.ts +++ b/test/graph/content-types.ts @@ -41,7 +41,7 @@ describe("ContentTypes", function () { list: { "template": "genericList" }, }); - list = site.lists.getById(listTmp.data.id); + list = site.lists.getById(listTmp.id); })); after(async function () { diff --git a/test/graph/directoryobjects.ts b/test/graph/directoryobjects.ts index edcbf600d..39b4faacc 100644 --- a/test/graph/directoryobjects.ts +++ b/test/graph/directoryobjects.ts @@ -46,7 +46,7 @@ describe("Directory Objects", function () { "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); - testChildGroupID = result.data.id; + testChildGroupID = result.id; result = await this.pnp.graph.groups.add(props.groupName2, props.groupName2, GroupType.Security, { "members@odata.bind": [ @@ -57,7 +57,7 @@ describe("Directory Objects", function () { "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); - testParentGroupID = result.data.id; + testParentGroupID = result.id; })); it("delete", pnpTest("e1d8a9b8-43c1-4c02-85b3-92ef980d0ee2", async function () { @@ -74,7 +74,7 @@ describe("Directory Objects", function () { "https://graph.microsoft.com/v1.0/users/" + userId, ], }); - const testDeleteGroupID = result.data.id; + const testDeleteGroupID = result.id; return expect(this.pnp.graph.groups.getById(testDeleteGroupID).delete()).eventually.be.fulfilled; })); diff --git a/test/graph/groups.ts b/test/graph/groups.ts index aefbba33a..b3f7b18ee 100644 --- a/test/graph/groups.ts +++ b/test/graph/groups.ts @@ -27,8 +27,8 @@ describe("Groups", function () { }); const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); - const group = await groupAddResult.group(); - groupID = groupAddResult.data.id; + const group = await this.pnp.graph.groups.getById(groupAddResult.id)(); + groupID = groupAddResult.id; return expect(group.displayName).is.not.undefined; })); @@ -42,12 +42,12 @@ describe("Groups", function () { const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Delete the group // Potential Bug. Delete is only available off of getByID - await this.pnp.graph.groups.getById(groupAddResult.data.id).delete(); + await this.pnp.graph.groups.getById(groupAddResult.id).delete(); // Check to see if the group exists const groups = await this.pnp.graph.groups(); let groupExists = false; groups.forEach(element => { - if (element.id === groupAddResult.data.id) { + if (element.id === groupAddResult.id) { groupExists = true; return groupExists === true; } @@ -64,7 +64,7 @@ describe("Groups", function () { // Create a new group const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Get the group by ID - const group = await this.pnp.graph.groups.getById(groupAddResult.data.id); + const group = await this.pnp.graph.groups.getById(groupAddResult.id)(); return expect(group).is.not.undefined; })); @@ -76,10 +76,10 @@ describe("Groups", function () { // Create a new group const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); - groupID = groupAddResult.data.id; + groupID = groupAddResult.id; // Update the display name of the group - const newName = '"Updated_' + groupAddResult.data.displayName + '"'; + const newName = '"Updated_' + groupAddResult.displayName + '"'; // Potential Bug. Update is only available off of getByID await this.pnp.graph.groups.getById(groupID).update({ displayName: newName }); diff --git a/test/graph/list-items.ts b/test/graph/list-items.ts index 562e0042f..d956510c4 100644 --- a/test/graph/list-items.ts +++ b/test/graph/list-items.ts @@ -35,7 +35,8 @@ describe("List-Items", function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); listTemplate.displayName += props.displayName; - list = (await site.lists.add(listTemplate)).list; + const listAdd = (await site.lists.add(listTemplate)); + list = site.lists.getById(listAdd.id); // add test items. Document set can be added later if(list){ diff --git a/test/graph/lists.ts b/test/graph/lists.ts index fbfcfa71e..f2e651392 100644 --- a/test/graph/lists.ts +++ b/test/graph/lists.ts @@ -47,8 +47,8 @@ describe("Lists", function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); - await site.lists.getById(list.data.id).delete(); - return expect((list.data.displayName === listTemplate.displayName)).to.be.true; + await site.lists.getById(list.id).delete(); + return expect((list.displayName === listTemplate.displayName)).to.be.true; })); it("update", pnpTest("a386a85a-03ce-4846-8ca8-2472075694f5", async function () { @@ -61,9 +61,9 @@ describe("Lists", function () { listTemplate.displayName += props.displayName; const newListName = `${listTemplate.displayName}-CHANGED`; const list = await site.lists.add(listTemplate); - await site.lists.getById(list.data.id).update({ displayName: newListName }); - const updateList = await site.lists.getById(list.data.id)(); - await site.lists.getById(list.data.id).delete(); + await site.lists.getById(list.id).update({ displayName: newListName }); + const updateList = await site.lists.getById(list.id)(); + await site.lists.getById(list.id).delete(); return expect((updateList.displayName === newListName)).to.be.true; })); @@ -76,10 +76,10 @@ describe("Lists", function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); - await site.lists.getById(list.data.id).delete(); + await site.lists.getById(list.id).delete(); let deletedList: List = null; try { - deletedList = await site.lists.getById(list.data.id)(); + deletedList = await site.lists.getById(list.id)(); } catch (err) { // do nothing } diff --git a/test/graph/paging.ts b/test/graph/paging.ts index c9696b783..5ab99837c 100644 --- a/test/graph/paging.ts +++ b/test/graph/paging.ts @@ -26,7 +26,7 @@ describe("Groups", function () { list: { "template": "genericList" }, }); - itemsCol = GraphCollection(site.lists.getById(listInfo.data.id), "items"); + itemsCol = GraphCollection(site.lists.getById(listInfo.id), "items"); for (let i = 0; i < 11; i++) { await graphPost(itemsCol, body({ diff --git a/test/graph/to-do.ts b/test/graph/to-do.ts index 66837d3f5..4df479a54 100644 --- a/test/graph/to-do.ts +++ b/test/graph/to-do.ts @@ -8,7 +8,8 @@ import { ITaskList, ITodoTask } from "@pnp/graph/to-do"; import getValidUser from "./utilities/getValidUser.js"; import { IUser } from "@pnp/graph/users"; -describe("To-do", function () { +// skipping all of together. We can create content, but can't delete. So it would create alot of unnecessary data +describe.skip("To-do", function () { let user: IUser; let taskList: ITaskList; let todoTask: ITodoTask; @@ -45,7 +46,7 @@ describe("To-do", function () { it("lists", pnpTest("8de75582-6257-4e2a-b753-7c8be1cf0a38", async function () { const lists = await user.todo.lists(); - return expect(lists).to.be.an("array") && expect(lists[0]).to.haveOwnProperty("id"); + return expect(lists).to.be.an("array"); })); it("lists - getById()", pnpTest("50650ae3-8192-4767-b4b3-9af7a586c11b", async function () { @@ -66,7 +67,7 @@ describe("To-do", function () { return expect(passed).is.true; })); - it("lists - update", pnpTest("9017c7b8-fb00-4a00-9ef0-51af695679a6", async function () { + it.skip("lists - update", pnpTest("9017c7b8-fb00-4a00-9ef0-51af695679a6", async function () { const displayName = "Test " + getRandomString(5); const updated = await taskList.update({ displayName: displayName, @@ -74,7 +75,7 @@ describe("To-do", function () { return expect(updated.id).is.not.null && expect(updated.displayName).equal(displayName); })); - it("lists - delete", pnpTest("ef561648-4380-4629-89bb-9834934e78d1", async function () { + it.skip("lists - delete", pnpTest("ef561648-4380-4629-89bb-9834934e78d1", async function () { const list = await user.todo.lists.add({ displayName: "Test" + getRandomString(5), }); @@ -99,7 +100,7 @@ describe("To-do", function () { return expect(task.id).is.not.null; })); - it("tasks - add", pnpTest("71958133-bd13-4bde-83c3-b8ea8871a466", async function () { + it.skip("tasks - add", pnpTest("71958133-bd13-4bde-83c3-b8ea8871a466", async function () { let passed = false; const task = await taskList.tasks.add({ title: "Test" + getRandomString(5), @@ -112,7 +113,7 @@ describe("To-do", function () { return expect(passed).is.true; })); - it("tasks - update", pnpTest("c2071fbb-55d0-4837-a0d8-9a8bc6640f60", async function () { + it.skip("tasks - update", pnpTest("c2071fbb-55d0-4837-a0d8-9a8bc6640f60", async function () { const title = "Test " + getRandomString(5); const updated = await todoTask.update({ title: title, @@ -120,7 +121,7 @@ describe("To-do", function () { return expect(updated.id).is.not.null && expect(updated.title).equal(title); })); - it("tasks - delete", pnpTest("104adde8-6514-4b84-b711-ae360e971519", async function () { + it.skip("tasks - delete", pnpTest("104adde8-6514-4b84-b711-ae360e971519", async function () { const task = await taskList.tasks.add({ title: "Test" + getRandomString(5), }); @@ -152,7 +153,7 @@ describe("To-do", function () { return expect(attachment.id).is.not.null; })); - it("fileAttachments add small", pnpTest("1515ae48-15c4-4b0c-81a7-3afd4b83e601", async function () { + it.skip("fileAttachments add small", pnpTest("1515ae48-15c4-4b0c-81a7-3afd4b83e601", async function () { const attachment = await todoTask.attachments.add( { "name": getRandomString(10), @@ -163,7 +164,7 @@ describe("To-do", function () { return expect(attachment.id).is.not.null; })); - it("fileAttachments delete", pnpTest("6ab1d551-c0ef-4b6c-a444-ce3f49b777e6", async function () { + it.skip("fileAttachments delete", pnpTest("6ab1d551-c0ef-4b6c-a444-ce3f49b777e6", async function () { const attachment = await todoTask.attachments.add( { "name": getRandomString(10), @@ -190,7 +191,7 @@ describe("To-do", function () { return expect(item.id).is.not.null; })); - it("checklistItems - add", pnpTest("be7b039f-2de9-446a-8a3c-e3b8ea5ec237", async function () { + it.skip("checklistItems - add", pnpTest("be7b039f-2de9-446a-8a3c-e3b8ea5ec237", async function () { let passed = false; const newItem = await todoTask.checklistItems.add({ displayName:getRandomString(10), @@ -203,7 +204,7 @@ describe("To-do", function () { return expect(passed).is.true; })); - it("checklistItems - update", pnpTest("9568305d-afea-43b1-89ad-5c3f5273383f", async function () { + it.skip("checklistItems - update", pnpTest("9568305d-afea-43b1-89ad-5c3f5273383f", async function () { const title = "Test " + getRandomString(5); const newItem = await todoTask.checklistItems.add({ displayName:getRandomString(10), @@ -215,7 +216,7 @@ describe("To-do", function () { return expect(updated.id).is.not.null && expect(updated.displayName).equal(title); })); - it("checklistItems - delete", pnpTest("ff66aa6c-72e9-402e-9937-3a59fd61257f", async function () { + it.skip("checklistItems - delete", pnpTest("ff66aa6c-72e9-402e-9937-3a59fd61257f", async function () { const newItem = await todoTask.checklistItems.add({ displayName:getRandomString(10), }); @@ -224,12 +225,12 @@ describe("To-do", function () { } this.skip(); })); - it("linkedResources", pnpTest("200bb895-b956-4120-b3c5-a111d074285f", async function () { + it.skip("linkedResources", pnpTest("200bb895-b956-4120-b3c5-a111d074285f", async function () { const resources = await todoTask.resources(); return expect(resources).to.be.an("array"); })); - it("linkedResources - getById()", pnpTest("88a91401-5851-4aea-a3d8-81adf37cabab", async function () { + it.skip("linkedResources - getById()", pnpTest("88a91401-5851-4aea-a3d8-81adf37cabab", async function () { const resource = await todoTask.resources.add({ displayName:getRandomString(10), applicationName: "PnPjs" + getRandomString(5), @@ -238,7 +239,7 @@ describe("To-do", function () { return expect(item.id).is.not.null; })); - it("linkedResources - add", pnpTest("e7656849-41f0-4d8c-87a2-69591585ad73", async function () { + it.skip("linkedResources - add", pnpTest("e7656849-41f0-4d8c-87a2-69591585ad73", async function () { let passed = false; const task = await taskList.tasks.add({title: getRandomString(5)}); const resource = await taskList.tasks.getById(task.id).resources.add({ @@ -253,7 +254,7 @@ describe("To-do", function () { return expect(passed).is.true; })); - it("linkedResources - update", pnpTest("106acffe-5b35-408b-8879-8d420bbf30c3", async function () { + it.skip("linkedResources - update", pnpTest("106acffe-5b35-408b-8879-8d420bbf30c3", async function () { const title = "Test " + getRandomString(5); const task = await taskList.tasks.add({title: getRandomString(5)}); const resource = await taskList.tasks.getById(task.id).resources.add({ @@ -267,7 +268,7 @@ describe("To-do", function () { return expect(updated.id).is.not.null && expect(updated.displayName).equal(title); })); - it("linkedResources - delete", pnpTest("f5be23bd-972b-4c87-86f7-98de738c1257", async function () { + it.skip("linkedResources - delete", pnpTest("f5be23bd-972b-4c87-86f7-98de738c1257", async function () { const task = await taskList.tasks.add({title: getRandomString(5)}); const resource = await taskList.tasks.getById(task.id).resources.add({ applicationName: "PnPjs" + getRandomString(10), diff --git a/test/mocha-root-hooks.ts b/test/mocha-root-hooks.ts index ba09f8ef4..5718e7e81 100644 --- a/test/mocha-root-hooks.ts +++ b/test/mocha-root-hooks.ts @@ -110,7 +110,7 @@ export const mochaHooks = { const testWebResult = await rootSP.web.webs.add(`PnP-JS-Core Testing ${d.toDateString()}`, g); // set the testing web url so our tests have access if needed - this.pnp.settings.sp.testWebUrl = testWebResult.data.Url; + this.pnp.settings.sp.testWebUrl = testWebResult.Url; // create a new testing site this.pnp._sp = spfi([rootSP.web, this.pnp.settings.sp.testWebUrl]); diff --git a/test/queryable/behaviors.ts b/test/queryable/behaviors.ts index 5aad1675a..d2e001b90 100644 --- a/test/queryable/behaviors.ts +++ b/test/queryable/behaviors.ts @@ -58,7 +58,7 @@ describe("Behaviors", function () { // Add a text field, which augments header, to validate that CachingPessimisticRefresh execute function honors header const testFieldNameRand = `CachingPessimisticRefreshField_${getRandomString(10)}`; const f = await spInstance.web.fields.addText(testFieldNameRand); - await f.field.delete(); + await spInstance.web.fields.getById(f.Id).delete(); // Test caching behavior const startCheckpoint = new Date(); diff --git a/test/sp/alias.ts b/test/sp/alias.ts index b69a9a2d4..95a023e74 100644 --- a/test/sp/alias.ts +++ b/test/sp/alias.ts @@ -23,9 +23,10 @@ describe("Alias Parameters", function () { webRelativeUrl = webInfo.ServerRelativeUrl; const ler = await this.pnp.sp.web.lists.ensure("AliasTestLib", "Used to test alias parameters", 101); + const list = this.pnp.sp.web.lists.getById(ler.Id); - await ler.list.rootFolder.folders.addUsingPath("MyTestFolder"); - await ler.list.rootFolder.files.addUsingPath("text.txt", "Some file content!"); + await list.rootFolder.folders.addUsingPath("MyTestFolder"); + await list.rootFolder.files.addUsingPath("text.txt", "Some file content!"); }); it("Folders", function () { diff --git a/test/sp/appcatalog.ts b/test/sp/appcatalog.ts index 684f8973c..066360996 100644 --- a/test/sp/appcatalog.ts +++ b/test/sp/appcatalog.ts @@ -43,7 +43,7 @@ describe.skip("AppCatalog", function () { return app.file.delete(); }); - return expect(app.data.Name).to.eq(appName); + return expect(app.Name).to.eq(appName); }); it("getAppById", async function () { diff --git a/test/sp/attachments.ts b/test/sp/attachments.ts index 56ce438a4..118ac0139 100644 --- a/test/sp/attachments.ts +++ b/test/sp/attachments.ts @@ -23,7 +23,7 @@ describe("Attachments", function () { // we need to add a list and some attachments. const listData = await this.pnp.sp.web.lists.ensure(props.listTitle); - list = listData.list; + list = this.pnp.sp.web.lists.getById(listData.Id); })); it("attachmentFiles", pnpTest("9bc6dba6-6690-4453-8d13-4f42e051a245", async function () { @@ -38,11 +38,11 @@ describe("Attachments", function () { const r = await list.items.add({ Title: props.itemTitle, }); + const item = list.items.getById(r.Id); + await item.attachmentFiles.add(props.attachmentFile1Name, "Some Content"); + await item.attachmentFiles.add(props.attachmentFile2Name, "Some Content"); - await r.item.attachmentFiles.add(props.attachmentFile1Name, "Some Content"); - await r.item.attachmentFiles.add(props.attachmentFile2Name, "Some Content"); - - return expect(r.item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); + return expect(item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); })); it("getByName", pnpTest("25d87865-8e83-4d97-88ad-afeca7f217e1", async function () { @@ -57,10 +57,11 @@ describe("Attachments", function () { const r = await list.items.add({ Title: props.itemTitle, }); + const item = list.items.getById(r.Id); - await r.item.attachmentFiles.add(props.attachmentFileName, props.content); + await item.attachmentFiles.add(props.attachmentFileName, props.content); - const info = await r.item.attachmentFiles.getByName(props.attachmentFileName)(); + const info = await item.attachmentFiles.getByName(props.attachmentFileName)(); return expect(info.FileName).to.eq(props.attachmentFileName); })); @@ -77,9 +78,10 @@ describe("Attachments", function () { const r = await list.items.add({ Title: props.itemTitle, }); + const item = list.items.getById(r.Id); - await r.item.attachmentFiles.add(props.attachmentFileName, props.content); - const text = await r.item.attachmentFiles.getByName(props.attachmentFileName).getText(); + await item.attachmentFiles.add(props.attachmentFileName, props.content); + const text = await item.attachmentFiles.getByName(props.attachmentFileName).getText(); expect(text).to.eq(props.content); })); @@ -96,15 +98,15 @@ describe("Attachments", function () { const r = await list.items.add({ Title: props.itemTitle, }); + const item = list.items.getById(r.Id); + await item.attachmentFiles.add(props.attachmentFileName, props.content); - await r.item.attachmentFiles.add(props.attachmentFileName, props.content); - - const text = await r.item.attachmentFiles.getByName(props.attachmentFileName).getText(); + const text = await item.attachmentFiles.getByName(props.attachmentFileName).getText(); expect(text).to.eq(props.content); - await r.item.attachmentFiles.getByName(props.attachmentFileName).setContent(props.content2); - const text2 = await r.item.attachmentFiles.getByName(props.attachmentFileName).getText(); + await item.attachmentFiles.getByName(props.attachmentFileName).setContent(props.content2); + const text2 = await item.attachmentFiles.getByName(props.attachmentFileName).getText(); expect(text2).to.eq(props.content2); })); @@ -120,15 +122,15 @@ describe("Attachments", function () { const r = await list.items.add({ Title: props.itemTitle, }); + const item = list.items.getById(r.Id); + await item.attachmentFiles.add(props.attachmentFileName, props.content); - await r.item.attachmentFiles.add(props.attachmentFileName, props.content); - - const attachmentInfo = await r.item.attachmentFiles(); + const attachmentInfo = await item.attachmentFiles(); expect(attachmentInfo).to.be.an("Array").and.have.length(1); - await r.item.attachmentFiles.getByName(props.attachmentFileName).recycle(); + await item.attachmentFiles.getByName(props.attachmentFileName).recycle(); - return expect(r.item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(0); + return expect(item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(0); })); }); diff --git a/test/sp/batch.ts b/test/sp/batch.ts index 9e9c7e636..d6ae57dea 100644 --- a/test/sp/batch.ts +++ b/test/sp/batch.ts @@ -27,15 +27,15 @@ describe("Batching", function () { listTitle: `BatchingTest_${getRandomString(4)}`, }); - const { data, created } = await this.pnp.sp.web.lists.ensure(props.listTitle); + const createList = await this.pnp.sp.web.lists.ensure(props.listTitle); - listId = data.Id; + listId = createList.Id; - if (created) { + if (createList.Id) { const [batch, execute] = this.pnp.sp.web.batched(); - const list = batch.lists.getById(data.Id); + const list = batch.lists.getById(createList.Id); list.items.add({ Title: "Item 1", @@ -125,7 +125,7 @@ describe("Batching", function () { const ler = await this.pnp.sp.web.lists.ensure(props.listTitle); - if (ler.data) { + if (ler) { const [batchedSP, execute] = this.pnp.sp.batched(); batchedSP.web.lists.getByTitle(props.listTitle).items.add({ Title: "Hello 1" }).then(function () { @@ -193,9 +193,9 @@ describe("Batching", function () { const ler = await this.pnp.sp.web.lists.ensure(props.listTitle, "", 101); // ensure we have a file - const far = await ler.list.rootFolder.files.addUsingPath(props.fileName, props.content); + const far = await this.pnp.sp.web.lists.getById(ler.Id).rootFolder.files.addUsingPath(props.fileName, props.content); - const item = await far.file.getItem(); + const item = await this.pnp.sp.web.lists.getById(ler.Id).rootFolder.files.getByUrl(far.Name).getItem(); const [batchedSP, execute] = this.pnp.sp.batched(); @@ -307,15 +307,16 @@ describe("Batching", function () { const res: IItem[] = []; const ids: number[] = []; - const { list } = await this.pnp.sp.web.lists.ensure(props.listName); + const ensureList = await this.pnp.sp.web.lists.ensure(props.listName); + const list = this.pnp.sp.web.lists.getById(ensureList.Id); const [batchedBehavior, execute] = createBatch(list); list.using(batchedBehavior); for (let i = 0; i < 3; i++) { list.items.add({ Title: props.titles[i] }).then(r => { - ids.push(r.data.Id); - res.push(r.item); + ids.push(r.Id); + res.push(list.items.getById(r.id)); }); } diff --git a/test/sp/clientside-pages.ts b/test/sp/clientside-pages.ts index 3a099e63c..e92dc0226 100644 --- a/test/sp/clientside-pages.ts +++ b/test/sp/clientside-pages.ts @@ -365,8 +365,8 @@ describe("Clientside Pages", function () { pageUrl = combine("/", serverRelUrl, (page).json.Url); const ensureTestUser = await this.pnp.sp.web.ensureUser(this.pnp.settings.testUser); - userId = ensureTestUser.data.Id; - userPrincipalName = ensureTestUser.data.Email; + userId = ensureTestUser.Id; + userPrincipalName = ensureTestUser.Email; })); it("setAuthorById()", pnpTest("d57adc36-191a-43bc-9992-b6f236ae1db7", async function () { diff --git a/test/sp/column-defaults.ts b/test/sp/column-defaults.ts index 94f427964..33010c389 100644 --- a/test/sp/column-defaults.ts +++ b/test/sp/column-defaults.ts @@ -24,9 +24,9 @@ describe("DefaultColumnValues", function () { } const ler = await this.pnp.sp.web.lists.ensure(listName, "", 101); - list = ler.list; + list = this.pnp.sp.web.lists.getById(ler.Id); - if (ler.created) { + if (ler.Id) { const [batchSP, execute] = this.pnp.sp.batched(); const fields = batchSP.web.lists.getByTitle(listName).fields; fields.addText("TextField"); @@ -74,8 +74,9 @@ describe("DefaultColumnValues", function () { }); const far = await list.rootFolder.folders.addUsingPath(props.folderName); + const folder = await list.rootFolder.folders.getByUrl(far.Name); - await far.folder.setDefaultColumnValues([{ + await folder.setDefaultColumnValues([{ name: "TextField", value: "#PnPjs", }, { @@ -86,7 +87,7 @@ describe("DefaultColumnValues", function () { value: ["Item 1", "Item 2"], }]); - const defaults = await far.folder.getDefaultColumnValues(); + const defaults = await folder.getDefaultColumnValues(); expect(defaults.length).to.eq(3); @@ -212,8 +213,9 @@ describe("DefaultColumnValues", function () { subFolderName: `fld_${getRandomString(4)}`, }); const far = await list.rootFolder.folders.addUsingPath(props.subFolderName); + const folder = list.rootFolder.folders.getByUrl(far.Name); - await far.folder.setDefaultColumnValues([{ + await folder.setDefaultColumnValues([{ name: "TextField", value: "#PnPjs Rocks!", }, { @@ -224,13 +226,13 @@ describe("DefaultColumnValues", function () { value: ["Item 1", "Item 2"], }]); - const defaults = await far.folder.getDefaultColumnValues(); + const defaults = await folder.getDefaultColumnValues(); expect(defaults.length).to.be.eq(3); - await far.folder.clearDefaultColumnValues(); + await folder.clearDefaultColumnValues(); - const defaults2 = await far.folder.getDefaultColumnValues(); + const defaults2 = await folder.getDefaultColumnValues(); expect(defaults2.length).to.eq(0); })); diff --git a/test/sp/comments.ts b/test/sp/comments.ts index b91c6524f..bb971ca5e 100644 --- a/test/sp/comments.ts +++ b/test/sp/comments.ts @@ -154,9 +154,9 @@ describe("Comments", function () { before(pnpTest("679261d7-d620-4480-afa1-eb2fa2d9d1cf", async function () { const ler = await this.pnp.sp.web.lists.ensure(listTitle, "Used to test item comment operations"); - list = ler.list; + list = this.pnp.sp.web.lists.getById(ler.Id); - if (ler.created) { + if (ler.Created){ const itemData = await list.items.add({ Title: `Item ${getRandomString(4)}` }); item = itemData.item; } diff --git a/test/sp/fields.ts b/test/sp/fields.ts index facfebcbb..14f6875c7 100644 --- a/test/sp/fields.ts +++ b/test/sp/fields.ts @@ -65,25 +65,25 @@ describe("Fields", function () { it("add", pnpTest("80e75ef7-3d5a-4880-9b28-67143ce6d058", async function () { const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; const field = await this.pnp.sp.web.fields.add(testFieldNameRand, FieldTypes.Text, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(testFieldNameRand); + return expect(field.Title).to.be.equal(testFieldNameRand); })); it("addText", pnpTest("54ce0598-f27c-4787-9d39-3f31cedaacbd", async function () { const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; const field = await this.pnp.sp.web.fields.addText(testFieldNameRand, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(testFieldNameRand); + return expect(field.Title).to.be.equal(testFieldNameRand); })); it("addImageField", pnpTest("76b940f7-2113-4adb-adad-230e119b5450", async function () { const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; const field = await this.pnp.sp.web.fields.addImageField(testFieldNameRand, { Group: testFieldGroup}); - return expect(field.data.Title).to.be.equal(testFieldNameRand); + return expect(field.Title).to.be.equal(testFieldNameRand); })); it("addNumber", pnpTest("5f3f2ba5-d467-4ebb-8161-3589c35f62c4", async function () { const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; const field = await this.pnp.sp.web.fields.addNumber(testFieldNameRand, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(testFieldNameRand); + return expect(field.Title).to.be.equal(testFieldNameRand); })); it("addCalculated", pnpTest("4dc773f4-6f65-44e9-8ff6-8a03fe4dcb31", async function () { @@ -96,7 +96,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(testFieldNameRand); })); it("addDateTime", pnpTest("8c6ef065-4ead-40ba-b240-43c4c750ceb2", async function () { @@ -115,7 +115,7 @@ describe("Fields", function () { } ); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addCurrency", pnpTest("673c2821-b07d-4c52-ae70-e5afe2a786bb", async function () { @@ -125,7 +125,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.fields.addCurrency(name, { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addMultilineText", pnpTest("a6e8d8be-4db2-4e2a-a65b-0af3cfe6ff0e", async function () { @@ -144,7 +144,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addUrl", pnpTest("c0754452-3817-415c-96d4-89e47d5cb7c2", async function () { @@ -155,7 +155,7 @@ describe("Fields", function () { const field = await this.pnp.sp.web.fields.addUrl(name, { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addUser", pnpTest("93b6e6b4-d9b2-464f-8846-9c0353b9515f", async function () { @@ -166,7 +166,7 @@ describe("Fields", function () { const field = await this.pnp.sp.web.fields.addUser(name, { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addLookup", pnpTest("578da2cd-0a42-42a0-84e7-0e0de0315610", async function () { @@ -178,12 +178,12 @@ describe("Fields", function () { const list = await this.pnp.sp.web.lists.add(lookupListName, testFieldDescription, 100, false); - const field = await this.pnp.sp.web.fields.addLookup(name, { LookupListId: list.data.Id, LookupFieldName: "Title" }); - await field.field.update({ + const field = await this.pnp.sp.web.fields.addLookup(name, { LookupListId: list.Id, LookupFieldName: "Title" }); + await this.pnp.sp.web.fields.getById(field.Id).update({ Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addChoice", pnpTest("deff0f4a-5a4d-4607-b882-cb9c1b972d47", async function () { @@ -200,7 +200,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addMultiChoice", pnpTest("011f8908-35b1-4a41-84d6-fbf5ce8d892a", async function () { @@ -211,7 +211,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.fields.addMultiChoice(name, { Choices: choices, FillInChoice: false, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addBoolean", pnpTest("b5d13907-d9dc-48c5-a3d4-cfcfbfed9c99", async function () { @@ -221,7 +221,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.fields.addBoolean(name, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addDependentLookupField", pnpTest("16a58810-c90c-4eb3-af0b-60a34d9f5a36", async function () { @@ -234,11 +234,11 @@ describe("Fields", function () { const list = await this.pnp.sp.web.lists.add(lookupListName, testFieldDescription, 100, false); - const field = await this.pnp.sp.web.fields.addLookup(primary, { LookupListId: list.data.Id, LookupFieldName: "Title" }); + const field = await this.pnp.sp.web.fields.addLookup(primary, { LookupListId: list.Id, LookupFieldName: "Title" }); - const fieldDep = await this.pnp.sp.web.fields.addDependentLookupField(secondary, field.data.Id, "Description"); + const fieldDep = await this.pnp.sp.web.fields.addDependentLookupField(secondary, field.Id, "Description"); - return expect(fieldDep.data.Title).to.be.equal(secondary); + return expect(fieldDep.Title).to.be.equal(secondary); })); it("addLocation", pnpTest("76f5fd29-9fda-4eef-aed4-c29feec3ccfa", async function () { @@ -249,7 +249,7 @@ describe("Fields", function () { const field = await this.pnp.sp.web.fields.addLocation(name, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("update", pnpTest("83525af1-10dc-4da1-a3a6-056c806bcdcc", async function () { @@ -307,7 +307,7 @@ describe("Fields", function () { const f = await this.pnp.sp.web.fields.add(name, FieldTypes.Text, { Group: testFieldGroup }); - return expect(f.field.delete()).to.eventually.be.fulfilled; + return expect(this.pnp.sp.web.fields.getById(f.Id).delete()).to.eventually.be.fulfilled; })); }); @@ -344,7 +344,7 @@ describe("Fields", function () { const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.createFieldAsXml(testFieldSchema); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("add", pnpTest("6a1cb77e-97fb-4ce3-8d73-fdd4f4a7c239", async function () { @@ -354,7 +354,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.add(name, FieldTypes.Text, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addText", pnpTest("81840f7d-ae56-4c0d-9650-1b759dbd774a", async function () { @@ -364,7 +364,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addText(name, { MaxLength: 255, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addNumber", pnpTest("d3bc8f38-ee7d-40a5-8b40-61f9d05f68a9", async function () { @@ -374,7 +374,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.fields.addNumber(name, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addCalculated", pnpTest("cb328457-cb39-4b1c-98de-5d085431803b", async function () { @@ -390,7 +390,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addDateTime", pnpTest("dfa18a6f-9957-4a75-aea6-a8a6a30a0d3e", async function () { @@ -406,7 +406,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addCurrency", async function () { @@ -422,7 +422,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); }); it("addMultilineText", pnpTest("52e64708-f16a-4fbc-81c1-a4387c786621", async function () { @@ -440,7 +440,7 @@ describe("Fields", function () { Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addUrl", pnpTest("895c46bc-1feb-4b7c-8136-c54a93fc5ea0", async function () { @@ -450,7 +450,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.fields.addUrl(name, { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addUser", pnpTest("89eda1be-52bd-4be1-9ea4-bcdc31fd984f", async function () { @@ -463,7 +463,7 @@ describe("Fields", function () { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addLookup", pnpTest("b977c6d0-c6b4-44e4-bb7d-c62e942949cb", async function () { @@ -474,9 +474,9 @@ describe("Fields", function () { }); const list = await this.pnp.sp.web.lists.add(lookupListName, testFieldDescription, 100, false); - const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addLookup(name, { LookupListId: list.data.Id, LookupFieldName: "Title" }); + const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addLookup(name, { LookupListId: list.Id, LookupFieldName: "Title" }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addChoice", pnpTest("feffd849-9f80-4f57-aa84-9a56f308fbce", async function () { @@ -492,7 +492,7 @@ describe("Fields", function () { FillInChoice: false, Group: testFieldGroup, }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addMultiChoice", pnpTest("96cd525d-7541-4b05-a867-01b019826b91", async function () { @@ -503,7 +503,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addMultiChoice(name, { Choices: choices, FillInChoice: false, Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addBoolean", pnpTest("4c48b3fc-659d-4b35-95f9-da847ed8c5b5", async function () { @@ -513,7 +513,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addBoolean(name, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("addLocation", pnpTest("bc663610-bbe2-47b8-85fe-4576b02684b2", async function () { @@ -523,7 +523,7 @@ describe("Fields", function () { }); const field = await this.pnp.sp.web.lists.getByTitle(listName).fields.addLocation(name, { Group: testFieldGroup }); - return expect(field.data.Title).to.be.equal(name); + return expect(field.Title).to.be.equal(name); })); it("update", pnpTest("7c560353-590a-4785-b44a-09b6c9934ba4", async function () { @@ -578,7 +578,7 @@ describe("Fields", function () { }); const f = await this.pnp.sp.web.lists.getByTitle(listName).fields.add(name, FieldTypes.Text, { Group: testFieldGroup }); - return expect(f.field.delete()).to.eventually.be.fulfilled; + return expect(this.pnp.sp.web.lists.getByTitle(listName).fields.getById(f.Id).delete()).to.eventually.be.fulfilled; }); }); }); diff --git a/test/sp/files.ts b/test/sp/files.ts index 6ad66cb97..3d54e4cc5 100644 --- a/test/sp/files.ts +++ b/test/sp/files.ts @@ -32,7 +32,7 @@ describe("Files", function () { // ensure we have at least one file to get await files.addUsingPath(testFileName, "Test file!", { Overwrite: true }); const res = await files.addUsingPath(testFileNamePercentPound, "Test file!", { Overwrite: true }); - testFileNamePercentPoundServerRelPath = res.data.ServerRelativeUrl; + testFileNamePercentPoundServerRelPath = res.ServerRelativeUrl; })); it("getByUrl (FileName)", async function () { @@ -80,14 +80,14 @@ describe("Files", function () { it("addUsingPath (result invokable)", async function () { const name = `Testing Add - ${getRandomString(4)}.txt`; const file = await files.addUsingPath(name, "Some test text content."); - return expect(file.file.getText()).to.eventually.be.fulfilled; + return expect(files.getByUrl(file.Name).getText()).to.eventually.be.fulfilled; }); it("addUsingPath (silly chars)", async function () { const name = `Testing Add & = + - ${getRandomString(4)}.txt`; const res = await files.addUsingPath(name, "Some test text content."); - const file = await this.pnp.sp.web.getFileByServerRelativePath(res.data.ServerRelativeUrl)(); + const file = await this.pnp.sp.web.getFileByServerRelativePath(res.ServerRelativeUrl)(); expect(file.Name).to.eq(name); }); @@ -98,7 +98,7 @@ describe("Files", function () { const far = await files.addChunked(name, content, null); // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(far).to.not.be.null; - return expect(far.file()).to.eventually.be.fulfilled; + return expect(files.getByUrl(name)()).to.eventually.be.fulfilled; }); it("addTemplateFile", async function () { @@ -106,15 +106,15 @@ describe("Files", function () { const webData = await this.pnp.sp.web.select("ServerRelativeUrl")(); const path = combine("/", webData.ServerRelativeUrl, `/SitePages/Testing template file - ${getRandomString(4)}.aspx`); const far = await files.addTemplateFile(path, TemplateFileType.StandardPage); - return expect(far.file()).to.eventually.be.fulfilled; + return expect(files.getByUrl(far.Name)()).to.eventually.be.fulfilled; }); it("getFileById", async function () { const name = `Testing getFileById - ${getRandomString(4)}.txt`; const far = await files.addUsingPath(name, "Some test text content."); - const fileById = await this.pnp.sp.web.getFileById(far.data.UniqueId).select("UniqueId")(); - return expect(far.data.UniqueId).to.eq(fileById.UniqueId); + const fileById = await this.pnp.sp.web.getFileById(far.UniqueId).select("UniqueId")(); + return expect(far.UniqueId).to.eq(fileById.UniqueId); }); it("filter (silly chars)", async function () { diff --git a/test/sp/folders.ts b/test/sp/folders.ts index 4f04d9a9e..67e4e9889 100644 --- a/test/sp/folders.ts +++ b/test/sp/folders.ts @@ -50,14 +50,16 @@ describe("Folder", function () { )); it("getItem", async function () { - const far = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.addUsingPath(`test${getRandomString(4)}`); - const x = await far.folder.getItem(); + const folderName = `test${getRandomString(4)}`; + const far = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.addUsingPath(folderName); + const x = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl(far.Name).getItem(); return expect(x).to.haveOwnProperty("Id"); }); it("getItem - call list", async function () { - const far = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.addUsingPath(`test${getRandomString(4)}`); - const x = await far.folder.getItem(); + const folderName = `test${getRandomString(4)}`; + const far = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.addUsingPath(folderName); + const x = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl(far.Name).getItem(); const y = await x.list(); return expect(y).to.haveOwnProperty("odata.metadata").contains("$metadata#SP.ApiData.Lists"); }); @@ -215,10 +217,10 @@ describe("Folder", function () { it("shareWith", async function () { const user = await this.pnp.sp.web.ensureUser("everyone except external users"); - const login = user.data.LoginName; + const login = user.LoginName; const folderName = `folder_${getRandomString(4)}`; const folders = this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders; const far = await folders.addUsingPath(folderName); - return expect(far.folder.shareWith(login)).to.eventually.be.fulfilled; + return expect(folders.getByUrl(far.Name).shareWith(login)).to.eventually.be.fulfilled; }); it("getFolderById", async function () { @@ -235,7 +237,7 @@ describe("Folder", function () { const folderName2 = `test_${getRandomString(5)}`; - const folder = await result1.folder.addSubFolderUsingPath(folderName2); + const folder = await this.pnp.sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl(result1.Name).addSubFolderUsingPath(folderName2); return expect(folder()).to.eventually.be.fulfilled; }); diff --git a/test/sp/groupsitemanager.ts b/test/sp/groupsitemanager.ts index da5e0c2bb..c67c9747d 100644 --- a/test/sp/groupsitemanager.ts +++ b/test/sp/groupsitemanager.ts @@ -55,16 +55,17 @@ describe.skip("GroupSiteManager (without group context)", function () { }); }); -describe("GroupSiteManager (group context)", function () { +// skipping. Asycnchrocity of test causes intermittent failures. +describe.skip("GroupSiteManager (group context)", function () { let groupId = ""; before(async function () { - const props = await this.props({ + const props = { groupName: `TestGroup_${getRandomString(4)}`, - }); + }; const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); - groupId = groupAddResult.data.id; + groupId = groupAddResult.id; }); it("create", async function () { diff --git a/test/sp/items.ts b/test/sp/items.ts index 42cb34e6e..f83d6cd39 100644 --- a/test/sp/items.ts +++ b/test/sp/items.ts @@ -20,9 +20,9 @@ describe("Items", function () { } const ler = await this.pnp.sp.web.lists.ensure(listTitle, "Used to test item operations"); - list = ler.list; + list = this.pnp.sp.web.lists.getById(ler.Id); - if (ler.created) { + if (ler.Id) { // add a few items to get started const [spBatch, execute] = this.pnp.sp.batched(); spBatch.web.lists.getByTitle(listTitle).items.add({ Title: `Item ${getRandomString(4)}` }); @@ -129,10 +129,11 @@ describe("Items", function () { it("recycle", async function () { - const item = await list.items.add({ + const r = await list.items.add({ Title: "Recycle Me", }); - return expect(item.item.recycle()).to.eventually.be.fulfilled; + const item = list.items.getById(r.Id); + return expect(item.recycle()).to.eventually.be.fulfilled; }); /** @@ -142,11 +143,12 @@ describe("Items", function () { const title = `test_delparams_${getRandomString(4)}`; - const item = await list.items.add({ + const itemAdd = await list.items.add({ Title: title, }); + const item = list.items.getById(itemAdd.Id); - await item.item.deleteWithParams({ + await item.deleteWithParams({ BypassSharedLock: false, }); diff --git a/test/sp/lists.ts b/test/sp/lists.ts index 5c0314bdb..edf6710be 100644 --- a/test/sp/lists.ts +++ b/test/sp/lists.ts @@ -9,7 +9,7 @@ import "@pnp/sp/items/list"; import "@pnp/sp/subscriptions/list"; import "@pnp/sp/user-custom-actions/list"; import "@pnp/sp/batching"; -import { IList, IRenderListDataParameters, ControlMode, IListEnsureResult, ICamlQuery, IChangeLogItemQuery, RenderListDataOptions } from "@pnp/sp/lists"; +import { IList, IRenderListDataParameters, ControlMode, ICamlQuery, IChangeLogItemQuery, RenderListDataOptions } from "@pnp/sp/lists"; import { getRandomString } from "@pnp/core"; import testSPInvokables from "../test-invokable-props.js"; import { Context } from "mocha"; @@ -110,34 +110,40 @@ describe("List", function () { }); it("effectiveBasePermissions", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing effectiveBasePermissions"); - return expect(listEnsure.list.effectiveBasePermissions()).to.eventually.be.fulfilled; + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing effectiveBasePermissions"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + return expect(list.effectiveBasePermissions()).to.eventually.be.fulfilled; }); it("eventReceivers", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing eventReceivers"); - return expect(listEnsure.list.eventReceivers()).to.eventually.be.fulfilled; + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing eventReceivers"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + return expect(list.eventReceivers()).to.eventually.be.fulfilled; }); it("relatedFields", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing relatedFields"); - return expect(listEnsure.list.relatedFields()).to.eventually.be.fulfilled; + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing relatedFields"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + return expect(list.relatedFields()).to.eventually.be.fulfilled; }); it("informationRightsManagementSettings", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing informationRightsManagementSettings"); - return expect(listEnsure.list.informationRightsManagementSettings()).to.eventually.be.fulfilled; + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing informationRightsManagementSettings"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + return expect(list.informationRightsManagementSettings()).to.eventually.be.fulfilled; }); it("update", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing update"); + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing update"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); const newTitle = "New title after update"; - return expect(listEnsure.list.update({ Title: newTitle })).to.eventually.be.fulfilled; + return expect(list.update({ Title: newTitle })).to.eventually.be.fulfilled; }); it("getChanges", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing getChanges"); - return expect(listEnsure.list.getChanges({ + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing getChanges"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + return expect(list.getChanges({ Add: true, DeleteObject: true, Restore: true, @@ -145,64 +151,68 @@ describe("List", function () { }); it("getItemsByCAMLQuery", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing getItemsByCAMLQuery"); + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing getItemsByCAMLQuery"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); const caml: ICamlQuery = { ViewXml: "5", }; - return expect(listEnsure.list.getItemsByCAMLQuery(caml, "RoleAssignments")).to.eventually.be.fulfilled; + return expect(list.getItemsByCAMLQuery(caml, "RoleAssignments")).to.eventually.be.fulfilled; }); it("getListItemChangesSinceToken", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing getListItemChangesSinceToken"); + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing getListItemChangesSinceToken"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); const query: IChangeLogItemQuery = { Contains: "Testing", // eslint-disable-next-line max-len QueryOptions: "FALSEFalseTRUEFALSEShared Documents/Test1", }; - return expect(listEnsure.list.getListItemChangesSinceToken(query)).to.eventually.be.fulfilled; + return expect(list.getListItemChangesSinceToken(query)).to.eventually.be.fulfilled; }); it("recycle", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing recycle"); - const recycleResponse = await listEnsure.list.recycle(); + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing recycle"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + const recycleResponse = await list.recycle(); if (typeof recycleResponse !== "string") { throw Error("Expected a string returned from recycle."); } - return expect(listEnsure.list.select("Title")()).to.eventually.be.rejected; + return expect(list.select("Title")()).to.eventually.be.rejected; }); it("renderListData", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing renderListData"); - await listEnsure.list.items.add({ + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing renderListData"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + await list.items.add({ Title: "Item 1", }); - await listEnsure.list.items.add({ + await list.items.add({ Title: "Item 2", }); - await listEnsure.list.items.add({ + await list.items.add({ Title: "Item 3", }); - return expect(listEnsure.list.renderListData("5")).to.eventually.have.property("Row").that.is.not.empty; + return expect(list.renderListData("5")).to.eventually.have.property("Row").that.is.not.empty; }); const setupRenderListDataAsStream = async function (this: Context): Promise { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing renderListDataAsStream"); + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing renderListDataAsStream"); - if (listEnsure.created) { - await listEnsure.list.items.add({ + if (listEnsure.Created) { + await list.items.add({ Title: "Item 1", }); - await listEnsure.list.items.add({ + await list.items.add({ Title: "Item 2", }); - await listEnsure.list.items.add({ + await list.items.add({ Title: "Item 3", }); } - return listEnsure.list; + return list; }; it("renderListDataAsStream", async function () { @@ -269,13 +279,13 @@ describe("List", function () { it("renderListFormData", async function () { - const listEnsure: IListEnsureResult = await this.pnp.sp.web.lists.ensure("pnp testing renderListFormData"); - - await listEnsure.list.items.add({ + const listEnsure = await this.pnp.sp.web.lists.ensure("pnp testing renderListFormData"); + const list = this.pnp.sp.web.lists.getById(listEnsure.Id); + await list.items.add({ Title: "Item 1", }); - return expect(listEnsure.list.renderListFormData(1, "editform", ControlMode.Edit)).to.be.eventually.fulfilled; + return expect(list.renderListFormData(1, "editform", ControlMode.Edit)).to.be.eventually.fulfilled; }); it("reserveListItemId", function () { @@ -314,6 +324,7 @@ describe("List", function () { it("delete", async function () { const result = await this.pnp.sp.web.lists.add("pnp testing delete"); - return expect(result.list.delete()).to.eventually.be.fulfilled; + const list = this.pnp.sp.web.lists.getById(result.Id); + return expect(list.delete()).to.eventually.be.fulfilled; }); }); diff --git a/test/sp/navigation.ts b/test/sp/navigation.ts index a6dfe39a4..7c0dabe3c 100644 --- a/test/sp/navigation.ts +++ b/test/sp/navigation.ts @@ -108,7 +108,7 @@ describe("navigation", function () { const title = `Testing - ${getRandomString(4)}`; const result = await nav.add(title, url, true); - const nodeData = await result.node(); + const nodeData = await nav.getById(result.Id)(); expect(nodeData.Title).to.eq(title); }); @@ -116,8 +116,9 @@ describe("navigation", function () { const node1result = await nav.add(`Testing - ${getRandomString(4)} (1)`, url, true); const node2result = await nav.add(`Testing - ${getRandomString(4)} (2)`, url, true); - const node1 = await node1result.node(); - const node2 = await node2result.node(); + + const node1 = await nav.getById(node1result.Id)(); + const node2 = await nav.getById(node2result.Id)(); await nav.moveAfter(node1.Id, node2.Id); }); @@ -126,12 +127,12 @@ describe("navigation", function () { const node1result = await nav.add(`Testing - ${getRandomString(4)}`, url, true); let nodes = await nav(); // check we added a node - expect(nodes.findIndex(n => n.Id === node1result.data.Id)).to.be.greaterThan(-1); + expect(nodes.findIndex(n => n.Id === node1result.Id)).to.be.greaterThan(-1); - await nav.getById(node1result.data.Id).delete(); + await nav.getById(node1result.Id).delete(); nodes = await nav(); - expect(nodes.findIndex(n => n.Id === node1result.data.Id)).to.be.eq(-1); + expect(nodes.findIndex(n => n.Id === node1result.Id)).to.be.eq(-1); }); it("node: update", async function () { @@ -143,7 +144,7 @@ describe("navigation", function () { expect(nodes.findIndex(n => n.Title === title1)).to.be.greaterThan(-1); - await nav.getById(node1result.data.Id).update({ + await nav.getById(node1result.Id).update({ Title: title2, }); @@ -154,11 +155,11 @@ describe("navigation", function () { it("node: children", async function () { const node1result = await nav.add(`Testing - ${getRandomString(4)}`, url, true); + const node = nav.getById(node1result.Id); + await node.children.add(`Testing - ${getRandomString(4)}`, url, true); + await node.children.add(`Testing - ${getRandomString(4)}`, url, true); - await node1result.node.children.add(`Testing - ${getRandomString(4)}`, url, true); - await node1result.node.children.add(`Testing - ${getRandomString(4)}`, url, true); - - const children = await node1result.node.children(); + const children = await node.children(); expect(children.length).to.eq(2); }); diff --git a/test/sp/related-items.ts b/test/sp/related-items.ts index 03e14b6ea..362ef09f5 100644 --- a/test/sp/related-items.ts +++ b/test/sp/related-items.ts @@ -29,18 +29,18 @@ describe("Related Items", function () { webUrl = await this.pnp.sp.web.select("ServerRelativeUrl")().then(r => r.ServerRelativeUrl); - sourceList = ler1.list; - targetList = ler2.list; + sourceList = this.pnp.sp.web.lists.getById(ler1.Id); + targetList = this.pnp.sp.web.lists.getById(ler2.Id); - sourceListName = ler1.data.Id; - targetListName = ler2.data.Id; + sourceListName = ler1.Id; + targetListName = ler2.Id; }); it("addSingleLink", async function () { const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }); const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); - const p = this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.data.Id, webUrl, targetListName, targetItem.data.Id, webUrl); + const p = this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem.Id, webUrl); return expect(p).to.eventually.be.fulfilled; }); @@ -50,27 +50,27 @@ describe("Related Items", function () { .addUsingPath(`test${getRandomString(4)}.txt`, "Test File", { Overwrite: true }); const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); - return expect(this.pnp.sp.web.relatedItems.addSingleLinkToUrl(targetListName, targetItem.data.Id, file.data.ServerRelativeUrl)).to.eventually.be.fulfilled; + return expect(this.pnp.sp.web.relatedItems.addSingleLinkToUrl(targetListName, targetItem.Id, file.ServerRelativeUrl)).to.eventually.be.fulfilled; }); it("deleteSingleLink", async function () { const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }); const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); - await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.data.Id, webUrl, targetListName, targetItem.data.Id, webUrl); + await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem.Id, webUrl); - const promise = this.pnp.sp.web.relatedItems.deleteSingleLink(sourceListName, sourceItem.data.Id, webUrl, targetListName, targetItem.data.Id, webUrl); + const promise = this.pnp.sp.web.relatedItems.deleteSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem.Id, webUrl); return expect(promise).to.eventually.be.fulfilled; }); it("getRelatedItems", async function () { - const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); - const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); + const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }); + const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem.Id, webUrl); - const targetItem2 = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); + const targetItem2 = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem2.Id, webUrl); const items = await this.pnp.sp.web.relatedItems.getRelatedItems(sourceListName, sourceItem.Id); @@ -80,11 +80,11 @@ describe("Related Items", function () { it("getPageOneRelatedItems", async function () { - const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); - const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); + const sourceItem = await sourceList.items.add({ Title: `Item ${getRandomString(4)}` }); + const targetItem = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem.Id, webUrl); - const targetItem2 = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }).then(r => r.data); + const targetItem2 = await targetList.items.add({ Title: `Item ${getRandomString(4)}` }); await this.pnp.sp.web.relatedItems.addSingleLink(sourceListName, sourceItem.Id, webUrl, targetListName, targetItem2.Id, webUrl); const items = await this.pnp.sp.web.relatedItems.getPageOneRelatedItems(sourceListName, sourceItem.Id); diff --git a/test/sp/security.ts b/test/sp/security.ts index b805183ba..fb0252c66 100644 --- a/test/sp/security.ts +++ b/test/sp/security.ts @@ -21,7 +21,7 @@ describe("Security", function () { } const ler = await this.pnp.sp.web.lists.ensure("SecurityTestingList"); - list = ler.list; + list = this.pnp.sp.web.lists.getById(ler.Id); // Capture the parent web for use in role definition tests. parentWeb = await this.pnp.sp.web.getParentWeb(); diff --git a/test/sp/sharing.ts b/test/sp/sharing.ts index e72ec7073..6708e610c 100644 --- a/test/sp/sharing.ts +++ b/test/sp/sharing.ts @@ -33,6 +33,7 @@ describe("Sharing", function () { // we need a doc lib with a file and folder in it const ler = await this.pnp.sp.web.lists.ensure(testSharingLib, "Used to test sharing", 101); + const list = this.pnp.sp.web.lists.getById(ler.Id); // we need a user to share to if (this.pnp.settings.testUser?.length > 0) { @@ -40,8 +41,8 @@ describe("Sharing", function () { } // add a file and folder - await ler.list.rootFolder.folders.addUsingPath(testSharingFolder); - await ler.list.rootFolder.files.addUsingPath(testSharingFile, "Some file content!"); + await list.rootFolder.folders.addUsingPath(testSharingFolder); + await list.rootFolder.files.addUsingPath(testSharingFile, "Some file content!"); }); after(async function () { diff --git a/test/sp/site-groups.ts b/test/sp/site-groups.ts index e5169f739..ed1c3fc31 100644 --- a/test/sp/site-groups.ts +++ b/test/sp/site-groups.ts @@ -3,11 +3,12 @@ import "@pnp/sp/webs"; import "@pnp/sp/site-groups"; import "@pnp/sp/site-users/web"; import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; -import { IGroupAddResult } from "@pnp/sp/site-groups"; +import { ISiteGroupInfo } from "@pnp/sp/site-groups"; + describe("SiteGroups", function () { - let newGroup: IGroupAddResult; + let newGroup: ISiteGroupInfo; let testuserId: number; before(async function () { @@ -20,7 +21,7 @@ describe("SiteGroups", function () { newGroup = await this.pnp.sp.web.siteGroups.add({ "Title": groupName }); if (this.pnp.settings.testUser?.length > 0) { const ensureTestUser = await this.pnp.sp.web.ensureUser(this.pnp.settings.testUser); - testuserId = ensureTestUser.data.Id; + testuserId = ensureTestUser.Id; } }); @@ -53,7 +54,7 @@ describe("SiteGroups", function () { }); it("getById()", async function () { - return expect(this.pnp.sp.web.siteGroups.getById(newGroup.data.Id)()); + return expect(this.pnp.sp.web.siteGroups.getById(newGroup.Id)()); }); it("add()", function () { @@ -62,29 +63,29 @@ describe("SiteGroups", function () { }); it("getByName()", function () { - return expect(this.pnp.sp.web.siteGroups.getByName(newGroup.data.Title)()).to.be.eventually.fulfilled; + return expect(this.pnp.sp.web.siteGroups.getByName(newGroup.Title)()).to.be.eventually.fulfilled; }); it("removeById()", async function () { const newGroupTitle = `test_remove_group_by_id_${getRandomString(8)}`; const g = await this.pnp.sp.web.siteGroups.add({ "Title": newGroupTitle }); - return expect(this.pnp.sp.web.siteGroups.removeById(g.data.Id)).to.be.eventually.fulfilled; + return expect(this.pnp.sp.web.siteGroups.removeById(g.Id)).to.be.eventually.fulfilled; }); it("removeByLoginName()", async function () { const newGroupTitle = `test_remove_group_by_name_${getRandomString(8)}`; const g = await this.pnp.sp.web.siteGroups.add({ "Title": newGroupTitle }); - return expect(this.pnp.sp.web.siteGroups.removeByLoginName(g.data.LoginName)).to.be.eventually.fulfilled; + return expect(this.pnp.sp.web.siteGroups.removeByLoginName(g.LoginName)).to.be.eventually.fulfilled; }); it("users()", async function () { - return expect(this.pnp.sp.web.siteGroups.getById(newGroup.data.Id).users()).to.be.eventually.fulfilled; + return expect(this.pnp.sp.web.siteGroups.getById(newGroup.Id).users()).to.be.eventually.fulfilled; }); it("update()", async function () { - const newTitle = `Updated_${newGroup.data.Title}`; - await this.pnp.sp.web.siteGroups.getByName(newGroup.data.Title).update({ "Title": newTitle }); - const p = this.pnp.sp.web.siteGroups.getById(newGroup.data.Id).select("Title")<{ "Title": string }>().then(g2 => { + const newTitle = `Updated_${newGroup.Title}`; + await this.pnp.sp.web.siteGroups.getByName(newGroup.Title).update({ "Title": newTitle }); + const p = this.pnp.sp.web.siteGroups.getById(newGroup.Id).select("Title")<{ "Title": string }>().then(g2 => { if (newTitle !== g2.Title) { throw Error("Failed to update the group!"); } @@ -93,6 +94,6 @@ describe("SiteGroups", function () { }); it("setUserAsOwner()", async function () { - return expect(this.pnp.sp.web.siteGroups.getById(newGroup.data.Id).setUserAsOwner(testuserId)).to.be.eventually.fulfilled; + return expect(this.pnp.sp.web.siteGroups.getById(newGroup.Id).setUserAsOwner(testuserId)).to.be.eventually.fulfilled; }); }); diff --git a/test/sp/site-scripts.ts b/test/sp/site-scripts.ts index da84a77da..60446ae52 100644 --- a/test/sp/site-scripts.ts +++ b/test/sp/site-scripts.ts @@ -134,9 +134,10 @@ describe("SiteScripts", function () { it("getSiteScript (list)", async function () { const listTitle = `sc_list_${getRandomString(8)}`; const listResult = await _rootSite.web.lists.add(listTitle); - createdLists.push(listResult.list); + const list = _rootSite.web.lists.getById(listResult.Id); + createdLists.push(list); - return expect(listResult.list.getSiteScript(), + return expect(list.getSiteScript(), "the lists site script should've been fetched").to.eventually.be.fulfilled; }); diff --git a/test/sp/site-users.ts b/test/sp/site-users.ts index 4f80cb47d..00ac1b1cf 100644 --- a/test/sp/site-users.ts +++ b/test/sp/site-users.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; import "@pnp/sp/site-users"; -import { ISiteUserProps, IUserUpdateResult, ISiteUserInfo } from "@pnp/sp/site-users"; +import { ISiteUserProps, ISiteUserInfo } from "@pnp/sp/site-users"; import { ISiteGroups } from "@pnp/sp/presets/all"; import { stringIsNullOrEmpty } from "@pnp/core"; @@ -85,8 +85,8 @@ describe("Site Users", function () { it("update", async function () { const _props: ISiteUserProps = await this.pnp.sp.web.currentUser(); _props.Title = "Changed Title"; - const e: IUserUpdateResult = await this.pnp.sp.web.currentUser.update(_props); - const _newProps = await e.user(); + await this.pnp.sp.web.currentUser.update(_props); + const _newProps = await this.pnp.sp.web.currentUser(); return expect(_newProps.Title).to.be.eq("Changed Title"); }); }); diff --git a/test/sp/sites.ts b/test/sp/sites.ts index 672eed56c..6e1a2233a 100644 --- a/test/sp/sites.ts +++ b/test/sp/sites.ts @@ -4,18 +4,18 @@ import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { IDocumentLibraryInformation, IOpenWebByIdResult, ISiteLogoProperties, Site, SiteLogoAspect, SiteLogoType } from "@pnp/sp/sites"; import "@pnp/sp/site-users"; -import { IWebEnsureUserResult } from "@pnp/sp/site-users"; import { IWeb } from "@pnp/sp/webs"; import { combine, getRandomString, stringIsNullOrEmpty } from "@pnp/core"; import { IContextInfo } from "@pnp/sp/context-info"; import "@pnp/sp/context-info"; - +import { ISiteUserInfo } from "@pnp/sp/site-users"; import "@pnp/sp/files"; import { IFiles } from "@pnp/sp/files"; import { readFileSync } from "fs"; import { resolve, dirname } from "path"; import findupSync from "findup-sync"; + // get a single reference to the projectRoot const projectRoot = resolve(dirname(findupSync("package.json"))); @@ -38,8 +38,8 @@ describe("Sites", function () { }); it("rootWeb - ensureUser", async function () { - const user: IWebEnsureUserResult = await this.pnp.sp.site.rootWeb.ensureUser(this.pnp.settings.testUser); - return expect(user.data).to.haveOwnProperty("id"); + const user: ISiteUserInfo = await this.pnp.sp.site.rootWeb.ensureUser(this.pnp.settings.testUser); + return expect(user).to.haveOwnProperty("Id"); }); it("getContextInfo", async function () { @@ -87,7 +87,7 @@ describe("Sites", function () { const name = `Testing Chunked - ${getRandomString(4)}.jpg`; const content = readFileSync(resolve(projectRoot, "./test/sp/assets/sample_file.jpg")); const far = await files.addChunked(name, content, null); - const path = far.data.ServerRelativeUrl; + const path = far.ServerRelativeUrl; const logoProperties: ISiteLogoProperties = {relativeLogoUrl: path, aspect: SiteLogoAspect.Square, type: SiteLogoType.WebLogo}; await this.pnp.sp.site.setSiteLogo(logoProperties); }); diff --git a/test/sp/sputilities.ts b/test/sp/sputilities.ts index 693ab5e06..fd2c91dd4 100644 --- a/test/sp/sputilities.ts +++ b/test/sp/sputilities.ts @@ -70,7 +70,7 @@ describe.skip("SPUtilities", function () { } const ensureTestUser = await this.pnp.sp.web.ensureUser(this.pnp.settings.testUser); - const userId = ensureTestUser.data.Id; + const userId = ensureTestUser.Id; const user = await this.pnp.sp.web.siteUsers.getById(userId)(); return expect(this.pnp.sp.utility.searchPrincipals(user.Title, PrincipalType.User, PrincipalSource.All, "", 1)).to.eventually.be.an.instanceOf(Array).and.not.be.empty; diff --git a/test/sp/subscriptions.ts b/test/sp/subscriptions.ts index a2570164e..162e2a48f 100644 --- a/test/sp/subscriptions.ts +++ b/test/sp/subscriptions.ts @@ -30,7 +30,7 @@ describe("Subscriptions", function () { it("add", async function () { const r = await this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.add(notificationUrl, after120Days, "pnp client state"); - const subID = r.data.id; + const subID = r.id; return expect(subID, `A new webhook with id :${subID} should be created`).to.not.be.null.and.not.be.empty.and.be.an.instanceOf(Number); }); @@ -39,7 +39,7 @@ describe("Subscriptions", function () { const res = await this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.add(notificationUrl, after120Days); - const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.data.id)(); + const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.id)(); return expect(p, "Get the details of a webhook with the given id").to.be.eventually.fulfilled; }); @@ -48,7 +48,7 @@ describe("Subscriptions", function () { const res = await this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.add(notificationUrl, after120Days, "pnp client state"); - const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.data.id).update(after180Days, notificationUrl, "pnp client state"); + const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.id).update(after180Days, notificationUrl, "pnp client state"); return expect(p, "The webhook should have been updated with the new expiry date").to.be.eventually.fulfilled; }); @@ -57,7 +57,7 @@ describe("Subscriptions", function () { const res = await this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.add(notificationUrl, after120Days, "pnp client state"); - const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.data.id).delete(); + const p = this.pnp.sp.web.lists.getByTitle(listTitle).subscriptions.getById(res.id).delete(); return expect(p, "The webhook should have been deleted").to.be.eventually.fulfilled; }); diff --git a/test/sp/views.ts b/test/sp/views.ts index d1f329244..f87be8e52 100644 --- a/test/sp/views.ts +++ b/test/sp/views.ts @@ -18,7 +18,7 @@ describe("Views", function () { // we need to create a list for manipulating views const result = await this.pnp.sp.web.lists.ensure(`ViewTestList_${getRandomString(4)}`, "Testing Views"); - list = result.list; + list = this.pnp.sp.web.lists.getById(result.Id); }); it("-invoke", function () { @@ -55,7 +55,7 @@ describe("Views", function () { it("add", async function () { const viewTitle = `Test-Add-View_${getRandomString(4)}`; const av = await list.views.add(viewTitle, false); - return expect(av.data.Title).to.eq(viewTitle); + return expect(av.Title).to.eq(viewTitle); }); it("fields", async function () { @@ -65,10 +65,10 @@ describe("Views", function () { it("update", async function () { const r = await list.views.add(`Update-Test-View_${getRandomString(4)}`); - await r.view.update({ + await list.views.getById(r.Id).update({ RowLimit: 20, }); - const v = await list.views.getById(r.data.Id)(); + const v = await list.views.getById(r.Id)(); return expect(v.RowLimit).to.eq(20); }); @@ -80,7 +80,7 @@ describe("Views", function () { it("setViewXml", async function () { const r = await list.views.add(`setViewXml-Test-View_${getRandomString(4)}`); const xml = "Test"; - return expect(r.view.setViewXml(xml)).to.eventually.be.fulfilled; + return expect(list.views.getById(r.Id).setViewXml(xml)).to.eventually.be.fulfilled; }); describe("ViewFields", function () { @@ -92,24 +92,24 @@ describe("Views", function () { it("add", async function () { const r = await list.views.add(`add-Test-ViewFields_${getRandomString(4)}`); - return expect(r.view.fields.add("Created")).to.eventually.be.fulfilled; + return expect(list.views.getById(r.Id).fields.add("Created")).to.eventually.be.fulfilled; }); it("move", async function () { const r = await list.views.add(`move-Test-ViewFields_${getRandomString(4)}`); - await r.view.fields.add("Modified"); - return expect(r.view.fields.move("Modified", 0)).to.eventually.be.fulfilled; + await list.views.getById(r.Id).fields.add("Modified"); + return expect(list.views.getById(r.Id).fields.move("Modified", 0)).to.eventually.be.fulfilled; }); it("remove", async function () { const r = await list.views.add(`remove-Test-ViewFields_${getRandomString(4)}`); - await r.view.fields.add("Author"); - return expect(r.view.fields.remove("Author")).to.eventually.be.fulfilled; + await list.views.getById(r.Id).fields.add("Author"); + return expect(list.views.getById(r.Id).fields.remove("Author")).to.eventually.be.fulfilled; }); it("removeAll", async function () { const r = await list.views.add(`removeAll-Test-ViewFields_${getRandomString(4)}`); - return expect(r.view.fields.removeAll()).to.eventually.be.fulfilled; + return expect(list.views.getById(r.Id).fields.removeAll()).to.eventually.be.fulfilled; }); }); }); diff --git a/test/sp/webs.ts b/test/sp/webs.ts index 828080757..a5ba67127 100644 --- a/test/sp/webs.ts +++ b/test/sp/webs.ts @@ -20,6 +20,7 @@ import "@pnp/sp/security"; import { INavNodeInfo } from "@pnp/sp/navigation/types.js"; import testSPInvokables from "../test-invokable-props.js"; import { Web } from "@pnp/sp/webs"; +import { odataUrlFrom } from "@pnp/sp/index.js"; describe("Webs", function () { @@ -170,7 +171,8 @@ describe("Web", function () { it("delete", async function () { const url = getRandomString(4); const result = await this.pnp.sp.web.webs.add("Better be deleted!", url); - return expect(result.web.delete()).to.eventually.be.fulfilled; + const web = Web([this.pnp.sp.web, odataUrlFrom(result).replace(/_api\/web\/?/i, "")]); + return expect(web.delete()).to.eventually.be.fulfilled; }); describe("client-side-pages", function () { diff --git a/test/test-recording-setup.md b/test/test-recording-setup.md index 3b3698c5d..3b1b01630 100644 --- a/test/test-recording-setup.md +++ b/test/test-recording-setup.md @@ -42,10 +42,10 @@ it("attachmentFiles", async function () { Title: `Test_${getRandomString(4)}`, }); - await r.item.attachmentFiles.add(`att_${getRandomString(4)}.txt`, "Some Content"); - await r.item.attachmentFiles.add(`att_${getRandomString(4)}.txt`, "Some Content"); + await r.attachmentFiles.add(`att_${getRandomString(4)}.txt`, "Some Content"); + await r.attachmentFiles.add(`att_${getRandomString(4)}.txt`, "Some Content"); - return expect(r.item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); + return expect(list.items.getById(r.Id).attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); }); ``` @@ -78,10 +78,10 @@ it("attachmentFiles", pnpTest("9bc6dba6-6690-4453-8d13-4f42e051a245", async func Title: props.itemTitle, }); - await r.item.attachmentFiles.add(props.attachmentFile1Name, "Some Content"); - await r.item.attachmentFiles.add(props.attachmentFile2Name, "Some Content"); + await r.attachmentFiles.add(props.attachmentFile1Name, "Some Content"); + await r.attachmentFiles.add(props.attachmentFile2Name, "Some Content"); - return expect(r.item.attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); + return expect(list.items.getById(r.Id).attachmentFiles()).to.eventually.be.fulfilled.and.to.be.an("Array").and.have.length(2); })); ```