From fcb2fac9741de4c5f6cdfe0a9d94de71652a5c29 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Mon, 2 Oct 2023 19:57:56 -0600 Subject: [PATCH 1/5] v4- Graph Items Docs Update and Document Set Versions WIP - Initial check-in --- docs/graph/items.md | 105 ++++++++++++++++-- packages/graph/documentSetVersions/index.ts | 10 ++ .../graph/documentSetVersions/list-item.ts | 14 +++ packages/graph/documentSetVersions/types.ts | 60 ++++++++++ 4 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 packages/graph/documentSetVersions/index.ts create mode 100644 packages/graph/documentSetVersions/list-item.ts create mode 100644 packages/graph/documentSetVersions/types.ts diff --git a/docs/graph/items.md b/docs/graph/items.md index 26bfb3429..3877ff6ee 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -1,38 +1,119 @@ # @pnp/graph/items -Currently, there is no module in graph to access all items directly. Please, instead, default to search by path using the following methods. - [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) ### Get list items ```TypeScript -import { Site } from "@pnp/graph/sites"; +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; -const sites = graph.sites.getById("{site id}"); +const graph = graphfi(...); +const items = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items(); -const items = await Site(sites, "lists/{listid}/items")(); ``` ### Get File/Item version information ```TypeScript -import { Site } from "@pnp/graph/sites"; - -const sites = graph.sites.getById("{site id}"); +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; -const users = await Site(sites, "lists/{listid}/items/{item id}/versions")(); +const graph = graphfi(...); +const itemVersions = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items.getById(1).versions(); + ``` ### Get list items with fields included ```TypeScript -import { Site } from "@pnp/graph/sites"; +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; + +const graph = graphfi(...); +const listItems = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items..expand("fields")(); + +``` + +### Create a new list item + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; import "@pnp/graph/lists"; -const sites = graph.sites.getById("{site id}"); +const graph = graphfi(...); +var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.add({ + Title: "Widget", +}); + +``` +### Update a list item + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; + +const graph = graphfi(...); +var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").update({ + Title: "Widget", +}); + +``` + +### Delete a list item + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; + +const graph = graphfi(...); +var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").delete(); + +``` + +### Get Document Set Versions of an Item + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; +import "@pnp/graph/documentSetVersions"; +const graph = graphfi(...); +var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}")(); +var documentSetVersions = item.documentSetVersions(); + +``` + +### Create a new Document Set Version + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; +import "@pnp/graph/documentSetVersions"; + +const graph = graphfi(...); +var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment"); + +``` + +### Restore a Document Set version + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; +import "@pnp/graph/documentSetVersions"; -const listItems : IList[] = await Site(sites, "lists/{site id}/items?$expand=fields")(); +const graph = graphfi(...); +var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById(1).restore(); + ``` #### Hint: Note that you can just use normal [graph queries](https://developer.microsoft.com/en-us/graph/graph-explorer) in this search. diff --git a/packages/graph/documentSetVersions/index.ts b/packages/graph/documentSetVersions/index.ts new file mode 100644 index 000000000..b988dbc0b --- /dev/null +++ b/packages/graph/documentSetVersions/index.ts @@ -0,0 +1,10 @@ + +import "./list-item.js"; +export { + IDocumentSetVersion, + DocumentSetVersion, + IDocumentSetVersions, + DocumentSetVersions, + IDocumentSetVersionAddResult +} from "./types.js"; + diff --git a/packages/graph/documentSetVersions/list-item.ts b/packages/graph/documentSetVersions/list-item.ts new file mode 100644 index 000000000..686a38cc7 --- /dev/null +++ b/packages/graph/documentSetVersions/list-item.ts @@ -0,0 +1,14 @@ +import { addProp } from "@pnp/queryable"; +import { DocumentSetVersions, IDocumentSetVersions } from "./types.js"; +import { _ListItem } from "../list-item/types.js"; + +declare module "../list-item/types" { + interface _ListItem { + readonly documentSetVersions: IDocumentSetVersions; + } + interface IListItem { + readonly documentSetVersions: IDocumentSetVersions; + } +} + +addProp(_ListItem, "documentSetVersions", DocumentSetVersions); \ No newline at end of file diff --git a/packages/graph/documentSetVersions/types.ts b/packages/graph/documentSetVersions/types.ts new file mode 100644 index 000000000..6b94508c4 --- /dev/null +++ b/packages/graph/documentSetVersions/types.ts @@ -0,0 +1,60 @@ +import { DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost, GraphInstance, GraphQueryable } from "../graphqueryable.js"; +import { defaultPath, deleteable, IDeleteable, getById, IGetById } from "../decorators.js"; +import { body } from "@pnp/queryable"; + +/** + * Represents a document set version + */ +@deleteable() +export class _DocumentSetVersion extends _GraphInstance { + /** + * Restore a document set version + * + */ + public async restore(): Promise { + return graphPost(DocumentSetVersion(this, "restore")); + } +} +export interface IDocumentSetVersion extends _DocumentSetVersion, IDeleteable { } +export const DocumentSetVersion = graphInvokableFactory(_DocumentSetVersion); + +/** + * Describes a collection of document set versions + * + */ +@defaultPath("documentSetVersions") +@getById(DocumentSetVersion) +export class _DocumentSetVersions extends _GraphCollection{ + /** + * Create a new document set version as specified in the request body. + * + * @param comment a comment about the captured version + * @param shouldCaptureMinorVersion If true, minor versions of items are also captured; otherwise, only major versions will be captured. + * + */ + public async add(comment: string, shouldCaptureMinorVersion:boolean = false): Promise { + + const postBody = { + comment: comment, + shouldCaptureMinorVersion: shouldCaptureMinorVersion + } + const data = await graphPost(this, body(postBody)); + + return { + data, + item: (this).getById(data.id), + }; + } +} + +export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById {} +export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); + +/** + * IListAddResult + */ +export interface IDocumentSetVersionAddResult { + item: IDocumentSetVersion; + data: IDocumentSetVersionEntity; +} \ No newline at end of file From 8fd18a44347d94f1b2cad98ef2cfcaef44a80c99 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Fri, 13 Oct 2023 09:25:29 -0600 Subject: [PATCH 2/5] Refactor and List-Item Tests. --- docs/graph/items.md | 22 ++- packages/graph/documentSetVersions/index.ts | 10 -- packages/graph/documentSetVersions/types.ts | 60 -------- .../document-sets.ts} | 7 +- packages/graph/list-item/index.ts | 6 + packages/graph/list-item/types.ts | 60 +++++++- settings.example.js | 1 + test/graph/list-items.ts | 133 ++++++++++++++++++ 8 files changed, 217 insertions(+), 82 deletions(-) delete mode 100644 packages/graph/documentSetVersions/index.ts delete mode 100644 packages/graph/documentSetVersions/types.ts rename packages/graph/{documentSetVersions/list-item.ts => list-item/document-sets.ts} (50%) create mode 100644 test/graph/list-items.ts diff --git a/docs/graph/items.md b/docs/graph/items.md index 3877ff6ee..6401e7a0b 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -83,23 +83,34 @@ var newItem = await graph.sites.getById("{site identifier}").lists.getById("{lis import { graphfi } from "@pnp/graph"; import "@pnp/graph/list-items"; import "@pnp/graph/lists"; -import "@pnp/graph/documentSetVersions"; + const graph = graphfi(...); -var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}")(); +var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions(); var documentSetVersions = item.documentSetVersions(); ``` +### Get Document Set Versions By Id + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/list-items"; +import "@pnp/graph/lists"; + +const graph = graphfi(...); +var documentSetVersion = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById("{document set version id}"); + +``` + ### Create a new Document Set Version ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/list-items"; import "@pnp/graph/lists"; -import "@pnp/graph/documentSetVersions"; const graph = graphfi(...); -var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment"); +var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment"); ``` @@ -109,10 +120,9 @@ var item = await graph.sites.getById("{site identifier}").lists.getById("{list i import { graphfi } from "@pnp/graph"; import "@pnp/graph/list-items"; import "@pnp/graph/lists"; -import "@pnp/graph/documentSetVersions"; const graph = graphfi(...); -var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById(1).restore(); +await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById("{document set version id}").restore(); ``` diff --git a/packages/graph/documentSetVersions/index.ts b/packages/graph/documentSetVersions/index.ts deleted file mode 100644 index b988dbc0b..000000000 --- a/packages/graph/documentSetVersions/index.ts +++ /dev/null @@ -1,10 +0,0 @@ - -import "./list-item.js"; -export { - IDocumentSetVersion, - DocumentSetVersion, - IDocumentSetVersions, - DocumentSetVersions, - IDocumentSetVersionAddResult -} from "./types.js"; - diff --git a/packages/graph/documentSetVersions/types.ts b/packages/graph/documentSetVersions/types.ts deleted file mode 100644 index 6b94508c4..000000000 --- a/packages/graph/documentSetVersions/types.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost, GraphInstance, GraphQueryable } from "../graphqueryable.js"; -import { defaultPath, deleteable, IDeleteable, getById, IGetById } from "../decorators.js"; -import { body } from "@pnp/queryable"; - -/** - * Represents a document set version - */ -@deleteable() -export class _DocumentSetVersion extends _GraphInstance { - /** - * Restore a document set version - * - */ - public async restore(): Promise { - return graphPost(DocumentSetVersion(this, "restore")); - } -} -export interface IDocumentSetVersion extends _DocumentSetVersion, IDeleteable { } -export const DocumentSetVersion = graphInvokableFactory(_DocumentSetVersion); - -/** - * Describes a collection of document set versions - * - */ -@defaultPath("documentSetVersions") -@getById(DocumentSetVersion) -export class _DocumentSetVersions extends _GraphCollection{ - /** - * Create a new document set version as specified in the request body. - * - * @param comment a comment about the captured version - * @param shouldCaptureMinorVersion If true, minor versions of items are also captured; otherwise, only major versions will be captured. - * - */ - public async add(comment: string, shouldCaptureMinorVersion:boolean = false): Promise { - - const postBody = { - comment: comment, - shouldCaptureMinorVersion: shouldCaptureMinorVersion - } - const data = await graphPost(this, body(postBody)); - - return { - data, - item: (this).getById(data.id), - }; - } -} - -export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById {} -export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); - -/** - * IListAddResult - */ -export interface IDocumentSetVersionAddResult { - item: IDocumentSetVersion; - data: IDocumentSetVersionEntity; -} \ No newline at end of file diff --git a/packages/graph/documentSetVersions/list-item.ts b/packages/graph/list-item/document-sets.ts similarity index 50% rename from packages/graph/documentSetVersions/list-item.ts rename to packages/graph/list-item/document-sets.ts index 686a38cc7..11ae2c21e 100644 --- a/packages/graph/documentSetVersions/list-item.ts +++ b/packages/graph/list-item/document-sets.ts @@ -1,8 +1,7 @@ import { addProp } from "@pnp/queryable"; -import { DocumentSetVersions, IDocumentSetVersions } from "./types.js"; -import { _ListItem } from "../list-item/types.js"; +import { DocumentSetVersions, _ListItem } from "./types.js"; -declare module "../list-item/types" { +declare module "./types" { interface _ListItem { readonly documentSetVersions: IDocumentSetVersions; } @@ -11,4 +10,4 @@ declare module "../list-item/types" { } } -addProp(_ListItem, "documentSetVersions", DocumentSetVersions); \ No newline at end of file +addProp(_ListItem, "documentSetVersions", DocumentSetVersions); diff --git a/packages/graph/list-item/index.ts b/packages/graph/list-item/index.ts index 86195c15b..f85c30980 100644 --- a/packages/graph/list-item/index.ts +++ b/packages/graph/list-item/index.ts @@ -1,4 +1,5 @@ import "./list.js"; +import "./document-sets.js"; export { ListItems, @@ -6,4 +7,9 @@ export { 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 57a66fdde..62af34f61 100644 --- a/packages/graph/list-item/types.ts +++ b/packages/graph/list-item/types.ts @@ -1,4 +1,4 @@ -import { ListItem as IListItemEntity, ListItemVersion as IListItemVersion } from "@microsoft/microsoft-graph-types"; +import { ListItem as IListItemEntity, ListItemVersion as IListItemVersion, DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance, IGraphCollection, GraphCollection, graphPost } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; import { body } from "@pnp/queryable"; @@ -17,7 +17,7 @@ export class _ListItem extends _GraphInstance { return GraphCollection(this, "versions"); } } -export interface IListItem extends _ListItem, IDeleteable, IUpdateable { } +export interface IListItem extends _ListItem, IDeleteable, IUpdateable {} export const ListItem = graphInvokableFactory(_ListItem); /** @@ -45,6 +45,62 @@ export class _ListItems extends _GraphCollection{ export interface IListItems extends _ListItems, IGetById { } export const ListItems = graphInvokableFactory(_ListItems); +/** + * Represents a document set version + */ +@deleteable() +export class _DocumentSetVersion extends _GraphInstance { + /** + * Restore a document set version + * + */ + public async restore(): Promise { + return graphPost(DocumentSetVersion(this, "restore")); + } +} +export interface IDocumentSetVersion extends _DocumentSetVersion, IDeleteable { } +export const DocumentSetVersion = graphInvokableFactory(_DocumentSetVersion); + +/** + * Describes a collection of document set versions + * + */ +@defaultPath("documentSetVersions") +@getById(DocumentSetVersion) +export class _DocumentSetVersions extends _GraphCollection{ + /** + * Create a new document set version as specified in the request body. + * + * @param comment a comment about the captured version + * @param shouldCaptureMinorVersion If true, minor versions of items are also captured; otherwise, only major versions will be captured. + * + */ + public async add(comment: string, shouldCaptureMinorVersion = false): Promise { + + const postBody = { + comment: comment, + shouldCaptureMinorVersion: shouldCaptureMinorVersion, + }; + const data = await graphPost(this, body(postBody)); + + return { + data, + item: (this).getById(data.id), + }; + } +} + +export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById {} +export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); + +/** + * IListAddResult + */ +export interface IDocumentSetVersionAddResult { + item: IDocumentSetVersion; + data: IDocumentSetVersionEntity; +} + /** * IListAddResult */ diff --git a/settings.example.js b/settings.example.js index 0eedaad3d..bf1b6bc30 100644 --- a/settings.example.js +++ b/settings.example.js @@ -39,6 +39,7 @@ export const settings = { // set your scopes as needed here scopes: ["https://{tenant}.sharepoint.com/.default"] }, + testWebUrl:"{ site collection for testing }" }, // all are optional if using msal graph: { diff --git a/test/graph/list-items.ts b/test/graph/list-items.ts new file mode 100644 index 000000000..50019a36e --- /dev/null +++ b/test/graph/list-items.ts @@ -0,0 +1,133 @@ +import { expect } from "chai"; +import "@pnp/graph/sites"; +import "@pnp/graph/lists"; +import { List } from "@microsoft/microsoft-graph-types"; +import { ISite } from "@pnp/graph/sites"; +import { getRandomString } from "@pnp/core"; +import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; +import { IList } from "@pnp/graph/lists"; +import { IListItem } from "@pnp/graph/list-item/types.js"; + +describe("List-Items", function () { + let site: ISite; + let list: IList; + let item: IListItem; + + const sampleList: List = { + displayName: "PnPGraphTestList", + list: { "template": "ItemTestList-Graph" }, + }; + + before(async function () { + + if (!this.pnp.settings.enableWebTests) { + this.skip(); + } + + site = await getTestingGraphSPSite(this); + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); + + const listTemplate = JSON.parse(JSON.stringify(sampleList)); + listTemplate.displayName += props.displayName; + const list = (await site.lists.add(listTemplate)).list; + + // add test items. Document set can be added later + if(list){ + await list.items.add({Title: `Item ${getRandomString(4)}`} as any); + await list.items.add({Title: `Item ${getRandomString(4)}`} as any); + // can't do until Graph Drives is done. + /* const documentSetCT = await site.contentTypes.getById("0x0120D520")(); + await list.contentTypes.add(documentSetCT); + // create item + const itemData = await list.items.select("Id").top(1)<{ Id: number }[]>(); + item = list.items.getById(itemData[0].Id?.toString()); + + // add document set version to item + item.documentSetVersions.add("Test"); + */ + } + + }); + + it("items", pnpTest("3e0e16a0-5683-4c3a-aa3d-f35bb6912de1", async function () { + const items = await list.items(); + return expect(items).to.be.an("array") && expect(items[0]).to.haveOwnProperty("id"); + })); + + it("getById()", pnpTest("6f9592fd-1568-4d9c-a3f5-7f45165d84f2", async function () { + const itemData = await list.items.select("Id").top(1)<{ Id: number }[]>(); + return expect(itemData[0].Id).is.not.null; + })); + + it("add", pnpTest("587e280b-0342-4515-a166-1b05cee9f242", async function () { + // fieldvalueset. ugh. Casting as any. + const itemAdded = await list.items.add({fields: + { + title: getRandomString(5) + "Add", + }, + } as any); + + return expect((itemAdded.data.id)).is.not.null; + })); + + it("update", pnpTest("5766613a-51b8-4f88-ba0f-2436d160b86b", async function () { + // fieldvalueset. ugh. Casting as any. + const itemUpdated = await item.update({fields: + { + title: getRandomString(5) + "Update", + }, + } as any); + + + return expect(itemUpdated).is.not.null; + })); + + it("delete", pnpTest("e55bf53f-1316-4e47-97c1-b0c0cdd860ef", async function () { + const item = await list.items.add({fields: + { + title: getRandomString(5) + "Add", + }, + } as any); + const r = await list.items.filter(`Id eq '${item.data.id}'`)(); + return expect(r.length).to.eq(0); + })); + + it.skip("documentSetVersions", pnpTest("c2889ca3-0230-4c6e-879d-71cc9cd08e83", async function () { + const versions = await item.documentSetVersions(); + return expect(versions).to.be.an("array") && expect(versions[0]).to.haveOwnProperty("id"); + })); + + it.skip("documentSetVersions - getById()", pnpTest("35226d93-204b-4877-9041-26e04e437914", async function () { + const versions = await item.documentSetVersions(); + + const version = await item.documentSetVersions.getById(versions[0].id); + return expect(version).to.not.be.null && expect(version).to.haveOwnProperty("id"); + })); + + it.skip("documentSetVersions - add()", pnpTest("a192e096-fe84-4c2c-adc5-b1b9021c0031", async function () { + const documentSetVersion = await item.documentSetVersions.add("New Comment"); + return expect(documentSetVersion).to.not.be.null && expect(documentSetVersion).to.haveOwnProperty("id"); + })); + + it.skip("documentSetVersions - restore()", pnpTest("8814b247-4087-4c87-9a8f-af997f7d8745", async function () { + const restore = await item.documentSetVersions[0].restore(); + return expect(restore).to.be.fulfilled; + })); + + // Remove the test list we created + after(async function () { + if (list) { + try { + await list.delete(); + } catch (err) { + console.error("Cannot clean up test list"); + } + } + return; + }); + +}); From d4ad5e1d2c9a9fb535b2dd4672e6ec6b4e3dd400 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Fri, 13 Oct 2023 10:30:03 -0600 Subject: [PATCH 3/5] Update list-items.ts --- test/graph/list-items.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/graph/list-items.ts b/test/graph/list-items.ts index 50019a36e..9f134b60b 100644 --- a/test/graph/list-items.ts +++ b/test/graph/list-items.ts @@ -39,16 +39,6 @@ describe("List-Items", function () { if(list){ await list.items.add({Title: `Item ${getRandomString(4)}`} as any); await list.items.add({Title: `Item ${getRandomString(4)}`} as any); - // can't do until Graph Drives is done. - /* const documentSetCT = await site.contentTypes.getById("0x0120D520")(); - await list.contentTypes.add(documentSetCT); - // create item - const itemData = await list.items.select("Id").top(1)<{ Id: number }[]>(); - item = list.items.getById(itemData[0].Id?.toString()); - - // add document set version to item - item.documentSetVersions.add("Test"); - */ } }); From 755eacef4b5515017ff7e5f330a154809d2b4229 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Mon, 13 Nov 2023 07:56:53 -0500 Subject: [PATCH 4/5] Update addable --- docs/graph/items.md | 2 +- packages/graph/list-item/types.ts | 51 +++++-------------------------- test/graph/list-items.ts | 6 ++-- 3 files changed, 12 insertions(+), 47 deletions(-) diff --git a/docs/graph/items.md b/docs/graph/items.md index 6401e7a0b..21eab2757 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -110,7 +110,7 @@ import "@pnp/graph/list-items"; import "@pnp/graph/lists"; const graph = graphfi(...); -var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment"); +var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add({comment:"Test Comment", shouldCaptureMinorVersion: true}); ``` diff --git a/packages/graph/list-item/types.ts b/packages/graph/list-item/types.ts index 62af34f61..101734540 100644 --- a/packages/graph/list-item/types.ts +++ b/packages/graph/list-item/types.ts @@ -1,7 +1,6 @@ import { ListItem as IListItemEntity, ListItemVersion as IListItemVersion, DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance, IGraphCollection, GraphCollection, graphPost } from "../graphqueryable.js"; -import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { body } from "@pnp/queryable"; +import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById, addable, IAddable } from "../decorators.js"; /** * Represents a list item entity @@ -26,23 +25,10 @@ export const ListItem = graphInvokableFactory(_ListItem); */ @defaultPath("items") @getById(ListItem) -export class _ListItems extends _GraphCollection{ - /** - * Create a new list item as specified in the request body. - * - * @param listItem a JSON representation of a List object. - */ - public async add(listItem: IListItemEntity): Promise { - const data = await graphPost(this, body(listItem)); +@addable() +export class _ListItems extends _GraphCollection{} - return { - data, - list: (this).getById(data.id), - }; - } -} - -export interface IListItems extends _ListItems, IGetById { } +export interface IListItems extends _ListItems, IGetById, IAddable { } export const ListItems = graphInvokableFactory(_ListItems); /** @@ -67,34 +53,13 @@ export const DocumentSetVersion = graphInvokableFactory(_Do */ @defaultPath("documentSetVersions") @getById(DocumentSetVersion) -export class _DocumentSetVersions extends _GraphCollection{ - /** - * Create a new document set version as specified in the request body. - * - * @param comment a comment about the captured version - * @param shouldCaptureMinorVersion If true, minor versions of items are also captured; otherwise, only major versions will be captured. - * - */ - public async add(comment: string, shouldCaptureMinorVersion = false): Promise { - - const postBody = { - comment: comment, - shouldCaptureMinorVersion: shouldCaptureMinorVersion, - }; - const data = await graphPost(this, body(postBody)); - - return { - data, - item: (this).getById(data.id), - }; - } -} - -export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById {} +@addable() +export class _DocumentSetVersions extends _GraphCollection{} +export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById, IAddable {} export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); /** - * IListAddResult + * IDocumentSetVersionAddResult */ export interface IDocumentSetVersionAddResult { item: IDocumentSetVersion; diff --git a/test/graph/list-items.ts b/test/graph/list-items.ts index 9f134b60b..b0d4d5b4f 100644 --- a/test/graph/list-items.ts +++ b/test/graph/list-items.ts @@ -61,7 +61,7 @@ describe("List-Items", function () { }, } as any); - return expect((itemAdded.data.id)).is.not.null; + return expect((itemAdded.id)).is.not.null; })); it("update", pnpTest("5766613a-51b8-4f88-ba0f-2436d160b86b", async function () { @@ -82,7 +82,7 @@ describe("List-Items", function () { title: getRandomString(5) + "Add", }, } as any); - const r = await list.items.filter(`Id eq '${item.data.id}'`)(); + const r = await list.items.filter(`Id eq '${item.id}'`)(); return expect(r.length).to.eq(0); })); @@ -99,7 +99,7 @@ describe("List-Items", function () { })); it.skip("documentSetVersions - add()", pnpTest("a192e096-fe84-4c2c-adc5-b1b9021c0031", async function () { - const documentSetVersion = await item.documentSetVersions.add("New Comment"); + const documentSetVersion = await item.documentSetVersions.add({comment:"Test Comment"}); return expect(documentSetVersion).to.not.be.null && expect(documentSetVersion).to.haveOwnProperty("id"); })); From 2e8f7459eae55fdc1430ecb8092e6fd5e83cd2ba Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Mon, 20 Nov 2023 08:30:51 -0500 Subject: [PATCH 5/5] Updating Docs --- docs/graph/items.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/graph/items.md b/docs/graph/items.md index 21eab2757..949cb0787 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -85,8 +85,7 @@ import "@pnp/graph/list-items"; import "@pnp/graph/lists"; const graph = graphfi(...); -var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions(); -var documentSetVersions = item.documentSetVersions(); +var documentSetVersions = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions(); ```