From 55b012d5a20a0bce9adcf95783d55e5397bde051 Mon Sep 17 00:00:00 2001 From: Santiago Adolfo Gutierrez Akel Date: Thu, 23 Nov 2017 18:01:22 -0300 Subject: [PATCH] updated documentation for relationship and lookup --- lib/FakeAdaptor.js | 66 ++++++++++++++++++++++++++++++++++++++++++-- lib/sourceHelpers.js | 23 ++++++++------- src/sourceHelpers.js | 23 ++++++++------- 3 files changed, 90 insertions(+), 22 deletions(-) diff --git a/lib/FakeAdaptor.js b/lib/FakeAdaptor.js index e59e126..2968449 100644 --- a/lib/FakeAdaptor.js +++ b/lib/FakeAdaptor.js @@ -1,3 +1,4 @@ +/** @module FakeAdaptor */ 'use strict'; Object.defineProperty(exports, "__esModule", { @@ -137,8 +138,17 @@ var _lodashFp = require('lodash-fp'); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } -/** @module FakeAdaptor */ +/** + * Flattens an array of operations. + * @example + * steps( + * createIf(params), + * update(params) + * ) + * @function + * @returns {Array} + */ function steps() { for (var _len = arguments.length, operations = Array(_len), _key = 0; _key < _len; _key++) { operations[_key] = arguments[_key]; @@ -147,13 +157,40 @@ function steps() { return (0, _lodashFp.flatten)(operations); } -// TODO: use the one from language-common +/** + * Expands references. + * @example + * expandReferences( + * state, + * { + * attr1: "foo", + * attr2: "bar" + * } + * ) + * @function + * @param {Object} attrs - Field attributes for the new object. + * @param {State} state - Runtime state. + * @returns {State} + */ function expandReferences(attrs, state) { + // TODO: use the one from language-common return (0, _lodashFp.mapValues)(function (value) { return typeof value == 'function' ? value(state) : value; })(attrs); } +/** + * Create a new object. + * @example + * create('obj_name', { + * attr1: "foo", + * attr2: "bar" + * }) + * @function + * @param {String} sObject - API name of the sObject. + * @param {Object} fields - Field attributes for the new object. + * @returns {Operation} + */ function create(sObject, fields) { return function (state) { @@ -171,6 +208,18 @@ function create(sObject, fields) { }; } +/** + * Update an object. + * @example + * update('obj_name', { + * attr1: "foo", + * attr2: "bar" + * }) + * @function + * @param {String} sObject - API name of the sObject. + * @param {Object} fields - Field attributes for the new object. + * @returns {Operation} + */ function update(sObject, fields) { return function (state) { @@ -188,6 +237,19 @@ function update(sObject, fields) { }; } +/** + * Upsert an object. + * @example + * upsert('obj_name', 'ext_id', { + * attr1: "foo", + * attr2: "bar" + * }) + * @function + * @param {String} sObject - API name of the sObject. + * @param {String} externalId - ID. + * @param {Object} fields - Field attributes for the new object. + * @returns {Operation} + */ function upsert(sObject, externalId, fields) { return function (state) { diff --git a/lib/sourceHelpers.js b/lib/sourceHelpers.js index 56abcf2..4ec2630 100644 --- a/lib/sourceHelpers.js +++ b/lib/sourceHelpers.js @@ -14,11 +14,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope /** * Adds a lookup or 'dome insert' to a record. - * @example Example - * lookup("relationship_name__r", "externalID on related object", "$.path") - * @constructor + * @public + * @example + * lookup("relationship_name__r", "externalID on related object", "$.path") + * @function * @param {string} relationshipName - `__r` relationship field on the record. - * @param {string} externalID - Salesforce ExternalID field. + * @param {string} externalId - Salesforce ExternalID field. * @param {string} path - JSONPath to data source. * @returns {object} */ @@ -30,13 +31,15 @@ function lookup(relationshipName, externalId, path) { /** * Adds a lookup or 'dome insert' to a record. - * @example Data Sourced Value - * relationship("relationship_name__r", "externalID on related object", dataSource("path")) - * @example Fixed Value - * relationship("relationship_name__r", "externalID on related object", "hello world") - * @constructor + * @public + * @example + * Data Sourced Value: + * relationship("relationship_name__r", "externalID on related object", dataSource("path")) + * Fixed Value: + * relationship("relationship_name__r", "externalID on related object", "hello world") + * @function * @param {string} relationshipName - `__r` relationship field on the record. - * @param {string} externalID - Salesforce ExternalID field. + * @param {string} externalId - Salesforce ExternalID field. * @param {string} dataSource - resolvable source. * @returns {object} */ diff --git a/src/sourceHelpers.js b/src/sourceHelpers.js index 354a5ce..5658d80 100644 --- a/src/sourceHelpers.js +++ b/src/sourceHelpers.js @@ -3,11 +3,12 @@ import { sourceValue, field } from 'language-common'; /** * Adds a lookup or 'dome insert' to a record. - * @example Example - * lookup("relationship_name__r", "externalID on related object", "$.path") - * @constructor + * @public + * @example + * lookup("relationship_name__r", "externalID on related object", "$.path") + * @function * @param {string} relationshipName - `__r` relationship field on the record. - * @param {string} externalID - Salesforce ExternalID field. + * @param {string} externalId - Salesforce ExternalID field. * @param {string} path - JSONPath to data source. * @returns {object} */ @@ -20,13 +21,15 @@ export function lookup(relationshipName, externalId, path) { /** * Adds a lookup or 'dome insert' to a record. - * @example Data Sourced Value - * relationship("relationship_name__r", "externalID on related object", dataSource("path")) - * @example Fixed Value - * relationship("relationship_name__r", "externalID on related object", "hello world") - * @constructor + * @public + * @example + * Data Sourced Value: + * relationship("relationship_name__r", "externalID on related object", dataSource("path")) + * Fixed Value: + * relationship("relationship_name__r", "externalID on related object", "hello world") + * @function * @param {string} relationshipName - `__r` relationship field on the record. - * @param {string} externalID - Salesforce ExternalID field. + * @param {string} externalId - Salesforce ExternalID field. * @param {string} dataSource - resolvable source. * @returns {object} */