@firecms/schema_inference 3.0.0-canary.24 → 3.0.0-canary.241
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/LICENSE +114 -21
- package/dist/builders/reference_property_builder.d.ts +1 -1
- package/dist/builders/string_property_builder.d.ts +1 -1
- package/dist/builders/validation_builder.d.ts +1 -1
- package/dist/cms_types.d.ts +596 -0
- package/dist/collection_builder.d.ts +3 -2
- package/dist/index.es.js +447 -202
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.cjs +493 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/util.d.ts +5 -0
- package/package.json +7 -9
- package/src/builders/reference_property_builder.ts +1 -1
- package/src/builders/string_property_builder.ts +2 -3
- package/src/builders/validation_builder.ts +1 -1
- package/src/cms_types.ts +760 -0
- package/src/collection_builder.ts +136 -47
- package/src/strings.ts +1 -2
- package/src/test_schemas/pop_products.json +948 -0
- package/src/test_schemas/test_schema.ts +6 -2
- package/src/types.ts +1 -1
- package/src/util.ts +61 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
package/dist/index.es.js
CHANGED
@@ -1,244 +1,489 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
function
|
4
|
-
|
5
|
-
return;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
const
|
10
|
-
if (!
|
11
|
-
return;
|
12
|
-
const
|
13
|
-
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
}
|
18
|
-
|
19
|
-
|
1
|
+
function findCommonInitialStringInPath(valuesCount) {
|
2
|
+
if (!valuesCount) return void 0;
|
3
|
+
function getPath(value) {
|
4
|
+
if (typeof value === "string") return value;
|
5
|
+
else if (value?.type === "document" && value.path) return value.path;
|
6
|
+
else return void 0;
|
7
|
+
}
|
8
|
+
const strings = valuesCount.values.map((v) => getPath(v)).filter((v) => !!v);
|
9
|
+
const pathWithSlash = strings.find((s) => s.includes("/"));
|
10
|
+
if (!pathWithSlash)
|
11
|
+
return void 0;
|
12
|
+
const searchedPath = pathWithSlash.substr(0, pathWithSlash.lastIndexOf("/"));
|
13
|
+
const yep = valuesCount.values.filter((value) => {
|
14
|
+
const path = getPath(value);
|
15
|
+
if (!path) return false;
|
16
|
+
return path.startsWith(searchedPath);
|
17
|
+
}).length > valuesCount.values.length / 3 * 2;
|
18
|
+
return yep ? searchedPath : void 0;
|
19
|
+
}
|
20
|
+
function extractEnumFromValues(values) {
|
21
|
+
if (!Array.isArray(values)) {
|
20
22
|
return [];
|
21
|
-
|
22
|
-
|
23
|
+
}
|
24
|
+
const enumValues = values.map((value) => {
|
25
|
+
if (typeof value === "string") {
|
26
|
+
return { id: value, label: unslugify(value) };
|
27
|
+
} else
|
28
|
+
return null;
|
29
|
+
}).filter(Boolean);
|
30
|
+
enumValues.sort((a, b) => a.label.localeCompare(b.label));
|
31
|
+
return enumValues;
|
32
|
+
}
|
33
|
+
function unslugify(slug) {
|
34
|
+
if (!slug) return "";
|
35
|
+
if (slug.includes("-") || slug.includes("_") || !slug.includes(" ")) {
|
36
|
+
const result = slug.replace(/[-_]/g, " ");
|
37
|
+
return result.replace(/\w\S*/g, function(txt) {
|
38
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1);
|
39
|
+
}).trim();
|
40
|
+
} else {
|
41
|
+
return slug.trim();
|
42
|
+
}
|
23
43
|
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
44
|
+
function resolveEnumValues(input) {
|
45
|
+
if (typeof input === "object") {
|
46
|
+
return Object.entries(input).map(([id, value]) => typeof value === "string" ? {
|
47
|
+
id,
|
48
|
+
label: value
|
49
|
+
} : value);
|
50
|
+
} else if (Array.isArray(input)) {
|
51
|
+
return input;
|
52
|
+
} else {
|
53
|
+
return void 0;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
function mergeDeep(target, source, ignoreUndefined = false) {
|
57
|
+
const targetIsObject = isObject(target);
|
58
|
+
const output = targetIsObject ? { ...target } : target;
|
59
|
+
if (targetIsObject && isObject(source)) {
|
60
|
+
Object.keys(source).forEach((key) => {
|
61
|
+
const sourceElement = source[key];
|
62
|
+
if (ignoreUndefined && sourceElement === void 0) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
if (sourceElement instanceof Date) {
|
66
|
+
Object.assign(output, { [key]: new Date(sourceElement.getTime()) });
|
67
|
+
} else if (isObject(sourceElement)) {
|
68
|
+
if (!(key in target))
|
69
|
+
Object.assign(output, { [key]: sourceElement });
|
70
|
+
else
|
71
|
+
output[key] = mergeDeep(target[key], sourceElement);
|
72
|
+
} else {
|
73
|
+
Object.assign(output, { [key]: sourceElement });
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
return output;
|
78
|
+
}
|
79
|
+
function isObject(item) {
|
80
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
81
|
+
}
|
82
|
+
const IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png", ".webp", ".gif", ".avif"];
|
83
|
+
const AUDIO_EXTENSIONS = [".mp3", ".ogg", ".opus", ".aac"];
|
84
|
+
const VIDEO_EXTENSIONS = [".avi", ".mp4"];
|
85
|
+
const emailRegEx = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
86
|
+
function buildStringProperty({
|
87
|
+
totalDocsCount,
|
88
|
+
valuesResult
|
28
89
|
}) {
|
29
|
-
let
|
90
|
+
let stringProperty = {
|
30
91
|
dataType: "string"
|
31
92
|
};
|
32
|
-
if (
|
33
|
-
const
|
34
|
-
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
const f = d(Array.from(e.valuesCount.keys()));
|
40
|
-
Object.keys(f).length > 1 && (o.enumValues = f);
|
41
|
-
}
|
42
|
-
if (!a && !i && !c && !i && !o.enumValues) {
|
43
|
-
const f = F(e, r);
|
44
|
-
f && (o.storage = {
|
45
|
-
acceptedFiles: [f],
|
46
|
-
storagePath: y(e) ?? "/"
|
47
|
-
});
|
93
|
+
if (valuesResult) {
|
94
|
+
const totalEntriesCount = valuesResult.values.length;
|
95
|
+
const totalValues = Array.from(valuesResult.valuesCount.keys()).length;
|
96
|
+
const config = {};
|
97
|
+
const probablyAURL = valuesResult.values.filter((value) => typeof value === "string" && value.toString().startsWith("http")).length > totalDocsCount / 3 * 2;
|
98
|
+
if (probablyAURL) {
|
99
|
+
config.url = true;
|
48
100
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
101
|
+
const probablyAnEmail = valuesResult.values.filter((value) => typeof value === "string" && emailRegEx.test(value)).length > totalDocsCount / 3 * 2;
|
102
|
+
if (probablyAnEmail) {
|
103
|
+
config.email = true;
|
104
|
+
}
|
105
|
+
const probablyUserIds = valuesResult.values.filter((value) => typeof value === "string" && value.length === 28 && !value.includes(" ")).length > totalDocsCount / 3 * 2;
|
106
|
+
if (probablyUserIds)
|
107
|
+
config.readOnly = true;
|
108
|
+
if (!probablyAnEmail && !probablyAURL && !probablyUserIds && !probablyAURL && totalValues < totalEntriesCount / 3) {
|
109
|
+
const enumValues = extractEnumFromValues(Array.from(valuesResult.valuesCount.keys()));
|
110
|
+
if (Object.keys(enumValues).length > 1)
|
111
|
+
config.enumValues = enumValues;
|
112
|
+
}
|
113
|
+
if (!probablyAnEmail && !probablyAURL && !probablyUserIds && !probablyAURL && !config.enumValues) {
|
114
|
+
const fileType = probableFileType(valuesResult, totalDocsCount);
|
115
|
+
if (fileType) {
|
116
|
+
config.storage = {
|
117
|
+
acceptedFiles: [fileType],
|
118
|
+
storagePath: findCommonInitialStringInPath(valuesResult) ?? "/"
|
119
|
+
};
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (Object.keys(config).length > 0)
|
123
|
+
stringProperty = {
|
124
|
+
...stringProperty,
|
125
|
+
...config,
|
126
|
+
editable: true
|
127
|
+
};
|
54
128
|
}
|
55
|
-
return
|
129
|
+
return stringProperty;
|
56
130
|
}
|
57
|
-
function
|
58
|
-
const
|
59
|
-
|
131
|
+
function probableFileType(valuesCount, totalDocsCount) {
|
132
|
+
const probablyAnImage = valuesCount.values.filter((value) => typeof value === "string" && IMAGE_EXTENSIONS.some((extension) => value.toString().endsWith(extension))).length > totalDocsCount / 3 * 2;
|
133
|
+
const probablyAudio = valuesCount.values.filter((value) => typeof value === "string" && AUDIO_EXTENSIONS.some((extension) => value.toString().endsWith(extension))).length > totalDocsCount / 3 * 2;
|
134
|
+
const probablyVideo = valuesCount.values.filter((value) => typeof value === "string" && VIDEO_EXTENSIONS.some((extension) => value.toString().endsWith(extension))).length > totalDocsCount / 3 * 2;
|
135
|
+
const fileType = probablyAnImage ? "image/*" : probablyAudio ? "audio/*" : probablyVideo ? "video/*" : false;
|
136
|
+
return fileType;
|
60
137
|
}
|
61
|
-
function
|
62
|
-
totalDocsCount
|
63
|
-
valuesResult
|
138
|
+
function buildValidation({
|
139
|
+
totalDocsCount,
|
140
|
+
valuesResult
|
64
141
|
}) {
|
65
|
-
if (
|
66
|
-
const
|
67
|
-
if (
|
142
|
+
if (valuesResult) {
|
143
|
+
const totalEntriesCount = valuesResult.values.length;
|
144
|
+
if (totalDocsCount === totalEntriesCount)
|
68
145
|
return {
|
69
|
-
required:
|
146
|
+
required: true
|
70
147
|
};
|
71
148
|
}
|
149
|
+
return void 0;
|
72
150
|
}
|
73
|
-
function
|
74
|
-
totalDocsCount
|
75
|
-
valuesResult
|
151
|
+
function buildReferenceProperty({
|
152
|
+
totalDocsCount,
|
153
|
+
valuesResult
|
76
154
|
}) {
|
77
|
-
|
155
|
+
const property = {
|
78
156
|
dataType: "reference",
|
79
|
-
path:
|
80
|
-
editable:
|
157
|
+
path: findCommonInitialStringInPath(valuesResult) ?? "!!!FIX_ME!!!",
|
158
|
+
editable: true
|
81
159
|
};
|
160
|
+
return property;
|
82
161
|
}
|
83
|
-
async function
|
84
|
-
const
|
85
|
-
|
86
|
-
|
87
|
-
|
162
|
+
async function buildEntityPropertiesFromData(data, getType) {
|
163
|
+
const typesCount = {};
|
164
|
+
const valuesCount = {};
|
165
|
+
if (data) {
|
166
|
+
data.forEach((entry) => {
|
167
|
+
if (entry) {
|
168
|
+
Object.entries(entry).forEach(([key, value]) => {
|
169
|
+
if (key.startsWith("_")) return;
|
170
|
+
increaseMapTypeCount(typesCount, key, value, getType);
|
171
|
+
increaseValuesCount(valuesCount, key, value, getType);
|
172
|
+
});
|
173
|
+
}
|
88
174
|
});
|
89
|
-
}
|
175
|
+
}
|
176
|
+
return buildPropertiesFromCount(data.length, typesCount, valuesCount);
|
90
177
|
}
|
91
|
-
function
|
92
|
-
const
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
178
|
+
function buildPropertyFromData(data, property, getType) {
|
179
|
+
const typesCount = {};
|
180
|
+
const valuesCount = {};
|
181
|
+
if (data) {
|
182
|
+
data.forEach((entry) => {
|
183
|
+
increaseTypeCount(property.dataType, typesCount, entry, getType);
|
184
|
+
increaseValuesCount(valuesCount, "inferred_prop", entry, getType);
|
185
|
+
});
|
186
|
+
}
|
187
|
+
const enumValues = "enumValues" in property ? resolveEnumValues(property["enumValues"]) : void 0;
|
188
|
+
if (enumValues) {
|
189
|
+
const newEnumValues = extractEnumFromValues(Array.from(valuesCount["inferred_prop"].valuesCount.keys()));
|
99
190
|
return {
|
100
|
-
...
|
101
|
-
enumValues: [...
|
191
|
+
...property,
|
192
|
+
enumValues: [...newEnumValues, ...enumValues]
|
102
193
|
};
|
103
194
|
}
|
104
|
-
const
|
105
|
-
|
195
|
+
const generatedProperty = buildPropertyFromCount(
|
196
|
+
"inferred_prop",
|
197
|
+
data.length,
|
198
|
+
property.dataType,
|
199
|
+
typesCount,
|
200
|
+
valuesCount["inferred_prop"]
|
201
|
+
);
|
202
|
+
return mergeDeep(generatedProperty, property);
|
106
203
|
}
|
107
|
-
function
|
108
|
-
|
109
|
-
|
110
|
-
|
204
|
+
function buildPropertiesOrder(properties, propertiesOrder, priorityKeys) {
|
205
|
+
const lowerCasePriorityKeys = (priorityKeys ?? []).map((key) => key.toLowerCase());
|
206
|
+
function propOrder(s) {
|
207
|
+
const k = s.toLowerCase();
|
208
|
+
if (lowerCasePriorityKeys.includes(k)) return 4;
|
209
|
+
if (k === "title" || k === "name") return 3;
|
210
|
+
if (k.includes("title") || k.includes("name")) return 2;
|
211
|
+
if (k.includes("image") || k.includes("picture")) return 1;
|
212
|
+
return 0;
|
111
213
|
}
|
112
|
-
const
|
113
|
-
|
214
|
+
const keys = propertiesOrder ?? Object.keys(properties);
|
215
|
+
keys.sort();
|
216
|
+
keys.sort((a, b) => {
|
217
|
+
return propOrder(b) - propOrder(a);
|
218
|
+
});
|
219
|
+
return keys;
|
114
220
|
}
|
115
|
-
function
|
116
|
-
if (
|
117
|
-
if (
|
118
|
-
let
|
119
|
-
|
120
|
-
|
221
|
+
function increaseTypeCount(type, typesCount, fieldValue, getType) {
|
222
|
+
if (type === "map") {
|
223
|
+
if (fieldValue) {
|
224
|
+
let mapTypesCount = typesCount[type];
|
225
|
+
if (!mapTypesCount) {
|
226
|
+
mapTypesCount = {};
|
227
|
+
typesCount[type] = mapTypesCount;
|
228
|
+
}
|
229
|
+
Object.entries(fieldValue).forEach(([key, value]) => {
|
230
|
+
increaseMapTypeCount(mapTypesCount, key, value, getType);
|
121
231
|
});
|
122
232
|
}
|
123
|
-
} else if (
|
124
|
-
let
|
125
|
-
if (
|
126
|
-
|
127
|
-
|
128
|
-
}
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
}
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
233
|
+
} else if (type === "array") {
|
234
|
+
let arrayTypesCount = typesCount[type];
|
235
|
+
if (!arrayTypesCount) {
|
236
|
+
arrayTypesCount = {};
|
237
|
+
typesCount[type] = arrayTypesCount;
|
238
|
+
}
|
239
|
+
if (fieldValue && Array.isArray(fieldValue) && fieldValue.length > 0) {
|
240
|
+
const arrayType = getMostProbableTypeInArray(fieldValue, getType);
|
241
|
+
if (arrayType === "map") {
|
242
|
+
let mapTypesCount = arrayTypesCount[arrayType];
|
243
|
+
if (!mapTypesCount) {
|
244
|
+
mapTypesCount = {};
|
245
|
+
}
|
246
|
+
fieldValue.forEach((value) => {
|
247
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
248
|
+
Object.entries(value).forEach(
|
249
|
+
([key, v]) => increaseMapTypeCount(mapTypesCount, key, v, getType)
|
250
|
+
);
|
251
|
+
}
|
252
|
+
});
|
253
|
+
arrayTypesCount[arrayType] = mapTypesCount;
|
254
|
+
} else {
|
255
|
+
if (!arrayTypesCount[arrayType]) arrayTypesCount[arrayType] = 1;
|
256
|
+
else arrayTypesCount[arrayType]++;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
} else {
|
260
|
+
if (!typesCount[type]) typesCount[type] = 1;
|
261
|
+
else typesCount[type]++;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
function increaseMapTypeCount(typesCountRecord, key, fieldValue, getType) {
|
265
|
+
if (key.startsWith("_")) return;
|
266
|
+
let typesCount = typesCountRecord[key];
|
267
|
+
if (!typesCount) {
|
268
|
+
typesCount = {};
|
269
|
+
typesCountRecord[key] = typesCount;
|
270
|
+
}
|
271
|
+
if (fieldValue != null) {
|
272
|
+
const type = getType(fieldValue);
|
273
|
+
increaseTypeCount(type, typesCount, fieldValue, getType);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
function increaseValuesCount(typeValuesRecord, key, fieldValue, getType) {
|
277
|
+
if (key.startsWith("_")) return;
|
278
|
+
const dataType = getType(fieldValue);
|
279
|
+
let valuesRecord = typeValuesRecord[key];
|
280
|
+
if (!valuesRecord) {
|
281
|
+
valuesRecord = {
|
282
|
+
values: [],
|
283
|
+
valuesCount: /* @__PURE__ */ new Map()
|
284
|
+
};
|
285
|
+
typeValuesRecord[key] = valuesRecord;
|
286
|
+
}
|
287
|
+
if (dataType === "map") {
|
288
|
+
let mapValuesRecord = valuesRecord.map;
|
289
|
+
if (!mapValuesRecord) {
|
290
|
+
mapValuesRecord = {};
|
291
|
+
valuesRecord.map = mapValuesRecord;
|
292
|
+
}
|
293
|
+
if (fieldValue)
|
294
|
+
Object.entries(fieldValue).forEach(
|
295
|
+
([subKey, value]) => increaseValuesCount(mapValuesRecord, subKey, value, getType)
|
296
|
+
);
|
297
|
+
} else if (dataType === "array") {
|
298
|
+
if (Array.isArray(fieldValue)) {
|
299
|
+
fieldValue.forEach((value) => {
|
300
|
+
valuesRecord.values.push(value);
|
301
|
+
valuesRecord.valuesCount.set(value, (valuesRecord.valuesCount.get(value) ?? 0) + 1);
|
302
|
+
});
|
303
|
+
}
|
304
|
+
} else {
|
305
|
+
if (fieldValue !== null && fieldValue !== void 0) {
|
306
|
+
valuesRecord.values.push(fieldValue);
|
307
|
+
valuesRecord.valuesCount.set(fieldValue, (valuesRecord.valuesCount.get(fieldValue) ?? 0) + 1);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
}
|
311
|
+
function getHighestTypesCount(typesCount) {
|
312
|
+
let highestCount = 0;
|
313
|
+
Object.entries(typesCount).forEach(([type, count]) => {
|
314
|
+
let countValue = 0;
|
315
|
+
if (type === "map") {
|
316
|
+
countValue = getHighestRecordCount(count);
|
317
|
+
} else if (type === "array") {
|
318
|
+
countValue = getHighestTypesCount(count);
|
319
|
+
} else {
|
320
|
+
countValue = count;
|
321
|
+
}
|
322
|
+
if (countValue > highestCount) {
|
323
|
+
highestCount = countValue;
|
324
|
+
}
|
325
|
+
});
|
326
|
+
return highestCount;
|
327
|
+
}
|
328
|
+
function getHighestRecordCount(record) {
|
329
|
+
return Object.entries(record).map(([key, typesCount]) => getHighestTypesCount(typesCount)).reduce((a, b) => Math.max(a, b), 0);
|
330
|
+
}
|
331
|
+
function getMostProbableType(typesCount) {
|
332
|
+
let highestCount = -1;
|
333
|
+
let probableType = "string";
|
334
|
+
Object.entries(typesCount).forEach(([type, count]) => {
|
335
|
+
let countValue;
|
336
|
+
if (type === "map") {
|
337
|
+
countValue = getHighestRecordCount(count);
|
338
|
+
} else if (type === "array") {
|
339
|
+
countValue = getHighestTypesCount(count);
|
340
|
+
} else {
|
341
|
+
countValue = count;
|
342
|
+
}
|
343
|
+
if (countValue > highestCount) {
|
344
|
+
highestCount = countValue;
|
345
|
+
probableType = type;
|
346
|
+
}
|
347
|
+
});
|
348
|
+
return probableType;
|
349
|
+
}
|
350
|
+
function buildPropertyFromCount(key, totalDocsCount, mostProbableType, typesCount, valuesResult) {
|
351
|
+
let title;
|
352
|
+
if (key) {
|
353
|
+
title = formatString(key.toLowerCase());
|
354
|
+
}
|
355
|
+
let result = void 0;
|
356
|
+
if (mostProbableType === "map") {
|
357
|
+
const highVariability = checkTypesCountHighVariability(typesCount);
|
358
|
+
if (highVariability) {
|
359
|
+
result = {
|
360
|
+
dataType: "map",
|
361
|
+
name: title,
|
362
|
+
keyValue: true,
|
363
|
+
properties: {}
|
364
|
+
};
|
365
|
+
}
|
366
|
+
const properties = buildPropertiesFromCount(
|
367
|
+
totalDocsCount,
|
368
|
+
typesCount.map,
|
369
|
+
valuesResult ? valuesResult.mapValues : void 0
|
370
|
+
);
|
371
|
+
result = {
|
183
372
|
dataType: "map",
|
184
|
-
name:
|
185
|
-
properties
|
373
|
+
name: title,
|
374
|
+
properties
|
186
375
|
};
|
187
|
-
} else if (
|
188
|
-
const
|
189
|
-
|
376
|
+
} else if (mostProbableType === "array") {
|
377
|
+
const arrayTypesCount = typesCount.array;
|
378
|
+
const arrayMostProbableType = getMostProbableType(arrayTypesCount);
|
379
|
+
const of = buildPropertyFromCount(
|
380
|
+
key,
|
381
|
+
totalDocsCount,
|
382
|
+
arrayMostProbableType,
|
383
|
+
arrayTypesCount,
|
384
|
+
valuesResult
|
385
|
+
);
|
386
|
+
result = {
|
190
387
|
dataType: "array",
|
191
|
-
name:
|
192
|
-
of
|
388
|
+
name: title,
|
389
|
+
of
|
193
390
|
};
|
194
391
|
}
|
195
|
-
if (!
|
196
|
-
const
|
197
|
-
name:
|
198
|
-
totalDocsCount
|
199
|
-
valuesResult
|
392
|
+
if (!result) {
|
393
|
+
const propertyProps = {
|
394
|
+
name: key,
|
395
|
+
totalDocsCount,
|
396
|
+
valuesResult
|
200
397
|
};
|
201
|
-
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
|
398
|
+
if (mostProbableType === "string") {
|
399
|
+
result = buildStringProperty(propertyProps);
|
400
|
+
} else if (mostProbableType === "reference") {
|
401
|
+
result = buildReferenceProperty(propertyProps);
|
402
|
+
} else {
|
403
|
+
result = {
|
404
|
+
dataType: mostProbableType
|
405
|
+
};
|
406
|
+
}
|
407
|
+
if (title) {
|
408
|
+
result.name = title;
|
409
|
+
}
|
410
|
+
const validation = buildValidation(propertyProps);
|
411
|
+
if (validation) {
|
412
|
+
result.validation = validation;
|
413
|
+
}
|
206
414
|
}
|
207
415
|
return {
|
208
|
-
...
|
209
|
-
editable:
|
416
|
+
...result,
|
417
|
+
editable: true
|
210
418
|
};
|
211
419
|
}
|
212
|
-
function
|
213
|
-
const
|
214
|
-
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
})
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
420
|
+
function buildPropertiesFromCount(totalDocsCount, typesCountRecord, valuesCountRecord) {
|
421
|
+
const res = {};
|
422
|
+
Object.entries(typesCountRecord).forEach(([key, typesCount]) => {
|
423
|
+
const mostProbableType = getMostProbableType(typesCount);
|
424
|
+
res[key] = buildPropertyFromCount(
|
425
|
+
key,
|
426
|
+
totalDocsCount,
|
427
|
+
mostProbableType,
|
428
|
+
typesCount,
|
429
|
+
valuesCountRecord ? valuesCountRecord[key] : void 0
|
430
|
+
);
|
431
|
+
});
|
432
|
+
return res;
|
433
|
+
}
|
434
|
+
function countMaxDocumentsUnder(typesCount) {
|
435
|
+
let count = 0;
|
436
|
+
Object.entries(typesCount).forEach(([type, value]) => {
|
437
|
+
if (typeof value === "object") {
|
438
|
+
count = Math.max(count, countMaxDocumentsUnder(value));
|
439
|
+
} else {
|
440
|
+
count = Math.max(count, value);
|
441
|
+
}
|
442
|
+
});
|
443
|
+
return count;
|
444
|
+
}
|
445
|
+
function getMostProbableTypeInArray(array, getType) {
|
446
|
+
const typesCount = {};
|
447
|
+
array.forEach((value) => {
|
448
|
+
increaseTypeCount(getType(value), typesCount, value, getType);
|
449
|
+
});
|
450
|
+
return getMostProbableType(typesCount);
|
451
|
+
}
|
452
|
+
function checkTypesCountHighVariability(typesCount) {
|
453
|
+
const maxCount = countMaxDocumentsUnder(typesCount);
|
454
|
+
let keysWithFewValues = 0;
|
455
|
+
Object.entries(typesCount.map ?? {}).forEach(([key, value]) => {
|
456
|
+
const count = countMaxDocumentsUnder(value);
|
457
|
+
if (count < maxCount / 3) {
|
458
|
+
keysWithFewValues++;
|
459
|
+
}
|
460
|
+
});
|
461
|
+
return keysWithFewValues / Object.entries(typesCount.map ?? {}).length > 0.5;
|
462
|
+
}
|
463
|
+
function formatString(input) {
|
464
|
+
const normalized = input.replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
|
465
|
+
const words = normalized.split(" ");
|
466
|
+
const formatted = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
467
|
+
return formatted;
|
468
|
+
}
|
469
|
+
function inferTypeFromValue(value) {
|
470
|
+
if (value === null || value === void 0) return "string";
|
471
|
+
if (typeof value === "string") return "string";
|
472
|
+
if (typeof value === "number") return "number";
|
473
|
+
if (typeof value === "boolean") return "boolean";
|
474
|
+
if (Array.isArray(value)) return "array";
|
475
|
+
if (typeof value === "object") return "map";
|
476
|
+
return "string";
|
237
477
|
}
|
238
478
|
export {
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
479
|
+
buildEntityPropertiesFromData,
|
480
|
+
buildPropertiesOrder,
|
481
|
+
buildPropertyFromData,
|
482
|
+
extractEnumFromValues,
|
483
|
+
inferTypeFromValue,
|
484
|
+
isObject,
|
485
|
+
mergeDeep,
|
486
|
+
resolveEnumValues,
|
487
|
+
unslugify
|
243
488
|
};
|
244
489
|
//# sourceMappingURL=index.es.js.map
|