@brightspace-hmc/siren-sdk
Advanced tools
Comparing version 3.11.0 to 3.11.1
{ | ||
"name": "@brightspace-hmc/siren-sdk", | ||
"version": "3.11.0", | ||
"version": "3.11.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -5,2 +5,7 @@ import { dispose, entityFactory, updateEntity } from './EntityFactory.js'; | ||
/** | ||
* @typedef {import('siren-parser').Entity} ParsedEntity | ||
* @typedef {import('./EntityFactory').EntityListener} EntityListener | ||
*/ | ||
/** | ||
* Abstract Entity class to help create entity classes. | ||
@@ -11,5 +16,5 @@ */ | ||
* Primes the object used by the entityFactory. Should never be called outside. | ||
* @param {Object} entity A hypermedia siren entity as defined by [the siren specification]{@link https://github.com/kevinswiber/siren} | ||
* @param {String|Function|null} token JWT Token for brightspace | a function that returns a JWT token for brightspace | null (defaults to cookie authentication in a browser) | ||
* @param {Function} listener Listener helper class | ||
* @param {ParsedEntity} entity A hypermedia siren entity as defined by [the siren specification]{@link https://github.com/kevinswiber/siren} | ||
* @param {String|Function} [token] JWT Token for brightspace | a function that returns a JWT token for brightspace | null (defaults to cookie authentication in a browser) | ||
* @param {EntityListener} listener Listener helper class | ||
*/ | ||
@@ -22,2 +27,6 @@ constructor(entity, token, listener) { | ||
this._entity = entity; | ||
/** | ||
* @type {Map<string, EntitySirenProperties>} | ||
*/ | ||
this._subEntities = new Map(); | ||
@@ -41,2 +50,6 @@ this._token = token; | ||
} | ||
/** | ||
* @param {ParsedEntity} entity | ||
*/ | ||
update(entity) { | ||
@@ -56,5 +69,7 @@ updateEntity(this.self(), this._token, entity); | ||
* Protected: Add a listener to a subentity of this entity. | ||
* @param {*} entityType A entity class that extends this class. | ||
* @param {*} href Href or Entity of the entity to be created | ||
* @param {*} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
* | ||
* @template {EntitySirenProperties} EntityType | ||
* @param {new (...args: any[]) => EntityType} entityType A entity class that extends this class. | ||
* @param {string|ParsedEntity} href Href or Entity of the entity to be created | ||
* @param {(entityType: EntityType, error: any) => void} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
*/ | ||
@@ -75,5 +90,7 @@ _subEntity(entityType, href, onChange) { | ||
* Protected: Add a listener to a subentity of this entity. | ||
* @param {*} entityType A entity class that extends this class. | ||
* @param {*} source Href of the entity to be created | ||
* @param {*} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
* | ||
* @template {EntitySirenProperties} EntityType | ||
* @param {new (...args: any[]) => EntityType} entityType A entity class that extends this class. | ||
* @param {string} source Href of the entity to be created | ||
* @param {(entityType: EntityType, error: any) => void} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
*/ | ||
@@ -111,5 +128,7 @@ _subEntityByHref(entityType, source, onChange) { | ||
* Protected: Add a listener to a subentity of this entity. | ||
* @param {*} entityType A entity class that extends this class. | ||
* @param {*} entity Entity that has already been fetched as a sub-entity. Requires either an href or a self link | ||
* @param {*} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
* | ||
* @template {EntitySirenProperties} EntityType | ||
* @param {new (...args: any[]) => EntityType} entityType A entity class that extends this class. | ||
* @param {ParsedEntity} entity Entity that has already been fetched as a sub-entity. Requires either an href or a self link | ||
* @param {(entityType: EntityType, error: any) => void} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
*/ | ||
@@ -116,0 +135,0 @@ _subEntityByEntity(entityType, entity, onChange) { |
import 'd2l-polymer-siren-behaviors/store/entity-store.js'; | ||
/** | ||
* @typedef {import('siren-parser').Entity} ParsedEntity | ||
* @typedef {import('siren-parser').Link} SirenLink | ||
* @typedef {import('./EntitySirenProperties').EntitySirenProperties} EntitySirenProperties | ||
*/ | ||
/** Allows one to manage the event store listeners. Makes it easy to update, add and remove a listener for the entity store. */ | ||
class EntityListener { | ||
export class EntityListener { | ||
constructor() { | ||
@@ -60,7 +66,7 @@ this._href; | ||
* This creates and fetch a new entity. Whenever the entity changes onChange is called. | ||
* @param {Function} entityType The type of the entity. For example OrganizationEntity | ||
* @param {Object|String} href Siren Link or Href of the entity to be created | ||
* @param {String|Token|Null} token JWT Token for brightspace | a function that returns a JWT token for brightspace | null (defaults to cookie authentication in a browser) | ||
* @param {Function} onChange Callback function that accepts an {entityType} to be called when entity changes. If there are errors onChange is called with (null, error) | ||
* @param {Object} entity (Optional) Entity that has already been fetched. | ||
* @param {new(...args: any[]) => EntitySirenProperties} entityType The type of the entity. For example OrganizationEntity | ||
* @param {SirenLink|String} href Siren Link or Href of the entity to be created | ||
* @param {String|Function} [token] JWT Token for brightspace | a function that returns a JWT token for brightspace | null (defaults to cookie authentication in a browser) | ||
* @param {(entity: EntitySirenProperties, error: any) => void} onChange Callback function that accepts an {entityType} to be called when entity changes. If there are errors onChange is called with (null, error) | ||
* @param {ParsedEntity} entity (Optional) Entity that has already been fetched. | ||
*/ | ||
@@ -103,3 +109,3 @@ export function entityFactory(entityType, href, token, onChange, entity) { | ||
* Some times the entity doesn't exists so this allows the cleanup code to be cleaner. | ||
* @param {Object|Null} entity Object that is of an Entity type. | ||
* @param {EntitySirenProperties|null} entity Object that is of an Entity type. | ||
*/ | ||
@@ -106,0 +112,0 @@ export function dispose(entity) { |
import { EntitySirenProperties } from './EntitySirenProperties.js'; | ||
/** | ||
* @typedef {import('siren-parser').Entity} ParsedEntity | ||
* @typedef {import('./Entity').Entity} SDKEntity | ||
*/ | ||
/** | ||
* Abstract Entity class to help create entity classes without self-links. | ||
@@ -10,4 +15,4 @@ * These entities are transient, and are not saved within the Entity Store. | ||
* Sets the parent object and setups the siren entity ready to be decoded by extending this class. | ||
* @param {Object} sdkParentEntity Parent entity that is a Entity. | ||
* @param {Object} entity A hypermedia siren entity as defined by [the siren specification]{@link https://github.com/kevinswiber/siren} | ||
* @param {SDKEntity} sdkParentEntity Parent entity that is a Entity. | ||
* @param {ParsedEntity} entity A hypermedia siren entity as defined by [the siren specification]{@link https://github.com/kevinswiber/siren} | ||
*/ | ||
@@ -24,5 +29,7 @@ constructor(sdkParentEntity, entity) { | ||
* Protected: Add a listener to a subentity of the this entity and gives ownership to parent entity. | ||
* @param {*} entityType A entity class that extends this class. | ||
* @param {*} href Href or Entity of the entity to be created | ||
* @param {*} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
* | ||
* @template {EntitySirenProperties} EntityType | ||
* @param {new (...args: any[]) => EntityType} entityType A entity class that extends this class. | ||
* @param {string} href Href or Entity of the entity to be created | ||
* @param {(entityType: EntityType, error: any) => void} onChange callback function that accepts an {entityType} to be called when subentity changes. | ||
*/ | ||
@@ -29,0 +36,0 @@ _subEntity(entityType, href, onChange) { |
@@ -6,2 +6,13 @@ import 'd2l-fetch/d2l-fetch.js'; | ||
/** | ||
* @typedef {import('siren-parser').Action} Action | ||
* @typedef {import('siren-parser').Field} Field | ||
* @typedef {import('siren-parser').Entity} ParsedEntity | ||
* @typedef {{ name: string; value: string }} FieldOverride | ||
*/ | ||
/** | ||
* @param {Action} action | ||
* @returns {FieldOverride[]} | ||
*/ | ||
const _getSirenFields = function(action) { | ||
@@ -28,2 +39,6 @@ const url = new URL(action.href, window.location.origin); | ||
/** | ||
* @param {FieldOverride[]} fields | ||
* @returns {URLSearchParams} | ||
*/ | ||
const _createURLSearchParams = function(fields) { | ||
@@ -38,2 +53,7 @@ const sequence = []; | ||
/** | ||
* @param {Action} action | ||
* @param {FieldOverride[]} fields | ||
* @returns {URL} | ||
*/ | ||
const _getEntityUrl = function(action, fields) { | ||
@@ -61,2 +81,7 @@ if (!action) { | ||
/** | ||
* @param {Action} action | ||
* @param {FieldOverride[]} fields | ||
* @returns {FieldOverride[]} | ||
*/ | ||
const _appendHiddenFields = function(action, fields) { | ||
@@ -211,2 +236,6 @@ if (action.fields && action.fields.forEach) { | ||
* Then executes list of combined actions. Performing siren actions immediately not supported. | ||
* | ||
* @param {string|Function} token | ||
* @param {{ action: Action, fields: FieldOverride[] }[]} actionsAndFields | ||
* @returns {Promise<ParsedEntity[]>} | ||
*/ | ||
@@ -229,2 +258,10 @@ export const performSirenActions = function(token, actionsAndFields) { | ||
/** | ||
* @param {string|Function} token | ||
* @param {Action} action | ||
* @param {FieldOverride[]} fields | ||
* @param {boolean} [immediate] | ||
* @param {boolean} [bypassCache] | ||
* @returns {Promise<ParsedEntity>} | ||
*/ | ||
export const performSirenAction = function(token, action, fields, immediate, bypassCache) { | ||
@@ -240,2 +277,9 @@ return window.D2L.Siren.EntityStore.getToken(token) | ||
/** | ||
* @param {string|Function} token | ||
* @param {() => Action} actionFactory | ||
* @param {FieldOverride[]} fieldOverrides | ||
* @param {boolean} [bypassCache] | ||
* @returns {Promise<ParsedEntity>} | ||
*/ | ||
export const performLazySirenAction = function(token, actionFactory, fieldOverrides, bypassCache) { | ||
@@ -242,0 +286,0 @@ fieldOverrides = fieldOverrides || {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
415254
11501