@chainfuse/helpers 4.0.2 → 4.0.4

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/common.d.mts CHANGED
@@ -39,5 +39,15 @@ export declare class Helpers {
39
39
  * @returns A promise that resolves after the specified delay.
40
40
  */
41
41
  static sleep(ms: number): Promise<void>;
42
+ /**
43
+ * Replaces a substring in the input string between the specified start and end indices with the provided replacement string.
44
+ *
45
+ * @param input - The original string to modify.
46
+ * @param start - The starting index (inclusive) of the substring to replace.
47
+ * @param end - The ending index (exclusive) of the substring to replace.
48
+ * @param replacement - The string to insert in place of the specified substring.
49
+ * @returns The resulting string after replacement.
50
+ */
51
+ static replaceByIndex(input: string, start: number, end: number, replacement: string): string;
42
52
  }
43
53
  export {};
package/dist/common.mjs CHANGED
@@ -97,4 +97,16 @@ export class Helpers {
97
97
  static sleep(ms) {
98
98
  return new Promise((resolve) => setTimeout(resolve, ms));
99
99
  }
100
+ /**
101
+ * Replaces a substring in the input string between the specified start and end indices with the provided replacement string.
102
+ *
103
+ * @param input - The original string to modify.
104
+ * @param start - The starting index (inclusive) of the substring to replace.
105
+ * @param end - The ending index (exclusive) of the substring to replace.
106
+ * @param replacement - The string to insert in place of the specified substring.
107
+ * @returns The resulting string after replacement.
108
+ */
109
+ static replaceByIndex(input, start, end, replacement) {
110
+ return input.slice(0, start) + replacement + input.slice(end);
111
+ }
100
112
  }
@@ -17,12 +17,11 @@ export declare class DiscordHelpers {
17
17
  * @link https://discord.com/developers/docs/reference#snowflakes-snowflake-id-format-structure-left-to-right
18
18
  */
19
19
  static discordSnowflakeToDate(snowflakeRaw?: bigint | string): Date;
20
- static customLogging: z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>;
21
20
  static disordRestLogging: z.ZodMiniDefault<z.ZodMiniObject<{
22
21
  level: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
23
22
  error: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
24
23
  color: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
25
- custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>, z.ZodMiniTransform<(args_0: any, ...args: any[]) => void | Promise<void>, z.core.$InferOuterFunctionType<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>>>>;
24
+ custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnknown, z.ZodMiniTransform<(...args: any[]) => void | Promise<void>, unknown>>>;
26
25
  }, z.core.$strip>>;
27
26
  static discordRest(apiKey: string, _logging: z.input<typeof this.disordRestLogging>, cacheTtl?: number, forceCache?: boolean, executionContext?: ExecutionContext, restOptions?: Partial<Omit<RESTOptions, 'agent' | 'authPrefix' | 'makeRequest'>>): Promise<import("@discordjs/rest").REST>;
28
27
  static userIcon(userId: bigint | string, userIconHash?: Parameters<CDN['avatar']>[1] | null, guildId?: bigint | string, memberIconHash?: Parameters<CDN['avatar']>[1] | null, options?: Parameters<CDN['avatar']>[2]): string;
package/dist/discord.mjs CHANGED
@@ -31,17 +31,11 @@ export class DiscordHelpers {
31
31
  const snowflake = BigInt(snowflakeRaw);
32
32
  return new Date(Number((snowflake >> BigInt(22)) + this.discordEpoch));
33
33
  }
34
- static customLogging = z.function({
35
- input: z.tuple([z.any()], z.any()),
36
- output: z.union([z.promise(z.void()), z.void()]),
37
- });
38
34
  static disordRestLogging = z._default(z.object({
39
35
  level: z._default(z.int().check(z.minimum(0), z.maximum(3)), 0),
40
36
  error: z._default(z.int().check(z.minimum(0), z.maximum(3)), 1),
41
37
  color: z._default(z.boolean(), true),
42
- custom: z.optional(z.pipe(this.customLogging,
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- z.transform((fn) => fn))),
38
+ custom: z.optional(z.pipe(z.unknown(), z.transform((fn) => fn))),
45
39
  }), {
46
40
  level: 0,
47
41
  error: 1,
@@ -65,16 +59,12 @@ export class DiscordHelpers {
65
59
  error: logging.error >= 2 ? logging.error - 1 : logging.error,
66
60
  ...('color' in logging && { color: logging.color }),
67
61
  ...((logging.level > 0 || logging.error > 0) && {
68
- custom: this.customLogging.implementAsync(async (args_0, ...args_x) => {
69
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
70
- const args = [args_0, ...args_x];
62
+ custom: async (...args) => {
71
63
  const [, id, , url] = args;
72
64
  const customUrl = new URL(url);
73
65
  if ('custom' in logging && logging.custom) {
74
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
75
- const [argsFirst, ...argsRest] = args.slice(0, -1);
76
66
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
77
- return logging.custom(argsFirst, ...argsRest);
67
+ return logging.custom(...args.slice(0, -1));
78
68
  }
79
69
  else {
80
70
  await Promise.all([
@@ -116,7 +106,7 @@ export class DiscordHelpers {
116
106
  }
117
107
  });
118
108
  }
119
- }),
109
+ },
120
110
  }),
121
111
  },
122
112
  };
@@ -144,10 +134,8 @@ export class DiscordHelpers {
144
134
  });
145
135
  }
