@shware/http 0.2.1 → 0.2.2
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/dist/index.d.mts +5 -5
- package/dist/index.mjs +10 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -251,17 +251,17 @@ declare function valid<S extends ZodSchema>(request: Request, target: Target, sc
|
|
|
251
251
|
*/
|
|
252
252
|
declare class UidGenerator {
|
|
253
253
|
readonly MAX: bigint;
|
|
254
|
-
private readonly
|
|
254
|
+
private readonly machineBits;
|
|
255
255
|
private readonly sequenceBits;
|
|
256
256
|
private readonly epochMillisecond;
|
|
257
257
|
private readonly sequenceMask;
|
|
258
|
-
private readonly
|
|
259
|
-
private readonly
|
|
258
|
+
private readonly maxMachineId;
|
|
259
|
+
private readonly machineIdShift;
|
|
260
260
|
private readonly timeStampShift;
|
|
261
|
-
private readonly
|
|
261
|
+
private readonly machineId;
|
|
262
262
|
private sequence;
|
|
263
263
|
private lastTimestamp;
|
|
264
|
-
constructor(
|
|
264
|
+
constructor(mackineId: number);
|
|
265
265
|
readonly next: () => bigint;
|
|
266
266
|
}
|
|
267
267
|
declare const uid: UidGenerator;
|
package/dist/index.mjs
CHANGED
|
@@ -318,19 +318,19 @@ function getNextMillisecond(timestamp) {
|
|
|
318
318
|
}
|
|
319
319
|
class UidGenerator {
|
|
320
320
|
MAX = (1n << 63n) - 1n;
|
|
321
|
-
|
|
321
|
+
machineBits = BigInt(10);
|
|
322
322
|
sequenceBits = BigInt(12);
|
|
323
323
|
epochMillisecond = BigInt(1577808e6);
|
|
324
324
|
// 2020-1-1 00:00:00
|
|
325
325
|
sequenceMask = ~(BigInt(-1) << this.sequenceBits);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
timeStampShift = this.
|
|
329
|
-
|
|
326
|
+
maxMachineId = ~(BigInt(-1) << this.machineBits);
|
|
327
|
+
machineIdShift = this.sequenceBits;
|
|
328
|
+
timeStampShift = this.machineBits + this.sequenceBits;
|
|
329
|
+
machineId;
|
|
330
330
|
sequence = BigInt(0);
|
|
331
331
|
lastTimestamp = BigInt(-1);
|
|
332
|
-
constructor(
|
|
333
|
-
this.
|
|
332
|
+
constructor(mackineId) {
|
|
333
|
+
this.machineId = BigInt(mackineId) % this.maxMachineId;
|
|
334
334
|
}
|
|
335
335
|
next = () => {
|
|
336
336
|
let timestamp = BigInt(Date.now());
|
|
@@ -347,10 +347,10 @@ class UidGenerator {
|
|
|
347
347
|
this.sequence = BigInt(0);
|
|
348
348
|
}
|
|
349
349
|
this.lastTimestamp = timestamp;
|
|
350
|
-
return timestamp - this.epochMillisecond << this.timeStampShift | this.
|
|
350
|
+
return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
|
-
const
|
|
354
|
-
const uid = new UidGenerator(
|
|
353
|
+
const machineId = Math.floor(Math.random() * 1024);
|
|
354
|
+
const uid = new UidGenerator(machineId);
|
|
355
355
|
|
|
356
356
|
export { Code, DEFAULT_MESSAGES, DetailType, Details, Status, StatusCode, StatusError, UidGenerator, uid, valid };
|