url-safe-bitpacking 0.1.15 → 0.2.1

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.
Files changed (44) hide show
  1. package/README.md +6 -6
  2. package/dist/enums/dataTypes.d.ts +4 -9
  3. package/dist/factory/arrayFactory.d.ts +2 -0
  4. package/dist/factory/enumArrayFactory.d.ts +2 -2
  5. package/dist/factory/enumFactory.d.ts +2 -1
  6. package/dist/factory/enumOptionsFactory.d.ts +2 -0
  7. package/dist/factory/factory.d.ts +13 -7
  8. package/dist/factory/optionalFactory.d.ts +2 -0
  9. package/dist/factory/utils.d.ts +19 -0
  10. package/dist/index.d.ts +6 -5
  11. package/dist/index.js +465 -352
  12. package/dist/parsers/arrayParser.d.ts +4 -0
  13. package/dist/parsers/enumOptionsFactory.d.ts +4 -0
  14. package/dist/parsers/optionalParser.d.ts +4 -0
  15. package/dist/parsers/parsers.d.ts +16 -12
  16. package/dist/stateHandling/index.d.ts +1 -0
  17. package/dist/stateHandling/stateData.d.ts +3 -0
  18. package/dist/stateHandling/stateDataObject.d.ts +15 -0
  19. package/dist/typeFactory/stateDataTyping.d.ts +1 -9
  20. package/dist/types/arrayData.d.ts +10 -0
  21. package/dist/types/booleanData.d.ts +1 -2
  22. package/dist/types/dataEntry.d.ts +12 -5
  23. package/dist/types/enumArrayData.d.ts +3 -3
  24. package/dist/types/enumData.d.ts +4 -2
  25. package/dist/types/enumOptionsData.d.ts +8 -0
  26. package/dist/types/floatData.d.ts +1 -2
  27. package/dist/types/index.d.ts +7 -5
  28. package/dist/types/intData.d.ts +1 -2
  29. package/dist/types/optionalData.d.ts +7 -0
  30. package/dist/types/stateDataEntry.d.ts +16 -0
  31. package/dist/types/versionData.d.ts +1 -2
  32. package/dist/update/arrayUpdate.d.ts +2 -0
  33. package/dist/update/enumOptionsUpdate.d.ts +2 -0
  34. package/dist/update/nestedDataMatching.d.ts +2 -0
  35. package/dist/update/optionalUpdate.d.ts +2 -0
  36. package/dist/update/updateValues.d.ts +8 -1
  37. package/package.json +1 -1
  38. package/dist/objectmap/index.d.ts +0 -4
  39. package/dist/objectmap/stateDataModel.d.ts +0 -33
  40. package/dist/objectmap/stateValueHelperMethods.d.ts +0 -13
  41. package/dist/objectmap/userMethods.d.ts +0 -12
  42. package/dist/types/arrayDefinitions.d.ts +0 -58
  43. package/dist/types/semanticMapping.d.ts +0 -6
  44. package/dist/types/stateValueModel.d.ts +0 -33
package/README.md CHANGED
@@ -28,7 +28,7 @@ Currently, there are 4 data types implemented (+1 special case for safety). All
28
28
  Bool type values are simple yes or no, 1 or 0s, nothing special
29
29
 
30
30
  ```typescript
31
- DataEntryFactory.createBoolean(false, 'shapePreProcessingWarpabsolute');
31
+ DescriptorFactory.BOOLEAN(false, 'shapePreProcessingWarpabsolute');
32
32
  ```
33
33
 
34
34
  ### enum
@@ -36,7 +36,7 @@ DataEntryFactory.createBoolean(false, 'shapePreProcessingWarpabsolute');
36
36
  An enum in this context is a continuous array of integers. The Bitwidth of this data type is defined by the maximum entry. eg. in case you you would need 21 states, the larges value would be 20. The value 20 would require at least five bits (log2(20) ~ 4.32). The maximum bitwidth for enums is right now hardcoded to 8-bit (which would be the range [0, 255] ).
37
37
 
38
38
  ```typescript
39
- DataEntryFactory.createEnum(0, 3, 'footprintType');
39
+ DescriptorFactory.ENUM(0, 3, 'footprintType');
40
40
  ```
41
41
 
42
42
  ### int
@@ -44,7 +44,7 @@ DataEntryFactory.createEnum(0, 3, 'footprintType');
44
44
  An int type is rather similar to the enum, except that it starts at a specific minimum value. The range that then needs to be able to be stored is: max - min. In case you would need values from -30 to 10, you would have to be able to store 10 - 30 + 1 = 51 states. This would require a bitwidth of 6 (log2(51) ~ 5.67). The max bitwidth is now hardcoded to be 12 (which would be the range [minimum, 4095 - minimum])
45
45
 
46
46
  ```typescript
47
- DataEntryFactory.createInt(5, 3, 20, 'circleDivisions');
47
+ DescriptorFactory.INT(5, 3, 20, 'circleDivisions');
48
48
  ```
