<private> new ResourcefulEndpoint(resourceful)
Parameters:
| Name | Type | Description |
|---|---|---|
resourceful |
Object | the Sequoia descriptor part that describes this endpoint |
- Source:
Returns:
- Type
- ResourcefulEndpoint
Example
// `contents` is used in the rest of the examples as our reference
// to a ResourcefulEndpoint
let contents;
client.login('username', 'password').then(session => {
client.service('metadata').then(service => {
// Get a resourceful endpoint (this is synchronous as the service passed
// all the necessary data):
contents = service.resourcefulEndpoint('contents');
// whatever
});
});
Members
-
batchSize :number
-
Get the
batchSizefrom the descriptor'sstoreBatchoperation. This is how many resources can be saved at once when saving a ResourceCollectionType:
- number
- Source:
-
hyphenatedPluralName :string
-
Get the
hyphenatedPluralNamefrom the descriptor. The hyphenated plural name is used to identify what the resourceful endpoint is called. e.g. a camelCased resource (pluralName) likecontentSegmentswill live under an HTTP endpoint ofcontent-segmentsType:
- string
- Source:
-
pluralName :string
-
Get the
pluralNamefrom the descriptor. The plural name is used to identify the content array from the JSON response from Sequoia. e.g. forassets, the response will be of the form:{ assets: [ asset resource, asset resource ... ], linked: [ linked resource, linked resource ... ], meta: { ...meta info } }Type:
- string
- Source:
-
relationships :object
-
Get the relationship info from the descriptor.
Type:
- object
- Source:
Example
contents.relationships // Returns: { "children": { "description": "The associated child contents", "type": "indirect", "resourceType": "contents", "filterName": "withParentRef", "fields": [ "ref", "title", "parentRef", "type" ], "batchSize": 10, "name": "children" }, "assets": { "description": "The associated assets", "type": "indirect", "resourceType": "assets", "filterName": "withContentRef", "fields": [ "ref", "name", "contentRef", "type", "url", "fileFormat", "title", "fileSize", "tags" ], "batchSize": 10, "name": "assets" } } -
serviceName :string
-
Get the
serviceNamefrom the descriptor.Type:
- string
- Source:
-
singularName :string
-
Get the
singularNamefrom the descriptor. The singular name is used to identify what the specific resourceful resource is identified as.Type:
- string
- Source:
Methods
-
<async> all(criteria, options)
-
The same as ResourcefulEndpoint#browse but will fetch all pages as a single ResourceCollection
Parameters:
Name Type Description criteriastring | Query A query string to append to the request
optionsobject - Source:
- See:
Returns:
- Type
- Promise
-
browse(criteria, options)
-
Perform a browse (a GET for all items on this resourceful endpoint, with optional
criteria). The collection returned is the first page of results as specified byperPage(or the Resourceful default e.g. 100)Parameters:
Name Type Description criteriastring | Query A query string to append to the request
optionsobject - Source:
- See:
-
- Trasport#get
Returns:
- Type
- Promise
-
<private> criteriaToQuery(criteria)
-
Return a query string to append to the HTTP call. Will default to appending
?owner=<owner>Parameters:
Name Type Argument Description criteriastring | Query <nullable>
A (potential) query string to append to the request
- Source:
Returns:
- Type
- string
-
destroy(resource, options)
-
Destroy (perform an HTTP DELETE for) an existing item
Parameters:
Name Type Description resourceObject An Object corresponding to the resouce you wish to delete
optionsobject - Source:
- See:
Returns:
- Type
- Promise
-
<private> endPointUrl(ref, criteria)
-
Get the full URL to the resourceful endpoint/item we will send the request to
Parameters:
Name Type Argument Description refstring <nullable>
An optional unique ref for performing actions on a unique item (rather than browsing)
criteriastring | Query <nullable>
A (potential) query string to append to the request
Returns:
- Type
- string
-
newResource(data)
-
Obtain a new Resource for this endpoint. A new resource is something that has not yet been created remotely.
The
ownerproperty will be pre-populated with the current tenancy. Provding a a value for this will override the current tenancy. This is useful when using root tenancy but populating data on behalf of non-root tenancies. See Client#setTenancy for more information.When a
nameproperty is provided, theref(unique id) of this resource will also be populated. This is useful for allowing linking different kinds of resources together (see Resource#link) before saving the resources.There is a potential that
names you choose will conflict with already stored resources. In this case, your changes will override the remote resource. See the below example for how to handle these situations.Parameters:
Name Type Description dataObject data to populate the Resource with
Properties
Name Type Argument Description ownerstring <optional>
Defaults to the current tenancy name
- Source:
Returns:
- Type
- Resource
Examples
Create a new resource
const contentItem = contents.newResource({ name: 'my-new-content', title: 'something', synopsis: 'a really long synopsis' }); // You can now call methods on it, for example, a usual flow for creating // a Resource would be: contentItem.validate() .then(() => contentItem.save()) .then(() => { // Success, do something (redirect to a new view?) }).catch((error) => { // Validation error (from Resource object or the server), show the user what went wrong });Update or create a piece of content
const potentiallyNewContentItem = contents.newResource({ name: 'my-potentially-new-content', title: 'something new', synopsis: 'a really long synopsis' }); function findOrCreateResource(resourceful, data) { return resourceful.readOne(`${resourceful.owner}:${data.name}`).catch(() => resourceful.newResource(data)); } // You can now call methods on it, for example, a usual flow for creating // a Resource would be: findOrCreateResource(contents, potentiallyNewContentItem) .then((contentItem) => { // Update with new data in case it was an existing resource Object.assign(contentItem, potentiallyNewContentItem); contentItem.duration = 'PT75M'; return contentItem.save()) .then(() => { // Success, do something (redirect to a new view?) }).catch((error) => { // Validation error (from the server), show the user what went wrong }); -
newResourceCollection(data)
-
Create a new ResourceCollection for this endpoint.
Useful for creating many resources for ingest.
Parameters:
Name Type Description dataArray.<Object> data to populate the ResourceCollection with
- Source:
Returns:
- Type
- ResourceCollection
Example
Create a new resource
const contentItems = contents.newResourceCollection([{ name: 'one', title: 'something', synopsis: 'a really long synopsis' }, { name: 'two', title: 'something else', synopsis: 'another really long synopsis' }]); contentItems.validate() .then(() => contentItems.save()) .then(() => { // Success, do something (redirect to a new view?) }).catch((error) => { // Validation error (from a nested Resource object or the server), show the user what went wrong }); -
readMany(refs, criteria, options)
-
Fetch (performs an HTTP GET on) many items, with optional criteria
Parameters:
Name Type Description refsArray.<String> The unique
referencesfor the itemscriteriastring | Query A query string to append to the request
optionsobject - Source:
- See:
Returns:
- Type
- Promise
-
readOne(ref, criteria, options)
-
Fetch (performs an HTTP GET on) an individual item, with optional criteria
Parameters:
Name Type Description refstring The unique
referencefor this itemcriteriastring | Query A query string to append to the request
optionsobject - Source:
- See:
Returns:
- A Resource
- Type
- Promise
-
relationshipFor(relationshipName)
-
Get the relationship info for
relationshipNamefrom the descriptorParameters:
Name Type Description relationshipNamestring The name of the relationship e.g. 'assets'
- Source:
Throws:
-
- Throws when the relationship doesn't exist
- Type
- Error
Returns:
- Type
- Object
Example
contents.relationshipFor('categories'); // Returns: { "description": "The associated categories", "type": "direct", "resourceType": "categories", "fieldNamePath": "categoryRefs", "fields": [ "ref", "title", "parentRef", "scheme", "value" ], "name": "categories", "batchSize": 10 } -
<private> responseToResource()
-
Turn the first item in the Sequoia response for this endpoint into a Resource. This is a convenience for when operating on individual Resources (read, update, store) where the sequoia response is of the form
{ <pluralName>: [<Resource>], meta: { ... } }and we want to just operate on
Resource- Source:
Returns:
- Type
- Resource
-
store(resource, options)
-
Store (perform an HTTP POST for) a new item
Parameters:
Name Type Description resourceResource A Resource corresponding to the new resource you wish to save
optionsobject - Source:
- See:
- To Do:
-
- Validate against the descriptor that this is a valid item to store
Returns:
- Type
- Promise
-
update(resource, options)
-
Update (perform an HTTP PUT for) an existing item
Parameters:
Name Type Description resourceObject An Object corresponding to the new resouce you wish to save
optionsobject - Source:
- See:
- To Do:
-
- Validate against the descriptor that this is a valid item to store
Returns:
- Type
- Promise
Javascript Client SDK