@hkdigital/lib-core 0.5.40 → 0.5.41

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.
@@ -162,13 +162,13 @@
162
162
  * @param {DragEvent} event
163
163
  */
164
164
  function handleDragStart(event) {
165
- console.debug('handleDragStart called', {
166
- target: event.target,
167
- currentTarget: event.currentTarget,
168
- disabled,
169
- canDrag: canDrag(item),
170
- dataTransfer: !!event.dataTransfer
171
- });
165
+ // console.debug('handleDragStart called', {
166
+ // target: event.target,
167
+ // currentTarget: event.currentTarget,
168
+ // disabled,
169
+ // canDrag: canDrag(item),
170
+ // dataTransfer: !!event.dataTransfer
171
+ // });
172
172
 
173
173
  if (disabled || !canDrag(item)) {
174
174
  console.debug('Drag prevented: disabled or cannot drag');
@@ -189,7 +189,7 @@
189
189
  return;
190
190
  }
191
191
 
192
- console.debug('Starting drag operation');
192
+ // console.debug('Starting drag operation');
193
193
  currentState = DRAGGING;
194
194
  startDrag(event);
195
195
  }
@@ -69,18 +69,25 @@ export function generateOrGetInstanceId(randomSize?: number, reset?: boolean): s
69
69
  * @param {number} [timeMs]
70
70
  * Custom time value to be used instead of Date.now()
71
71
  *
72
- * @returns {string} global id
72
+ * @returns {string}
73
+ * Global id (max 39 chars: 1 length prefix + 23 instance + 15 local)
73
74
  */
74
75
  export function generateGlobalId(timeMs?: number): string;
75
76
  /**
76
77
  * Generates and returns a new unique local id
77
- * - The generated id is garanteed to be unique on the currently running
78
+ * - The generated id is guaranteed to be unique on the currently running
78
79
  * local system
80
+ * - Format: <boot-prefix><length-indicator><time-based><count-based>
81
+ * - Boot prefix provides uniqueness across process restarts
82
+ * - Time-based component changes every 30 seconds
83
+ * - Counter resets every 30 seconds (656M IDs per 30s window = 5 chars)
84
+ * - Optimized for high-frequency generation (thousands per second)
79
85
  *
80
86
  * @param {number} [timeMs]
81
87
  * Custom time value to be used instead of Date.now()
82
88
  *
83
- * @returns {string} local id
89
+ * @returns {string}
90
+ * Local id (max 15 chars: 3 boot prefix + 1 length + 6 time + 5 count)
84
91
  */
85
92
  export function generateLocalId(timeMs?: number): string;
86
93
  /**
@@ -141,8 +141,8 @@ export function generateClientSessionId() {
141
141
  */
142
142
  export function generateOrGetInstanceId(randomSize = 16, reset = false) {
143
143
  if (!vars.instanceId || reset) {
144
- const timeBasedPart = getTimeBasedNumber30sBase58();
145
- const lengthPrefix = base58fromNumber(timeBasedPart.length);
144
+ const timeBasedPart = getTimeBasedNumber30sBase58(); // max 6 chars
145
+ const lengthPrefix = base58fromNumber(timeBasedPart.length); // 1 char
146
146
 
147
147
  vars.instanceId =
148
148
  lengthPrefix +
@@ -166,25 +166,35 @@ export function generateOrGetInstanceId(randomSize = 16, reset = false) {
166
166
  * @param {number} [timeMs]
167
167
  * Custom time value to be used instead of Date.now()
168
168
  *
169
- * @returns {string} global id
169
+ * @returns {string}
170
+ * Global id (max 39 chars: 1 length prefix + 23 instance + 15 local)
170
171
  */
171
172
  export function generateGlobalId(timeMs) {
172
- const instanceId = generateOrGetInstanceId();
173
- const localId = generateLocalId(timeMs);
173
+ const instanceId = generateOrGetInstanceId(); // max 1 + 6 + 16 = 23 chars
174
+ const localId = generateLocalId(timeMs); // max 15 chars
175
+
176
+ // Max 1 char (23 + 15 = 38)
174
177
  const lengthPrefix = base58fromNumber(instanceId.length + localId.length);
175
178
 
179
+ // Max 39 chars (1 + 23 + 15 = 39)
176
180
  return lengthPrefix + instanceId + localId;
177
181
  }
178
182
 
179
183
  /**
180
184
  * Generates and returns a new unique local id
181
- * - The generated id is garanteed to be unique on the currently running
185
+ * - The generated id is guaranteed to be unique on the currently running
182
186
  * local system
187
+ * - Format: <boot-prefix><length-indicator><time-based><count-based>
188
+ * - Boot prefix provides uniqueness across process restarts
189
+ * - Time-based component changes every 30 seconds
190
+ * - Counter resets every 30 seconds (656M IDs per 30s window = 5 chars)
191
+ * - Optimized for high-frequency generation (thousands per second)
183
192
  *
184
193
  * @param {number} [timeMs]
185
194
  * Custom time value to be used instead of Date.now()
186
195
  *
187
- * @returns {string} local id
196
+ * @returns {string}
197
+ * Local id (max 15 chars: 3 boot prefix + 1 length + 6 time + 5 count)
188
198
  */
189
199
  export function generateLocalId(timeMs) {
190
200
  const timeBasedNumber = getTimeBasedNumber30s(timeMs);
@@ -222,6 +232,15 @@ export function generateLocalId(timeMs) {
222
232
  //
223
233
  // @note ALPHABET_BASE_58 is used because it is faster than
224
234
  // base58fromNumber for single character encoding
235
+
236
+ //
237
+ // bootTimePrefix => 3 chars
238
+ // ALPHABET_BASE_58[timeBasedValue58.length] => 1 char
239
+ // timeBasedValue58 => max 6 chars
240
+ // countBasedValue58 => max 5 chars
241
+ // (resets every 30 seconds => 58^5 = 656.356.768)
242
+ //
243
+ // Realistic max length: 3 + 1 + 6 + 5 = 15 chars
225
244
  //
226
245
  const id =
227
246
  // idFormatPrefix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.40",
3
+ "version": "0.5.41",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"