-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v4- Graph Items Docs Update and Document Set Versions
WIP - Initial check-in
- Loading branch information
1 parent
d23039a
commit fcb2fac
Showing
4 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
import "./list-item.js"; | ||
export { | ||
IDocumentSetVersion, | ||
DocumentSetVersion, | ||
IDocumentSetVersions, | ||
DocumentSetVersions, | ||
IDocumentSetVersionAddResult | ||
} from "./types.js"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IDocumentSetVersionEntity> { | ||
/** | ||
* Restore a document set version | ||
* | ||
*/ | ||
public async restore(): Promise<void> { | ||
return graphPost(DocumentSetVersion(this, "restore")); | ||
} | ||
} | ||
export interface IDocumentSetVersion extends _DocumentSetVersion, IDeleteable { } | ||
export const DocumentSetVersion = graphInvokableFactory<IDocumentSetVersion>(_DocumentSetVersion); | ||
|
||
/** | ||
* Describes a collection of document set versions | ||
* | ||
*/ | ||
@defaultPath("documentSetVersions") | ||
@getById(DocumentSetVersion) | ||
export class _DocumentSetVersions extends _GraphCollection<IDocumentSetVersionEntity[]>{ | ||
/** | ||
* 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<IDocumentSetVersionAddResult> { | ||
|
||
const postBody = { | ||
comment: comment, | ||
shouldCaptureMinorVersion: shouldCaptureMinorVersion | ||
} | ||
const data = await graphPost(this, body(postBody)); | ||
|
||
return { | ||
data, | ||
item: (<any>this).getById(data.id), | ||
}; | ||
} | ||
} | ||
|
||
export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById<IDocumentSetVersion> {} | ||
export const DocumentSetVersions = graphInvokableFactory<IDocumentSetVersions>(_DocumentSetVersions); | ||
|
||
/** | ||
* IListAddResult | ||
*/ | ||
export interface IDocumentSetVersionAddResult { | ||
item: IDocumentSetVersion; | ||
data: IDocumentSetVersionEntity; | ||
} |