url-safe-bitpacking 0.1.14 → 0.2.0

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 (51) hide show
  1. package/README.md +9 -0
  2. package/dist/enums/dataTypes.d.ts +4 -8
  3. package/dist/factory/arrayFactory.d.ts +2 -0
  4. package/dist/factory/enumArrayFactory.d.ts +2 -0
  5. package/dist/factory/enumFactory.d.ts +1 -1
  6. package/dist/factory/enumOptionsFactory.d.ts +2 -0
  7. package/dist/factory/factory.d.ts +13 -0
  8. package/dist/factory/floatFactory.d.ts +9 -0
  9. package/dist/factory/helperMethod.d.ts +19 -0
  10. package/dist/factory/optionalFactory.d.ts +2 -0
  11. package/dist/factory/utils.d.ts +9 -0
  12. package/dist/index.d.ts +5 -5
  13. package/dist/index.js +536 -306
  14. package/dist/parsers/arrayParser.d.ts +4 -0
  15. package/dist/parsers/enumArrayParser.d.ts +4 -0
  16. package/dist/parsers/enumOptionsFactory.d.ts +4 -0
  17. package/dist/parsers/intParser.d.ts +6 -0
  18. package/dist/parsers/optionalParser.d.ts +4 -0
  19. package/dist/parsers/parsers.d.ts +81 -13
  20. package/dist/stateHandling/index.d.ts +1 -0
  21. package/dist/stateHandling/stateData.d.ts +3 -0
  22. package/dist/stateHandling/stateDataObject.d.ts +15 -0
  23. package/dist/typeFactory/dataEntryTyping.d.ts +6 -0
  24. package/dist/typeFactory/index.d.ts +1 -0
  25. package/dist/typeFactory/stateDataTyping.d.ts +1 -0
  26. package/dist/types/arrayData.d.ts +10 -0
  27. package/dist/types/booleanData.d.ts +1 -2
  28. package/dist/types/dataEntry.d.ts +64 -6
  29. package/dist/types/enumArrayData.d.ts +20 -0
  30. package/dist/types/enumData.d.ts +8 -2
  31. package/dist/types/enumOptionsData.d.ts +8 -0
  32. package/dist/types/floatData.d.ts +10 -2
  33. package/dist/types/index.d.ts +7 -5
  34. package/dist/types/intData.d.ts +8 -2
  35. package/dist/types/optionalData.d.ts +7 -0
  36. package/dist/types/stateDataEntry.d.ts +16 -0
  37. package/dist/types/versionData.d.ts +1 -2
  38. package/dist/update/arrayUpdate.d.ts +2 -0
  39. package/dist/update/enumArrayUpdate.d.ts +2 -0
  40. package/dist/update/enumOptionsUpdate.d.ts +2 -0
  41. package/dist/update/nestedDataMatching.d.ts +2 -0
  42. package/dist/update/optionalUpdate.d.ts +2 -0
  43. package/dist/update/updateValues.d.ts +14 -1
  44. package/package.json +3 -2
  45. package/dist/objectmap/index.d.ts +0 -4
  46. package/dist/objectmap/stateDataModel.d.ts +0 -19
  47. package/dist/objectmap/stateValueHelperMethods.d.ts +0 -13
  48. package/dist/objectmap/userMethods.d.ts +0 -12
  49. package/dist/types/arrayDefinitions.d.ts +0 -10
  50. package/dist/types/semanticMapping.d.ts +0 -6
  51. package/dist/types/stateValueModel.d.ts +0 -33
