url-safe-bitpacking 0.2.1 → 0.3.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 (58) hide show
  1. package/README.md +20 -60
  2. package/dist/enums/dataTypes.d.ts +16 -4
  3. package/dist/factory/arrayFactory.d.ts +3 -2
  4. package/dist/factory/booleanFactory.d.ts +2 -1
  5. package/dist/factory/enumArrayFactory.d.ts +3 -2
  6. package/dist/factory/enumFactory.d.ts +2 -1
  7. package/dist/factory/enumOptionsFactory.d.ts +3 -2
  8. package/dist/factory/factory.d.ts +14 -10
  9. package/dist/factory/floatFactory.d.ts +2 -2
  10. package/dist/factory/intFactory.d.ts +2 -1
  11. package/dist/factory/objectFactory.d.ts +3 -0
  12. package/dist/factory/optionalFactory.d.ts +3 -2
  13. package/dist/factory/utils.d.ts +1 -1
  14. package/dist/factory/versionFactory.d.ts +2 -1
  15. package/dist/index.d.ts +5 -5
  16. package/dist/index.js +767 -532
  17. package/dist/parsers/arrayParser.d.ts +4 -3
  18. package/dist/parsers/enumArrayParser.d.ts +3 -1
  19. package/dist/parsers/enumOptionsParser.d.ts +5 -0
  20. package/dist/parsers/index.d.ts +1 -0
  21. package/dist/parsers/intParser.d.ts +2 -4
  22. package/dist/parsers/objectParser.d.ts +4 -0
  23. package/dist/parsers/optionalParser.d.ts +4 -3
  24. package/dist/parsers/parserNestedDataUtils.d.ts +14 -0
  25. package/dist/parsers/parserUtils.d.ts +56 -0
  26. package/dist/parsers/parsers.d.ts +14 -80
  27. package/dist/stateHandling/index.d.ts +2 -1
  28. package/dist/stateHandling/stateData.d.ts +2 -3
  29. package/dist/stateHandling/stateNode.d.ts +123 -0
  30. package/dist/typeFactory/dataEntryTyping.d.ts +2 -2
  31. package/dist/types/arrayData.d.ts +3 -3
  32. package/dist/types/dataEntry.d.ts +45 -15
  33. package/dist/types/enumArrayData.d.ts +2 -0
  34. package/dist/types/enumData.d.ts +1 -1
  35. package/dist/types/enumOptionsData.d.ts +5 -3
  36. package/dist/types/index.d.ts +3 -1
  37. package/dist/types/objectData.d.ts +8 -0
  38. package/dist/types/optionalData.d.ts +4 -3
  39. package/dist/types/stateData.d.ts +4 -0
  40. package/dist/types/stateDataEntry.d.ts +10 -6
  41. package/dist/types/updateType.d.ts +16 -0
  42. package/dist/update/arrayUpdate.d.ts +4 -2
  43. package/dist/update/booleanUpdate.d.ts +3 -2
  44. package/dist/update/enumArrayUpdate.d.ts +3 -2
  45. package/dist/update/enumOptionsUpdate.d.ts +3 -2
  46. package/dist/update/enumUpdate.d.ts +2 -1
  47. package/dist/update/floatUpdate.d.ts +2 -1
  48. package/dist/update/index.d.ts +1 -0
  49. package/dist/update/intUpdate.d.ts +2 -1
  50. package/dist/update/objectUpdate.d.ts +2 -0
  51. package/dist/update/optionalUpdate.d.ts +3 -2
  52. package/dist/update/updateUtils.d.ts +27 -0
  53. package/dist/update/updateValues.d.ts +5 -4
  54. package/dist/update/validateUtils.d.ts +2 -0
  55. package/dist/update/versionUpdate.d.ts +3 -2
  56. package/dist/utils/interpolateData.d.ts +4 -1
  57. package/dist/utils/relativeValue.d.ts +4 -1
  58. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
- import { ArrayDataEntry } from '@/types';
2
- export declare const rawParser: (bitString: string, arrayData: ArrayDataEntry) => [ArrayDataEntry, string];
3
- export declare const rawStateStringifier: (arrayData: ArrayDataEntry) => string;
1
+ import { ArrayDataEntry } from '../types';
2
+ export declare const rawParser: (arrayData: ArrayDataEntry, bitString: string) => [ArrayDataEntry, string];
3
+ export declare const rawStateStringifier: (state: ArrayDataEntry["state"], minCount: ArrayDataEntry["minCount"], stateBits: ArrayDataEntry["stateBits"]) => string;
4
4
  export declare const rawStringifier: (arrayData: ArrayDataEntry) => string;
5
+ export declare const getContentBitsCountForValue: (arrayData: ArrayDataEntry["value"]) => number;
@@ -1,4 +1,6 @@
1
1
  import { EnumArrayData } from '../types/enumArrayData';
2
2
  export declare const getBitsCount: (enumArrayData: EnumArrayData, bitString: string) => number;
