url-safe-bitpacking 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -11,7 +11,9 @@ Package for creating definitions of parametric models that can be stored as comp
11
11
  | updating model entries | ✓ | ✓ | |
12
12
  | re-using data from old model on change in definition | ½ | ¼ | |
13
13
  | flattening and reading of the objects | ✓ | ✓ | ¿ |
14
- | arrays (both bit-level as arrays of objects) | ½ | ¼ | |
14
+ | arrays (both bit-level as arrays of objects) | ½ | ½ | |
15
+ | utility to create StateValueType | | | |
16
+ | ability to migrate one version to another | | | |
15
17
 
16
18
  ## concept
17
19
 
@@ -53,6 +55,14 @@ Floating points work very much like the integer type, with the main difference t
53
55
  DataEntryFactory.createFloat(20, 10, 200, -1, 'shapePreProcessingWarptotal');
54
56
  ```
55
57
 
58
+ ### enum array
59
+
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
+
62
+ ```typescript
63
+ DataEntryFactory.createEnumArray([0, 1, 2], 0, 10, 3, 5, 'enumArrayA')
64
+ ```
65
+
56
66
  ### version
57
67
 
58
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.
@@ -3,6 +3,7 @@ export declare enum DataType {
3
3
  BOOLEAN = 1,
4
4
  ENUM = 2,
5
5
  INT = 3,
6
- FLOAT = 4
6
+ FLOAT = 4,
7
+ ENUM_ARRAY = 5
7
8
  }
8
9
  export declare const getDataTypeName: (type: DataType) => string;
@@ -0,0 +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;
@@ -3,10 +3,15 @@ import { create as createInt } from './intFactory';
3
3
  import { create as createBoolean } from './booleanFactory';
4
4
  import { create as createVersion } from './versionFactory';
5
5
  import { create as createEnum } from './enumFactory';
6
+ import { create as createEnumArray } from './enumArrayFactory';
7
+ /**
8
+ * Record containing all the factory methods for the different data entry objects
9
+ */
6
10
  export declare const DataEntryFactory: {
7
11
  createFloat: typeof createFloat;
8
12
  createInt: typeof createInt;
9
13
  createEnum: typeof createEnum;
10
14
  createBoolean: typeof createBoolean;
11
15
  createVersion: typeof createVersion;
16
+ createEnumArray: typeof createEnumArray;
12
17
  };
@@ -1,3 +1,12 @@
1
1
  import { FloatDataEntry } from '../types';
2
2
  import { PrecisionRangeType } from '../types/floatData';
3
+ /**
4
+ * Method to create a float data entry
5
+ * @param value - `number` default value, should be between `min` and `max`
6
+ * @param min - `number` (default: 0), should be smaller than `max`
7
+ * @param max - `number` (default: 1), should be larger than `min`
8
+ * @param precision - `PrecisionRangeType` (default: 2 -> .01),
9
+ * @param name - `string`
10
+ * @param index - `number`
11
+ */
3
12
  export declare const create: (value: number, min?: number, max?: number, precision?: PrecisionRangeType, name?: string, index?: number) => FloatDataEntry;
@@ -1,5 +1,24 @@
1
1
  import { VersionRangeType } from '../types';
2
+ /**
3
+ * Helper method to get the minimum bits required to store a given integer value
4
+ * @param number - `number` value to get the minimum bits for
5
+ * @param maxBits - `number` maximum bits allowed
6
+ */
2
7
  export declare const getBitsForIntegerNumber: (number: number, maxBits: number) => number;
8
+ /**
9
+ * Helper method to get the minimum bits required to store a given integer value
10
+ * @param v - `number` value to get the minimum bits for
11
+ */
3
12
  export declare const getMinimumBitsForInteger: (v: number) => number;
13
+ /**
14
+ * Helper method to get the version value range value for a given number
15
+ * @param v - `number` value to get the version value range value for
16
+ * @returns `VersionRangeType` the version value range value
17
+ */
4
18
  export declare const getVersionValueRangeValueForNumber: (v: number) => VersionRangeType;
19
+ /**
20
+ * Helper method to get the maximum integer value for a given bit count
21
+ * @param bitCount - `number` bit width to get the maximum integer value for
22
+ * @returns `number` the maximum integer value
23
+ */
5
24
  export declare const getMaxIntegerValueForGivenBitWidth: (bitCount: number) => number;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { DataType } from './enums';
2
2
  export { DataEntryFactory } from './factory';
3
- export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, OptionalEntryDataType, EnumEntryDataType, PrecisionRangeType, SignificandMaxBits, FloatData, IntegerMaxBits, IntData, VersionRangeType, VersionData, BooleanData, DataEntry, DataEntryArray, StateDataType, StateValueType, EnumSemantics, } from './types';
4
- export { createParserObject, getStateValue, getBase64String, getDataEntryArray } from './objectmap';
5
- export { parseBase64ToBits } from './parsers';
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';
6
6
  export { interpolateEntryAt, getRelativeValue } from './utils';
package/dist/index.js CHANGED
@@ -1,25 +1,33 @@
1
1
  // src/enums/dataTypes.ts
2
2
  var DataType;
3
- (function(DataType2) {
3
+ ((DataType2) => {
4
4
  DataType2[DataType2["VERSION"] = 0] = "VERSION";
5
5
  DataType2[DataType2["BOOLEAN"] = 1] = "BOOLEAN";
6
6
  DataType2[DataType2["ENUM"] = 2] = "ENUM";
7
7
  DataType2[DataType2["INT"] = 3] = "INT";
8
8
  DataType2[DataType2["FLOAT"] = 4] = "FLOAT";
9
- })(DataType || (DataType = {}));
10
- // src/enums/objectGenerationTypes.ts
11
- var ObjectGenerationOutputStatus;
12
- (function(ObjectGenerationOutputStatus2) {
13
- ObjectGenerationOutputStatus2[ObjectGenerationOutputStatus2["DEFAULT"] = 0] = "DEFAULT";
14
- ObjectGenerationOutputStatus2[ObjectGenerationOutputStatus2["FROM_TYPE"] = 1] = "FROM_TYPE";
15
- ObjectGenerationOutputStatus2[ObjectGenerationOutputStatus2["PARSED"] = 2] = "PARSED";
16
- ObjectGenerationOutputStatus2[ObjectGenerationOutputStatus2["ERROR_PARSING"] = 3] = "ERROR_PARSING";
17
- })(ObjectGenerationOutputStatus || (ObjectGenerationOutputStatus = {}));
9
+ DataType2[DataType2["ENUM_ARRAY"] = 5] = "ENUM_ARRAY";
10
+ })(DataType ||= {});
18
11
  // src/types/floatData.ts
19
12
  var SignificandMaxBits = 20;
20
13
 
21
14
  // src/types/arrayDefinitions.ts
22
15
  var PREFIX_SEPERATOR_DELIMETER = "_";
16
+ // src/types/dataEntry.ts
17
+ var PROTECTED_ATTRIBUTE_NAMES = [
18
+ "type",
19
+ "value",
20
+ "name",
21
+ "internalName",
22
+ "index",
23
+ "min",
24
+ "max",
25
+ "bits",
26
+ "precision",
27
+ "significand",
28
+ "minCount",
29
+ "maxCount"
30
+ ];
23
31
  // src/types/enumData.ts
24
32
  var EnumMaxBits = 8;
25
33
  // src/types/intData.ts
@@ -51,7 +59,7 @@ var create = (value, min = 0, max = 1, precision = 2, name = "", index = -1) =>
51
59
  const significand = Math.max(1, getBitsForIntegerNumber(delta, SignificandMaxBits));
52
60
  return {
53
61
  value,
54
- type: DataType.FLOAT,
62
+ type: 4 /* FLOAT */,
55
63
  min: roundedMin / precisionMultiplier,
56
64
  max: roundedMax / precisionMultiplier,
57
65
  precision,
@@ -70,16 +78,16 @@ var create2 = (value, min = 0, max = 10, name = "", index = -1) => {
70
78
  if (Math.abs(max - min) > 2 ** IntegerMaxBits - 1)
71
79
  throw new Error("max - min must be less than 1024");
72
80
  const bits = getBitsForIntegerNumber(max - min + 1, IntegerMaxBits);
73
- return { value, type: DataType.INT, min, max, bits, name, index };
81
+ return { value, type: 3 /* INT */, min, max, bits, name, index };
74
82
  };
75
83
 
76
84
  // src/factory/booleanFactory.ts
77
- var create3 = (value, name = "", index = -1) => ({ value, type: DataType.BOOLEAN, name, index });
85
+ var create3 = (value, name = "", index = -1) => ({ value, type: 1 /* BOOLEAN */, name, index });
78
86
 
79
87
  // src/factory/versionFactory.ts
80
88
  var create4 = (value, bits = 8, name = "", index = -1) => ({
81
89
  value,
82
- type: DataType.VERSION,
90
+ type: 0 /* VERSION */,
83
91
  bits,
84
92
  name,
85
93
  index
@@ -94,7 +102,38 @@ var create5 = (value, max = 10, name = "", index = -1) => {
94
102
  if (max > 2 ** EnumMaxBits - 1)
95
103
  throw new Error("max - min must be less than 256");
96
104
  const bits = getBitsForIntegerNumber(max + 1, EnumMaxBits);
97
- return { value, type: DataType.ENUM, max, bits, name, index };
105
+ return { value, type: 2 /* ENUM */, max, bits, name, index };
106
+ };
107
+
108
+ // src/factory/enumArrayFactory.ts
109
+ var create6 = (value, min = 0, max = 10, minCount = 1, maxCount = 10, name = "", index = -1) => {
110
+ if (!Number.isInteger(min) || !Number.isInteger(max))
111
+ throw new Error("min and max must be integers");
112
+ if (!Number.isInteger(minCount) || !Number.isInteger(maxCount))
113
+ throw new Error("minCount and maxCount must be integers");
114
+ min = Math.min(min, max);
115
+ max = Math.max(min, max);
116
+ if (max - min < 1)
117
+ throw new Error("range length must be at least one");
118
+ if (Math.abs(max - min) > 2 ** IntegerMaxBits - 1)
119
+ throw new Error("range length must be less than 1024");
120
+ minCount = Math.min(minCount, maxCount);
121
+ maxCount = Math.max(minCount, maxCount);
122
+ if (minCount < 1)
123
+ throw new Error("minCount must be at least one");
124
+ if (maxCount - minCount < 0)
125
+ throw new Error(`count range length must be positive, given count range length is ${Math.abs(maxCount - minCount)}`);
126
+ if (Math.abs(maxCount - minCount) > 2 ** IntegerMaxBits - 1)
127
+ throw new Error(`count range length must be less than 1024, given count range length is ${Math.abs(maxCount - minCount)}`);
128
+ value.forEach((v, i) => {
129
+ if (!Number.isInteger(v))
130
+ throw new Error(`all entries must be integers, index ${i} (${v}) is not`);
131
+ if (v < min || v > max)
132
+ throw new Error(`all entries must be within the range ${min} - ${max}, index ${i} (${v}) is not`);
133
+ });
134
+ if (value.length < minCount || value.length > maxCount)
135
+ throw new Error(`value length must be between minCount and maxCount, ${value.length} is not between ${minCount} and ${maxCount}`);
136
+ return { type: 5 /* ENUM_ARRAY */, minCount, maxCount, value, min, max, name, index };
98
137
  };
99
138
 
100
139
  // src/factory/factory.ts
@@ -103,10 +142,11 @@ var DataEntryFactory = {
103
142
  createInt: create2,
104
143
  createEnum: create5,
105
144
  createBoolean: create3,
106
- createVersion: create4
145
+ createVersion: create4,
146
+ createEnumArray: create6
107
147
  };
108
148
  // src/parsers/intParser.ts
109
- var getBitsCount = (intData3) => intData3.bits;
149
+ var getBitsCount = (intData2) => intData2.bits;
110
150
  var rawValueParser = (stateString, bitCount) => {
111
151
  if (stateString.length < bitCount)
112
152
  throw new Error(`To few bits for this int bit string (${stateString.length} instead of ${bitCount})`);
@@ -117,9 +157,9 @@ var rawValueParser = (stateString, bitCount) => {
117
157
  throw new Error("Invalid int state string");
118
158
  return parsed;
119
159
  };
120
- var rawParser = (stateString, intData3) => {
121
- const v = rawValueParser(stateString, intData3.bits) + intData3.min;
122
- if (v > intData3.max)
160
+ var rawParser = (stateString, intData2) => {
161
+ const v = rawValueParser(stateString, intData2.bits) + intData2.min;
162
+ if (v > intData2.max)
123
163
  throw new Error("Value exceeds max");
124
164
  return v;
125
165
  };
@@ -128,16 +168,16 @@ var rawIntStringifier = (value, bitCount) => {
128
168
  throw new Error("Value is not an integer");
129
169
  return value.toString(2).padStart(bitCount, "0");
130
170
  };
131
- var rawStringifier = (value, intData3) => {
132
- if (value < intData3.min)
171
+ var rawStringifier = (value, intData2) => {
172
+ if (value < intData2.min)
133
173
  throw new Error("Value is below min");
134
- if (value > intData3.max)
174
+ if (value > intData2.max)
135
175
  throw new Error("Value exceeds max");
136
- return rawIntStringifier(value - intData3.min, intData3.bits);
176
+ return rawIntStringifier(value - intData2.min, intData2.bits);
137
177
  };
138
178
 
139
179
  // src/parsers/floatParser.ts
140
- var getBitsCount2 = (floatData3) => floatData3.significand;
180
+ var getBitsCount2 = (floatData2) => floatData2.significand;
141
181
  var rawValueParser2 = (stateString, significandBits, precision) => {
142
182
  if (stateString.length < significandBits)
143
183
  throw new Error(`To few bits for this float bit string (${stateString.length} instead of ${significandBits})`);
@@ -146,13 +186,13 @@ var rawValueParser2 = (stateString, significandBits, precision) => {
146
186
  const significand = rawValueParser(stateString, significandBits);
147
187
  return significand * 10 ** -precision;
148
188
  };
149
- var rawParser2 = (stateString, floatData3) => {
150
- const v = floatData3.min + rawValueParser2(stateString, floatData3.significand, floatData3.precision);
151
- if (v > floatData3.max)
189
+ var rawParser2 = (stateString, floatData2) => {
190
+ const v = floatData2.min + rawValueParser2(stateString, floatData2.significand, floatData2.precision);
191
+ if (v > floatData2.max)
152
192
  throw new Error("Float value exceeds max");
153
193
  return v;
154
194
  };
155
- var rawStringifier2 = (value, floatData3) => rawIntStringifier(Math.round((value - floatData3.min) * 10 ** floatData3.precision), floatData3.significand);
195
+ var rawStringifier2 = (value, floatData2) => rawIntStringifier(Math.round((value - floatData2.min) * 10 ** floatData2.precision), floatData2.significand);
156
196
 
157
197
  // src/parsers/enumParser.ts
158
198
  var getBitsCount3 = (versionData2) => versionData2.bits;
@@ -184,66 +224,131 @@ var rawValueParser3 = (stateString) => {
184
224
  var rawParser5 = (stateString) => rawValueParser3(stateString);
185
225
  var rawStringifier5 = (value) => value ? "1" : "0";
186
226
 
227
+ // src/parsers/enumArrayParser.ts
228
+ var getCountBitsCount = (enumArrayData) => getBitsForIntegerNumber(enumArrayData.maxCount - enumArrayData.minCount + 1, IntegerMaxBits);
229
+ var getNumberBitsCountForBase = (count, base) => getBitsForEnumArrayCountOfBase(count, base);
230
+ var getEnumArrayBase = (enumArrayData) => enumArrayData.max - enumArrayData.min + 1;
231
+ var getCount = (enumArrayData, bitString) => {
232
+ const countBits = getCountBitsCount(enumArrayData);
233
+ if (countBits === 0)
234
+ return enumArrayData.minCount;
235
+ return rawValueParser(bitString.slice(0, countBits), countBits) + enumArrayData.minCount;
236
+ };
237
+ var getBitsCount6 = (enumArrayData, bitString) => {
238
+ const countBits = getCountBitsCount(enumArrayData);
239
+ const count = getCount(enumArrayData, bitString);
240
+ const valuesBitCount = getNumberBitsCountForBase(count, getEnumArrayBase(enumArrayData));
241
+ return countBits + valuesBitCount;
242
+ };
243
+ var rawParser6 = (bitString, enumArrayData) => {
244
+ const countBits = getCountBitsCount(enumArrayData);
245
+ const count = getCount(enumArrayData, bitString);
246
+ const base = getEnumArrayBase(enumArrayData);
247
+ const valuesBitCount = getNumberBitsCountForBase(count, base);
248
+ const value = convertBitStringToArbitraryBase(bitString.slice(countBits, countBits + valuesBitCount), base, count);
249
+ return value.map((v) => v + enumArrayData.min);
250
+ };
251
+ var rawStringifier6 = (value, enumArrayData) => {
252
+ const countBits = getCountBitsCount(enumArrayData);
253
+ const count = value.length;
254
+ const base = getEnumArrayBase(enumArrayData);
255
+ const countBitstring = countBits ? rawIntStringifier(count - enumArrayData.minCount, countBits) : "";
256
+ const enumArrayBitstring = convertArbitraryBaseToBitString(value.map((v) => v - enumArrayData.min), base);
257
+ return countBitstring + enumArrayBitstring;
258
+ };
259
+
187
260
  // src/parsers/parsers.ts
188
261
  var valueBitsParser = (bitString, mapData) => {
189
262
  switch (mapData.type) {
190
- case DataType.BOOLEAN:
263
+ case 1 /* BOOLEAN */:
191
264
  return rawParser5(bitString);
192
- case DataType.INT:
265
+ case 3 /* INT */:
193
266
  return rawParser(bitString, mapData);
194
- case DataType.ENUM:
267
+ case 2 /* ENUM */:
195
268
  return rawParser3(bitString, mapData);
196
- case DataType.FLOAT:
269
+ case 4 /* FLOAT */:
197
270
  return rawParser2(bitString, mapData);
198
- case DataType.VERSION:
271
+ case 0 /* VERSION */:
199
272
  return rawParser4(bitString, mapData);
273
+ case 5 /* ENUM_ARRAY */:
274
+ return rawParser6(bitString, mapData);
200
275
  }
201
276
  };
202
277
  var dataBitsParser = (rawString, mapData) => {
203
278
  switch (mapData.type) {
204
- case DataType.BOOLEAN:
279
+ case 1 /* BOOLEAN */:
205
280
  return { ...mapData, value: valueBitsParser(rawString, mapData) };
206
- case DataType.ENUM:
207
- case DataType.INT:
208
- case DataType.FLOAT:
209
- case DataType.VERSION:
281
+ case 2 /* ENUM */:
282
+ case 3 /* INT */:
283
+ case 4 /* FLOAT */:
284
+ case 0 /* VERSION */:
285
+ return { ...mapData, value: valueBitsParser(rawString, mapData) };
286
+ case 5 /* ENUM_ARRAY */:
210
287
  return { ...mapData, value: valueBitsParser(rawString, mapData) };
211
288
  }
212
289
  };
213
- var getBitsCount6 = (mapData) => {
290
+ var getBitsCount7 = (mapData, bitString) => {
214
291
  switch (mapData.type) {
215
- case DataType.BOOLEAN:
292
+ case 1 /* BOOLEAN */:
216
293
  return getBitsCount5();
217
- case DataType.INT:
294
+ case 3 /* INT */:
218
295
  return getBitsCount(mapData);
219
- case DataType.FLOAT:
296
+ case 4 /* FLOAT */:
220
297
  return getBitsCount2(mapData);
221
- case DataType.VERSION:
298
+ case 0 /* VERSION */:
222
299
  return getBitsCount4(mapData);
223
- case DataType.ENUM:
300
+ case 2 /* ENUM */:
224
301
  return getBitsCount3(mapData);
302
+ case 5 /* ENUM_ARRAY */:
303
+ return getBitsCount6(mapData, bitString);
225
304
  }
226
305
  };
227
306
  var dataEntryBitstringParser = (bitstring, dataEntry2) => [
228
- dataBitsParser(bitstring.slice(0, getBitsCount6(dataEntry2)), dataEntry2),
229
- bitstring.slice(getBitsCount6(dataEntry2))
307
+ dataBitsParser(bitstring.slice(0, getBitsCount7(dataEntry2, bitstring)), dataEntry2),
308
+ bitstring.slice(getBitsCount7(dataEntry2, bitstring))
230
309
  ];
231
310
  var dataBitsStringifier = (data) => {
232
311
  switch (data.type) {
233
- case DataType.BOOLEAN:
312
+ case 1 /* BOOLEAN */:
234
313
  return rawStringifier5(data.value);
235
- case DataType.INT:
314
+ case 3 /* INT */:
236
315
  return rawStringifier(data.value, data);
237
- case DataType.FLOAT:
316
+ case 4 /* FLOAT */:
238
317
  return rawStringifier2(data.value, data);
239
- case DataType.VERSION:
318
+ case 0 /* VERSION */:
240
319
  return rawStringifier4(data.value, data);
241
- case DataType.ENUM:
320
+ case 2 /* ENUM */:
242
321
  return rawStringifier3(data.value, data);
322
+ case 5 /* ENUM_ARRAY */:
323
+ return rawStringifier6(data.value, data);
243
324
  }
244
325
  };
245
326
  var dataEntryCorrecting = (dataEntry2) => dataBitsParser(dataBitsStringifier(dataEntry2), dataEntry2);
246
327
  var base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
328
+ var getBitsForEnumArrayCountOfBase = (count, base) => Math.ceil(Math.log2(base) * count);
329
+ var convertArbitraryBaseToBitString = (input, fromBase) => {
330
+ const expectedOutputLength = getBitsForEnumArrayCountOfBase(input.length, fromBase);
331
+ const fromBaseBigInt = BigInt(fromBase);
332
+ let decimalValue = BigInt(0);
333
+ for (let i = input.length - 1;i >= 0; i--)
334
+ decimalValue = decimalValue * fromBaseBigInt + BigInt(input[i]);
335
+ const s = decimalValue.toString(2).padStart(expectedOutputLength, "0");
336
+ return s;
337
+ };
338
+ var convertBitStringToArbitraryBase = (input, toBase, expectedOutputLength) => {
339
+ let decimalValue = BigInt(`0b${input}`);
340
+ const toBaseBigInt = BigInt(toBase);
341
+ const result = [];
342
+ while (decimalValue > 0) {
343
+ const remainder = decimalValue % toBaseBigInt;
344
+ result.push(Number(remainder));
345
+ decimalValue = decimalValue / toBaseBigInt;
346
+ }
347
+ if (expectedOutputLength !== undefined && result.length !== expectedOutputLength)
348
+ for (let i = result.length;i < expectedOutputLength; i++)
349
+ result.push(0);
350
+ return result;
351
+ };
247
352
  var parseBitsToBase64 = (bits) => {
248
353
  const chunks = bits.match(/.{1,6}/g);
249
354
  const numbers = chunks?.map((c) => Number.parseInt(c.padEnd(6, "0"), 2)) ?? [];
@@ -299,21 +404,32 @@ var updateValue5 = (original, update) => ({
299
404
  value: update.value
300
405
  });
301
406
 
302
- // src/update/updateValues.ts
407
+ // src/update/enumArrayUpdate.ts
303
408
  var updateValue6 = (original, update) => {
409
+ const value = update.value.map((v) => Math.max(Math.min(original.max, v), original.min));
410
+ return {
411
+ ...original,
412
+ value
413
+ };
414
+ };
415
+
416
+ // src/update/updateValues.ts
417
+ var updateValue7 = (original, update) => {
304
418
  if (original.type !== update.type)
305
419
  throw new Error("Types do not match");
306
420
  switch (original.type) {
307
- case DataType.FLOAT:
421
+ case 4 /* FLOAT */:
308
422
  return updateValue(original, update);
309
- case DataType.INT:
423
+ case 3 /* INT */:
310
424
  return updateValue2(original, update);
311
- case DataType.ENUM:
425
+ case 2 /* ENUM */:
312
426
  return updateValue3(original, update);
313
- case DataType.BOOLEAN:
427
+ case 1 /* BOOLEAN */:
314
428
  return updateValue5(original, update);
315
- case DataType.VERSION:
429
+ case 0 /* VERSION */:
316
430
  return updateValue4(original, update);
431
+ case 5 /* ENUM_ARRAY */:
432
+ return updateValue6(original, update);
317
433
  }
318
434
  };
319
435
  // src/objectmap/stateValueHelperMethods.ts
@@ -350,6 +466,7 @@ var singleLevelContentTypeIsNestedContentDataType = (data) => Array.isArray(data
350
466
  var doubleLevelContentTypeIsEnumEntryDataType = (data) => isDoubleLevelContentType(data) && typeof data[0] === "number";
351
467
  var doubleLevelContentTypeIsOptionalEntryDataType = (data) => isDoubleLevelContentType(data) && typeof data[0] === "boolean";
352
468
  var doubleLevelContentTypeIsArrayDefinitionType = (data) => Array.isArray(data[0]) && data[0].length === 2 && typeof data[0][0] === "number" && typeof data[0][1] === "number";
469
+ var isDataEntry = (v) => typeof v === "object" && !Array.isArray(v) && v?.type !== undefined && v?.value !== undefined;
353
470
 
354
471
  // src/objectmap/stateDataModel.ts
355
472
  var currentDataEntryIndex = 0;
@@ -362,7 +479,13 @@ var readDataEntry = (dataEntry2, bitString) => {
362
479
  var updateDataEntry = (dataEntry2, existingData) => {
363
480
  const existingDataEntry = findExistingDataEntry(dataEntry2, existingData);
364
481
  currentDataEntryIndex++;
365
- return [existingData, [dataEntry2.name, { ...existingDataEntry ? updateValue6(dataEntry2, existingDataEntry) : dataEntry2, index: currentDataEntryIndex }]];
482
+ return [
483
+ existingData,
484
+ [
485
+ dataEntry2.name,
486
+ { ...existingDataEntry ? updateValue7(dataEntry2, existingDataEntry) : dataEntry2, index: currentDataEntryIndex }
487
+ ]
488
+ ];
366
489
  };
367
490
  var internalGetDataEntry = (dataEntry2, prefix, additionalData) => {
368
491
  const internalName = `${prefix}${PREFIX_SEPERATOR_DELIMETER}${dataEntry2.name}`;
@@ -394,9 +517,9 @@ var getStateFromEnumEntryDataType = (eedt, prefix, attributeName) => (additional
394
517
  if (Math.round(eedt[0]) !== eedt[0])
395
518
  `given default (${eedt[0]}) value isn't an integer, rounding it`;
