From fe98a462a497e5e959eed496889f5dcecd6ce97b Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Mon, 27 Jan 2020 10:12:29 -0500 Subject: [PATCH 1/3] updates to address docs for entity parsers and fix missing export in preset all --- docs/sp/entity-merging.md | 28 ++++++++++++++++++++++++---- packages/sp/presets/all.ts | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/sp/entity-merging.md b/docs/sp/entity-merging.md index 2e4937595..c3dd98262 100644 --- a/docs/sp/entity-merging.md +++ b/docs/sp/entity-merging.md @@ -2,12 +2,32 @@ Sometimes when we make a query entity's data we would like then to immediately run other commands on the returned entity. To have data returned as its representing type we make use of the _spODataEntity_ and _spODataEntityArray_ parsers. The below approach works for all instance types such as List, Web, Item, or Field as examples. +## Importing spODataEntity and spODataEntityArray + +You can import spODataEntity and spODataEntityArray in two ways, depending on your use case. The simplest way is to use the presets/all import as shown in the examples. The downside of this approach is that you can't take advantage of selective imports. + +If you want to take advantage of selective imports while using either of the entity parsers you can use: + +```TypeScript +import { spODataEntity, spODataEntityArray } from "@pnp/sp/odata"; +``` + +The full selective import for the first sample would be: + +```TypeScript +import { sp } from "@pnp/sp"; +import { spODataEntity } from "@pnp/sp/odata"; +import { Item, IItem } from "@pnp/sp/items"; +import "@pnp/sp/webs"; +import "@pnp/sp/lists"; +``` + ## Request a single entity If we are loading a single entity we use the _spODataEntity_ method. Here we show loading a list item using the Item class and a simple get query. ```TypeScript -import { sp, spODataEntity, Item } from "@pnp/sp/presets/all"; +import { sp, spODataEntity, Item, IItem } from "@pnp/sp/presets/all"; // interface defining the returned properties interface MyProps { @@ -17,7 +37,7 @@ interface MyProps { try { // get a list item loaded with data and merged into an instance of Item - const item = await sp.web.lists.getByTitle("ListTitle").items.getById(1).get(spODataEntity(Item)); + const item = await sp.web.lists.getByTitle("ListTitle").items.getById(1).usingParser(spODataEntity(Item))(); // log the item id, all properties specified in MyProps will be type checked Logger.write(`Item id: ${item.Id}`); @@ -37,7 +57,7 @@ try { The same pattern works when requesting a collection of objects with the exception of using the _spODataEntityArray_ method. ```TypeScript -import { sp, spODataEntityArray, Item } from "@pnp/sp/presets/all"; +import { sp, spODataEntityArray, Item, IItem } from "@pnp/sp/presets/all"; // interface defining the returned properties interface MyProps { @@ -48,7 +68,7 @@ interface MyProps { try { // get a list item loaded with data and merged into an instance of Item - const items = await sp.web.lists.getByTitle("ListTitle").items.select("Id", "Title").get(spODataEntityArray(Item)); + const items = await sp.web.lists.getByTitle("OrderByList").items.select("Id", "Title").usingParser(spODataEntityArray(Item))(); Logger.write(`Item id: ${items.length}`); diff --git a/packages/sp/presets/all.ts b/packages/sp/presets/all.ts index 514917b78..e9c931fea 100644 --- a/packages/sp/presets/all.ts +++ b/packages/sp/presets/all.ts @@ -47,6 +47,7 @@ export * from "../hubsites"; export * from "../items"; export * from "../lists"; export * from "../navigation"; +export { spODataEntity, spODataEntityArray } from "../odata"; export * from "../profiles"; export * from "../regional-settings"; export * from "../related-items"; From 6eccf383f23a7904dd6b6ad0346ef0047dbb9e6f Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Mon, 27 Jan 2020 10:15:20 -0500 Subject: [PATCH 2/3] fix for #1030 --- docs/packages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/packages.md b/docs/packages.md index 05259e5c2..892189697 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -3,7 +3,7 @@ The following packages comprise the Patterns and Practices client side libraries. All of the packages are published as a set and depend on their peers within the @pnp scope. -The latest published version is **{{version}}**. +The latest published version is [![npm version](https://badge.fury.io/js/%40pnp%2Fcommon.svg)](https://badge.fury.io/js/%40pnp%2Fcommon). | || | | ---| -------------|-------------| From a2e74e58badd21dce9575db4c12874bb777278cd Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Mon, 27 Jan 2020 10:43:55 -0500 Subject: [PATCH 3/3] fix typo in PR templates --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c9b75c303..a82275077 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -17,7 +17,7 @@ fixes #X, mentioned in #Y *You can delete this section when you are submitting the pull request.* * Please update this PR information accordingly. We'll use this as part of our release notes in monthly communications. -* Please target your PR to "dev-v2" branch for v2 changes and "version-1" branch for v1 changes +* Please target your PR to "version-2" branch for v2 changes and "version-1" branch for v1 changes * Please ensure you have updated any associated docs files based on your code changes * Please ensure you have updated/added tests to cover your change. * If you are fixing a bug include a test that would have caught the bug you are fixing