3
- export declare const rawParser: (bitString: string, enumArrayData: EnumArrayData) => number[];
3
+ export declare const getContentBitsCountForValue: (value: number[], enumArrayData: EnumArrayData) => number;
4
+ export declare const rawParser: (enumArrayData: EnumArrayData, bitString: string) => [EnumArrayData, string];
5
+ export declare const rawStateStringifier: (value: number[], minCount: EnumArrayData["minCount"], stateBits: EnumArrayData["stateBits"]) => string;
4
6
  export declare const rawStringifier: (value: number[], enumArrayData: EnumArrayData) => string;
@@ -0,0 +1,5 @@
1
+ import { EnumOptionsDataEntry } from '../types';
2
+ export declare const rawParser: (enumOptionsData: EnumOptionsDataEntry, bitString: string) => [EnumOptionsDataEntry, string];
3
+ export declare const rawStateStringifier: (state: EnumOptionsDataEntry["state"], stateBits: EnumOptionsDataEntry["stateBits"]) => string;
4
+ export declare const rawStringifier: (enumOptionsData: EnumOptionsDataEntry) => string;
5
+ export declare const getContentBitsCountForValue: (enumOptionsValue: EnumOptionsDataEntry["value"]) => number;
@@ -1 +1,2 @@
1
1
  export * from './parsers';
2
+ export * from './parserUtils';
@@ -3,10 +3,8 @@ export declare const getBitsCount: (intData: IntData) => number;
3
3
  /**
4
4
  * Method that parses a state bitstring into a raw positive int
5
5
  * @param stateString - `string` 0 | 1
6
- * @param bitCount - `number` amount of bits to consider
7
- * @returns number
6
+ * @param intData - `IntData` that represents the int data entry to parse
7
+ * @returns `number` that represents the parsed value
8
8
  */
9
- export declare const rawValueParser: (stateString: string, bitCount: number) => number;
10
9
  export declare const rawParser: (stateString: string, intData: IntData) => number;
11
- export declare const rawIntStringifier: (value: number, bitCount: number) => string;
12
10
  export declare const rawStringifier: (value: number, intData: IntData) => string;
@@ -0,0 +1,4 @@
1
+ import { ObjectDataEntry } from '../types';
2
+ export declare const rawParser: (objectData: ObjectDataEntry, bitString: string) => [ObjectDataEntry, string];
3
+ export declare const getContentBitsCountForValue: (objectValue: ObjectDataEntry["value"]) => number;
4
+ export declare const rawStringifier: (objectData: ObjectDataEntry) => string;
@@ -1,4 +1,5 @@
1
- import { OptionalDataEntry } from '@/types';
2
- export declare const rawParser: (bitString: string, optionalData: OptionalDataEntry) => [OptionalDataEntry, string];
3
- export declare const rawStateStringifier: (optionalData: OptionalDataEntry) => string;
1
+ import { OptionalDataEntry } from '../types';
2
+ export declare const rawParser: (optionalData: OptionalDataEntry, bitString: string) => [OptionalDataEntry, string];
3
+ export declare const rawStateStringifier: (state: OptionalDataEntry["state"]) => string;
4
4
  export declare const rawStringifier: (optionalData: OptionalDataEntry) => string;