396
519
  if (eedt.length - 2 < Math.round(eedt[0]))
397
- console.log(`given default value (${eedt[0]}) was larger than the amount of options available, using the largest value (${eedt.length - 2}) instead`);
520
+ throw new Error(`given default value (${eedt[0]}) was larger than the amount of options available, using the largest value (${eedt.length - 2}) instead`);
398
521
  if (eedt[0] < 0)
399
- console.log(`given default value (${eedt[0]}) was negative, using first index (0) instead`);
522
+ throw new Error(`given default value (${eedt[0]}) was negative, using first index (0) instead`);
400
523
  const [updatedLocalAdditionalData, [__, s]] = internalGetDataEntry(DataEntryFactory.createEnum(Math.max(Math.min(eedt.length - 2, Math.round(eedt[0])), 0), eedt.length - 1, attributeName), prefix, additionalData);
401
524
  const [nestedAdditionalData, [_, v]] = getStateDateFromSingleLevelContentTypeArray(eedt[1 + s.value], s.internalName, attributeName)(updatedLocalAdditionalData);
402
525
  return [
@@ -459,7 +582,7 @@ var getStateDataFromSingleLevelContentType = (slct, prefix) => {
459
582
  if (singleLevelContentTypeIsDataEntry(slct))
460
583
  return (additionalData) => internalGetDataEntry(slct, prefix, additionalData);
461
584
  else if (singleLevelContentTypeIsNestedContentDataType(slct))
462
- return getStateDataFromNestedContentType(slct[1], prefix, slct[0]);
585
+ return getStateDataFromNestedContentType(slct[1], `${prefix}_${slct[0]}`, slct[0]);
463
586
  throw new Error("this is an invalid output value, wonder why?");
464
587
  };
465
588
  var getGenerationMethodForSingleLevelContentTypeArray = (slct) => {
@@ -488,7 +611,7 @@ var getParserMethodForVersionDefinition = (vadt, versionBits, defaultVersion) =>
488
611
  const versionEntry = DataEntryFactory.createVersion(versionIndex, versionBits, "version");
489
612
  return getGenerationMethodForSingleLevelContentTypeArray([versionEntry, ...versionDefinition])(additionalData);
490
613
  };
491
- var getUpdaterMethodForVersionDefinition = (parser) => (state, entryToUpdate) => parser([entryToUpdate, ...getDataEntryArray(state)]);
614
+ var getUpdaterMethodForVersionDefinition = (parser) => (state, entryToUpdate) => parser([...Array.isArray(entryToUpdate) ? entryToUpdate : [entryToUpdate], ...getDataEntryArray(state)]);
492
615
  var getStringifyMethodForVersionDefinition = (parser) => (data) => getBase64String(parser(data));
493
616
  var createParserObject = (versionContent, maximumExpectedVersions, defaultVersion, enumSemanticsMapping, attributeSemanticsMapping, exposedVersions) => {
494
617
  const versionBitCount = getVersionValueRangeValueForNumber(maximumExpectedVersions);
@@ -496,7 +619,7 @@ var createParserObject = (versionContent, maximumExpectedVersions, defaultVersio
496
619
  if (versionContent.length > maximumExpectedVersions)
497
620
  throw new Error(`Cannot have more than ${maximumExpectedVersions} versions`);
498
621
  if (localDefaultVersion !== (defaultVersion ?? 0))
499
- console.log(`Default version must be between 0 and ${versionContent.length - 1}, instead of ${defaultVersion} will be using ${localDefaultVersion}`);
622
+ throw new Error(`Default version must be between 0 and ${versionContent.length - 1}.`);
500
623
  const parser = getParserMethodForVersionDefinition(versionContent, versionBitCount, localDefaultVersion);
501
624
  const updater = getUpdaterMethodForVersionDefinition(parser);
502
625
  const stringify = getStringifyMethodForVersionDefinition(parser);
@@ -515,42 +638,60 @@ var interpolateEntryAt = (dataEntry2, t) => {
515
638
  const localT = Math.max(Math.min(1, t), 0);
516
639
  const cosT = Math.cos(localT * 2 * Math.PI) * 0.5 + 0.5;
517
640
  switch (dataEntry2.type) {
518
- case DataType.BOOLEAN:
641
+ case 1 /* BOOLEAN */:
519
642
  return { ...dataEntry2, value: Boolean(Math.round(localT)) };
520
- case DataType.VERSION:
643
+ case 0 /* VERSION */:
521
644
  return { ...dataEntry2, value: Math.floor(localT * (dataEntry2.bits ** 2 - 0.001)) };
522
- case DataType.ENUM:
645
+ case 2 /* ENUM */:
523
646
  return { ...dataEntry2, value: Math.floor(localT * (dataEntry2.max + 0.999)) };
524
- case DataType.INT:
647
+ case 3 /* INT */:
525
648
  return { ...dataEntry2, value: dataEntry2.min + Math.floor(cosT * (dataEntry2.max - dataEntry2.min + 0.999)) };
526
- case DataType.FLOAT:
649
+ case 4 /* FLOAT */:
527
650
  const v = dataEntry2.min + cosT * (dataEntry2.max - dataEntry2.min);
528
651
  return dataEntryCorrecting({ ...dataEntry2, value: Math.min(dataEntry2.max, Math.max(v, dataEntry2.min)) });
652
+ case 5 /* ENUM_ARRAY */:
653
+ return { ...dataEntry2, value: dataEntry2.value.map((v2) => Math.floor(localT * (v2 + 0.999))) };
529
654
  }
530
655
  };
531
656
  // src/utils/relativeValue.ts
532
657
  var getRelativeValue = (dataEntry2) => {
533
658
  switch (dataEntry2.type) {
534
- case DataType.BOOLEAN:
659
+ case 1 /* BOOLEAN */:
535
660
  return Number(dataEntry2.value);
536
- case DataType.INT:
537
- case DataType.FLOAT:
661
+ case 3 /* INT */:
662
+ case 4 /* FLOAT */:
538
663
  return (dataEntry2.value - dataEntry2.min) / (dataEntry2.max - dataEntry2.min);
539
- case DataType.VERSION:
664
+ case 0 /* VERSION */:
540
665
  return dataEntry2.value / (2 ** dataEntry2.bits - 1);
541
- case DataType.ENUM:
666
+ case 2 /* ENUM */:
542
667
  return dataEntry2.value / dataEntry2.max;
668
+ case 5 /* ENUM_ARRAY */:
669
+ return dataEntry2.value.reduce((acc, v) => acc + v, 0) / dataEntry2.value.length;
543
670
  }
544
671
  };
545
672
  export {
673
+ valueBitsParser,
546
674
  parseBase64ToBits,
675
+ isSingleLevelContentType,
676
+ isDoubleLevelContentType,
677
+ isDataEntry,
547
678
  interpolateEntryAt,
548
679
  getStateValue,
549
680
  getRelativeValue,
550
681
  getDataEntryArray,
682
+ getBitsCount7 as getBitsCount,
551
683
  getBase64String,
684
+ doubleLevelContentTypeIsOptionalEntryDataType,
685
+ doubleLevelContentTypeIsEnumEntryDataType,
686
+ doubleLevelContentTypeIsArrayDefinitionType,
687
+ dataEntryCorrecting,
688
+ dataEntryBitstringParser,
689
+ dataBitsStringifier,
690
+ dataBitsParser,
552
691
  createParserObject,
553
692
  SignificandMaxBits,
693
+ PROTECTED_ATTRIBUTE_NAMES,
694
+ PREFIX_SEPERATOR_DELIMETER,
554
695
  IntegerMaxBits,
555
696
  DataType,
556
697
  DataEntryFactory
@@ -7,9 +7,23 @@ import { DataEntry, DataEntryArray, NestedContentType, SingleLevelContentType, D
7
7
  export declare const findExistingDataEntry: (dataEntry: DataEntry, dataEntryArray: DataEntryArray) => DataEntry | undefined;
8
8
  export declare const readDataEntry: (dataEntry: DataEntry, bitString: string) => DataEntryParsingReturnType;
9
9
  export declare const updateDataEntry: (dataEntry: DataEntry, existingData: DataEntryArray) => DataEntryParsingReturnType;
10
+ /**
11
+ * Method that extracts the data for a data entry from the given data
12
+ * @param dataEntry - `DataEntry` object that represents the data entry to extract the data for
13
+ * @param prefix - `string` that represents the prefix of the data internam name of the `DataEntry` object
14
+ * @param additionalData - `DataEntryArray` or `string` that represents the additional data to extract the data from, if not provided, the default value will be returned
15
+ * @returns `[DataEntryArray | string | undefined, [string, DataEntry]]` tuple that represents the updated additional data and the extracted data entry
16
+ */
10
17
  export declare const internalGetDataEntry: (dataEntry: DataEntry, prefix: string, additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DataEntry]];
11
18
  export declare const getStateFromOptionalEntryDataType: (oedt: OptionalEntryDataType, prefix: string, attributeName: string) => InternalStateDataGenerationMethod;
12
19
  export declare const getStateFromEnumEntryDataType: (eedt: EnumEntryDataType, prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, StateDataType]];
20
+ /**
21
+ * Helper method to get the method to parse, initiliaze, or update the state data for an array entry data type
22
+ * @param aedt - `ArrayEntryDataType` object that represents the array entry data type
23
+ * @param prefix - `string` that represents the prefix of the data internam name of the `DataEntry` object
24
+ * @param attributeName - `string` that represents the name of the attribute to extract the data from
25
+ * @returns `InternalStateDataGenerationMethod` object that represents the method to parse, initiliaze, or update the state data for an array entry data type
26
+ */
13
27
  export declare const getStateFromArrayEntryDataType: (aedt: ArrayEntryDataType, prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DerivativeStateDataType]];
14
28
  export declare const getStateDataFromDoubleLevelContentType: (dct: DoubleLevelContentType, prefix: string, attributeName: string) => InternalStateDataGenerationMethod;
15
29
  export declare const getStateDateFromSingleLevelContentTypeArray: (slcta: SingleLevelContentType[], prefix: string, attributeName: string) => (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, StateDataType]];
@@ -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;
@@ -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;
@@ -1,7 +1,31 @@
1
1
  import { DataEntryArray, DataEntry } from '../types/dataEntry';
2
- export declare const valueBitsParser: (bitString: string, mapData: DataEntry) => number | boolean;
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
31
  * Method to convert a bitstring into an array of data entries
@@ -9,10 +33,50 @@ export declare const dataEntryBitstringParser: (bitstring: string, dataEntry: Da
9
33
  * @param mapDataArray Data descriptions to map the bits to data entries
10
34
  * @returns array of data entries
11
35
  */
12
- export declare const dataBitsArrayParser: (bitString: string, mapDataArray: DataEntry[]) => DataEntryArray;
36
+ export declare const dataBitsArrayParser: (bitString: string, mapDataArray: DataEntryArray) => DataEntryArray;
13
37
  export declare const dataBitsStringifier: (data: DataEntry) => string;
14
38
  export declare const dataEntryCorrecting: (dataEntry: DataEntry) => DataEntry;
39
+ export declare const base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
40
+ /**
41
+ * Method that returns the bits required for a given amount of numners for a specific base
42
+ * @param count - `number` amount of numbers
43
+ * @param base - `number` max value of the numbers
44
+ */
45
+ export declare const getBitsForEnumArrayCountOfBase: (count: number, base: number) => number;
46
+ /**
47
+ * Method to convert an array of numbers to a bit string
48
+ * @param input - `number[]` the input array of numbers to convert to a bit string
49
+ * @param fromBase - `number` that represents the base of the input numbers
50
+ * @returns `string` that represents the bit string of the input numbers
51
+ * @returns 0 | 1 bit string
52
+ */
53
+ export declare const convertArbitraryBaseToBitString: (input: number[], fromBase: number) => string;
54
+ /**
55
+ * Method to convert a bit string to an array of numbers of a specific base
56
+ * @param input - `string` that represents the bit string to convert to an array of numbers
57
+ * @param toBase - `number` that represents the base of the output numbers
58
+ * @param expectedOutputLength - `number` that represents the expected length of the output array
59
+ */
60
+ export declare const convertBitStringToArbitraryBase: (input: string, toBase: number, expectedOutputLength: number) => number[];
61
+ /**
62
+ * Unused method to convert an array of numbers from an arbitrary base to an arbitrary base
63
+ * @param input - `number[]` the input array of numbers to convert to a bit string
64
+ * @param fromBase - `number` that represents the base of the input numbers
65
+ * @param toBase - `number` that represents the base of the output numbers
66
+ * @param expectedOutputLength - `number` | optional, should be given when you should find a specific amount of output numbers
67
+ */
68
+ export declare const convertArbitraryBaseToArbitraryBase: (input: number[], fromBase: number, toBase: number, expectedOutputLength?: number) => number[];
69
+ /**
70
+ * Method that convists a bitstring to a url safe base64 string
71
+ * @param bits - `string` of 0 | 1
72
+ * @returns `string` that represents the url safe base64 string
73
+ */
15
74
  export declare const parseBitsToBase64: (bits: string) => string;
75
+ /**
76
+ * Method that convists a url safe base64 string to a bitstring
77
+ * @param base64 - `string` that represents the url safe base64 string
78
+ * @returns `string` of 0 | 1
79
+ */
16
80
  export declare const parseBase64ToBits: (base64: string) => string;
17
81
  /**
18
82
  * Method to convert an array of data entries into a base64 string
@@ -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,9 @@
1
+ import { ArrayEntryDataType, DoubleLevelContentType, EnumEntryDataType, NestedContentType, OptionalEntryDataType, SingleLevelContentType, VersionContentDefinition } from '../types';
2
+ export declare const getVersionContentTypeFile: (versionContent: VersionContentDefinition) => string;
3
+ export declare const getStateDataTypeForSingleLevelContentTypeArray: (slcta: SingleLevelContentType[]) => string;
4
+ export declare const getStateDataTypeForSingleLevelContentType: (slct: SingleLevelContentType) => string;
5
+ export declare const getStateDataTypeNestedContentType: (ncdt: NestedContentType, attributeName: string) => string;
6
+ export declare const getStateDataTypeForDoubleLevelContentType: (dncdt: DoubleLevelContentType, attributeName: string) => string;
7
+ export declare const getStateDataTypeForOptionalEntryDataType: (oedt: OptionalEntryDataType, attributeName: string) => string;
8
+ export declare const getStateDataTypeForEnumEntryDataType: (eedt: EnumEntryDataType, attributeName: string) => string;
9
+ export declare const getStateDataTypeForArrayEntryDataType: (aedt: ArrayEntryDataType, attributeName: string) => string;
@@ -1,10 +1,58 @@
1
1
  import { DataEntry } from './dataEntry';
2
- export type SingleLevelContentType = DataEntry | NestedContentDataType;
2
+ /**
3
+ * Nested Content Type
4
+ * content type that does nothing more than provide a name to an entry so that the data can be read from a key-value pair object
5
+ */
3
6
  export type NestedContentDataType = [string, NestedContentType];
7
+ /**
8
+ * Single Level Content Type
9
+ * data that can be behind a string in an object definition
10
+ */
11
+ export type SingleLevelContentType = DataEntry | NestedContentDataType;
12
+ /**
13
+ * Content Type Union
14
+ */
4
15
  export type NestedContentType = SingleLevelContentType[] | DoubleLevelContentType;
16
+ /**
17
+ * Double Level Content Type
18
+ * is a data model array definition for which the first entry describes relevant data for the datamodel content type, but data model definition in of itself
19
+ *
20
+ * this additional state data is represented in the object model with a boolean for the OptionalEntryDataType, an Enum for the EnumEntryDataType and an array for the ArrayEntryDataType+++++++++
21
+ */
5
22
  export type DoubleLevelContentType = OptionalEntryDataType | EnumEntryDataType | ArrayEntryDataType;
23
+ /**
24
+ * Non Empty Valid Entry Array Type
25
+ * is a data model array definition that is not empty
26
+ */
6
27
  export type NonEmptyValidEntryArrayType = [SingleLevelContentType, ...SingleLevelContentType[]];
28
+ /**
29
+ * Optional Entry
30
+ * An optional entry is where the user can choose between two data model options
31
+ *
32
+ * the first value of the array is whether the user by default chooses the first option or the second option
33
+ *
34
+ * the two options should always be present!
35
+ */
7
36
  export type OptionalEntryDataType = [boolean, NonEmptyValidEntryArrayType, []] | [boolean, [], NonEmptyValidEntryArrayType];
37
+ /**
38
+ * Enum Entry
39
+ * An enum defintion is where the user is offered a list of optional data models to choose from
40
+ *
41
+ * the first value of the arrea the default option available
42
+ * all the other values are the option definitions
43
+ *
44
+ * the first value can't be bigger than the amount of options defined
45
+ * there should be at least two options given!
46
+ */
8
47
  export type EnumEntryDataType = [number, NonEmptyValidEntryArrayType, NonEmptyValidEntryArrayType, ...SingleLevelContentType[][]];
48
+ /**
49
+ * Array Entry
50
+ * An array definition is where the user is offered a list data models
51
+ *
52
+ * the first value of the array is the min and max count of the array
53
+ * the second value is the data model that is expected
54
+ *
55
+ * the delta of min and max count can't be less than 1 (and larger than 1024)
56
+ */
9
57
  export type ArrayEntryDataType = [[number, number], NonEmptyValidEntryArrayType];
10
58
  export declare const PREFIX_SEPERATOR_DELIMETER = "_";
@@ -3,6 +3,7 @@ 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';
6
7
  export type Prettify<T> = {
7
8
  [K in keyof T]: T[K];
8
9
  };
@@ -11,12 +12,62 @@ type DataDescription = {
11
12
  internalName?: string;
12
13
  index: number;
13
14
  };
15
+ /**
16
+ * Boolean object
17
+ *
18
+ * Boolean objects are a simple `true` or `false`, 1 or 0 - one bitwidth object.
19
+ */
14
20
  export type BooleanDataEntry = Prettify<BooleanData & DataDescription>;
15
- export type IntDataEntry = Prettify<IntData & DataDescription>;
21
+ /**
22
+ * Enum object
23
+ *
24
+ * An enum object is a continious range of integer values, starting at 0 upto its max.
25
+ * The maximum acceptable value for the max is `255` (8 bits)
26
+ */
16
27
  export type EnumDataEntry = Prettify<EnumData & DataDescription>;
28
+ /**
29
+ * Int object
30
+ *
31
+ * Int objects are a simple integer value, starting at its min upto its max.
32
+ * The maximum and minimum value can be any integar values represntabled as a double yet,
33
+ * the maximum acceptable delta between min and max is `4095` (12 bits).
34
+ */
35
+ export type IntDataEntry = Prettify<IntData & DataDescription>;
36
+ /**
37
+ * Float object
38
+ *
39
+ * Float objects are a fixed point extension of the int object, with a larger available precision range.
40
+ * Dispite a `min` and a `max` value, they also have a `precision` and a `significand` attribute.
41
+ * 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)
42
+ * 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.
43
+ * Maximum value for the significand is `20` bits, which allows for a maximum of 1048576 possible values.
44
+ */
17
45
  export type FloatDataEntry = Prettify<FloatData & DataDescription>;
46
+ /**
47
+ * Version object
48
+ *
49
+ * 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)
50
+ * 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
51
+ *
52
+ * Acceptable bitwidths are: `4 | 6 | 8 | 10`, giving a total of respectively 16, 64, 256 and 1024 possible versions
53
+ * Choose wisely, as it is not possible to increase this value later on (that would require the inclusion of an additional version object)
54
+ */
18
55
  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>;
56
+ /**
57
+ * Enum Array object
58
+ *
59
+ * enum arrays are as the name implies an array of enums.
60
+ * This object interprets the enums as being a number of a specific base and translates them to base 2.
61
+ * Besides the base, which is derived from the min and max (integer) values (its delta)
62
+ * There is also a given min and max count of values.
63
+ * The count itself is stored as the first bits, like for an Int object.
64
+ * The value itself is implied by the length of the value array.
65
+ *
66
+ * Note: the partical maximum benefit of using this versus using a `ArrayEntryDataType` with only enums is only about 22% for base_5
67
+ */
68
+ export type EnumArrayDataEntry = Prettify<EnumArrayData & DataDescription>;
69
+ export type DataEntry = BooleanDataEntry | IntDataEntry | EnumDataEntry | FloatDataEntry | VersionDataEntry | EnumArrayDataEntry;
70
+ export type ProtectedAttributeNames = Prettify<keyof BooleanDataEntry | keyof IntDataEntry | keyof EnumDataEntry | keyof FloatDataEntry | keyof VersionDataEntry | keyof EnumArrayDataEntry>;
71
+ export declare const PROTECTED_ATTRIBUTE_NAMES: readonly ["type", "value", "name", "internalName", "index", "min", "max", "bits", "precision", "significand", "minCount", "maxCount"];
21
72
  export type DataEntryArray = DataEntry[];
22
73
  export {};
@@ -0,0 +1,21 @@
1
+ import { DataType } from '../enums/dataTypes';
2
+ /**
3
+ * Enum Array object
4
+ *
5
+ * enum arrays are as the name implies an array of enums.
6
+ * This object interprets the enums as being a number of a specific base and translates them to base 2.
7
+ * Besides the base, which is derived from the min and max (integer) values (its delta)
8
+ * There is also a given min and max count of values.
9
+ * The count itself is stored as the first bits, like for an Int object.
10
+ * The value itself is implied by the length of the value array.
11
+ *
12
+ * Note: the partical maximum benefit of using this versus using a `ArrayEntryDataType` with only enums is only about 22% for base_5
13
+ */
14
+ export type EnumArrayData = {
15
+ type: DataType.ENUM_ARRAY;
16
+ minCount: number;
17
+ maxCount: number;
18
+ value: number[];
19
+ min: number;
20
+ max: number;
21
+ };
@@ -1,5 +1,11 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export declare const EnumMaxBits = 8;
3
+ /**
4
+ * Enum object
5
+ *
6
+ * An enum object is a continious range of integer values, starting at 0 upto its max.
7
+ * The maximum acceptable value for the max is `255` (8 bits)
8
+ */
3
9
  export type EnumData = {
4
10
  type: DataType.ENUM;
5
11
  value: number;
@@ -1,6 +1,15 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export type PrecisionRangeType = -3 | -2 | -1 | 0 | 1 | 2 | 3;
3
3
  export declare const SignificandMaxBits = 20;
4
+ /**
5
+ * Float object
6
+ *
7
+ * Float objects are a fixed point extension of the int object, with a larger available precision range.
8
+ * Dispite a `min` and a `max` value, they also have a `precision` and a `significand` attribute.
9
+ * 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)
10
+ * 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.
11
+ * Maximum value for the significand is `20` bits, which allows for a maximum of 1048576 possible values.
12
+ */
4
13
  export type FloatData = {
5
14
  type: DataType.FLOAT;
6
15
  value: number;
@@ -1,5 +1,12 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export declare const IntegerMaxBits = 12;
3
+ /**
4
+ * Int object
5
+ *
6
+ * Int objects are a simple integer value, starting at its min upto its max.
7
+ * The maximum and minimum value can be any integar values represntabled as a double yet,
8
+ * the maximum acceptable delta between min and max is `4095` (12 bits).
9
+ */
3
10
  export type IntData = {
4
11
  type: DataType.INT;
5
12
  value: number;
@@ -9,17 +9,17 @@ export type DerivativeStateDataType = {
9
9
  v: StateDataType | StateDataType[];
10
10
  };
11
11
  export type StateValueType = {
12
- [attribute: string]: boolean | number | string | StateValueType | DerivativeStateValueType;
12
+ [attribute: string]: boolean | number | number[] | string | StateValueType | DerivativeStateValueType;
13
13
  };
14
14
  export type DerivativeStateValueType = {
15
- s: boolean | number | string;
15
+ s: boolean | number | string | number[];
16
16
  v: StateValueType | StateValueType[];
17
17
  };
18
18
  export type StateDataGenerationMethod = (additionalData?: DataEntryArray | string) => StateDataType;
19
19
  export type DataEntryParsingReturnType = [DataEntryArray | string | undefined, [string, DataEntry]];
20
20
  export type InternalStateDataGenerationMethod = (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DataEntry | StateDataType | DerivativeStateDataType]];
21
21
  export type ExposedParserStateDataMethod = (additionalData?: StateDataType | DataEntryArray | string) => StateDataType;
22
- export type UpdateStateDataMethod = (state: StateDataType, entryToUpdate: DataEntry) => StateDataType;
22
+ export type UpdateStateDataMethod = (state: StateDataType, entryToUpdate: DataEntry | DataEntry[]) => StateDataType;
23
23
  export type StringifyStateDataMethod = (data: StateDataType | DataEntryArray) => string;
24
24
  export type VersionContentDefinition = SingleLevelContentType[][];
25
25
  export type VersionHandler = {
@@ -0,0 +1,2 @@
1
+ import { EnumArrayDataEntry } from '@/types';
2
+ export declare const updateValue: (original: EnumArrayDataEntry, update: EnumArrayDataEntry) => EnumArrayDataEntry;
@@ -1,2 +1,8 @@
1
1
  import { DataEntry } 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;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "dist/*"
7
7
  ],
8
8
  "type": "module",
9
- "version": "0.1.13",
9
+ "version": "0.1.15",
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
  }