@@ -0,0 +1,4 @@
1
+ import { ArrayDataEntry } from '@/types';
2
+ export declare const rawParser: (bitString: string, arrayData: ArrayDataEntry) => [ArrayDataEntry, string];
3
+ export declare const rawStateStringifier: (arrayData: ArrayDataEntry) => string;
4
+ export declare const rawStringifier: (arrayData: ArrayDataEntry) => string;
@@ -0,0 +1,4 @@
1
+ import { EnumArrayData } from '../types/enumArrayData';
2
+ export declare const getBitsCount: (enumArrayData: EnumArrayData, bitString: string) => number;
3
+ export declare const rawParser: (bitString: string, enumArrayData: EnumArrayData) => number[];
4
+ export declare const rawStringifier: (value: number[], enumArrayData: EnumArrayData) => string;
@@ -0,0 +1,4 @@
1
+ import { EnumOptionsDataEntry } from '@/types';
2
+ export declare const rawParser: (bitString: string, enumOptionsData: EnumOptionsDataEntry) => [EnumOptionsDataEntry, string];
3
+ export declare const rawStateStringifier: (enumOptionsData: EnumOptionsDataEntry) => string;
4
+ export declare const rawStringifier: (enumOptionsData: EnumOptionsDataEntry) => string;
@@ -1,5 +1,11 @@
1
1
  import { IntData } from '../types/intData';
2
2
  export declare const getBitsCount: (intData: IntData) => number;
3
+ /**
4
+ * Method that parses a state bitstring into a raw positive int
5
+ * @param stateString - `string` 0 | 1
6
+ * @param bitCount - `number` amount of bits to consider
7
+ * @returns number
8
+ */
3
9
  export declare const rawValueParser: (stateString: string, bitCount: number) => number;
4
10
  export declare const rawParser: (stateString: string, intData: IntData) => number;
5
11
  export declare const rawIntStringifier: (value: number, bitCount: number) => string;
@@ -0,0 +1,4 @@
1
+ import { OptionalDataEntry } from '@/types';
2
+ export declare const rawParser: (bitString: string, optionalData: OptionalDataEntry) => [OptionalDataEntry, string];
3
+ export declare const rawStateStringifier: (optionalData: OptionalDataEntry) => string;
4
+ export declare const rawStringifier: (optionalData: OptionalDataEntry) => string;
@@ -1,22 +1,90 @@
1
- import { DataEntryArray, DataEntry } from '../types/dataEntry';
2
- export declare const valueBitsParser: (bitString: string, mapData: DataEntry) => number | boolean;
1
+ import { DataEntry, ComplexDataEntry, NestedData } from '../types/dataEntry';
2
+ /**
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
7
+ */
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
+ */
3
15
  export declare const dataBitsParser: (rawString: string, mapData: DataEntry) => DataEntry;
4
- export declare const getBitsCount: (mapData: DataEntry) => number;
16
+ /**
17
+ * 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
19
+ * @param bitString - `string` 0 | 1
20
+ * @returns `number` that represents the bits count for the given data entry
21
+ */
22
+ export declare const getBitsCount: (mapData: DataEntry, bitString: string) => number;
23
+ /**
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
28
+ */
5
29
  export declare const dataEntryBitstringParser: (bitstring: string, dataEntry: DataEntry) => [DataEntry, string];
6
30
  /**
7
- * Method to convert a bitstring into an array of data entries
8
- * @param bitString bitstring to parse into bits and then data entries
9
- * @param mapDataArray Data descriptions to map the bits to data entries
10
- * @returns array of data entries
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
11
35
  */
12
- export declare const dataBitsArrayParser: (bitString: string, mapDataArray: DataEntry[]) => DataEntryArray;
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];
13
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;
14
48
  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
+ */
15
84
  export declare const parseBitsToBase64: (bits: string) => string;
16
- export declare const parseBase64ToBits: (base64: string) => string;
17
85
  /**
18
- * Method to convert an array of data entries into a base64 string
19
- * @param dataArray Data Entries to read to parse into bits and then a base64 string
20
- * @returns bitstring representation of the data entries
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
21
89
  */