5
+ export declare const getContentBitsCountForValue: (optionalData: OptionalDataEntry["value"]) => number;
@@ -0,0 +1,14 @@
1
+ import { DataEntry } from '../types';
2
+ /**
3
+ * Helper method to get the bit count for a nested data entry
4
+ * @param nestedData - `DataEntry[]` that represents the nested data entry
5
+ * @returns
6
+ */
7
+ export declare const getContentBitsCountForNestedData: (data: DataEntry[]) => number;
8
+ export declare const nestedDataStringifier: (nestedData: DataEntry[]) => string;
9
+ /**
10
+ * Method that parses a bitstring for a given nested data descriptor
11
+ * @param bitstring - `string` of 0 | 1
12
+ * @param descriptor - `DataEntry[]` that represents the framework applicable to the bitstring
13
+ */
14
+ export declare const nestedDataBitstringParser: (bitstring: string, descriptor: DataEntry[]) => [DataEntry[], string];
@@ -0,0 +1,56 @@
1
+ export declare const base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2
+ /**
3
+ * Method that returns the bits required for a given amount of numners for a specific base
4
+ * @param count - `number` amount of numbers
5
+ * @param base - `number` max value of the numbers
6
+ */
7
+ export declare const getBitsForEnumArrayCountOfBase: (count: number, base: number) => number;
8
+ /**
9
+ * Method to convert an array of numbers to a bit string
10
+ * @param input - `number[]` the input array of numbers to convert to a bit string
11
+ * @param fromBase - `number` that represents the base of the input numbers
12
+ * @returns `string` that represents the bit string of the input numbers
13
+ * @returns 0 | 1 bit string
14
+ */
15
+ export declare const convertArbitraryBaseToBitString: (input: number[], fromBase: number) => string;
16
+ /**
17
+ * Method to convert a bit string to an array of numbers of a specific base
18
+ * @param input - `string` that represents the bit string to convert to an array of numbers
19
+ * @param toBase - `number` that represents the base of the output numbers
20
+ * @param expectedOutputLength - `number` that represents the expected length of the output array
21
+ */
22
+ export declare const convertBitStringToArbitraryBase: (input: string, toBase: number, expectedOutputLength: number) => number[];
23
+ /**
24
+ * Unused method to convert an array of numbers from an arbitrary base to an arbitrary base
25
+ * @param input - `number[]` the input array of numbers to convert to a bit string
26
+ * @param fromBase - `number` that represents the base of the input numbers
27
+ * @param toBase - `number` that represents the base of the output numbers
28
+ * @param expectedOutputLength - `number` | optional, should be given when you should find a specific amount of output numbers
29
+ */
30
+ export declare const convertArbitraryBaseToArbitraryBase: (input: number[], fromBase: number, toBase: number, expectedOutputLength?: number) => number[];
31
+ /**
32
+ * Method that convists a bitstring to a url safe base64 string
33
+ * @param bits - `string` of 0 | 1
34
+ * @returns `string` that represents the url safe base64 string
35
+ */
36
+ export declare const parseBitsToBase64: (bits: string) => string;
37
+ /**
38
+ * Method that convists a url safe base64 string to a bitstring
39
+ * @param base64 - `string` that represents the url safe base64 string
40
+ * @returns `string` of 0 | 1
41
+ */
42
+ export declare const parseBase64ToBits: (base64: string) => string;
43
+ /**
44
+ * Method that stringifies a raw positive int
45
+ * @param value - `number`
46
+ * @param bitCount - `number` amount of bits to consider
47
+ * @returns `string` of 0 | 1
48
+ */
49
+ export declare const rawIntStringifier: (value: number, bitCount: number) => string;
50
+ /**
51
+ * Method that parses a state bitstring into a raw positive int
52
+ * @param stateString - `string` 0 | 1
53
+ * @param bitCount - `number` amount of bits to consider
54
+ * @returns number
55
+ */
56
+ export declare const rawValueParser: (stateString: string, bitCount: number) => number;
@@ -1,90 +1,24 @@
1
- import { DataEntry, ComplexDataEntry, NestedData } from '../types/dataEntry';
1
+ import { HasStateBitsDataTypes, SpecifiedDataEntry } from '../enums/dataTypes';
2
+ import { DataEntry, SimpleDataEntry } from '../types/dataEntry';
3
+ export declare const getStateBitsCountForDataEntry: (entry: DataEntry) => number;
4
+ export declare const getStateBitsForDataEntry: (entry: SpecifiedDataEntry<(typeof HasStateBitsDataTypes)[number]>) => string;
2
5
  /**
3
- * Method that parses a bitstring into a value
4
- * @param bitString - `string` of 0 | 1
5
- * @param mapData - `DataEntry` that represents the data entry to parse
6
- * @returns `number` | `boolean` that represents the parsed value
6
+ * Helper method to get the bit-width for the content of a data entry (based on current value, doesn't do any validation)
7
+ * @param entry - `DataEntry`
7
8
  */
8
- export declare const valueBitsParser: (bitString: string, mapData: DataEntry) => number | boolean | number[];
9
- /**
10
- * Method that parses a bitstring into a data entry
11
- * @param rawString - `string` of 0 | 1
12
- * @param mapData - `DataEntry` that represents the data entry to parse
13
- * @returns `DataEntry` that represents the parsed data entry
14
- */
15
- export declare const dataBitsParser: (rawString: string, mapData: DataEntry) => DataEntry;
9
+ export declare const getContentBitsCountForDataEntry: (entry: DataEntry) => number;
10
+ export declare const dataEntryBitstringParser: <T extends DataEntry>(entry: T, bitString: string) => [T, string];
16
11
  /**
17
12
  * Method that returns the amount of bits required for a given data entry
18
- * @param mapData - `DataEntry` that represents the data entry to get the bits count for
13
+ * @param data - `DataEntry` that represents the data entry to get the bits count for
19
14
  * @param bitString - `string` 0 | 1
20
15
  * @returns `number` that represents the bits count for the given data entry
21
16
  */
22
- export declare const getBitsCount: (mapData: DataEntry, bitString: string) => number;
17
+ export declare const getBitsCount: (mapData: SimpleDataEntry) => number;
23
18
  /**
24
- * Method that parses a bitstring into a data entry and returns the remaining bitstring
25
- * @param bitstring - `string` of 0 | 1
26
- * @param dataEntry - `DataEntry` that represents the data entry to parse
27
- * @returns `[DataEntry, string]` that represents the data entry and the remaining bitstring
19
+ * Get the bitstring for a given data entry
20
+ * @param entry
21
+ * @returns `0 | 1` string that represents the bitstate for the given object
28
22
  */
