url-safe-bitpacking 0.3.11 → 0.3.12
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/index.js
CHANGED
|
@@ -375,41 +375,46 @@ var validateDataEntry = (descriptorValue, differentValue) => {
|
|
|
375
375
|
return descriptorValue;
|
|
376
376
|
if (descriptorValue.type === differentValue.type)
|
|
377
377
|
if (ComplexDataTypes.includes(descriptorValue.type))
|
|
378
|
-
return updateStateEntry(descriptorValue, differentValue.state);
|
|
378
|
+
return updateStateEntry(descriptorValue, differentValue.state, differentValue.value);
|
|
379
379
|
else
|
|
380
|
-
return updateValueEntry(descriptorValue, differentValue.value);
|
|
380
|
+
return updateValueEntry({ ...descriptorValue }, differentValue.value);
|
|
381
381
|
return descriptorValue;
|
|
382
382
|
};
|
|
383
383
|
|
|
384
384
|
// src/update/optionalUpdate.ts
|
|
385
385
|
var constrainState = (state) => state === true ? true : false;
|
|
386
|
-
var updateState = (original, state) => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return original;
|
|
386
|
+
var updateState = (original, state, current) => {
|
|
387
|
+
const updatedState = constrainState(state);
|
|
388
|
+
const value = validateDataEntry(original.descriptor[Number(state)], current ?? original.value);
|
|
389
|
+
return { ...original, state: updatedState, value };
|
|
390
390
|
};
|
|
391
391
|
|
|
392
392
|
// src/update/enumOptionsUpdate.ts
|
|
393
393
|
var constrainState2 = (descriptorLength, state) => constrainUnsignedInt(state, descriptorLength - 1);
|
|
394
|
-
var updateState2 = (original, state) => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return original;
|
|
394
|
+
var updateState2 = (original, state, current) => {
|
|
395
|
+
const updatedState = constrainState2(original.descriptor.length, state);
|
|
396
|
+
const value = validateDataEntry(original.descriptor[updatedState], current ?? original.value);
|
|
397
|
+
return { ...original, state: updatedState, value };
|
|
398
398
|
};
|
|
399
399
|
|
|
400
400
|
// src/update/arrayUpdate.ts
|
|
401
401
|
var constrainState3 = (state, minCount, maxCount) => constrainSignedInt(state, minCount, maxCount);
|
|
402
|
-
var updateState3 = (original, state) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
402
|
+
var updateState3 = (original, state, current) => {
|
|
403
|
+
const updatedState = constrainState3(state, original.minCount, original.maxCount);
|
|
404
|
+
const currentValue = current ?? original.value;
|
|
405
|
+
const value = [...new Array(updatedState)].map((_, i) => currentValue[i] ? validateDataEntry(original.descriptor, currentValue[i] ?? null) : original.descriptor);
|
|
406
|
+
return {
|
|
407
|
+
...original,
|
|
408
|
+
state: updatedState,
|
|
409
|
+
value
|
|
410
|
+
};
|
|
406
411
|
};
|
|
407
412
|
|
|
408
413
|
// src/update/objectUpdate.ts
|
|
409
|
-
var updateValue7 = (original, value) => {
|
|
410
|
-
original
|
|
411
|
-
|
|
412
|
-
};
|
|
414
|
+
var updateValue7 = (original, value) => ({
|
|
415
|
+
...original,
|
|
416
|
+
value: original.descriptor.map((v, i) => validateDataEntry(v, value[i] ?? null))
|
|
417
|
+
});
|
|
413
418
|
|
|
414
419
|
// src/update/updateValues.ts
|
|
415
420
|
var updateValueEntry = (original, update) => {
|
|
@@ -446,14 +451,14 @@ var constrainValue7 = (original, update) => {
|
|
|
446
451
|
return constrainValue6(original, update);
|
|
447
452
|
}
|
|
448
453
|
};
|
|
449
|
-
var updateStateEntry = (original, update) => {
|
|
454
|
+
var updateStateEntry = (original, update, current) => {
|
|
450
455
|
switch (original.type) {
|
|
451
456
|
case "OPTIONAL":
|
|
452
|
-
return updateState(original, update);
|
|
457
|
+
return updateState(original, update, current);
|
|
453
458
|
case "ENUM_OPTIONS":
|
|
454
|
-
return updateState2(original, update);
|
|
459
|
+
return updateState2(original, update, current);
|
|
455
460
|
case "ARRAY":
|
|
456
|
-
return updateState3(original, update);
|
|
461
|
+
return updateState3(original, update, current);
|
|
457
462
|
}
|
|
458
463
|
};
|
|
459
464
|
// src/factory/utils.ts
|
|
@@ -13,4 +13,4 @@ export type UpdateWithStateEntries = DataEntry & {
|
|
|
13
13
|
type: (typeof ComplexDataTypes)[number];
|
|
14
14
|
};
|
|
15
15
|
export type UpdateValue<T extends UpdateWithValuesEntries> = (entry: T, value: T['value']) => T;
|
|
16
|
-
export type UpdateState<T extends UpdateWithStateEntries> = (entry: T, state: T['state']) => T;
|
|
16
|
+
export type UpdateState<T extends UpdateWithStateEntries> = (entry: T, state: T['state'], current?: T['value']) => T;
|
|
@@ -13,4 +13,4 @@ export declare const constrainValue: <T extends UpdateWithValidationTypes>(origi
|
|
|
13
13
|
* @param original - the original data entry
|
|
14
14
|
* @param update - the update data entry
|
|
15
15
|
*/
|
|
16
|
-
export declare const updateStateEntry: <T extends UpdateWithStateEntries>(original: T, update: T["state"]) => T;
|
|
16
|
+
export declare const updateStateEntry: <T extends UpdateWithStateEntries>(original: T, update: T["state"], current?: T["value"]) => T;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { DataEntry } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Method used as an interchange for validating data entries
|
|
4
|
+
* @param descriptorValue - `DataEntry` - used as a mask for the state
|
|
5
|
+
* @param differentValue - `DataEntry` - the one with the updated value and or state
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
2
8
|
export declare const validateDataEntry: <T extends DataEntry>(descriptorValue: T | null, differentValue: T | null) => T | null;
|