49
49
 
50
50
  ### float
@@ -52,7 +52,7 @@ DataEntryFactory.createInt(5, 3, 20, 'circleDivisions');
52
52
  Floating points work very much like the integer type, with the main difference that one can also define a precision to define at what order of magnitude (from -3 to +3) the variable should be considered. The significand can be up to 20 bits, which eg. at precision -3 would allow a range of .001 to 1048.576.
53
53
 
54
54
  ```typescript
55
- DataEntryFactory.createFloat(20, 10, 200, -1, 'shapePreProcessingWarptotal');
55
+ DescriptorFactory.FLOAT(20, 10, 200, -1, 'shapePreProcessingWarptotal');
56
56
  ```
57
57
 
58
58
  ### enum array
@@ -60,7 +60,7 @@ DataEntryFactory.createFloat(20, 10, 200, -1, 'shapePreProcessingWarptotal');
60
60
  Enum arrays are a special type of arrays where integer values are intepreted as being values of a **specific base** to then be transformed to base 2. The base is derived from the delta of the max `and` the `min` value of the enums. Besides that, there is also a `minCount` and `maxCount` value (which can be the same value, but `minCount` is at least 1). This only offers a compression rate of upto 22% vis-a-vis an array of `IntDataEntry` (worst case its 0% percent, it never takes up more space), so sometimes questionable whether it makese sense to use ^^.
61
61
 
62
62
  ```typescript
63
- DataEntryFactory.createEnumArray([0, 1, 2], 0, 10, 3, 5, 'enumArrayA')
63
+ DescriptorFactory.ENUM_ARRAY([0, 1, 2], 0, 10, 3, 5, 'enumArrayA')
64
64
  ```
65
65
 
66
66
  ### version
@@ -68,7 +68,7 @@ DataEntryFactory.createEnumArray([0, 1, 2], 0, 10, 3, 5, 'enumArrayA')
68
68
  There is also a Version object which is a special case of the enum data type and has a bitwidth of 4, 6, 8 or, 10 and always occupies the first bits of the bitarray.
69
69
 
70
70
  ```typescript
71
- DataEntryFactory.createVersion(0, 8, 'version');
71
+ DescriptorFactory.VERSION(0, 8, 'version');
72
72
  ```
73
73
 
74
74
  ## nested attribute definitions
@@ -1,9 +1,4 @@
1
- export declare enum DataType {
2
- VERSION = 0,
3
- BOOLEAN = 1,
4
- ENUM = 2,
5
- INT = 3,
6
- FLOAT = 4,
7
- ENUM_ARRAY = 5
8
- }
9
- export declare const getDataTypeName: (type: DataType) => string;
1
+ export declare const DataTypeValues: readonly ["VERSION", "BOOLEAN", "ENUM", "INT", "FLOAT", "ENUM_ARRAY"];
2
+ export declare const ComplexDataValues: readonly ["OPTIONAL", "ENUM_OPTIONS", "ARRAY"];
3
+ export type DataType = (typeof DataTypeValues)[number];
4
+ export type ComplexDataType = (typeof ComplexDataValues)[number];
@@ -0,0 +1,2 @@
1
+ import { ArrayDataEntry, NestedData } from '@/types';
2
+ export declare const create: (descriptor: NestedData, defaultState?: number, minCount?: number, maxCount?: number, name?: string, index?: number) => ArrayDataEntry;
@@ -1,2 +1,2 @@
1
- import { EnumArrayDataEntry } from '@/types';
2
- export declare const create: (value: number[], min?: number, max?: number, minCount?: number, maxCount?: number, name?: string, index?: number) => EnumArrayDataEntry;
1
+ import { EnumArrayDataEntry, EnumOptionsType } from '@/types';
2
+ export declare const create: (value: number[], options: EnumOptionsType, minCount?: number, maxCount?: number, name?: string, index?: number) => EnumArrayDataEntry;
@@ -1,2 +1,3 @@
1
1
  import { EnumDataEntry } from '../types';
2
- export declare const create: (value: number, max?: number, name?: string, index?: number) => EnumDataEntry;
2
+ import { EnumOptionsType } from '../types/enumData';
3
+ export declare const create: (value: number, options: EnumOptionsType, name?: string, index?: number) => EnumDataEntry;
@@ -0,0 +1,2 @@
1
+ import { EnumOptionsDataEntry, NestedData } from '@/types';
2
+ export declare const create: (descriptor: NestedData[], defaultState?: number, name?: string, index?: number) => EnumOptionsDataEntry;
@@ -4,14 +4,20 @@ import { create as createBoolean } from './booleanFactory';
4
4
  import { create as createVersion } from './versionFactory';
5
5
  import { create as createEnum } from './enumFactory';
6
6
  import { create as createEnumArray } from './enumArrayFactory';