146
136
  if ('custom' in logging && logging.custom) {
147
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
148
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
149
137
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
150
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
138
+ await logging.custom(...loggingItems);
151
139
  }
152
140
  else {
153
141
  console.info(
@@ -184,10 +172,8 @@ export class DiscordHelpers {
184
172
  });
185
173
  }
186
174
  if ('custom' in logging && logging.custom) {
187
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
188
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
189
175
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
190
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
176
+ await logging.custom(...loggingItems);
191
177
  }
192
178
  else {
193
179
  console.info(
@@ -224,10 +210,8 @@ export class DiscordHelpers {
224
210
  });
225
211
  }
226
212
  if ('custom' in logging && logging.custom) {
227
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
228
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
229
213
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
230
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
214
+ await logging.custom(...loggingItems);
231
215
  }
232
216
  else {
233
217
  console.info(
@@ -254,10 +238,8 @@ export class DiscordHelpers {
254
238
  });
255
239
  }
256
240
  if ('custom' in logging && logging.custom) {
257
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
258
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
259
241
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
260
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
242
+ await logging.custom(...loggingItems);
261
243
  }
262
244
  else {
263
245
  console.info(
@@ -288,10 +270,8 @@ export class DiscordHelpers {
288
270
  });
289
271
  }
290
272
  if ('custom' in logging && logging.custom) {
291
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
292
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
293
273
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
294
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
274
+ await logging.custom(...loggingItems);
295
275
  }
296
276
  else {
297
277
  console.info(
@@ -318,10 +298,8 @@ export class DiscordHelpers {
318
298
  });
319
299
  }
320
300
  if ('custom' in logging && logging.custom) {
321
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
322
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
323
301
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
324
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
302
+ await logging.custom(...loggingItems);
325
303
  }
326
304
  else {
327
305
  console.info(
@@ -354,10 +332,8 @@ export class DiscordHelpers {
354
332
  });
355
333
  }
356
334
  if ('custom' in logging && logging.custom) {
357
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
358
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
359
335
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
360
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
336
+ await logging.custom(...loggingItems);
361
337
  }
362
338
  else {
363
339
  console.info(
@@ -384,10 +360,8 @@ export class DiscordHelpers {
384
360
  });
385
361
  }
386
362
  if ('custom' in logging && logging.custom) {
387
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
388
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
389
363
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
390
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
364
+ await logging.custom(...loggingItems);
391
365
  }
392
366
  else {
393
367
  console.info(
@@ -418,10 +392,8 @@ export class DiscordHelpers {
418
392
  });
419
393
  }
420
394
  if ('custom' in logging && logging.custom) {
421
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
422
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
423
395
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
424
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
396
+ await logging.custom(...loggingItems);
425
397
  }
426
398
  else {
427
399
  console.info(
@@ -448,10 +420,8 @@ export class DiscordHelpers {
448
420
  });
449
421
  }
450
422
  if ('custom' in logging && logging.custom) {
451
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
452
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
453
423
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
454
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
424
+ await logging.custom(...loggingItems);
455
425
  }
456
426
  else {
457
427
  console.info(
@@ -485,10 +455,8 @@ export class DiscordHelpers {
485
455
  });
486
456
  }
487
457
  if ('custom' in logging && logging.custom) {
488
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
489
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
490
458
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
491
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
459
+ await logging.custom(...loggingItems);
492
460
  }
493
461
  else {
494
462
  console.info(
@@ -516,10 +484,8 @@ export class DiscordHelpers {
516
484
  });
517
485
  }
518
486
  if ('custom' in logging && logging.custom) {
519
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
520
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
521
487
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
522
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
488
+ await logging.custom(...loggingItems);
523
489
  }
524
490
  else {
525
491
  console.info(
@@ -548,10 +514,8 @@ export class DiscordHelpers {
548
514
  });
549
515
  }
550
516
  if ('custom' in logging && logging.custom) {
551
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
552
- const [loggingItemsFirst, ...loggingItemsRest] = loggingItems;
553
517
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
554
- await logging.custom(loggingItemsFirst, ...loggingItemsRest);
518
+ await logging.custom(...loggingItems);
555
519
  }
556
520
  else {
557
521
  console.info(
package/dist/net.d.mts CHANGED
@@ -17,13 +17,12 @@ export declare enum Methods {
17
17
  'PATCH' = "PATCH"
18
18
  }
19
19
  export declare class NetHelpers {
20
- static customLogging: z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>;
21
20
  static cfApiConfig: z.ZodMiniDefault<z.ZodMiniObject<{
22
21
  logging: z.ZodMiniDefault<z.ZodMiniObject<{
23
22
  level: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
24
23
  error: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
25
24
  color: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
26
- custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>, z.ZodMiniTransform<(args_0: any, ...args: any[]) => void | Promise<void>, z.core.$InferOuterFunctionType<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>>>>;
25
+ custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnknown, z.ZodMiniTransform<(...args: any[]) => void | Promise<void>, unknown>>>;
27
26
  }, z.core.$strip>>;
28
27
  cf: z.ZodMiniDefault<z.ZodMiniObject<{
29
28
  /**
@@ -102,19 +101,23 @@ export declare class NetHelpers {
102
101
  * - Formatting and coloring log output for better readability.
103
102
  * - Stripping redundant parts of URLs and wrapping unique IDs in brackets with color coding.
104
103
  */
105
- static cfApi(apiKey: string, config?: z.input<typeof NetHelpers.cfApiConfig>): Promise<import("cloudflare").Cloudflare>;
104
+ static cfApi(apiKey: string, config?: z.input<typeof NetHelpers.cfApiConfig> & {
105
+ logging?: {
106
+ custom?: (...args: any[]) => void | Promise<void>;
107
+ };
108
+ }): Promise<import("cloudflare").Cloudflare>;
106
109
  static loggingFetchInitLogging: z.ZodMiniDefault<z.ZodMiniObject<{
107
110
  level: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
108
111
  error: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
109
112
  color: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
110
- custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>, z.ZodMiniTransform<(args_0: any, ...args: any[]) => void | Promise<void>, z.core.$InferOuterFunctionType<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>>>>;
113
+ custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnknown, z.ZodMiniTransform<(...args: any[]) => void | Promise<void>, unknown>>>;
111
114
  }, z.core.$strip>>;
112
115
  static loggingFetchInit: z.ZodMiniObject<{
113
116
  logging: z.ZodMiniDefault<z.ZodMiniObject<{
114
117
  level: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
115
118
  error: z.ZodMiniDefault<z.ZodMiniNumberFormat>;
116
119
  color: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
117
- custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniFunction<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>, z.ZodMiniTransform<(args_0: any, ...args: any[]) => void | Promise<void>, z.core.$InferOuterFunctionType<z.ZodMiniTuple<readonly [z.ZodMiniAny], z.ZodMiniAny>, z.ZodMiniUnion<readonly [z.ZodMiniPromise<z.ZodMiniVoid>, z.ZodMiniVoid]>>>>>;
120
+ custom: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnknown, z.ZodMiniTransform<(...args: any[]) => void | Promise<void>, unknown>>>;
118
121
  }, z.core.$strip>>;
119
122
  }, z.core.$strip>;
120
123
  /**
@@ -151,7 +154,11 @@ export declare class NetHelpers {
151
154
  * - Allows for colorized output using the `chalk` library.
152
155
  * - Provides hooks for custom logging implementations.
153
156
  */
154
- static loggingFetch<RI extends RequestInit = RequestInit>(info: Parameters<typeof fetch>[0], init?: LoggingFetchInitType<RI>): Promise<Response>;
157
+ static loggingFetch<RI extends RequestInit = RequestInit>(info: Parameters<typeof fetch>[0], _init?: LoggingFetchInitType<RI> & {
158
+ logging?: {
159
+ custom?: (...args: any[]) => void | Promise<void>;
160
+ };
161
+ }): Promise<Response>;
155
162
  /**
156
163
  * Removes sensitive headers from the provided `Headers` object. Specifically, it deletes the `Set-Cookie` and `Authorization` headers.
157
164
  *
package/dist/net.mjs CHANGED
@@ -17,18 +17,12 @@ export var Methods;
17
17
  Methods["PATCH"] = "PATCH";
18
18
  })(Methods || (Methods = {}));
19
19
  export class NetHelpers {
20
- static customLogging = z.function({
21
- input: z.tuple([z.any()], z.any()),
22
- output: z.union([z.promise(z.void()), z.void()]),
23
- });
24
20
  static cfApiConfig = z._default(z.object({
25
21
  logging: z._default(z.object({
26
22
  level: z._default(z.int().check(z.minimum(0), z.maximum(3)), 0),
27
23
  error: z._default(z.int().check(z.minimum(0), z.maximum(3)), 1),
28
24
  color: z._default(z.boolean(), true),
29
- custom: z.optional(z.pipe(this.customLogging,
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- z.transform((fn) => fn))),
25
+ custom: z.optional(z.pipe(z.unknown(), z.transform((fn) => fn))),
32
26
  }), {
33
27
  level: 0,
34
28
  error: 1,
@@ -145,9 +139,7 @@ export class NetHelpers {
145
139
  error: config.logging.error === 1 ? 2 : config.logging.error,
146
140
  ...('color' in config.logging && { color: config.logging.color }),
147
141
  ...((config.logging.level > 0 || config.logging.error > 0) && {
148
- custom: this.customLogging.implementAsync(async (args_0, ...args_x) => {
149
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
150
- const args = [args_0, ...args_x];
142
+ custom: async (...args) => {
151
143
  const [, id, , url, headers] = args;
152
144
  const customUrl = new URL(url);
153
145
  const customHeaders = new Headers(headers);
@@ -165,16 +157,12 @@ export class NetHelpers {
165
157
  if ('custom' in config && config.logging.custom) {
166
158
  // We faked level 1 as 2 to get headers for ray-id
167
159
  if (config.logging.level === 1 || config.logging.error === 1) {
168
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
169
- const [argsFirst, ...argsRest] = args.slice(0, -1);
170
160
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
171
- return config.logging.custom(argsFirst, ...argsRest);
161
+ return void config.logging.custom(...args.slice(0, -1));
172
162
  }
173
163
  else {
174
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
175
- const [argsFirst, ...argsRest] = args;
176
164
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
177
- return config.logging.custom(argsFirst, ...argsRest);
165
+ return void config.logging.custom(...args);
178
166
  }
179
167
  }
180
168
  else {
@@ -300,7 +288,7 @@ export class NetHelpers {
300
288
  }
301
289
  });
302
290
  }
303
- }),
291
+ },
304
292
  }),
305
293
  },
306
294
  }),
@@ -310,9 +298,7 @@ export class NetHelpers {
310
298
  level: z._default(z.int().check(z.minimum(0), z.maximum(3)), 0),
311
299
  error: z._default(z.int().check(z.minimum(0), z.maximum(3)), 1),
312
300
  color: z._default(z.boolean(), true),
313
- custom: z.optional(z.pipe(this.customLogging,
314
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
315
- z.transform((fn) => fn))),
301
+ custom: z.optional(z.pipe(z.unknown(), z.transform((fn) => fn))),
316
302
  }), {
317
303
  level: 0,
318
304
  error: 1,
@@ -355,7 +341,7 @@ export class NetHelpers {
355
341
  * - Allows for colorized output using the `chalk` library.
356
342
  * - Provides hooks for custom logging implementations.
357
343
  */
358
- static loggingFetch(info, init) {
344
+ static loggingFetch(info, _init) {
359
345
  return Promise.all([
360
346
  z
361
347
  .pipe(z._default(z.looseObject(this.loggingFetchInit.def.shape), {
@@ -365,7 +351,7 @@ export class NetHelpers {
365
351
  color: true,
366
352
  },
367
353
  }), z.transform((parsed) => parsed))
368
- .parseAsync(init),
354
+ .parseAsync(_init),
369
355
  import("./crypto.mjs").then(({ CryptoHelpers }) => CryptoHelpers.base62secret(8)),
370
356
  ]).then(async ([init, id]) => {
371
357
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -421,10 +407,8 @@ export class NetHelpers {
421
407
  ]).catch(() => { });
422
408
  }
423
409
  if (init.logging.level > 0 && 'custom' in init.logging && init.logging.custom) {
424
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
425
- const [requestLoggingItemsFirst, ...requestLoggingItemsRest] = requestLoggingItems;
426
410
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
427
- await init.logging.custom(requestLoggingItemsFirst, ...requestLoggingItemsRest);
411
+ await init.logging.custom(...requestLoggingItems);
428
412
  }
429
413
  else if (init.logging.level > 0) {
430
414
  console.info(
@@ -489,21 +473,15 @@ export class NetHelpers {
489
473
  .catch(() => { });
490
474
  }
491
475
  if (init.logging.level > 0 && 'custom' in init.logging && init.logging.custom) {
492
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
493
- const [responseLoggingItemsFirst, ...responseLoggingItemsRest] = responseLoggingItems;
494
476
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
495
- await init.logging.custom(responseLoggingItemsFirst, ...responseLoggingItemsRest);
477
+ await init.logging.custom(...responseLoggingItems);
496
478
  }
497
479
  else if (init.logging.error > 0 && !response.ok && 'custom' in init.logging && init.logging.custom) {
498
480
  // Send request errors too (since we barely now know if error or not)
499
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
500
- const [requestErrorItemsFirst, ...requestErrorItemsRest] = requestErrorItems;
501
481
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
502
- await init.logging.custom(requestErrorItemsFirst, ...requestErrorItemsRest);
503
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
504
- const [responseErrorItemsFirst, ...responseErrorItemsRest] = responseErrorItems;
482
+ await init.logging.custom(...requestErrorItems);
505
483
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
506
- await init.logging.custom(responseErrorItemsFirst, ...responseErrorItemsRest);
484
+ await init.logging.custom(...responseErrorItems);
507
485
  }
508
486
  else if (init.logging.level > 0) {
509
487
  console.info(
package/dist/uuid8.d.mts CHANGED
@@ -14,7 +14,7 @@ export declare const v8Options: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
14
14
  location: z.ZodMiniUnion<readonly [z.ZodMiniDefault<z.ZodMiniCustomStringFormat<"hex">>, z.ZodMiniPipe<z.ZodMiniDefault<z.ZodMiniEnum<typeof DOCombinedLocations>>, z.ZodMiniTransform<string, DOCombinedLocations>>]>;
15
15
  shardType: z.ZodMiniUnion<readonly [z.ZodMiniDefault<z.ZodMiniCustomStringFormat<"hex">>, z.ZodMiniPipe<z.ZodMiniDefault<z.ZodMiniEnum<typeof ShardType>>, z.ZodMiniTransform<string, ShardType>>]>;
16
16
  suffix: z.ZodMiniUnion<readonly [z.ZodMiniDefault<z.ZodMiniCustomStringFormat<"hex">>, z.ZodMiniPipe<z.ZodMiniDefault<z.ZodMiniCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>, z.ZodMiniTransform<string, Uint8Array<ArrayBuffer>>>]>;
17
- rng: z.ZodMiniOptional<z.ZodMiniFunction<z.ZodMiniTuple<[], null>, z.ZodMiniCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>>;
17
+ rng: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnknown, z.ZodMiniTransform<() => Uint8Array, unknown>>>;
18
18
  }, z.core.$strip>]>;
19
19
  export type Version8Options = z.input<typeof v8Options>;
20
20
  /**
package/dist/uuid8.mjs CHANGED
@@ -3,6 +3,7 @@ import { ShardType } from '@chainfuse/types/d0';
3
3
  import { v7 } from 'uuid';
4
4
  import * as z from 'zod/mini';
5
5
  import { BufferHelpersInternals } from "./bufferInternals.mjs";
6
+ import { Helpers } from "./common.mjs";
6
7
  const v8OptionsBase = z.object({
7
8
  /**
8
9
  * RFC "timestamp" field
@@ -43,15 +44,9 @@ export const v8Options = z.union([
43
44
  /**
44
45
  * Alternative to options.random, a Function that returns an Array of 16 random bytes (0-255)
45
46
  */
46
- rng: z.optional(z.function({
47
- input: [],
48
- output: z.instanceof(Uint8Array).check(z.refine((arr) => arr.byteLength === 16, { message: '`random` must be a Uint8Array of 16 random bytes' })),
49
- })),
47
+ rng: z.optional(z.pipe(z.unknown(), z.transform((fn) => fn))),
50
48
  }),
51
49
  ]);
52
- function replaceByIndex(input, start, end, replacement) {
53
- return input.slice(0, start) + replacement + input.slice(end);
54
- }
55
50
  /**
56
51
  * Generates a UUID version 8 with custom fields for location, shard type, and suffix.
57
52
  *
@@ -73,11 +68,11 @@ export function v8(_options) {
73
68
  // 36 character string including hyphens
74
69
  const uuid7 = v7(options);
75
70
  // Swap version
76
- const uuid8 = replaceByIndex(uuid7, 14, 15, '8');
71
+ const uuid8 = Helpers.replaceByIndex(uuid7, 14, 15, '8');
77
72
  // Inject
78
- const uuid8Suffix = replaceByIndex(uuid8, 15, 18, options.suffix);
79
- const uuid8SuffixLocation = replaceByIndex(uuid8Suffix, 20, 22, options.location);
80
- const uuid8SuffixLocationShard = replaceByIndex(uuid8SuffixLocation, 22, 23, options.shardType);
73
+ const uuid8Suffix = Helpers.replaceByIndex(uuid8, 15, 18, options.suffix);
74
+ const uuid8SuffixLocation = Helpers.replaceByIndex(uuid8Suffix, 20, 22, options.location);
75
+ const uuid8SuffixLocationShard = Helpers.replaceByIndex(uuid8SuffixLocation, 22, 23, options.shardType);
81
76
  return uuid8SuffixLocationShard;
82
77
  }
83
78
  export default v8;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -93,5 +93,5 @@
93
93
  "@cloudflare/workers-types": "^4.20250910.0",
94
94
  "@types/node": "^22.18.1"
95
95
  },
96
- "gitHead": "c20b4ff8bb19d397282f183966fb7e45a6d9942d"
96
+ "gitHead": "1cb8770950dfb9b294ada5352427cca884fd27bb"
97
97
  }