@openframe-org/criteria-set-protocol 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v1/utils.d.ts +11 -1
- package/dist/v1/utils.js +48 -1
- package/package.json +1 -1
package/dist/v1/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, CriteriaTree, CriteriaTreeElement, Theme, Criterion, Task, TaskGroup, TaskItem, ThemeOptions, CriterionOptions, TaskOptions, CertificationDefinition, TaskItemValue } from "./types";
|
|
1
|
+
import { Color, CriteriaTree, CriteriaTreeElement, Theme, Criterion, Task, TaskGroup, TaskItem, ThemeOptions, CriterionOptions, TaskOptions, CertificationDefinition, TaskItemValue, TaskItemData, ElementData, TreeResult } from "./types";
|
|
2
2
|
interface ApplyTextFormattingPlaceholdersForThemeFunction {
|
|
3
3
|
(options: ThemeOptions, element: Pick<Task, "title" | "code">): string;
|
|
4
4
|
}
|
|
@@ -50,4 +50,14 @@ export declare const isNil: (value: unknown) => value is null | undefined;
|
|
|
50
50
|
* Given a list of certification definitions, return the ones for which the given value is valid
|
|
51
51
|
*/
|
|
52
52
|
export declare const getCertificationsByValue: (certificationDefinitions: CertificationDefinition[], value?: TaskItemValue) => CertificationDefinition[] | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Given a tree element or a data object, validate that it contains valid data. If it is a tree element,
|
|
55
|
+
* extract the data object from it and validate it:
|
|
56
|
+
* - If the data is a number/<undefined> type, ensure that it has a numeric value and total
|
|
57
|
+
* - If the data is a percentage type, ensure that it has a numeric value
|
|
58
|
+
* - If the data is a boolean type, ensure that it has a boolean value
|
|
59
|
+
* - If it is a different type, throw an error
|
|
60
|
+
* In all cases, the data should contain 'text' and 'readOnly' properties
|
|
61
|
+
*/
|
|
62
|
+
export declare const validateData: (dataOrTreeElement: CriteriaTreeElement | TaskItemData | ElementData | TreeResult) => void;
|
|
53
63
|
export {};
|
package/dist/v1/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCertificationsByValue = exports.isNil = exports.applyReportTitleTextFormatFormattingPlaceholders = exports.applyCriteriaTreeElementTextFormatFormattingPlaceholders = exports.applyDocumentTreeFolderTextFormattingPlaceholders = exports.applyBreadcrumbTextFormattingPlaceholders = exports.findInTree = exports.toColorHexString = exports.isTaskItem = exports.isTask = exports.isTaskGroup = exports.isCriterion = exports.isTheme = void 0;
|
|
3
|
+
exports.validateData = exports.getCertificationsByValue = exports.isNil = exports.applyReportTitleTextFormatFormattingPlaceholders = exports.applyCriteriaTreeElementTextFormatFormattingPlaceholders = exports.applyDocumentTreeFolderTextFormattingPlaceholders = exports.applyBreadcrumbTextFormattingPlaceholders = exports.findInTree = exports.toColorHexString = exports.isTaskItem = exports.isTask = exports.isTaskGroup = exports.isCriterion = exports.isTheme = void 0;
|
|
4
4
|
const isTheme = (element) => element.type === "theme";
|
|
5
5
|
exports.isTheme = isTheme;
|
|
6
6
|
const isCriterion = (element) => element.type === "criterion";
|
|
@@ -91,3 +91,50 @@ const getCertificationsByValue = (certificationDefinitions, value) => {
|
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
exports.getCertificationsByValue = getCertificationsByValue;
|
|
94
|
+
/**
|
|
95
|
+
* Given a tree element or a data object, validate that it contains valid data. If it is a tree element,
|
|
96
|
+
* extract the data object from it and validate it:
|
|
97
|
+
* - If the data is a number/<undefined> type, ensure that it has a numeric value and total
|
|
98
|
+
* - If the data is a percentage type, ensure that it has a numeric value
|
|
99
|
+
* - If the data is a boolean type, ensure that it has a boolean value
|
|
100
|
+
* - If it is a different type, throw an error
|
|
101
|
+
* In all cases, the data should contain 'text' and 'readOnly' properties
|
|
102
|
+
*/
|
|
103
|
+
const validateData = (dataOrTreeElement) => {
|
|
104
|
+
const data = "data" in dataOrTreeElement ? dataOrTreeElement.data : dataOrTreeElement;
|
|
105
|
+
if (!data) {
|
|
106
|
+
throw new Error("Invalid data object");
|
|
107
|
+
}
|
|
108
|
+
["readOnly", "value", "text"].forEach((property) => {
|
|
109
|
+
if (!(property in data)) {
|
|
110
|
+
throw new Error(`Missing '${property}' property`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
switch (data.type) {
|
|
114
|
+
case "number":
|
|
115
|
+
case undefined: {
|
|
116
|
+
if (typeof data.value !== "number") {
|
|
117
|
+
throw new Error("Invalid numeric data");
|
|
118
|
+
}
|
|
119
|
+
if (!("total" in data) || typeof data.total !== "number") {
|
|
120
|
+
throw new Error("Invalid numeric total");
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case "percentage": {
|
|
125
|
+
if (typeof data.value !== "number") {
|
|
126
|
+
throw new Error("Invalid percentage data");
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "boolean": {
|
|
131
|
+
if (typeof data.value !== "boolean") {
|
|
132
|
+
throw new Error("Invalid boolean data");
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
default:
|
|
137
|
+
throw new Error(`Invalid data type: ${data.type}`);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.validateData = validateData;
|
package/package.json
CHANGED