22
- export declare const dataArrayStringifier: (dataEntryArray: DataEntryArray) => string;
90
+ export declare const parseBase64ToBits: (base64: string) => string;
@@ -0,0 +1 @@
1
+ export * from './stateDataObject';
@@ -0,0 +1,3 @@
1
+ import { NestedData } from '@/types';
2
+ import { StateDataObject } from '@/types/stateDataEntry';
3
+ export declare const getStateData: (state: NestedData) => StateDataObject;
@@ -0,0 +1,15 @@
1
+ import { StateDescriptor, StateObject } from '@/types/stateDataEntry';
2
+ /**
3
+ * Creates a state object from a state descriptor and updates the state object when the state changes.
4
+ * @param initialState - the initial state descriptor
5
+ * @param updateCallback - the callback that gets triggered when the state gets updated
6
+ * @returns the state object
7
+ */
8
+ export declare const createStateDataObject: (initialState: StateDescriptor, updateCallback: (currentState: StateObject) => StateObject) => StateObject;
9
+ /**
10
+ * Creates a state descriptor from a base64 string and a state descriptor
11
+ * @param base64 - the base64 string
12
+ * @param descriptor - the state descriptor
13
+ * @returns the state descriptor
14
+ */
15
+ export declare const getInitialStateFromBase64: (base64: string, descriptor: StateDescriptor) => StateDescriptor;
@@ -0,0 +1,6 @@
1
+ import { DataEntry } from '../types';
2
+ export declare const getDataEntryTypeString: (d: DataEntry, withLibraryInformation?: boolean, retainValue?: boolean) => string;
3
+ export declare const getStateDataContentType: (d: DataEntry) => string;
4
+ export declare const getStateValueContentType: (d: DataEntry) => string;
5
+ export declare const getSafeName: (name: string) => string;
6
+ export declare const getDateEntryTypeNamedString: (d: DataEntry, withLibraryInformation?: boolean) => string;
@@ -0,0 +1 @@
1
+ export * from './dataEntryTyping';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { NestedData } from './dataEntry';
2
+ export type ArrayData = {
3
+ type: 'ARRAY';
4
+ minCount: number;
5
+ maxCount: number;
6
+ stateBits: number;
7
+ state: number;
8
+ descriptor: NestedData;
9
+ value: NestedData[];
10
+ };
@@ -1,5 +1,4 @@
1
- import { DataType } from '../enums/dataTypes';
2
1
  export type BooleanData = {
3
- type: DataType.BOOLEAN;
2
+ type: 'BOOLEAN';
4
3
  value: boolean;
5
4
  };
@@ -3,20 +3,78 @@ import { EnumData } from './enumData';
3
3
  import { FloatData } from './floatData';
4
4
  import { IntData } from './intData';
5
5
  import { VersionData } from './versionData';
6
+ import { EnumArrayData } from './enumArrayData.ts';
7
+ import { OptionalData } from './optionalData.ts';
8
+ import { EnumOptionsData } from './enumOptionsData.ts';
9
+ import { ArrayData } from './arrayData.ts';
6
10
  export type Prettify<T> = {
7
11
  [K in keyof T]: T[K];
8
12
  };
9
13
  type DataDescription = {
10
14
  name: string;
11
- internalName?: string;
12
- index: number;
15
+ internalName?: number[];
16
+ index?: number;
13
17
  };
18
+ /**
19
+ * Boolean object
20
+ *
21
+ * Boolean objects are a simple `true` or `false`, 1 or 0 - one bitwidth object.
22
+ */
14
23
  export type BooleanDataEntry = Prettify<BooleanData & DataDescription>;
15
- export type IntDataEntry = Prettify<IntData & DataDescription>;
24
+ /**
25
+ * Enum object
26
+ *
27
+ * An enum object is a continious range of integer values, starting at 0 upto its max.
28
+ * The maximum acceptable value for the max is `255` (8 bits)
29
+ */
16
30
  export type EnumDataEntry = Prettify<EnumData & DataDescription>;
