@gooder-ai/schemas 1.0.0 → 1.0.2
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/README.md +5 -0
- package/dist/tsc/index.js +2 -1
- package/dist/tsc/index.js.map +1 -1
- package/dist/tsc/schema.js +168 -230
- package/dist/tsc/transform.js +67 -0
- package/dist/tsc/transform.js.map +1 -0
- package/dist/tsc/tsconfig.tsbuildinfo +1 -1
- package/dist/tsc/utils.js +30 -37
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/schema.d.ts +2181 -2782
- package/dist/types/transform.d.ts +2 -0
- package/dist/types/transform.d.ts.map +1 -0
- package/dist/types/utils.d.ts +29 -29
- package/package.json +7 -1
package/README.md
ADDED
package/dist/tsc/index.js
CHANGED
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./schema"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
6
|
-
|
|
6
|
+
tslib_1.__exportStar(require("./transform"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/dist/tsc/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,kDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,kDAAwB;AACxB,sDAA4B"}
|
package/dist/tsc/schema.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChartDefinitionSchema =
|
|
4
|
-
exports.VariableSelectorsSchema =
|
|
5
|
-
exports.VariableSelectorSchema =
|
|
6
|
-
exports.FiltersSchema =
|
|
7
|
-
exports.FilterSchema =
|
|
8
|
-
exports.RuleSchema =
|
|
9
|
-
exports.SliderAssociationSchema =
|
|
10
|
-
exports.SlidersSchema =
|
|
11
|
-
exports.SliderDefinitionSchema =
|
|
12
|
-
exports.SliderInfoSchema =
|
|
13
|
-
exports.ChartLayoutSchema =
|
|
14
|
-
exports.LayoutSchema =
|
|
15
|
-
exports.ScoreSchema =
|
|
16
|
-
exports.CustomChartDefinitionSchema =
|
|
17
|
-
exports.DatumSchema =
|
|
18
|
-
exports.DatumValueSchema =
|
|
19
|
-
void 0;
|
|
3
|
+
exports.ChartDefinitionSchema = exports.VariableSelectorsSchema = exports.VariableSelectorSchema = exports.FiltersSchema = exports.FilterSchema = exports.RuleSchema = exports.SliderAssociationSchema = exports.SlidersSchema = exports.SliderDefinitionSchema = exports.SliderInfoSchema = exports.ChartLayoutSchema = exports.LayoutSchema = exports.ScoreSchema = exports.CustomChartDefinitionSchema = exports.DatumSchema = exports.DatumValueSchema = void 0;
|
|
20
4
|
const tslib_1 = require("tslib");
|
|
21
5
|
const utils_1 = require("./utils");
|
|
22
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
23
7
|
const zod_1 = require("zod");
|
|
24
8
|
exports.DatumValueSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).nullish();
|
|
25
9
|
exports.DatumSchema = zod_1.z.record(exports.DatumValueSchema);
|
|
26
|
-
exports.CustomChartDefinitionSchema = zod_1.z
|
|
27
|
-
.object({
|
|
10
|
+
exports.CustomChartDefinitionSchema = zod_1.z.object({
|
|
28
11
|
id: zod_1.z.string().uuid(),
|
|
29
12
|
dataInitializationCode: zod_1.z.string().min(1),
|
|
30
13
|
metricCalculationCode: zod_1.z.string().min(1),
|
|
@@ -44,11 +27,10 @@ exports.CustomChartDefinitionSchema = zod_1.z
|
|
|
44
27
|
showBaseline: zod_1.z.boolean().nullish(),
|
|
45
28
|
description: zod_1.z.string().nullish(),
|
|
46
29
|
metricTableRowOrder: zod_1.z.number().nullish(),
|
|
47
|
-
aspectRatio: zod_1.z
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.nullish(), // aspect ratio should be greater than 0,
|
|
30
|
+
aspectRatio: zod_1.z.number()
|
|
31
|
+
.min(1 / 5)
|
|
32
|
+
.max(5)
|
|
33
|
+
.nullish(), // aspect ratio should be greater than 0,
|
|
52
34
|
scaleMetric: zod_1.z.boolean().nullish(),
|
|
53
35
|
suppressBar: zod_1.z.boolean().nullish(),
|
|
54
36
|
suppressXAxisLabel: zod_1.z.boolean().nullish(),
|
|
@@ -57,48 +39,43 @@ exports.CustomChartDefinitionSchema = zod_1.z
|
|
|
57
39
|
aiPrompt: zod_1.z.string().nullish(),
|
|
58
40
|
highlightType: zod_1.z.nativeEnum(utils_1.HighlightType).nullish(),
|
|
59
41
|
optimizeResolution: zod_1.z.boolean().nullish(),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
message: "Range max value should be greater than range min value.",
|
|
67
|
-
path: ["maxRange"],
|
|
68
|
-
},
|
|
69
|
-
);
|
|
42
|
+
}).refine(({ minRange, maxRange }) => {
|
|
43
|
+
return maxRange > minRange;
|
|
44
|
+
}, {
|
|
45
|
+
message: "Range max value should be greater than range min value.",
|
|
46
|
+
path: ["maxRange"],
|
|
47
|
+
});
|
|
70
48
|
exports.ScoreSchema = zod_1.z.object({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
fieldName: zod_1.z.string(),
|
|
50
|
+
fieldLabel: zod_1.z.string().nullish(),
|
|
51
|
+
sortOrder: zod_1.z.nativeEnum(utils_1.SortOrderDictionary).nullish(),
|
|
74
52
|
});
|
|
75
53
|
// Adopted from : https://github.com/react-grid-layout/react-grid-layout/blob/f5f3b5da17ed16522d0ae8769042b48f37ae24cf/lib/utils.js#L19C1-L19C1
|
|
76
54
|
exports.LayoutSchema = zod_1.z.object({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
55
|
+
i: zod_1.z.string().min(1),
|
|
56
|
+
x: zod_1.z.number().nonnegative(),
|
|
57
|
+
y: zod_1.z.number().nonnegative(),
|
|
58
|
+
w: zod_1.z.number().min(1),
|
|
59
|
+
h: zod_1.z.number().min(1),
|
|
60
|
+
minW: zod_1.z.number().min(1).optional(),
|
|
61
|
+
maxW: zod_1.z.number().min(1).optional(),
|
|
62
|
+
minH: zod_1.z.number().min(1).optional(),
|
|
63
|
+
maxH: zod_1.z.number().min(1).optional(),
|
|
64
|
+
moved: zod_1.z.boolean().optional(),
|
|
65
|
+
static: zod_1.z.boolean().optional(),
|
|
66
|
+
isDraggable: zod_1.z.boolean().optional(),
|
|
67
|
+
isResizable: zod_1.z.boolean().optional(),
|
|
68
|
+
resizeHandles: zod_1.z.array(zod_1.z.enum(["s", "w", "e", "n", "sw", "nw", "se", "ne"])).optional(),
|
|
69
|
+
isBounded: zod_1.z.boolean().optional(),
|
|
92
70
|
});
|
|
93
71
|
exports.ChartLayoutSchema = zod_1.z.object({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
72
|
+
xl: zod_1.z.array(exports.LayoutSchema).optional(),
|
|
73
|
+
lg: zod_1.z.array(exports.LayoutSchema).optional(),
|
|
74
|
+
md: zod_1.z.array(exports.LayoutSchema).optional(),
|
|
75
|
+
sm: zod_1.z.array(exports.LayoutSchema).optional(),
|
|
76
|
+
xs: zod_1.z.array(exports.LayoutSchema).optional(),
|
|
99
77
|
});
|
|
100
|
-
exports.SliderInfoSchema = zod_1.z
|
|
101
|
-
.object({
|
|
78
|
+
exports.SliderInfoSchema = zod_1.z.object({
|
|
102
79
|
id: zod_1.z.string().min(1),
|
|
103
80
|
name: zod_1.z.string().min(1, { message: "Slider name is required." }),
|
|
104
81
|
description: zod_1.z.string().nullish(),
|
|
@@ -106,172 +83,135 @@ exports.SliderInfoSchema = zod_1.z
|
|
|
106
83
|
max: zod_1.z.number(),
|
|
107
84
|
value: zod_1.z.number(),
|
|
108
85
|
label: zod_1.z.string().min(1).nullish(), // Slider label is optional.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
path: ["min"],
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
exports.SliderDefinitionSchema = exports.SliderInfoSchema.refine(
|
|
120
|
-
({ max, min, value }) => {
|
|
86
|
+
}).refine(({ max, min }) => {
|
|
87
|
+
return max > min;
|
|
88
|
+
}, {
|
|
89
|
+
message: "min value should be less than max.",
|
|
90
|
+
path: ["min"],
|
|
91
|
+
});
|
|
92
|
+
exports.SliderDefinitionSchema = exports.SliderInfoSchema.refine(({ max, min, value }) => {
|
|
121
93
|
return value <= max && value >= min;
|
|
122
|
-
|
|
123
|
-
{
|
|
94
|
+
}, {
|
|
124
95
|
message: "value should be between the min and max range.",
|
|
125
96
|
path: ["value"],
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
exports.SlidersSchema = zod_1.z.array(exports.SliderDefinitionSchema).refine(
|
|
129
|
-
(sliders) => {
|
|
97
|
+
});
|
|
98
|
+
exports.SlidersSchema = zod_1.z.array(exports.SliderDefinitionSchema).refine((sliders) => {
|
|
130
99
|
const names = new Set();
|
|
131
100
|
return sliders.every((slider) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
101
|
+
let output = true;
|
|
102
|
+
if (names.has(slider.name)) {
|
|
103
|
+
output = false;
|
|
104
|
+
}
|
|
105
|
+
names.add(slider.name);
|
|
106
|
+
return output;
|
|
138
107
|
});
|
|
139
|
-
|
|
140
|
-
{
|
|
108
|
+
}, {
|
|
141
109
|
message: "Slider names should be unique.",
|
|
142
110
|
path: ["sliders"],
|
|
143
|
-
|
|
144
|
-
);
|
|
111
|
+
});
|
|
145
112
|
exports.SliderAssociationSchema = zod_1.z.object({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
113
|
+
sliderID: zod_1.z.string().min(1),
|
|
114
|
+
uswID: zod_1.z.string().min(1),
|
|
115
|
+
showInDashboard: zod_1.z.boolean().nullish(),
|
|
149
116
|
});
|
|
150
|
-
exports.RuleSchema = zod_1.z
|
|
151
|
-
.object({
|
|
117
|
+
exports.RuleSchema = zod_1.z.object({
|
|
152
118
|
id: zod_1.z.string().uuid(),
|
|
153
119
|
// Reference for customizing error message union: https://www.answeroverflow.com/m/1154335103284150314#solution-1154949739666751538
|
|
154
120
|
value: zod_1.z.union([
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.array(
|
|
162
|
-
zod_1.z.union([
|
|
121
|
+
// Reference for customizing error message with number: https://zod.dev/?id=numbers
|
|
122
|
+
zod_1.z.number({ required_error: "Please enter a value." }),
|
|
123
|
+
zod_1.z.string().min(1, { message: "Please enter a value." }),
|
|
124
|
+
zod_1.z.boolean({ required_error: "Please enter a value." }),
|
|
125
|
+
// TODO: add date support.
|
|
126
|
+
zod_1.z.array(zod_1.z.union([
|
|
163
127
|
zod_1.z.string().min(1, { message: "Please enter a value." }),
|
|
164
128
|
zod_1.z.number({ required_error: "Please enter a value." }),
|
|
165
129
|
zod_1.z.boolean({ required_error: "Please enter a value." }),
|
|
166
130
|
// TODO: add date array support.
|
|
167
|
-
|
|
168
|
-
)
|
|
169
|
-
.min(1, { message: "Array must contain at least 1 element." }),
|
|
131
|
+
])).min(1, { message: "Array must contain at least 1 element." }),
|
|
170
132
|
]),
|
|
171
133
|
// Ref: https://github.com/colinhacks/zod/issues/580#issuecomment-1073353683
|
|
172
134
|
operator: zod_1.z.nativeEnum(utils_1.Operators, {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
135
|
+
errorMap: () => {
|
|
136
|
+
return { message: "Please select an operator." };
|
|
137
|
+
},
|
|
176
138
|
}),
|
|
177
139
|
model: zod_1.z.string().min(1, { message: "Please select a variable." }), // model should not be `""`
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
(
|
|
181
|
-
let output = false;
|
|
182
|
-
switch (operator) {
|
|
140
|
+
}).refine(({ operator, value }) => {
|
|
141
|
+
let output = false;
|
|
142
|
+
switch (operator) {
|
|
183
143
|
case utils_1.Operators.Between:
|
|
184
144
|
case utils_1.Operators.BetweenInclusive: // Between operation can be applied between 2 operands.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
145
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
146
|
+
output = true;
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
189
149
|
case utils_1.Operators.In: // In operator can be applied only in string or an array.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
150
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
151
|
+
output = true;
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
194
154
|
default:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
);
|
|
207
|
-
exports.FilterSchema = zod_1.z
|
|
208
|
-
.object({
|
|
155
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
156
|
+
output = true;
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
return output;
|
|
161
|
+
}, {
|
|
162
|
+
message: "Invalid value format.",
|
|
163
|
+
path: ["value"],
|
|
164
|
+
});
|
|
165
|
+
exports.FilterSchema = zod_1.z.object({
|
|
209
166
|
name: zod_1.z.string().min(1, { message: "Please enter valid filter name." }),
|
|
210
167
|
rules: zod_1.z.array(zod_1.z.string().uuid()).min(1, {
|
|
211
|
-
|
|
168
|
+
message: "Please select at least 1 constraint.",
|
|
212
169
|
}), // These are the id's of selected rules
|
|
213
170
|
joinBy: zod_1.z.nativeEnum(utils_1.ConditionalOperators).nullish(),
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
(
|
|
217
|
-
let output = true;
|
|
218
|
-
if (rules.length > 1 && (joinBy === undefined || joinBy === null)) {
|
|
171
|
+
}).refine(({ rules, joinBy }) => {
|
|
172
|
+
let output = true;
|
|
173
|
+
if (rules.length > 1 && (joinBy === undefined || joinBy === null)) {
|
|
219
174
|
output = false;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
exports.FiltersSchema = zod_1.z.array(exports.FilterSchema).refine(
|
|
229
|
-
(filters) => {
|
|
230
|
-
return (
|
|
231
|
-
lodash_1.default.uniqBy(filters, (filter) => {
|
|
175
|
+
}
|
|
176
|
+
return output;
|
|
177
|
+
}, {
|
|
178
|
+
message: "Please select a logical operator.",
|
|
179
|
+
path: ["joinBy"],
|
|
180
|
+
});
|
|
181
|
+
exports.FiltersSchema = zod_1.z.array(exports.FilterSchema).refine((filters) => {
|
|
182
|
+
return (lodash_1.default.uniqBy(filters, (filter) => {
|
|
232
183
|
return filter.name;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
},
|
|
236
|
-
{
|
|
184
|
+
}).length === filters.length);
|
|
185
|
+
}, {
|
|
237
186
|
message: "Filter names should be unique.",
|
|
238
187
|
path: ["filters"],
|
|
239
|
-
|
|
240
|
-
);
|
|
188
|
+
});
|
|
241
189
|
exports.VariableSelectorSchema = zod_1.z.object({
|
|
242
|
-
|
|
243
|
-
|
|
190
|
+
name: zod_1.z.string().min(1, { message: "Variable name is required" }),
|
|
191
|
+
label: zod_1.z.string().min(1, { message: "Variable label is required" }),
|
|
244
192
|
});
|
|
245
|
-
exports.VariableSelectorsSchema = zod_1.z
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
(variables) => {
|
|
250
|
-
const uniqueVariables = lodash_1.default.uniqBy(variables, (ele) => {
|
|
193
|
+
exports.VariableSelectorsSchema = zod_1.z.array(exports.VariableSelectorSchema)
|
|
194
|
+
// Prevent user from adding a selector for multiple variables
|
|
195
|
+
.refine((variables) => {
|
|
196
|
+
const uniqueVariables = lodash_1.default.uniqBy(variables, (ele) => {
|
|
251
197
|
return ele.name;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
.refine(
|
|
262
|
-
(variables) => {
|
|
263
|
-
const uniqueVariables = lodash_1.default.uniqBy(variables, (ele) => {
|
|
198
|
+
});
|
|
199
|
+
return uniqueVariables.length === variables.length;
|
|
200
|
+
}, {
|
|
201
|
+
message: "This variable already has an assigned label.",
|
|
202
|
+
path: ["name"], // Show error on name field of the modal
|
|
203
|
+
})
|
|
204
|
+
// Prevent user from adding same alias for multiple variables
|
|
205
|
+
.refine((variables) => {
|
|
206
|
+
const uniqueVariables = lodash_1.default.uniqBy(variables, (ele) => {
|
|
264
207
|
return ele.label;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
273
|
-
exports.ChartDefinitionSchema = zod_1.z
|
|
274
|
-
.object({
|
|
208
|
+
});
|
|
209
|
+
return uniqueVariables.length === variables.length;
|
|
210
|
+
}, {
|
|
211
|
+
message: "Variable labels should be unique.",
|
|
212
|
+
path: ["label"], // Show error on label field of the modal
|
|
213
|
+
});
|
|
214
|
+
exports.ChartDefinitionSchema = zod_1.z.object({
|
|
275
215
|
// Chart definition with no version defined are to be treated as v1.0 chart definition.
|
|
276
216
|
// Post v1.0 all charts mandatorily have version specified.
|
|
277
217
|
version: zod_1.z.string().min(1).default("1.0"),
|
|
@@ -294,60 +234,58 @@ exports.ChartDefinitionSchema = zod_1.z
|
|
|
294
234
|
showFiltersOnDashboard: zod_1.z.boolean().nullish(),
|
|
295
235
|
numberOfRowsSentInAIPrompt: zod_1.z.number().min(0).nullish(),
|
|
296
236
|
variableSelectors: exports.VariableSelectorsSchema.nullish(),
|
|
297
|
-
|
|
298
|
-
.superRefine(({ dependentVariable, positivePolarityValues, scores, customCharts }, ctx) => {
|
|
237
|
+
}).superRefine(({ dependentVariable, positivePolarityValues, scores, customCharts }, ctx) => {
|
|
299
238
|
const isDependentVariableValid = typeof dependentVariable === "string";
|
|
300
239
|
const isPositivePolarityValuesValid = Array.isArray(positivePolarityValues);
|
|
301
240
|
const isScoresPresent = scores.length > 0;
|
|
302
241
|
const isWidgetPresent = Array.isArray(customCharts) && customCharts.length > 0;
|
|
303
|
-
const areCustomChartsValid =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
});
|
|
242
|
+
const areCustomChartsValid = Array.isArray(customCharts) &&
|
|
243
|
+
customCharts.every((chart) => {
|
|
244
|
+
let output = false;
|
|
245
|
+
// If series is bar, optimizeResolution should be false
|
|
246
|
+
if (chart.seriesType === utils_1.SeriesTypes.Bar && chart.optimizeResolution === false) {
|
|
247
|
+
output = true;
|
|
248
|
+
}
|
|
249
|
+
// If series is line, optimizeResolution can be true, false, null or undefined
|
|
250
|
+
else if (chart.seriesType === utils_1.SeriesTypes.Line) {
|
|
251
|
+
output = true;
|
|
252
|
+
}
|
|
253
|
+
return output;
|
|
254
|
+
});
|
|
317
255
|
if (isDependentVariableValid === false) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
256
|
+
ctx.addIssue({
|
|
257
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
258
|
+
message: "Dependent variable is not defined.",
|
|
259
|
+
path: ["dependentVariable"],
|
|
260
|
+
});
|
|
323
261
|
}
|
|
324
262
|
if (isDependentVariableValid === true && isPositivePolarityValuesValid === false) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
263
|
+
ctx.addIssue({
|
|
264
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
265
|
+
message: "Polarity values are not defined",
|
|
266
|
+
path: ["positivePolarityValues"],
|
|
267
|
+
});
|
|
330
268
|
}
|
|
331
269
|
if (isScoresPresent === false) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
270
|
+
ctx.addIssue({
|
|
271
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
272
|
+
message: "No model selected.",
|
|
273
|
+
path: ["scores"],
|
|
274
|
+
});
|
|
337
275
|
}
|
|
338
276
|
if (isWidgetPresent === false) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
277
|
+
ctx.addIssue({
|
|
278
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
279
|
+
message: "At least one widget must be defined.",
|
|
280
|
+
path: ["customCharts"],
|
|
281
|
+
});
|
|
344
282
|
}
|
|
345
283
|
if (areCustomChartsValid === false) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
284
|
+
ctx.addIssue({
|
|
285
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
286
|
+
message: "Invalid custom chart configuration",
|
|
287
|
+
path: ["customCharts"],
|
|
288
|
+
});
|
|
351
289
|
}
|
|
352
|
-
|
|
353
|
-
//# sourceMappingURL=schema.js.map
|
|
290
|
+
});
|
|
291
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformRawChartDefinition = transformRawChartDefinition;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
function transformRawChartDefinition(data) {
|
|
6
|
+
const output = Object.assign({}, data);
|
|
7
|
+
// "1.0", null and undefined all specifies the config version "1.0" because version was nullish.
|
|
8
|
+
if (data.version === "1.0" || data.version === undefined || data.version === null) {
|
|
9
|
+
if (Array.isArray(output.customCharts)) {
|
|
10
|
+
// Convert version-1.0 config to version-2.0 config.
|
|
11
|
+
const customCharts = output.customCharts.map((chart) => {
|
|
12
|
+
return Object.assign(Object.assign({ dataInitializationCode: "function initialize(params) { return {bins: []}; }", metricCalculationCode: "function calculate(params) { return []; }", metric: "", id: crypto.randomUUID(), title: null, resolution: 0, unit: utils_1.UnitTypes.None, seriesType: utils_1.SeriesTypes.Line, showRangeSlider: false, showInDashboard: true, showInMetricTable: true, showBaseline: false, scaleMetric: true, suppressBar: true, suppressXAxisLabel: true, aspectRatio: null, description: null, showThreshold: true, reverseXAxis: false, aiPrompt: null, highlightType: utils_1.HighlightType.None }, chart), { minRange: 0, maxRange: 100 });
|
|
13
|
+
});
|
|
14
|
+
output.customCharts = customCharts;
|
|
15
|
+
output.version = "2.0";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (output.version === "2.0") {
|
|
19
|
+
if (Array.isArray(output.customCharts)) {
|
|
20
|
+
// Convert version-2.0 config to version-2.1 config.
|
|
21
|
+
const customCharts = output.customCharts.map((chart) => {
|
|
22
|
+
return Object.assign(Object.assign({}, chart), { optimizeResolution: chart.seriesType !== utils_1.SeriesTypes.Bar });
|
|
23
|
+
});
|
|
24
|
+
output.xAxisName = "Percent treated";
|
|
25
|
+
output.percentTreated = 0; // Before version 2.1 we had a different state which keeps track of percent treated (previously called marklinevalue). Its default value was 0. Ref: https://github.com/manufac-analytics/ml-viz/pull/2258
|
|
26
|
+
output.customCharts = customCharts;
|
|
27
|
+
output.version = "2.1";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (output.version === "2.1") {
|
|
31
|
+
// This version ensure that on upload new config configuration settings should override the existing settings.
|
|
32
|
+
// Version update is needed because default chart definition indirectly influence the configuration from this version onwards.
|
|
33
|
+
output.projectedPopulation = null;
|
|
34
|
+
output.percentTreated = null;
|
|
35
|
+
output.rules = null;
|
|
36
|
+
output.filters = null;
|
|
37
|
+
output.activeFilter = null;
|
|
38
|
+
output.showFiltersOnDashboard = false;
|
|
39
|
+
output.variableSelectors = null;
|
|
40
|
+
output.version = "2.2";
|
|
41
|
+
}
|
|
42
|
+
if (output.version === "2.2") {
|
|
43
|
+
// In this version, the field "isSortOrderDescending" is removed and instead sort order is attached to each score field.
|
|
44
|
+
const isDescending = output.isSortOrderDescending;
|
|
45
|
+
if (Array.isArray(output.scores)) {
|
|
46
|
+
output.scores = output.scores.map((score) => {
|
|
47
|
+
return Object.assign(Object.assign({}, score), { sortOrder: isDescending === true || isDescending === null || isDescending === undefined
|
|
48
|
+
? utils_1.SortOrderDictionary.Descending
|
|
49
|
+
: utils_1.SortOrderDictionary.Ascending });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
output.version = "2.3";
|
|
53
|
+
// When config is parsed, it will remove all values which are not present in schema.
|
|
54
|
+
}
|
|
55
|
+
if (output.version === "2.3") {
|
|
56
|
+
if (Array.isArray(output.customCharts)) {
|
|
57
|
+
const customCharts = output.customCharts.map((chart) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return Object.assign(Object.assign({}, chart), { xAxisDecimalPlaces: (_a = chart.decimalPlaces) !== null && _a !== void 0 ? _a : 2, yAxisDecimalPlaces: (_b = chart.decimalPlaces) !== null && _b !== void 0 ? _b : 2 });
|
|
60
|
+
});
|
|
61
|
+
output.customCharts = customCharts;
|
|
62
|
+
output.version = "2.4";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return output;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":";;AAGA,kEAkGC;AArGD,mCAAqF;AAGrF,SAAgB,2BAA2B,CAAC,IAA6B;IACvE,MAAM,MAAM,qBAAQ,IAAI,CAAE,CAAC;IAE3B,gGAAgG;IAChG,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAClF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YACvC,oDAAoD;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAA8B,EAAE,EAAE;gBAC9E,qCACE,sBAAsB,EAAE,oDAAoD,EAC5E,qBAAqB,EAAE,2CAA2C,EAClE,MAAM,EAAE,EAAE,EACV,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE,EACvB,KAAK,EAAE,IAAI,EACX,UAAU,EAAE,CAAC,EACb,IAAI,EAAE,iBAAS,CAAC,IAAI,EACpB,UAAU,EAAE,mBAAW,CAAC,IAAI,EAC5B,eAAe,EAAE,KAAK,EACtB,eAAe,EAAE,IAAI,EACrB,iBAAiB,EAAE,IAAI,EACvB,YAAY,EAAE,KAAK,EACnB,WAAW,EAAE,IAAI,EACjB,WAAW,EAAE,IAAI,EACjB,kBAAkB,EAAE,IAAI,EACxB,WAAW,EAAE,IAAI,EACjB,WAAW,EAAE,IAAI,EACjB,aAAa,EAAE,IAAI,EACnB,YAAY,EAAE,KAAK,EACnB,QAAQ,EAAE,IAAI,EACd,aAAa,EAAE,qBAAa,CAAC,IAAI,IAC9B,KAAK,KACR,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,GAAG,IACb;YACJ,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;YACnC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YACvC,oDAAoD;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAA8B,EAAE,EAAE;gBAC9E,uCACK,KAAK,KACR,kBAAkB,EAAE,KAAK,CAAC,UAAU,KAAK,mBAAW,CAAC,GAAG,IACxD;YACJ,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,SAAS,GAAG,iBAAiB,CAAC;YACrC,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,0MAA0M;YACrO,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;YACnC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,8GAA8G;QAC9G,8HAA8H;QAC9H,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAClC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,MAAM,CAAC,sBAAsB,GAAG,KAAK,CAAC;QACtC,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;IACzB,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,wHAAwH;QACxH,MAAM,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC;QAClD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAY,EAAE,EAAE;gBACjD,uCACK,KAAK,KACR,SAAS,EACP,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,SAAS;wBAC1E,CAAC,CAAC,2BAAmB,CAAC,UAAU;wBAChC,CAAC,CAAC,2BAAmB,CAAC,SAAS,IACnC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,oFAAoF;IACtF,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YACvC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAA8B,EAAE,EAAE;;gBAC9E,uCACK,KAAK,KACR,kBAAkB,EAAE,MAAA,KAAK,CAAC,aAAa,mCAAI,CAAC,EAC5C,kBAAkB,EAAE,MAAA,KAAK,CAAC,aAAa,mCAAI,CAAC,IAC5C;YACJ,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;YACnC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/index.ts","../../src/schema.ts","../../src/utils.ts"],"version":"5.7.3"}
|
|
1
|
+
{"root":["../../src/index.ts","../../src/schema.ts","../../src/transform.ts","../../src/utils.ts"],"version":"5.7.3"}
|