29
- export declare const dataEntryBitstringParser: (bitstring: string, dataEntry: DataEntry) => [DataEntry, string];
30
- /**
31
- * Method that parses a bitstring for a given nested data descriptor
32
- * @param bitstring - `string` of 0 | 1
33
- * @param descriptor - `NestedData` that represents the framework applicable to the bitstring
34
- * @returns `[NestedData, string]` that represents the actual data and the remaining bitstring
35
- */
36
- export declare const nestedDataBitstringParser: (bitstring: string, descriptor: NestedData) => [NestedData, string];
37
- /**
38
- * Method that parses a bitstring into its data for complex data entries
39
- * @param bitstring - `string` of 0 | 1
40
- * @param complexDataEntry - `DataEntry` that represents the data entry to parse
41
- * @returns `[DataEntry, string]` that represents the data entry and the remaining bitstring
42
- */
43
- export declare const complexDataEntryBitstringParser: <T extends ComplexDataEntry>(bitstring: string, complexDataEntry: T) => [T, string];
44
- export declare const dataBitsStringifier: (data: DataEntry) => string;
45
- export declare const complexDataStringifier: <T extends ComplexDataEntry>(complexDataEntry: T) => string;
46
- export declare const complexDataStateStringifier: <T extends ComplexDataEntry>(complexDataEntry: T) => string;
47
- export declare const nestedDataStringifier: (nestedData: NestedData) => string;
23
+ export declare const dataEntryBitsStringifier: (entry: DataEntry) => string;
48
24
  export declare const dataEntryCorrecting: (dataEntry: DataEntry) => DataEntry;
