@openframe-org/criteria-set-protocol 2.7.9 → 2.7.11
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.
|
@@ -106,7 +106,7 @@ export declare const elementDataMapSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[
|
|
|
106
106
|
export declare const dataMapSchema: z.ZodObject<{
|
|
107
107
|
version: z.ZodString;
|
|
108
108
|
revision: z.ZodString;
|
|
109
|
-
|
|
109
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodType<{
|
|
110
110
|
text: string;
|
|
111
111
|
} & ({
|
|
112
112
|
[x: string]: any;
|
|
@@ -13,8 +13,8 @@ exports.dataMapSchema = zod_1.z
|
|
|
13
13
|
.string()
|
|
14
14
|
.describe("The version of the criteria set used to generate the data map"),
|
|
15
15
|
revision: zod_1.z.string().describe("The internal version of this criteria set"),
|
|
16
|
-
|
|
17
|
-
.describe("
|
|
16
|
+
data: exports.elementDataMapSchema
|
|
17
|
+
.describe("Map of element codes to data generated by the criteria set"),
|
|
18
18
|
result: common_1.treeResultSchema.describe("The overall result of the evaluation of the criteria set"),
|
|
19
19
|
certifications: zod_1.z
|
|
20
20
|
.array(zod_1.z.string())
|
package/dist/v1/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, CriteriaTree, CriteriaTreeElement, Theme, Criterion, Task, TaskGroup, TaskItem, CertificationDefinition, TaskItemValueReference, TaskItemData, ElementData, TreeResult, CriteriaTreeElementType } from "./types";
|
|
1
|
+
import { Color, CriteriaTree, CriteriaTreeElement, Theme, Criterion, Task, TaskGroup, TaskItem, CertificationDefinition, TaskItemValueReference, TaskItemData, ElementData, TreeResult, CriteriaTreeElementType, TaskItemDefinition } from "./types";
|
|
2
2
|
interface ApplyBreadcrumbTextFormattingPlaceholdersFunction {
|
|
3
3
|
(options: {
|
|
4
4
|
breadcrumbTextFormat: string | undefined;
|
|
@@ -86,4 +86,5 @@ export declare const getCertificationsByValue: (certificationDefinitions: Certif
|
|
|
86
86
|
export declare function validateData(data: TaskItemData | ElementData | TreeResult, dataType: Exclude<CriteriaTreeElementType, "task-group" | "task-item">): data is ElementData;
|
|
87
87
|
export declare function validateData(data: TaskItemData | ElementData | TreeResult, dataType: Extract<CriteriaTreeElementType, "task-item">): data is TaskItemData;
|
|
88
88
|
export declare function validateData(data: TaskItemData | ElementData | TreeResult, dataType: "tree-result"): data is TreeResult;
|
|
89
|
+
export declare const resolveTaskItemValue: (taskItemDefinition: TaskItemDefinition, valueReference: TaskItemValueReference) => number | boolean | null;
|
|
89
90
|
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.resolveTaskItemValue = 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
|
exports.validateData = validateData;
|
|
5
5
|
const isTheme = (element) => element.type === "theme";
|
|
6
6
|
exports.isTheme = isTheme;
|
|
@@ -46,14 +46,14 @@ exports.findInTree = findInTree;
|
|
|
46
46
|
/**
|
|
47
47
|
* Apply the text formatting used in document tree folder naming
|
|
48
48
|
*/
|
|
49
|
-
const applyBreadcrumbTextFormattingPlaceholders = ({ breadcrumbTextFormat =
|
|
49
|
+
const applyBreadcrumbTextFormattingPlaceholders = ({ breadcrumbTextFormat = ":code:" }, { title, code }) => breadcrumbTextFormat
|
|
50
50
|
.replace(/:code:/g, code)
|
|
51
51
|
.replace(/:title:/g, title);
|
|
52
52
|
exports.applyBreadcrumbTextFormattingPlaceholders = applyBreadcrumbTextFormattingPlaceholders;
|
|
53
53
|
/**
|
|
54
54
|
* Apply the text formatting used in the document tree
|
|
55
55
|
*/
|
|
56
|
-
const applyDocumentTreeFolderTextFormattingPlaceholders = ({ documentTreeFolderTextFormat =
|
|
56
|
+
const applyDocumentTreeFolderTextFormattingPlaceholders = ({ documentTreeFolderTextFormat = ":code:" }, { title, code }) => documentTreeFolderTextFormat
|
|
57
57
|
.replace(/:code:/g, code)
|
|
58
58
|
.replace(/:title:/g, title);
|
|
59
59
|
exports.applyDocumentTreeFolderTextFormattingPlaceholders = applyDocumentTreeFolderTextFormattingPlaceholders;
|
|
@@ -67,7 +67,7 @@ exports.applyCriteriaTreeElementTextFormatFormattingPlaceholders = applyCriteria
|
|
|
67
67
|
/**
|
|
68
68
|
* Apply the text formatting used in the report title
|
|
69
69
|
*/
|
|
70
|
-
const applyReportTitleTextFormatFormattingPlaceholders = ({ reportTitleTextFormat =
|
|
70
|
+
const applyReportTitleTextFormatFormattingPlaceholders = ({ reportTitleTextFormat = ":title:" }, { title, code }) => reportTitleTextFormat
|
|
71
71
|
.replace(/:code:/g, code)
|
|
72
72
|
.replace(/:title:/g, title);
|
|
73
73
|
exports.applyReportTitleTextFormatFormattingPlaceholders = applyReportTitleTextFormatFormattingPlaceholders;
|
|
@@ -127,10 +127,54 @@ function validateData(data, dataType) {
|
|
|
127
127
|
default:
|
|
128
128
|
throw new Error(`Data has an invalid 'type' property: ${data.type}`);
|
|
129
129
|
}
|
|
130
|
-
if (dataType ===
|
|
130
|
+
if (dataType === "task-item") {
|
|
131
131
|
if (!("readOnly" in data)) {
|
|
132
132
|
throw new Error("Data is missing 'readOnly' property");
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
return true;
|
|
136
136
|
}
|
|
137
|
+
const resolveTaskItemValue = (taskItemDefinition, valueReference) => {
|
|
138
|
+
const toFiniteNumberOrNull = (rawValue) => {
|
|
139
|
+
if ((0, exports.isNil)(rawValue)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const numericValue = Number(rawValue);
|
|
143
|
+
return Number.isFinite(numericValue) ? numericValue : null;
|
|
144
|
+
};
|
|
145
|
+
const resolveSingleOptionValue = (optionOrValueReference) => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
if (taskItemDefinition.type !== "select-single" && taskItemDefinition.type !== "select-multiple") {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (typeof optionOrValueReference === "number") {
|
|
151
|
+
return optionOrValueReference;
|
|
152
|
+
}
|
|
153
|
+
const foundValue = (_b = (_a = taskItemDefinition.options.find((option) => option.id === optionOrValueReference)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
154
|
+
return toFiniteNumberOrNull(foundValue);
|
|
155
|
+
};
|
|
156
|
+
switch (taskItemDefinition.type) {
|
|
157
|
+
case "number":
|
|
158
|
+
return toFiniteNumberOrNull(valueReference);
|
|
159
|
+
case "boolean":
|
|
160
|
+
return valueReference === "true" || valueReference === "1" || valueReference === true || valueReference === 1;
|
|
161
|
+
case "select-single": {
|
|
162
|
+
return resolveSingleOptionValue(valueReference);
|
|
163
|
+
}
|
|
164
|
+
case "select-multiple": {
|
|
165
|
+
const optionIds = Array.isArray(valueReference) ? valueReference : [valueReference];
|
|
166
|
+
let resolvedValue = null;
|
|
167
|
+
for (const optionId of optionIds) {
|
|
168
|
+
const resolvedOptionValue = resolveSingleOptionValue(optionId);
|
|
169
|
+
if (!(0, exports.isNil)(resolvedOptionValue)) {
|
|
170
|
+
resolvedValue !== null && resolvedValue !== void 0 ? resolvedValue : (resolvedValue = 0);
|
|
171
|
+
resolvedValue += resolvedOptionValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return resolvedValue;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
throw new Error(`Unsupported task item type: ${taskItemDefinition.type}`);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
exports.resolveTaskItemValue = resolveTaskItemValue;
|
package/package.json
CHANGED