7
+ import { create as createOptional } from './optionalFactory';
8
+ import { create as createEnumOptions } from './enumOptionsFactory';
9
+ import { create as createArray } from './arrayFactory';
7
10
  /**
8
11
  * Record containing all the factory methods for the different data entry objects
9
12
  */
10
- export declare const DataEntryFactory: {
11
- createFloat: typeof createFloat;
12
- createInt: typeof createInt;
13
- createEnum: typeof createEnum;
14
- createBoolean: typeof createBoolean;
15
- createVersion: typeof createVersion;
16
- createEnumArray: typeof createEnumArray;
13
+ export declare const DescriptorFactory: {
14
+ readonly FLOAT: typeof createFloat;
15
+ readonly INT: typeof createInt;
16
+ readonly ENUM: typeof createEnum;
17
+ readonly BOOLEAN: typeof createBoolean;
18
+ readonly VERSION: typeof createVersion;
19
+ readonly ENUM_ARRAY: typeof createEnumArray;
20
+ readonly OPTIONAL: typeof createOptional;
21
+ readonly ENUM_OPTIONS: typeof createEnumOptions;
22
+ readonly ARRAY: typeof createArray;
17
23
  };
@@ -0,0 +1,2 @@
1
+ import { NestedData, OptionalDataEntry } from '@/types';
2
+ export declare const create: (descriptor: [null, NestedData] | [NestedData, null], defaultState?: boolean, name?: string, index?: number) => OptionalDataEntry;
@@ -0,0 +1,19 @@
1
+ import { EnumMappingType, EnumOptionsType } from '@/types';
2
+ /**
3
+ * Method to get the max and mapping from the options
4
+ * @param options - `any[] | string | number` the options to get the max and mapping from
5
+ * @returns `{ max: number; mapping: any[] }` the max and mapping
6
+ */
7
+ export declare const getEnumMaxAndMappingFromOptions: (options: EnumOptionsType) => {
8
+ max: number;
9
+ mapping: EnumMappingType;
10
+ };
11
+ /**
12
+ * Method to get the options from the max and mapping of an ENUM & ENUM_ARRAY type
13
+ * @param v - `{ max: number; mapping: EnumMappingType }` the max and mapping to get the options from
14
+ * @returns `EnumOptionsType` the options
15
+ */
16
+ export declare const getOptionsFromMaxAndMapping: (v: {
17
+ max: number;
18
+ mapping: EnumMappingType;
19
+ }) => EnumOptionsType;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { DataType } from './enums';
2
- export { DataEntryFactory } from './factory';
3
- export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, ArrayEntryDataType, OptionalEntryDataType, EnumEntryDataType, PrecisionRangeType, SignificandMaxBits, FloatDataEntry, IntegerMaxBits, IntDataEntry, EnumDataEntry, EnumArrayDataEntry, VersionRangeType, VersionDataEntry, BooleanDataEntry, DataEntry, DataEntryArray, StateDataType, StateValueType, EnumSemantics, DerivativeStateDataType, VersionContentDefinition, PREFIX_SEPERATOR_DELIMETER, PROTECTED_ATTRIBUTE_NAMES } from './types';
4
- export { createParserObject, getStateValue, getBase64String, getDataEntryArray, isDataEntry, isDoubleLevelContentType, isSingleLevelContentType, doubleLevelContentTypeIsEnumEntryDataType, doubleLevelContentTypeIsOptionalEntryDataType, doubleLevelContentTypeIsArrayDefinitionType } from './objectmap';
5
- export { parseBase64ToBits, getBitsCount, valueBitsParser, dataBitsParser, dataEntryBitstringParser, dataBitsStringifier, dataEntryCorrecting } from './parsers';
1
+ export { DataType, DataTypeValues, ComplexDataType, ComplexDataValues } from './enums';
2
+ export { DescriptorFactory } from './factory';
3
+ export { PrecisionRangeType, SignificandMaxBits, FloatDataEntry, IntegerMaxBits, IntDataEntry, EnumDataEntry, EnumArrayDataEntry, VersionRangeType, VersionDataEntry, BooleanDataEntry, DataEntry, ComplexDataEntry, NestedData, ProtectedAttributeNames, StateDescriptor, StateObject, StateDataObject, StateDataEntry, State, EnumOptionsType, EnumMappingType, PROTECTED_ATTRIBUTE_NAMES } from './types';
4
+ export { parseBase64ToBits, getBitsCount, valueBitsParser, dataBitsParser, dataEntryBitstringParser, dataEntryCorrecting, dataBitsStringifier, complexDataStringifier, complexDataStateStringifier } from './parsers';
5
+ export { createStateDataObject, getInitialStateFromBase64 } from './stateHandling';
6
6
  export { interpolateEntryAt, getRelativeValue } from './utils';
7
+ export { getEnumMaxAndMappingFromOptions, getOptionsFromMaxAndMapping } from './factory/utils';