49
- export declare const base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
50
- /**
51
- * Method that returns the bits required for a given amount of numners for a specific base
52
- * @param count - `number` amount of numbers
53
- * @param base - `number` max value of the numbers
54
- */
55
- export declare const getBitsForEnumArrayCountOfBase: (count: number, base: number) => number;
56
- /**
57
- * Method to convert an array of numbers to a bit string
58
- * @param input - `number[]` the input array of numbers to convert to a bit string
59
- * @param fromBase - `number` that represents the base of the input numbers
60
- * @returns `string` that represents the bit string of the input numbers
61
- * @returns 0 | 1 bit string
62
- */
63
- export declare const convertArbitraryBaseToBitString: (input: number[], fromBase: number) => string;
64
- /**
65
- * Method to convert a bit string to an array of numbers of a specific base
66
- * @param input - `string` that represents the bit string to convert to an array of numbers
67
- * @param toBase - `number` that represents the base of the output numbers
68
- * @param expectedOutputLength - `number` that represents the expected length of the output array
69
- */
70
- export declare const convertBitStringToArbitraryBase: (input: string, toBase: number, expectedOutputLength: number) => number[];
71
- /**
72
- * Unused method to convert an array of numbers from an arbitrary base to an arbitrary base
73
- * @param input - `number[]` the input array of numbers to convert to a bit string
74
- * @param fromBase - `number` that represents the base of the input numbers
75
- * @param toBase - `number` that represents the base of the output numbers
76
- * @param expectedOutputLength - `number` | optional, should be given when you should find a specific amount of output numbers
77
- */
78
- export declare const convertArbitraryBaseToArbitraryBase: (input: number[], fromBase: number, toBase: number, expectedOutputLength?: number) => number[];
79
- /**
80
- * Method that convists a bitstring to a url safe base64 string
81
- * @param bits - `string` of 0 | 1
82
- * @returns `string` that represents the url safe base64 string
83
- */
84
- export declare const parseBitsToBase64: (bits: string) => string;
85
- /**
86
- * Method that convists a url safe base64 string to a bitstring
87
- * @param base64 - `string` that represents the url safe base64 string
88
- * @returns `string` of 0 | 1
89
- */
90
- export declare const parseBase64ToBits: (base64: string) => string;
@@ -1 +1,2 @@
1
- export * from './stateDataObject';
1
+ export * from './stateNode';
2
+ export * from './stateData';
@@ -1,3 +1,2 @@
1
- import { NestedData } from '@/types';
2
- import { StateDataObject } from '@/types/stateDataEntry';
3
- export declare const getStateData: (state: NestedData) => StateDataObject;
1
+ import { DataEntry, StateDataObjectValue } from '../types';
2
+ export declare const getStateData: (entry: DataEntry) => StateDataObjectValue;
@@ -0,0 +1,123 @@
1
+ import { DataType } from '../enums';
2
+ import { ArrayDataEntry, BooleanDataEntry, DataEntry, EnumArrayDataEntry, EnumDataEntry, EnumOptionsDataEntry, FloatDataEntry, IntDataEntry, ObjectDataEntry, OptionalDataEntry, VersionDataEntry, UpdateWithValidationTypes } from '../types';
3
+ export declare class StateNode {
4
+ protected parent: StateNode | null;
5
+ protected root: StateNode;
6
+ type: DataType;
7
+ name: string;
8
+ bitstring: string;
9
+ constructor(entry: DataEntry, parent: StateNode | null);
10
+ updateUpstream: () => void;
11
+ getStateBits: () => string;
12
+ getValueBits: () => string;
13
+ getBitString: () => string;
14
+ getBase64String: () => string;
15
+ /**
16
+ * Helper method to get a string representation of the parent of this node
17
+ */
18
+ getParentString: () => string;
19
+ getChildren: () => (StateNode | null)[];
20
+ getDescription: () => string;
21
+ /**
22
+ * Helper method to get the (nested) string representaiton of all the children (and grandchildren) of this node
23
+ */
24
+ getChildrenStrings: () => string[];
25
+ toDataEntry: () => DataEntry;
26
+ /**
27
+ * Method to get a string representation with the tree-like view of this node and all of its children
28
+ */
29
+ toString(): string;
30
+ }
31
+ declare class SimpleStateNodes<T extends UpdateWithValidationTypes> extends StateNode {
32
+ value: T['value'];
33
+ descriptor: T;
34
+ constructor(entry: T, parent: SpecificTypeNode | null);
35
+ getChildren: () => SpecificTypeNode[];
36
+ getDescription: () => string;
37
+ updateValue: (value: T["value"]) => void;
38
+ toDataEntry: () => T;
39
+ }
40
+ export declare class VersionNode extends SimpleStateNodes<VersionDataEntry> {
41
+ }
42
+ export declare class BooleanNode extends SimpleStateNodes<BooleanDataEntry> {
43
+ }
44
+ export declare class EnumNode extends SimpleStateNodes<EnumDataEntry> {
45
+ }
46
+ export declare class IntNode extends SimpleStateNodes<IntDataEntry> {
47
+ }
48
+ export declare class FloatNode extends SimpleStateNodes<FloatDataEntry> {
49
+ }
50
+ export declare class EnumArrayNode extends SimpleStateNodes<EnumArrayDataEntry> {
51
+ getStateBits: () => string;
52
+ getDescription: () => string;
53
+ }
54
+ export declare class OptionalNode extends StateNode {
55
+ private state;
56
+ private stateBits;
57
+ private descriptor;
58
+ private child;
59
+ constructor(entry: OptionalDataEntry, parent: SpecificTypeNode | null);
60
+ getChildren: () => (SpecificTypeNode | null)[];
61
+ getStateBits: () => string;
62
+ getValueBits: () => string;
63
+ updateState: (newState: OptionalDataEntry["state"]) => void;
64
+ toDataEntry: () => OptionalDataEntry;
65
+ getDescription: () => string;
66
+ }
67
+ export declare class EnumOptionsNode extends StateNode {
68
+ private state;
69
+ private stateBits;
70
+ private descriptor;
71
+ private mapping;
72
+ private child;
73
+ constructor(entry: EnumOptionsDataEntry, parent: SpecificTypeNode | null);
74
+ getChildren: () => (SpecificTypeNode | null)[];
75
+ getStateBits: () => string;
76
+ getValueBits: () => string;
77
+ updateState: (newState: EnumOptionsDataEntry["state"]) => void;
78
+ toDataEntry: () => EnumOptionsDataEntry;
79
+ getDescription: () => string;
80
+ }
81
+ export declare class ArrayNode extends StateNode {
82
+ private descriptor;
83
+ private children;
84
+ private minCount;
85
+ private maxCount;
86
+ private stateBits;
87
+ private state;
88
+ constructor(entry: ArrayDataEntry, parent: SpecificTypeNode | null);
89
+ getChildren: () => SpecificTypeNode[];
90
+ getStateBits: () => string;
91
+ getValueBits: () => string;
92
+ updateState: (newState: ArrayDataEntry["state"]) => void;
93
+ toDataEntry: () => ArrayDataEntry;
94
+ getDescription: () => string;
95
+ }
96
+ export declare class ObjectNode extends StateNode {
97
+ private descriptor;
98
+ private children;
99
+ constructor(entry: ObjectDataEntry, parent: SpecificTypeNode | null);
100
+ getChildren: () => SpecificTypeNode[];
101
+ getStateBits: () => string;
102
+ getValueBits: () => string;
103
+ toDataEntry: () => ObjectDataEntry;
104
+ }
105
+ export type StateNodeTypeMap = {
106
+ VERSION: VersionNode;
107
+ BOOLEAN: BooleanNode;
108
+ ENUM: EnumNode;
109
+ INT: IntNode;
110
+ FLOAT: FloatNode;
111
+ ENUM_ARRAY: EnumArrayNode;
112
+ OPTIONAL: OptionalNode;
113
+ ENUM_OPTIONS: EnumOptionsNode;
114
+ ARRAY: ArrayNode;
115
+ OBJECT: ObjectNode;
116
+ };
117
+ export type SpecificTypeNode = StateNodeTypeMap[keyof StateNodeTypeMap];
118
+ export declare const NodeFactory: <T extends DataType>(entry: DataEntry & {
119
+ type: T;
120
+ }, parent: SpecificTypeNode | null) => StateNodeTypeMap[T];
121
+ export declare const GetStateNodeTree: (entries: [VersionDataEntry, ...DataEntry[]], name?: string) => ObjectNode;
122
+ export declare const FromState: (stateDescriptor: [VersionDataEntry, ...DataEntry[]], name: string, base64String: string) => ObjectNode;
123
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { DataEntry } from '../types';
2
- export declare const getDataEntryTypeString: (d: DataEntry, withLibraryInformation?: boolean, retainValue?: boolean) => string;
2
+ export declare const getDataEntryTypeString: (d: DataEntry) => string;
3
3
  export declare const getStateDataContentType: (d: DataEntry) => string;