31
+ /**
32
+ * Int object
33
+ *
34
+ * Int objects are a simple integer value, starting at its min upto its max.
35
+ * The maximum and minimum value can be any integar values represntabled as a double yet,
36
+ * the maximum acceptable delta between min and max is `4095` (12 bits).
37
+ */
38
+ export type IntDataEntry = Prettify<IntData & DataDescription>;
39
+ /**
40
+ * Float object
41
+ *
42
+ * Float objects are a fixed point extension of the int object, with a larger available precision range.
43
+ * Dispite a `min` and a `max` value, they also have a `precision` and a `significand` attribute.
44
+ * The precision defines where the point is located and can be an integer value between -3 and 3 (-3 meaning **divided** by 1e-3 -> multiplied by 1000, 3 meaning **divided** by 1e3 -> multiplied by 1e-3 -> multiplied by .001)
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
+ * Maximum value for the significand is `20` bits, which allows for a maximum of 1048576 possible values.
47
+ */
17
48
  export type FloatDataEntry = Prettify<FloatData & DataDescription>;
49
+ /**
50
+ * Version object
51
+ *
52
+ * Version objects are a special type of the enum object, which have a fixed amount of bits assigned to them (and therefore a fixed amount of optional values)
53
+ * They are only used as the beginning of a DataStateDefinition to be able to find out which version of the data is actually being used
54
+ *
55
+ * Acceptable bitwidths are: `4 | 6 | 8 | 10`, giving a total of respectively 16, 64, 256 and 1024 possible versions
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
+ */
18
58
  export type VersionDataEntry = Prettify<VersionData & DataDescription>;
19
- export type DataEntry = BooleanDataEntry | IntDataEntry | EnumDataEntry | FloatDataEntry | VersionDataEntry;
20
- export type ProtectedAttributeNames = Prettify<keyof BooleanDataEntry | keyof IntDataEntry | keyof EnumDataEntry | keyof FloatDataEntry | keyof VersionDataEntry>;
21
- export type DataEntryArray = DataEntry[];
59
+ /**
60
+ * Enum Array object
61
+ *
62
+ * enum arrays are as the name implies an array of enums.
63
+ * This object interprets the enums as being a number of a specific base and translates them to base 2.
64
+ * Besides the base, which is derived from the min and max (integer) values (its delta)
65
+ * There is also a given min and max count of values.
66
+ * The count itself is stored as the first bits, like for an Int object.
67
+ * The value itself is implied by the length of the value array.
68
+ *
69
+ * Note: the partical maximum benefit of using this versus using a `ArrayEntryDataType` with only enums is only about 22% for base_5
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>;
79
+ export declare const PROTECTED_ATTRIBUTE_NAMES: readonly ["type", "value", "name", "internalName", "index", "min", "max", "bits", "precision", "significand", "minCount", "maxCount", "state", "stateBits", "descriptor", "mapping"];
22
80
  export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Enum Array object
3
+ *
4
+ * enum arrays are as the name implies an array of enums.
5
+ * This object interprets the enums as being a number of a specific base and translates them to base 2.
6
+ * Besides the base, which is derived from the min and max (integer) values (its delta)
7
+ * There is also a given min and max count of values.
8
+ * The count itself is stored as the first bits, like for an Int object.
9
+ * The value itself is implied by the length of the value array.
10
+ *
11
+ * Note: the partical maximum benefit of using this versus using a `ArrayEntryDataType` with only enums is only about 22% for base_5
12
+ */
13
+ export type EnumArrayData = {
14
+ type: 'ENUM_ARRAY';
15
+ minCount: number;
16
+ maxCount: number;
17
+ value: number[];
18
+ max: number;
19
+ mapping: any[];
20
+ };
@@ -1,8 +1,14 @@
1
- import { DataType } from '../enums/dataTypes';
2
1
  export declare const EnumMaxBits = 8;
