UNPKG

spws

Version:

SharePoint Web Services Wrapper

112 lines 4.28 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Creates an xml fields string */ var createFieldsXml = function (fields, type) { // Keys that are excluded based on type of operation (command) var excludedKeys = [ "Choices", "Default", "DefaultFormula", "Formula", "Validation", "Name", ]; switch (type) { case "New": excludedKeys.push("EnforceUniqueValues", "Filterable"); break; default: break; } // Create xml var xml = fields // Iterate through each field .map(function (field, index) { // Create field xml string var fieldXml = ""; switch (type) { case "Delete": fieldXml = "<Field Name=\"".concat(field.StaticName, "\"/>"); break; case "New": case "Update": // Create field xml string fieldXml = "<Field Name=\"".concat(field.StaticName, "\" ").concat(Object.entries(field).reduce( // Iterate through each field key and prop function (string, _a) { var _b = __read(_a, 2), key = _b[0], prop = _b[1]; // Get value from prop var value = ""; var fieldKey = key; // Exclude keys which are not allowed if (excludedKeys.includes(fieldKey)) return string; // Switch by type of prop switch (typeof prop) { case "boolean": value = prop ? "TRUE" : "FALSE"; break; default: value = prop; break; } // Append to string string += "".concat(fieldKey, "=\"").concat(value, "\" "); // Return string (accumulator) return string; }, ""), ">"); break; } // Handle Field Types switch (field.Type) { case "Calculated": if (typeof field.Formula === "string") fieldXml += field.Formula; break; case "Choice": case "MultiChoice": // Handle Choice Fields if (Array.isArray(field.Choices)) fieldXml += "<CHOICES>".concat(field.Choices.map(function (choice) { return "<CHOICE>".concat(choice, "</CHOICE>"); }).join(""), "</CHOICES>"); break; default: break; } // Handle Child Elements if (typeof field.Validation === "string") fieldXml += field.Validation; if (typeof field.DefaultFormula === "string") fieldXml += "<DefaultFormula>".concat(field.DefaultFormula, "</DefaultFormula>"); if (typeof field.DefaultFormulaValue === "string") fieldXml += "<DefaultFormulaValue>".concat(field.DefaultFormulaValue, "</DefaultFormulaValue>"); if (typeof field.Default === "string") fieldXml += "<Default>".concat(field.Default, "</Default>"); // Append to fieldXml fieldXml += "</Field>"; // Return method return "<Method ID=\"".concat(index + 1, "\">").concat(fieldXml, "</Method>\n "); }) .join(""); // Return xml return "<Fields>".concat(xml, "</Fields>"); }; exports.default = createFieldsXml; //# sourceMappingURL=createFieldsXml.js.map