tods-competition-factory 1.7.6 → 1.7.8
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/forge/generate.mjs +158 -144
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs +151 -142
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +153 -94
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/forge/utilities.d.ts +1 -1
- package/dist/forge/utilities.mjs +126 -75
- package/dist/forge/utilities.mjs.map +1 -1
- package/dist/index.mjs +456 -217
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +564 -298
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@ declare function isOdd(num: any): boolean | undefined;
|
|
|
4
4
|
declare function nextPowerOf2(n?: any): any;
|
|
5
5
|
|
|
6
6
|
declare const hasAttributeValues: (a: any) => (o: any) => boolean;
|
|
7
|
-
declare const extractAttributes: (
|
|
7
|
+
declare const extractAttributes: (accessor: any) => (element: any) => any;
|
|
8
8
|
declare function definedAttributes(obj: object, ignoreFalse?: boolean, ignoreEmptyArrays?: boolean, shallow?: boolean): any;
|
|
9
9
|
declare function undefinedToNull(obj: object, shallow?: boolean): any;
|
|
10
10
|
declare function generateHashCode(o: any): string | undefined;
|
package/dist/forge/utilities.mjs
CHANGED
|
@@ -164,17 +164,134 @@ function deepCopyEnabled() {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (!o)
|
|
174
|
-
return;
|
|
167
|
+
function isDateObject(value) {
|
|
168
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
169
|
+
return false;
|
|
170
|
+
} else {
|
|
171
|
+
const datePrototype = Object.prototype.toString.call(value);
|
|
172
|
+
return datePrototype === "[object Date]";
|
|
175
173
|
}
|
|
176
|
-
return o;
|
|
177
174
|
}
|
|
175
|
+
|
|
176
|
+
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
177
|
+
const deepCopy = deepCopyEnabled();
|
|
178
|
+
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
179
|
+
if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
|
|
180
|
+
return sourceObject;
|
|
181
|
+
}
|
|
182
|
+
const devContext = getDevContext({ makeDeepCopy: true });
|
|
183
|
+
if (devContext) {
|
|
184
|
+
setDeepCopyIterations(iteration);
|
|
185
|
+
if (typeof devContext === "object" && (iteration > (devContext.iterationThreshold || 15) || devContext.firstIteration && iteration === 0) && devContext.log && (!devContext.notInternalUse || devContext.notInternalUse && !internalUse)) {
|
|
186
|
+
console.log({ devContext, iteration, internalUse }, sourceObject);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
190
|
+
const sourceObjectKeys = Object.keys(sourceObject).filter(
|
|
191
|
+
(key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
|
|
192
|
+
);
|
|
193
|
+
const stringifyValue = (key, value) => {
|
|
194
|
+
targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
|
|
195
|
+
};
|
|
196
|
+
for (const key of sourceObjectKeys) {
|
|
197
|
+
const value = sourceObject[key];
|
|
198
|
+
const modulated = typeof modulate === "function" ? modulate(value) : void 0;
|
|
199
|
+
if (modulated !== void 0) {
|
|
200
|
+
targetObject[key] = modulated;
|
|
201
|
+
} else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
|
|
202
|
+
const extensionConversions = extensionsToAttributes(value);
|
|
203
|
+
Object.assign(targetObject, ...extensionConversions);
|
|
204
|
+
} else if (removeExtensions && key === "extensions") {
|
|
205
|
+
targetObject[key] = [];
|
|
206
|
+
} else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
207
|
+
stringifyValue(key, value);
|
|
208
|
+
} else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
|
|
209
|
+
targetObject[key] = value.toJSON();
|
|
210
|
+
} else if (value === null) {
|
|
211
|
+
targetObject[key] = void 0;
|
|
212
|
+
} else if (isDateObject(value)) {
|
|
213
|
+
targetObject[key] = new Date(value).toISOString();
|
|
214
|
+
} else {
|
|
215
|
+
targetObject[key] = makeDeepCopy(
|
|
216
|
+
value,
|
|
217
|
+
convertExtensions,
|
|
218
|
+
internalUse,
|
|
219
|
+
removeExtensions,
|
|
220
|
+
iteration + 1
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return targetObject;
|
|
225
|
+
}
|
|
226
|
+
function extensionsToAttributes(extensions) {
|
|
227
|
+
return extensions?.map((extension) => {
|
|
228
|
+
const { name, value } = extension;
|
|
229
|
+
return name && value && { [`_${name}`]: value };
|
|
230
|
+
}).filter(Boolean);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function getAccessorValue({ element, accessor }) {
|
|
234
|
+
if (typeof accessor !== "string")
|
|
235
|
+
return { values: [] };
|
|
236
|
+
const targetElement = makeDeepCopy(element);
|
|
237
|
+
const attributes = accessor.split(".");
|
|
238
|
+
const values = [];
|
|
239
|
+
let value;
|
|
240
|
+
processKeys({ targetElement, attributes });
|
|
241
|
+
const result = { value };
|
|
242
|
+
if (values.length)
|
|
243
|
+
result.values = values;
|
|
244
|
+
return result;
|
|
245
|
+
function processKeys({
|
|
246
|
+
targetElement: targetElement2,
|
|
247
|
+
attributes: attributes2 = [],
|
|
248
|
+
significantCharacters
|
|
249
|
+
}) {
|
|
250
|
+
for (const [index, attribute] of attributes2.entries()) {
|
|
251
|
+
if (targetElement2?.[attribute]) {
|
|
252
|
+
const remainingKeys = attributes2.slice(index + 1);
|
|
253
|
+
if (!remainingKeys.length) {
|
|
254
|
+
if (!value)
|
|
255
|
+
value = targetElement2[attribute];
|
|
256
|
+
if (!values.includes(targetElement2[attribute])) {
|
|
257
|
+
values.push(targetElement2[attribute]);
|
|
258
|
+
}
|
|
259
|
+
} else if (Array.isArray(targetElement2[attribute])) {
|
|
260
|
+
const values2 = targetElement2[attribute];
|
|
261
|
+
values2.forEach(
|
|
262
|
+
(nestedTarget) => processKeys({
|
|
263
|
+
targetElement: nestedTarget,
|
|
264
|
+
attributes: remainingKeys
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
} else {
|
|
268
|
+
targetElement2 = targetElement2[attribute];
|
|
269
|
+
checkValue({ targetElement: targetElement2, index });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function checkValue({ targetElement: targetElement3, index }) {
|
|
274
|
+
if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
|
|
275
|
+
const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
|
|
276
|
+
if (value) {
|
|
277
|
+
if (!values.includes(extractedValue)) {
|
|
278
|
+
values.push(extractedValue);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
value = extractedValue;
|
|
282
|
+
values.push(extractedValue);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
|
|
290
|
+
const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
|
|
291
|
+
[a]: getAccessorValue({ element, accessor: a })?.value
|
|
292
|
+
})) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
|
|
293
|
+
[key]: getAccessorValue({ element, accessor: key })?.value
|
|
294
|
+
})) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
|
|
178
295
|
function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
|
|
179
296
|
if (typeof obj !== "object" || obj === null)
|
|
180
297
|
return obj;
|
|
@@ -287,72 +404,6 @@ function generateTimeCode(index = 0) {
|
|
|
287
404
|
return uidate.getTime().toString(36).slice(-6).toUpperCase();
|
|
288
405
|
}
|
|
289
406
|
|
|
290
|
-
function isDateObject(value) {
|
|
291
|
-
if (typeof value !== "object" || Array.isArray(value)) {
|
|
292
|
-
return false;
|
|
293
|
-
} else {
|
|
294
|
-
const datePrototype = Object.prototype.toString.call(value);
|
|
295
|
-
return datePrototype === "[object Date]";
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
300
|
-
const deepCopy = deepCopyEnabled();
|
|
301
|
-
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
302
|
-
if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
|
|
303
|
-
return sourceObject;
|
|
304
|
-
}
|
|
305
|
-
const devContext = getDevContext({ makeDeepCopy: true });
|
|
306
|
-
if (devContext) {
|
|
307
|
-
setDeepCopyIterations(iteration);
|
|
308
|
-
if (typeof devContext === "object" && (iteration > (devContext.iterationThreshold || 15) || devContext.firstIteration && iteration === 0) && devContext.log && (!devContext.notInternalUse || devContext.notInternalUse && !internalUse)) {
|
|
309
|
-
console.log({ devContext, iteration, internalUse }, sourceObject);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
313
|
-
const sourceObjectKeys = Object.keys(sourceObject).filter(
|
|
314
|
-
(key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
|
|
315
|
-
);
|
|
316
|
-
const stringifyValue = (key, value) => {
|
|
317
|
-
targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
|
|
318
|
-
};
|
|
319
|
-
for (const key of sourceObjectKeys) {
|
|
320
|
-
const value = sourceObject[key];
|
|
321
|
-
const modulated = typeof modulate === "function" ? modulate(value) : void 0;
|
|
322
|
-
if (modulated !== void 0) {
|
|
323
|
-
targetObject[key] = modulated;
|
|
324
|
-
} else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
|
|
325
|
-
const extensionConversions = extensionsToAttributes(value);
|
|
326
|
-
Object.assign(targetObject, ...extensionConversions);
|
|
327
|
-
} else if (removeExtensions && key === "extensions") {
|
|
328
|
-
targetObject[key] = [];
|
|
329
|
-
} else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
330
|
-
stringifyValue(key, value);
|
|
331
|
-
} else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
|
|
332
|
-
targetObject[key] = value.toJSON();
|
|
333
|
-
} else if (value === null) {
|
|
334
|
-
targetObject[key] = void 0;
|
|
335
|
-
} else if (isDateObject(value)) {
|
|
336
|
-
targetObject[key] = new Date(value).toISOString();
|
|
337
|
-
} else {
|
|
338
|
-
targetObject[key] = makeDeepCopy(
|
|
339
|
-
value,
|
|
340
|
-
convertExtensions,
|
|
341
|
-
internalUse,
|
|
342
|
-
removeExtensions,
|
|
343
|
-
iteration + 1
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return targetObject;
|
|
348
|
-
}
|
|
349
|
-
function extensionsToAttributes(extensions) {
|
|
350
|
-
return extensions?.map((extension) => {
|
|
351
|
-
const { name, value } = extension;
|
|
352
|
-
return name && value && { [`_${name}`]: value };
|
|
353
|
-
}).filter(Boolean);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
407
|
function numericSort(a, b) {
|
|
357
408
|
return a - b;
|
|
358
409
|
}
|