4
4
  export declare const getStateValueContentType: (d: DataEntry) => string;
5
5
  export declare const getSafeName: (name: string) => string;
6
- export declare const getDateEntryTypeNamedString: (d: DataEntry, withLibraryInformation?: boolean) => string;
6
+ export declare const getDateEntryTypeNamedString: (d: DataEntry) => string;
@@ -1,10 +1,10 @@
1
- import { NestedData } from './dataEntry';
1
+ import { DataEntry } from './dataEntry';
2
2
  export type ArrayData = {
3
3
  type: 'ARRAY';
4
4
  minCount: number;
5
5
  maxCount: number;
6
6
  stateBits: number;
7
7
  state: number;
8
- descriptor: NestedData;
9
- value: NestedData[];
8
+ descriptor: DataEntry;
9
+ value: DataEntry[];
10
10
  };
@@ -7,27 +7,27 @@ import { EnumArrayData } from './enumArrayData.ts';
7
7
  import { OptionalData } from './optionalData.ts';
8
8
  import { EnumOptionsData } from './enumOptionsData.ts';
9
9
  import { ArrayData } from './arrayData.ts';
10
+ import { ObjectData } from './objectData.ts';
11
+ import { ConstantBitWidthDataTypes, VariableBitWidthDataTypes } from '@/enums/dataTypes.ts';
10
12
  export type Prettify<T> = {
11
13
  [K in keyof T]: T[K];
12
14
  };
13
15
  type DataDescription = {
14
16
  name: string;
15
- internalName?: number[];
16
- index?: number;
17
17
  };
18
18
  /**
19
19
  * Boolean object
20
20
  *
21
21
  * Boolean objects are a simple `true` or `false`, 1 or 0 - one bitwidth object.
22
22
  */
23
- export type BooleanDataEntry = Prettify<BooleanData & DataDescription>;
23
+ export type BooleanDataEntry = BooleanData & DataDescription;
24
24
  /**
25
25
  * Enum object
26
26
  *
27
27
  * An enum object is a continious range of integer values, starting at 0 upto its max.
28
28
  * The maximum acceptable value for the max is `255` (8 bits)
29
29
  */
30
- export type EnumDataEntry = Prettify<EnumData & DataDescription>;
30
+ export type EnumDataEntry = EnumData & DataDescription;
31
31
  /**
32
32
  * Int object
33
33
  *
@@ -35,7 +35,7 @@ export type EnumDataEntry = Prettify<EnumData & DataDescription>;
35
35
  * The maximum and minimum value can be any integar values represntabled as a double yet,
36
36
  * the maximum acceptable delta between min and max is `4095` (12 bits).
37
37
  */
38
- export type IntDataEntry = Prettify<IntData & DataDescription>;
38
+ export type IntDataEntry = IntData & DataDescription;
39
39
  /**
40
40
  * Float object
41
41
  *
@@ -45,7 +45,7 @@ export type IntDataEntry = Prettify<IntData & DataDescription>;
45
45
  * The significand defines the amount of bits that are used to store the numeric value of the number and is derived from the `min` and `max` values in relationship to the precision.
46
46
  * Maximum value for the significand is `20` bits, which allows for a maximum of 1048576 possible values.
47
47
  */
48
- export type FloatDataEntry = Prettify<FloatData & DataDescription>;
48
+ export type FloatDataEntry = FloatData & DataDescription;
49
49
  /**
50
50
  * Version object
51
51
  *
@@ -55,7 +55,7 @@ export type FloatDataEntry = Prettify<FloatData & DataDescription>;
55
55
  * Acceptable bitwidths are: `4 | 6 | 8 | 10`, giving a total of respectively 16, 64, 256 and 1024 possible versions
56
56
  * Choose wisely, as it is not possible to increase this value later on (that would require the inclusion of an additional version object)
57
57
  */
58
- export type VersionDataEntry = Prettify<VersionData & DataDescription>;
58
+ export type VersionDataEntry = VersionData & DataDescription;
59
59
  /**
60
60
  * Enum Array object
61
61
  *
@@ -68,13 +68,43 @@ export type VersionDataEntry = Prettify<VersionData & DataDescription>;
68
68
  *
69
69
  * Note: the partical maximum benefit of using this versus using a `ArrayEntryDataType` with only enums is only about 22% for base_5
70
70
  */