2
+ /**
3
+ * Enum object
4
+ *
5
+ * An enum object is a continious range of integer values, starting at 0 upto its max.
6
+ * The maximum acceptable value for the max is `255` (8 bits)
7
+ */
3
8
  export type EnumData = {
4
- type: DataType.ENUM;
9
+ type: 'ENUM';
5
10
  value: number;
6
11
  max: number;
7
12
  bits: number;
13
+ mapping: (string | number | object)[];
8
14
  };
@@ -0,0 +1,8 @@
1
+ import { NestedData } from './dataEntry';
2
+ export type EnumOptionsData = {
3
+ type: 'ENUM_OPTIONS';
4
+ stateBits: number;
5
+ state: number;
6
+ descriptor: NestedData[];
7
+ value: NestedData;
8
+ };
@@ -1,8 +1,16 @@
1
- import { DataType } from '../enums/dataTypes';
2
1
  export type PrecisionRangeType = -3 | -2 | -1 | 0 | 1 | 2 | 3;
3
2
  export declare const SignificandMaxBits = 20;
3
+ /**
4
+ * Float object
5
+ *
6
+ * Float objects are a fixed point extension of the int object, with a larger available precision range.
7
+ * Dispite a `min` and a `max` value, they also have a `precision` and a `significand` attribute.
8
+ * The precision defines where the point is located and can be an integer value between -3 and 3 (-3 meaning **divided** by 1e-3 -> multiplied by 1000, 3 meaning **divided** by 1e3 -> multiplied by 1e-3 -> multiplied by .001)
9
+ * 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.
10
+ * Maximum value for the significand is `20` bits, which allows for a maximum of 1048576 possible values.
11
+ */
4
12
  export type FloatData = {
5
- type: DataType.FLOAT;
13
+ type: 'FLOAT';
6
14
  value: number;
7
15
  min: number;
8
16
  max: number;
@@ -1,9 +1,11 @@
1
- export * from './arrayDefinitions';
2
- export * from './booleanData';
3
- export * from './dataEntry';
1
+ export * from './stateDataEntry';
2
+ export * from './enumOptionsData';
3
+ export * from './optionalData';
4
+ export * from './arrayData';
5
+ export * from './enumArrayData';
4
6
  export * from './enumData';
5
7
  export * from './floatData';
6
8
  export * from './intData';
7
- export * from './semanticMapping';
8
- export * from './stateValueModel';
9
9
  export * from './versionData';
10
+ export * from './booleanData';
11
+ export * from './dataEntry';
@@ -1,7 +1,13 @@
1
- import { DataType } from '../enums/dataTypes';
2
1
  export declare const IntegerMaxBits = 12;
2
+ /**
3
+ * Int object
4
+ *
5
+ * Int objects are a simple integer value, starting at its min upto its max.
6
+ * The maximum and minimum value can be any integar values represntabled as a double yet,
7
+ * the maximum acceptable delta between min and max is `4095` (12 bits).
8
+ */
3
9
  export type IntData = {
4
- type: DataType.INT;
10
+ type: 'INT';
5
11
  value: number;
6
12
  min: number;
7
13
  max: number;
@@ -0,0 +1,7 @@
1
+ import { NestedData } from './dataEntry';
2
+ export type OptionalData = {
3
+ type: 'OPTIONAL';
4
+ state: boolean;
5
+ descriptor: [NestedData, null] | [null, NestedData];
6
+ value: NestedData | null;
7
+ };
@@ -0,0 +1,16 @@
1
+ import { ComplexDataEntry, DataEntry, NestedData, VersionDataEntry } from './dataEntry';
2
+ export type StateDataEntry<T extends DataEntry | ComplexDataEntry> = T & {
3
+ bitstring: string;
4
+ updateValue: (newEntry: T) => void;
5
+ };
6
+ export type State = [StateDataEntry<VersionDataEntry>, ...StateDataEntry<DataEntry | ComplexDataEntry>[]];
7
+ export type StateDescriptor = [VersionDataEntry, ...NestedData];
8
+ export type StateDataObject = {
9
+ [key: string]: object | string | boolean | number | (string | number | object)[] | null | StateDataObject | StateDataObject[];
10
+ };
11
+ export type StateObject = {
12
+ state: State;
13
+ bitstring: string;
14
+ base64: string;
15
+ data: StateDataObject;
16
+ };
@@ -1,8 +1,7 @@
1
- import { DataType } from '../enums/dataTypes';
2
1
  export type VersionRangeType = 4 | 6 | 8 | 10;
3
2
  export declare const VersionRange: VersionRangeType[];
4
3
  export type VersionData = {
5
- type: DataType.VERSION;
4
+ type: 'VERSION';
6
5
  value: number;
7
6
  bits: VersionRangeType;
8
7
  };
@@ -0,0 +1,2 @@
1
+ import { ArrayDataEntry } from '@/types';
2
+ export declare const updateComplexValue: (original: ArrayDataEntry, update: ArrayDataEntry) => ArrayDataEntry;
@@ -0,0 +1,2 @@
1
+ import { EnumArrayDataEntry } from '@/types';
2
+ export declare const updateValue: (original: EnumArrayDataEntry, update: EnumArrayDataEntry) => EnumArrayDataEntry;
@@ -0,0 +1,2 @@
1
+ import { EnumOptionsDataEntry } from '@/types';
2
+ export declare const updateComplexValue: (original: EnumOptionsDataEntry, update: EnumOptionsDataEntry) => EnumOptionsDataEntry;
@@ -0,0 +1,2 @@
1
+ import { NestedData } from '@/types';
2
+ export declare const updateNestedData: (original: NestedData | undefined, descriptor: NestedData) => NestedData;
@@ -0,0 +1,2 @@
1
+ import { OptionalDataEntry } from '@/types';
2
+ export declare const updateComplexValue: (original: OptionalDataEntry, update: OptionalDataEntry) => OptionalDataEntry;
@@ -1,2 +1,15 @@
1
- import { DataEntry } from '../types/dataEntry';
1
+ import { DataEntry, ComplexDataEntry } from '../types/dataEntry';
2
+ /**
3
+ * Method to update the value of a data entry
4
+ * @param original - the original data entry
5
+ * @param update - the update data entry
6
+ * @returns the updated data entry
7
+ */
2
8
  export declare const updateValue: (original: DataEntry, update: DataEntry) => DataEntry;
9
+ /**
10
+ * Method to update the value of a data entry
11
+ * @param original - the original data entry
12
+ * @param update - the update data entry
13
+ * @returns the updated data entry
14
+ */
15
+ export declare const updateComplexValue: (original: ComplexDataEntry, update: ComplexDataEntry) => ComplexDataEntry;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "dist/*"
7
7
  ],
8
8
  "type": "module",
9
- "version": "0.1.14",
9
+ "version": "0.2.0",
10
10
  "author": "Jonas Ward",
11
11
  "description": "Library for creating web safe base64 objects with custom bith widths and dynamic values.",
12
12
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  "devDependencies": {
18
18
  "bun-types": "latest",
19
19
  "rimraf": "^6.0.1",
20
- "typescript": "^5.0.0"
20
+ "typescript": "^5.0.0",
21
+ "@types/bun": "latest"
21
22
  }
22
23
  }
