Sysdoc's Basic REST provider for Sharepoint
- Currently uses @pnp/sp v1.3.8 - needs to be updated to v2.0.0 at some point
``tsx
import { SPBasicRestProvider } from "@sysdoc/sp-rest-provider";
const provider = new SPBasicRestProvider({
contentTypeId: "",
listTitle: "",
webUrl: "
});
`
Once a provider has been instantiated you have the following fields available on the provider:
`tsx`
provider.fields;
This returns an array of field names as strings.
`tsx`
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:
`tsx`
{
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"
}
}
}
#### 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:
`tsx
const provider = new SPBasicRestProvider({
contentTypeId: "",
listTitle: "",
webUrl: "
});
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
If you want to extend the REST provider you can do so using the following pattern:
`tsx
import { SPBasicRestProvider } from "@sysdoc/sp-rest-provider";
export interface ISPFooProvider {
getBar(userId?: number, limit?: number): Promise
}
export class SPFooProvider extends SPBasicRestProvider
implements ISPFooProvider {
constructor(cfg: ISPBasicRestProviderConfig) {
super(cfg);
}
async getBar(userId?: number, limit?: number): Promise
return this.getByQuery(
FooBarUser eq ${userId || _spPageContextInfo.userId},
{
limit: limit || null,
orderBy: {
field: "FooBarDate",
sortAsc: false
}
}
);
}
}
const provider = new SPFooProvider({
contentTypeId: "",
listTitle: "",
webUrl: "
});
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