71
- export type EnumArrayDataEntry = Prettify<EnumArrayData & DataDescription>;
72
- export type DataEntry = BooleanDataEntry | IntDataEntry | EnumDataEntry | FloatDataEntry | VersionDataEntry | EnumArrayDataEntry;
73
- export type OptionalDataEntry = Prettify<OptionalData & DataDescription>;
74
- export type EnumOptionsDataEntry = Prettify<EnumOptionsData & DataDescription>;
75
- export type ArrayDataEntry = Prettify<ArrayData & DataDescription>;
76
- export type ComplexDataEntry = OptionalDataEntry | EnumOptionsDataEntry | ArrayDataEntry;
77
- export type NestedData = (DataEntry | ComplexDataEntry)[];
78
- export type ProtectedAttributeNames = Prettify<keyof BooleanDataEntry | keyof IntDataEntry | keyof EnumDataEntry | keyof FloatDataEntry | keyof VersionDataEntry | keyof EnumArrayDataEntry | keyof OptionalDataEntry | keyof EnumOptionsDataEntry | keyof ArrayDataEntry>;
71
+ export type EnumArrayDataEntry = EnumArrayData & DataDescription;
72
+ /**
73
+ * Object Wrapper Object
74
+ *
75
+ * contains a static set of NestedData, for which its structure always maps 1:1 to its descriptor
76
+ */
77
+ export type ObjectDataEntry = ObjectData & DataDescription;
78
+ /**
79
+ * Optional Wrapper Object
80
+ *
81
+ * has two optional states, `true` or `false` and a matching descriptor (either `[null, DataEntry]` or `[DataEntry, null]`) corresponding to the state
82
+ */
83
+ export type OptionalDataEntry = OptionalData & DataDescription;
84
+ /**
85
+ * Enum Options Wrapper Object
86
+ *
87
+ *
88
+ * similar to the optional wrapper, but using a `number` to offer many different states
89
+ * the maxAmount of states is derived from the descriptor length
90
+ * descriptor entries can be any `DataEntry` or `null`
91
+ */
92
+ export type EnumOptionsDataEntry = EnumOptionsData & DataDescription;
93
+ export type ArrayDataEntry = ArrayData & DataDescription;
94
+ /**
95
+ * Union Type of all the defined data types
96
+ */
97
+ export type DataEntry = BooleanDataEntry | IntDataEntry | EnumDataEntry | FloatDataEntry | VersionDataEntry | EnumArrayDataEntry | ObjectDataEntry | OptionalDataEntry | EnumOptionsDataEntry | ArrayDataEntry;
98
+ /**
99
+ * Union Type of all the data entries that have a bitwidth that are guaranteed to have only one level of complexity
100
+ * These are much easier to parse (both from and to bitstring )
101
+ */
102
+ export type SimpleDataEntry = DataEntry & {
103
+ type: (typeof ConstantBitWidthDataTypes)[number];
104
+ };
105
+ export type VariableBitWidthDataEntry = DataEntry & {
106
+ type: (typeof VariableBitWidthDataTypes)[number];
107
+ };
108
+ export type ProtectedAttributeNames = keyof BooleanDataEntry | keyof IntDataEntry | keyof EnumDataEntry | keyof FloatDataEntry | keyof VersionDataEntry | keyof EnumArrayDataEntry | keyof OptionalDataEntry | keyof EnumOptionsDataEntry | keyof ArrayDataEntry;
79
109
  export declare const PROTECTED_ATTRIBUTE_NAMES: readonly ["type", "value", "name", "internalName", "index", "min", "max", "bits", "precision", "significand", "minCount", "maxCount", "state", "stateBits", "descriptor", "mapping"];
80
110
  export {};
@@ -18,4 +18,6 @@ export type EnumArrayData = {
18
18
  value: number[];
19
19
  max: number;
20
20
  mapping: EnumMappingType;
21
+ stateBits: number;
22
+ state?: 0;
21
23
  };
@@ -1,5 +1,5 @@
1
1
  export declare const EnumMaxBits = 8;
2
- export type EnumMappingType = (string | number | object)[];
2
+ export type EnumMappingType = (string | number)[];
3
3
  export type EnumOptionsType = string | number | EnumMappingType;