@@ -1,4 +0,0 @@
1
- export * from './stateDataModel';
2
- export * from './userMethods';
3
- export * from './userMethods';
4
- export * from './stateValueHelperMethods';
@@ -1,19 +0,0 @@
1
- import { DataEntry, DataEntryArray, NestedContentType, SingleLevelContentType, DoubleLevelContentType, ArrayEntryDataType, EnumEntryDataType, OptionalEntryDataType, DataEntryParsingReturnType, DerivativeStateDataType, InternalStateDataGenerationMethod, StateDataGenerationMethod, StateDataType } from '../types';
2
- /**
3
- * Helper method for finding an existing data entry in case there was a previous object
4
- * @param dataEntry - new DataEntry
5
- * @param dataEntryArray - existing DataEntryArray
6
- */
7
- export declare const findExistingDataEntry: (dataEntry: DataEntry, dataEntryArray: DataEntryArray) => DataEntry | undefined;
8
- export declare const readDataEntry: (dataEntry: DataEntry, bitString: string) => DataEntryParsingReturnType;
9
- export declare const updateDataEntry: (dataEntry: DataEntry, existingData: DataEntryArray) => DataEntryParsingReturnType;
10
- export declare const internalGetDataEntry: (dataEntry: DataEntry, prefix: string, additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DataEntry]];
11
- export declare const getStateFromOptionalEntryDataType: (oedt: OptionalEntryDataType, prefix: string, attributeName: string) => InternalStateDataGenerationMethod;
12
- export declare const getStateFromEnumEntryDataType: (eedt: EnumEntryDataType, prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, StateDataType]];
13
- export declare const getStateFromArrayEntryDataType: (aedt: ArrayEntryDataType, prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DerivativeStateDataType]];
14
- export declare const getStateDataFromDoubleLevelContentType: (dct: DoubleLevelContentType, prefix: string, attributeName: string) => InternalStateDataGenerationMethod;
15
- export declare const getStateDateFromSingleLevelContentTypeArray: (slcta: SingleLevelContentType[], prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, StateDataType]];
16
- export declare const getStateDataFromNestedContentType: (nct: NestedContentType, prefix: string, attributeName: string) => InternalStateDataGenerationMethod;
17
- export declare const getStateDataFromSingleLevelContentType: (slct: SingleLevelContentType, prefix: string) => InternalStateDataGenerationMethod;
18
- export declare const getGenerationMethodForSingleLevelContentTypeArray: (slct: SingleLevelContentType[]) => StateDataGenerationMethod;
19
- export declare const testOnlyResetCurrentDataEntryIndex: () => number;
@@ -1,13 +0,0 @@
1
- import { DataEntryArray, NestedContentType, SingleLevelContentType } from '../types';
2
- import { StateDataType, StateValueType } from '../types/stateValueModel';
3
- export declare const getStateValue: (stateValue: StateDataType) => StateValueType;
4
- export declare const getDataEntryArray: (stateValue: StateDataType) => DataEntryArray;
5
- export declare const getBase64String: (stateValue: StateDataType) => string;
6
- export declare const isSingleLevelContentType: (data: NestedContentType) => boolean;
7
- export declare const isDoubleLevelContentType: (data: NestedContentType) => boolean;
8
- export declare const singleLevelContentTypeIsDataEntry: (data: SingleLevelContentType) => boolean;
9
- export declare const singleLevelContentTypeIsNestedContentDataType: (data: SingleLevelContentType) => boolean;
10
- export declare const doubleLevelContentTypeIsEnumEntryDataType: (data: NestedContentType) => boolean;
11
- export declare const doubleLevelContentTypeIsOptionalEntryDataType: (data: NestedContentType) => boolean;
12
- export declare const doubleLevelContentTypeIsArrayDefinitionType: (data: NestedContentType) => boolean;
13
- export declare const isDataEntry: (v: any) => boolean;
@@ -1,12 +0,0 @@
1
- import { EnumSemantics, VersionHandler, VersionContentDefinition } from '../types';
2
- /**
3
- * Method to create version definition objects
4
- * @param {VersionArrayDefinitionType[]} versionContent - version definition array
5
- * @param {number} maximumExpectedVersions - maximum expected versions to define
6
- * @param {number} defaultVersion - number - optional, default it is the first,
7
- * @param {EnumSemantics[] | EnumSemantics} enumSemanticsMapping - optional - UI semantics mapping for enums. If not given, values will be numbers
8
- * @param {undefined | Record<string, string> | Record<string, string>[]} attributeSemanticsMapping - optional - UI semantics mapping, if nothing given no semantics will be mapped
9
- * @param {number[]} exposedVersions?: number[] - optional - UI semantics, masks which objects to show and hide
10
- * @returns ParsersForVersionObject
11
- */
12
- export declare const createParserObject: (versionContent: VersionContentDefinition, maximumExpectedVersions: number, defaultVersion?: number, enumSemanticsMapping?: EnumSemantics | EnumSemantics[], attributeSemanticsMapping?: Record<string, string> | Record<string, string>[], exposedVersions?: number[]) => VersionHandler;
@@ -1,10 +0,0 @@
1
- import { DataEntry } from './dataEntry';
2
- export type SingleLevelContentType = DataEntry | NestedContentDataType;
3
- export type NestedContentDataType = [string, NestedContentType];
4
- export type NestedContentType = SingleLevelContentType[] | DoubleLevelContentType;
5
- export type DoubleLevelContentType = OptionalEntryDataType | EnumEntryDataType | ArrayEntryDataType;
6
- export type NonEmptyValidEntryArrayType = [SingleLevelContentType, ...SingleLevelContentType[]];
7
- export type OptionalEntryDataType = [boolean, NonEmptyValidEntryArrayType, []] | [boolean, [], NonEmptyValidEntryArrayType];
8
- export type EnumEntryDataType = [number, NonEmptyValidEntryArrayType, NonEmptyValidEntryArrayType, ...SingleLevelContentType[][]];
9
- export type ArrayEntryDataType = [[number, number], NonEmptyValidEntryArrayType];
10
- export declare const PREFIX_SEPERATOR_DELIMETER = "_";
@@ -1,6 +0,0 @@
1
- export type EnumSemantics = {
2
- [dataEntryName: string]: {
3
- value: number;
4
- label: string;
5
- }[];
6
- };
@@ -1,33 +0,0 @@
1
- import { SingleLevelContentType } from './arrayDefinitions';
2
- import { DataEntry, DataEntryArray } from './dataEntry';
3
- import { EnumSemantics } from './semanticMapping';
4
- export type StateDataType = {
5
- [attribute: string]: DataEntry | StateDataType | DerivativeStateDataType;
6
- };
7
- export type DerivativeStateDataType = {
8
- s: DataEntry;
9
- v: StateDataType | StateDataType[];
10
- };
11
- export type StateValueType = {
12
- [attribute: string]: boolean | number | string | StateValueType | DerivativeStateValueType;
13
- };
14
- export type DerivativeStateValueType = {
15
- s: boolean | number | string;
16
- v: StateValueType | StateValueType[];
17
- };
18
- export type StateDataGenerationMethod = (additionalData?: DataEntryArray | string) => StateDataType;
19
- export type DataEntryParsingReturnType = [DataEntryArray | string | undefined, [string, DataEntry]];
20
- export type InternalStateDataGenerationMethod = (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DataEntry | StateDataType | DerivativeStateDataType]];
21
- export type ExposedParserStateDataMethod = (additionalData?: StateDataType | DataEntryArray | string) => StateDataType;
22
- export type UpdateStateDataMethod = (state: StateDataType, entryToUpdate: DataEntry | DataEntry[]) => StateDataType;
23
- export type StringifyStateDataMethod = (data: StateDataType | DataEntryArray) => string;
24
- export type VersionContentDefinition = SingleLevelContentType[][];
25
- export type VersionHandler = {
26
- versionBitCount: number;
27
- exposedVersions?: number[];
28
- enumSemanticsMapping?: EnumSemantics | EnumSemantics[];
29
- attributeSemanticsMapping?: Record<string, string> | Record<string, string>[];
30
- parser: ExposedParserStateDataMethod;
31
- updater: UpdateStateDataMethod;
32
- stringify: StringifyStateDataMethod;
33
- };