npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sysdoc/sp-rest-provider

v1.0.5

Published

Sysdoc's Basic REST provider for Sharepoint

Downloads

28

Readme

Sysdoc's Basic REST Provider for Sharepoint

Notes

  • Currently uses @pnp/sp v1.3.8 - needs to be updated to v2.0.0 at some point

Requirements

Basic Use

import { SPBasicRestProvider } from "@sysdoc/sp-rest-provider";

const provider = new SPBasicRestProvider({
  contentTypeId: "<A string value of a Sharepoint ContentTypeId>",
  listTitle: "<A string value of a Sharepoint list title>",
  webUrl: "<The string value of the Sharepoint WebURL you want to use>" // NB: You can use _spPageContextInfo.siteAbsoluteUrl here
});

Basic Use - Available Items

Once a provider has been instantiated you have the following fields available on the provider:

provider.fields;

This returns an array of field names as strings.

provider.schema;

This returns an object which contains all field names for the list used to instantiate the REST provider. Each field name has an object associated with it which contains various metadata fields i.e:

{
  schema: {
    title: {
      odata.type: "SP.FieldText",
      odata.id: "https://sysdoc.sharepoint.com/sites/sys-registers-dev/_api/Web/Lists(guid'4c90fdea-b467-4d80-a9b4-9133de1d8586')/Fields(guid'fa564e0f-0c70-4ab9-b863-0177e6ddd247')",
      odata.editLink: "Web/Lists(guid'4c90fdea-b467-4d80-a9b4-9133de1d8586')/Fields(guid'fa564e0f-0c70-4ab9-b863-0177e6ddd247')",
      EnforceUniqueValues: false,
      Group: "Custom Columns",
      Hidden: false,
      Id: "fa564e0f-0c70-4ab9-b863-0177e6ddd247",
      Indexed: false,
      InternalName: "Title",
      Required: true,
      TypeAsString: "Text"
    }
  }
}

Basic Use - Internal Methods

toItem

TODO: Write explanation of method

getSchema

getSchema is called by the constructor when SPBasicRestProvider is instantiated - it uses the listTitle passed in when the SPBasicRestProvider is instantiated to programatically generate a schema of that lists fields. It then makes this available via the schema prop i.e. - taking our example above the schema would be available:

const provider = new SPBasicRestProvider({
  contentTypeId: "<A string value of a Sharepoint ContentTypeId>",
  listTitle: "<A string value of a Sharepoint list title>",
  webUrl: "<The string value of the Sharepoint WebURL you want to use>" // NB: You can use _spPageContextInfo.siteAbsoluteUrl here
});

const schema = provider.schema;

whenReady

Internal method called by getSchema - generally you do not need to use this by itself.

createSchemaFromFields

Internal method called by whenReady - generally you do not need to use this by itself.

itemToRest

TODO: Write explanation of method

prepareObject

TODO: Write explanation of method

create

TODO: Write explanation of method

update

TODO: Write explanation of method

updateBatch

TODO: Write explanation of method

delete

TODO: Write explanation of method

deleteBatch

TODO: Write explanation of method

getAll

TODO: Write explanation of method

getByQuery

TODO: Write explanation of method

get

TODO: Write explanation of method

Advanced Use - Extending

If you want to extend the REST provider you can do so using the following pattern:

import { SPBasicRestProvider } from "@sysdoc/sp-rest-provider";

export interface ISPFooProvider {
  getBar(userId?: number, limit?: number): Promise<any>;
}

export class SPFooProvider extends SPBasicRestProvider
  implements ISPFooProvider {
  constructor(cfg: ISPBasicRestProviderConfig) {
    super(cfg);
  }

  async getBar(userId?: number, limit?: number): Promise<any> {
    return this.getByQuery(
      `FooBarUser eq ${userId || _spPageContextInfo.userId}`,
      {
        limit: limit || null,
        orderBy: {
          field: "FooBarDate",
          sortAsc: false
        }
      }
    );
  }
}

const provider = new SPFooProvider({
  contentTypeId: "<A string value of a Sharepoint ContentTypeId>",
  listTitle: "<A string value of a Sharepoint list title>",
  webUrl: "<The string value of the Sharepoint WebURL you want to use>" // NB: You can use _spPageContextInfo.siteAbsoluteUrl here
});

const baz = provider.getBar();

This strategy allows you to access all the available methods from basic use - but also allows you to add additional methods