4
4
  /**
5
5
  * Enum object
@@ -1,8 +1,10 @@
1
- import { NestedData } from './dataEntry';
1
+ import { DataEntry } from './dataEntry';
2
+ import { EnumMappingType } from './enumData';
2
3
  export type EnumOptionsData = {
3
4
  type: 'ENUM_OPTIONS';
4
5
  stateBits: number;
5
6
  state: number;
6
- descriptor: NestedData[];
7
- value: NestedData;
7
+ descriptor: (DataEntry | null)[];
8
+ mapping: EnumMappingType;
9
+ value: DataEntry | null;
8
10
  };
@@ -1,4 +1,3 @@
1
- export * from './stateDataEntry';
2
1
  export * from './enumOptionsData';
3
2
  export * from './optionalData';
4
3
  export * from './arrayData';
@@ -9,3 +8,6 @@ export * from './intData';
9
8
  export * from './versionData';
10
9
  export * from './booleanData';
11
10
  export * from './dataEntry';
11
+ export * from './objectData';
12
+ export * from './updateType';
13
+ export * from './stateData';
@@ -0,0 +1,8 @@
1
+ import { DataEntry } from './dataEntry';
2
+ export type ObjectData = {
3
+ type: 'OBJECT';
4
+ stateBits: 0;
5
+ state?: 0;
6
+ value: DataEntry[];
7
+ descriptor: DataEntry[];
8
+ };
@@ -1,7 +1,8 @@
1
- import { NestedData } from './dataEntry';
1
+ import { DataEntry } from './dataEntry';
2
2
  export type OptionalData = {
3
3
  type: 'OPTIONAL';
4
4
  state: boolean;
5
- descriptor: [NestedData, null] | [null, NestedData];
6
- value: NestedData | null;
5
+ descriptor: [DataEntry, null] | [null, DataEntry];
6
+ value: DataEntry | null;
7
+ stateBits: 1;
7
8
  };
@@ -0,0 +1,4 @@
1
+ export type StateDataObjectValue = object | string | number | number[] | boolean | null | StateDataObject;
2
+ export type StateDataObject = {
3
+ [key: string]: StateDataObjectValue;
4
+ };
@@ -1,12 +1,16 @@
1
- import { ComplexDataEntry, DataEntry, NestedData, VersionDataEntry } from './dataEntry';
2
- export type StateDataEntry<T extends DataEntry | ComplexDataEntry> = T & {
1
+ import { DataEntry, ObjectDataEntry, VersionDataEntry } from './dataEntry';
2
+ import { UpdateWithStateEntries } from './updateType';
3
+ export type StateDataEntry<T extends DataEntry> = T & {
3
4
  bitstring: string;
4
- updateValue: (newEntry: T) => void;
5
+ updateValue: (value: T['value'], state?: UpdateWithStateEntries['state'], withCallBack?: boolean) => StateDataEntry<T>;
6
+ };
7
+ export type State = [StateDataEntry<VersionDataEntry>, ...StateDataEntry<DataEntry>[]];
8
+ export type StateDataValue = string | boolean | number | object | null;
9
+ export type StateObjectDataEntry = ObjectDataEntry & {
10
+ descriptor: [VersionDataEntry, ...DataEntry[]];
5
11
  };
6
- export type State = [StateDataEntry<VersionDataEntry>, ...StateDataEntry<DataEntry | ComplexDataEntry>[]];
7
- export type StateDescriptor = [VersionDataEntry, ...NestedData];
8
12
  export type StateDataObject = {
9
- [key: string]: object | string | boolean | number | (string | number | object)[] | null | StateDataObject | StateDataObject[];
13
+ [key: string]: StateDataValue;
10
14
  };
11
15
  export type StateObject = {
12
16
  state: State;
@@ -0,0 +1,16 @@
1
+ import { DataEntry } from './dataEntry';
2
+ export declare const ComplexDataTypes: readonly ["ENUM_OPTIONS", "OPTIONAL", "ARRAY"];
3
+ export declare const SimpleDataTypes: readonly ["BOOLEAN", "INT", "ENUM", "FLOAT", "VERSION", "ENUM_ARRAY", "OBJECT"];
4
+ export declare const NestedUpdateTypes: readonly ["ENUM_OPTIONS", "OPTIONAL", "ARRAY", "OBJECT"];
5
+ export declare const SimpleUpdateTypes: readonly ["BOOLEAN", "INT", "ENUM", "FLOAT", "VERSION", "ENUM_ARRAY"];
6
+ export type UpdateWithValidationTypes = DataEntry & {
7
+ type: (typeof SimpleUpdateTypes)[number];
8
+ };
9
+ export type UpdateWithValuesEntries = DataEntry & {
10
+ type: (typeof SimpleDataTypes)[number];
11
+ };
12
+ export type UpdateWithStateEntries = DataEntry & {
13
+ type: (typeof ComplexDataTypes)[number];
14
+ };
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;
@@ -1,2 +1,4 @@
1
- import { ArrayDataEntry } from '@/types';
2
- export declare const updateComplexValue: (original: ArrayDataEntry, update: ArrayDataEntry) => ArrayDataEntry;
1
+ import { ArrayDataEntry } from '../types';
2
+ import { UpdateState } from '../types/updateType';
3
+ export declare const constrainState: (state: ArrayDataEntry["state"], minCount: ArrayDataEntry["minCount"], maxCount: ArrayDataEntry["maxCount"]) => ArrayDataEntry["state"];
4
+ export declare const updateState: UpdateState<ArrayDataEntry>;
@@ -1,2 +1,3 @@
1
- import { BooleanDataEntry } from '../types/dataEntry';
2
- export declare const updateValue: (original: BooleanDataEntry, update: BooleanDataEntry) => BooleanDataEntry;
1
+ import { BooleanDataEntry } from '../types/';
2
+ export declare const constrainValue: <T extends BooleanDataEntry>(original: T, update: T["value"]) => T["value"];
3
+ export declare const updateValue: <T extends BooleanDataEntry>(original: T, update: T["value"]) => T;