1.0.5 • Published 4 years ago

@sysdoc/sp-rest-provider v1.0.5

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
bitbucket
Last release
4 years ago

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

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago