| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.generateObjSchema = exports.enumArraySchema = exports.arraySchema = void 0;
|
|---|
| 7 | function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|---|
| 8 | function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|---|
| 9 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|---|
| 10 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 11 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|---|
| 12 | /**
|
|---|
| 13 | * JSON schema to accept an array of unique strings
|
|---|
| 14 | */
|
|---|
| 15 | var arraySchema = exports.arraySchema = {
|
|---|
| 16 | type: 'array',
|
|---|
| 17 | items: {
|
|---|
| 18 | type: 'string'
|
|---|
| 19 | },
|
|---|
| 20 | uniqueItems: true,
|
|---|
| 21 | additionalItems: false
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * JSON schema to accept an array of unique strings from an enumerated list.
|
|---|
| 26 | */
|
|---|
| 27 | var enumArraySchema = exports.enumArraySchema = function enumArraySchema() {
|
|---|
| 28 | var enumeratedList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|---|
| 29 | var minItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|---|
| 30 | return _objectSpread(_objectSpread({}, arraySchema), {}, {
|
|---|
| 31 | items: {
|
|---|
| 32 | type: 'string',
|
|---|
| 33 | "enum": enumeratedList
|
|---|
| 34 | },
|
|---|
| 35 | minItems
|
|---|
| 36 | });
|
|---|
| 37 | };
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * Factory function to generate an object schema
|
|---|
| 41 | * with specified properties object
|
|---|
| 42 | */
|
|---|
| 43 | var generateObjSchema = exports.generateObjSchema = function generateObjSchema() {
|
|---|
| 44 | var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|---|
| 45 | var required = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|---|
| 46 | return {
|
|---|
| 47 | type: 'object',
|
|---|
| 48 | properties,
|
|---|
| 49 | required
|
|---|
| 50 | };
|
|---|
| 51 | }; |
|---|