Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Moving from 2.0.* to 3.0.*

jspielmann edited this page Sep 25, 2017 · 10 revisions

The transition from 2 -> 3 versions of the library is disruptive, but we have made these changes with an eye to reducing future pain as we expand. This article outlines all of the changes that are externally visible and maps the previous to new way of doing things to try and make transitioning easier. We recognize updates like this create work on your end - but there is no immediate need to upgrade unless you need MS Graph support or are blocked by a bug fix contained in a 3.0.* version. We will also be updating the other main articles after the release to match these changes. As always feedback is welcome and appreciated.

Breaking Changes

This section outlines those changes that will break your code if you are using particular classes or patterns. Please review each change to see if it applies to you.

Configuration Interface Update

We have updated the configuration interface to split the SharePoint and MS Graph configurations. This is to make it clear what settings you are applying and take the area specific settings out of the global namespace. The properties on the internal RuntimeConfig class were renamed as appropriate.

New Interface Definition

export interface LibraryConfiguration {

    /**
     * Allows caching to be global disabled, default: false
     */
    globalCacheDisable?: boolean;

    /**
     * Defines the default store used by the usingCaching method, default: session
     */
    defaultCachingStore?: "session" | "local";

    /**
     * Defines the default timeout in seconds used by the usingCaching method, default 30
     */
    defaultCachingTimeoutSeconds?: number;

    /**
     * If true a timeout expired items will be removed from the cache in intervals determined by cacheTimeoutInterval
     */
    enableCacheExpiration?: boolean;

    /**
     * Determines the interval in milliseconds at which the cache is checked to see if items have expired (min: 100)
     */
    cacheExpirationIntervalMilliseconds?: number;

    /**
     * SharePoint specific library settings
     */
    sp?: {

        /**
         * Any headers to apply to all requests
         */
        headers?: TypedHash<string>;

        /**
         * Defines a factory method used to create fetch clients
         */
        fetchClientFactory?: () => HttpClientImpl;

        /**
         * The base url used for all requests
         */
        baseUrl?: string;
    };

    /**
     * MS Graph specific library settings
     */
    graph?: {

        /**
         * Any headers to apply to all requests
         */
        headers?: TypedHash<string>;

        /**
         * Defines a factory method used to create fetch clients
         */
        fetchClientFactory?: () => GraphHttpClientImpl;
    };

    /**
     * Used to supply the current context from an SPFx webpart to the library
     */
    spfxContext?: any;
}

Example

pnp.setup({

    sp: {
        baseUrl: "https://mytenant.sharepoint.com/sites/dev",
        headers: {
            "Header1": "Header1Value"

        },
    },

    graph: {
        headers: {
            "Header2": "Header2Value"
        }
    }
});

Renamed Exports

The following classes and functions were renamed as they are SharePoint specific. It is likely you are not using these directly but please review your code. This would apply especially if you are creating your own entities for use with getAs.

  • ODataEntity => spODataEntity
  • ODataEntityArray => spODataEntityArray
  • extractODataId => spExtractODataId
  • getEntityUrl => spGetEntityUrl

Queryable Generification

To support the graph work we have consolidated to a shared Queryable base class. This necessitated a rename of the existing Queryable to SharePointQueryable.

  • Queryable is now a generic and exported under the /exports/odata namespace
  • The previous Queryable* classes are renamed to SharePointQueryable* and are exported under /exports/sp
  • The new classes for graph are GraphQueryable* and exported under /exports/graph

Non-breaking Changes

Graph Support

This release adds initial support for calling MS Graph through the SPFx GraphHttpClient. You can access the methods from the "graph" property from the root. This will currently only work within SPFx and you must provide the current SPFx context.

pnp.graph.v1.groups.get().then({ 
  //...
});

Remove Locale.ts

Please see this page if you need to reference or use this enum.

Change to .clone behavior

The internally used clone method was updated to include the batch by default. Saving a lot of "true" literals within the code.

Locked package.json versions

The "^" was removed from all versions in package.json. This will avoid the cases where minor updates to dependencies resulted in breaking changes. The dependencies will be updated with each release to the latest available at that time. This allows proper testing of new versions and removes the element of surprise.

Clone this wiki locally