@shware/http 0.2.1 → 0.2.3

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 CHANGED
@@ -243,7 +243,7 @@ declare function valid<S extends ZodSchema>(request: Request, target: Target, sc
243
243
  *
244
244
  * ID data bits:
245
245
  * +----------------------+----------------+-----------+
246
- * | delta millisecond | worker node id | sequence |
246
+ * | delta millisecond | machine id | sequence |
247
247
  * +----------------------+----------------+-----------+
248
248
  * | 41bits | 10bits | 12bits |
249
249
  * +----------------------+----------------+-----------+
@@ -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 workerBits;
254
+ private readonly machineBits;
255
255
  private readonly sequenceBits;
256
256
  private readonly epochMillisecond;
257
257
  private readonly sequenceMask;
258
- private readonly maxWorkerId;
259
- private readonly workerIdShift;
258
+ private readonly maxMachineId;
259
+ private readonly machineIdShift;
260
260
  private readonly timeStampShift;
261
- private readonly workerId;
261
+ private readonly machineId;
262
262
  private sequence;
263
263
  private lastTimestamp;
264
- constructor(workerId: number);
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
- workerBits = BigInt(10);
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
- maxWorkerId = ~(BigInt(-1) << this.workerBits);
327
- workerIdShift = this.sequenceBits;
328
- timeStampShift = this.workerBits + this.sequenceBits;
329
- workerId;
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(workerId2) {
333
- this.workerId = BigInt(workerId2) % this.maxWorkerId;
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.workerId << this.workerIdShift | this.sequence;
350
+ return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
351
351
  };
352
352
  }
353
- const workerId = Math.floor(Math.random() * 1024);
354
- const uid = new UidGenerator(workerId);
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 };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,3 @@
1
+ BigInt.prototype.toJSON = function() {
2
+ return this.toString();
3
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -11,7 +11,8 @@
11
11
  "module": "./dist/index.mjs",
12
12
  "types": "./dist/index.d.mts",
13
13
  "exports": {
14
- ".": "./dist/index.mjs"
14
+ ".": "./dist/index.mjs",
15
+ "./polyfills": "./dist/polyfills.mjs"
15
16
  },
16
17
  "files": [
17
18
  "dist"