@nhtio/lucid-resourceful 1.20250718.2 → 1.20250724.0

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.
@@ -1,670 +0,0 @@
1
- "use strict";
2
- const Joi = require("joi");
3
- var DP = 20, RM = 1, MAX_DP = 1e6, MAX_POWER = 1e6, NE = -7, PE = 21, STRICT = false, NAME = "[big.js] ", INVALID = NAME + "Invalid ", INVALID_DP = INVALID + "decimal places", INVALID_RM = INVALID + "rounding mode", DIV_BY_ZERO = NAME + "Division by zero", P = {}, UNDEFINED = void 0, NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
4
- function _Big_() {
5
- function Big2(n) {
6
- var x = this;
7
- if (!(x instanceof Big2)) {
8
- return n === UNDEFINED && arguments.length === 0 ? _Big_() : new Big2(n);
9
- }
10
- if (n instanceof Big2) {
11
- x.s = n.s;
12
- x.e = n.e;
13
- x.c = n.c.slice();
14
- } else {
15
- if (typeof n !== "string") {
16
- if (Big2.strict === true && typeof n !== "bigint") {
17
- throw TypeError(INVALID + "value");
18
- }
19
- n = n === 0 && 1 / n < 0 ? "-0" : String(n);
20
- }
21
- parse(x, n);
22
- }
23
- x.constructor = Big2;
24
- }
25
- Big2.prototype = P;
26
- Big2.DP = DP;
27
- Big2.RM = RM;
28
- Big2.NE = NE;
29
- Big2.PE = PE;
30
- Big2.strict = STRICT;
31
- Big2.roundDown = 0;
32
- Big2.roundHalfUp = 1;
33
- Big2.roundHalfEven = 2;
34
- Big2.roundUp = 3;
35
- return Big2;
36
- }
37
- function parse(x, n) {
38
- var e, i, nl;
39
- if (!NUMERIC.test(n)) {
40
- throw Error(INVALID + "number");
41
- }
42
- x.s = n.charAt(0) == "-" ? (n = n.slice(1), -1) : 1;
43
- if ((e = n.indexOf(".")) > -1) n = n.replace(".", "");
44
- if ((i = n.search(/e/i)) > 0) {
45
- if (e < 0) e = i;
46
- e += +n.slice(i + 1);
47
- n = n.substring(0, i);
48
- } else if (e < 0) {
49
- e = n.length;
50
- }
51
- nl = n.length;
52
- for (i = 0; i < nl && n.charAt(i) == "0"; ) ++i;
53
- if (i == nl) {
54
- x.c = [x.e = 0];
55
- } else {
56
- for (; nl > 0 && n.charAt(--nl) == "0"; ) ;
57
- x.e = e - i - 1;
58
- x.c = [];
59
- for (e = 0; i <= nl; ) x.c[e++] = +n.charAt(i++);
60
- }
61
- return x;
62
- }
63
- function round(x, sd, rm, more) {
64
- var xc = x.c;
65
- if (rm === UNDEFINED) rm = x.constructor.RM;
66
- if (rm !== 0 && rm !== 1 && rm !== 2 && rm !== 3) {
67
- throw Error(INVALID_RM);
68
- }
69
- if (sd < 1) {
70
- more = rm === 3 && (more || !!xc[0]) || sd === 0 && (rm === 1 && xc[0] >= 5 || rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc[1] !== UNDEFINED)));
71
- xc.length = 1;
72
- if (more) {
73
- x.e = x.e - sd + 1;
74
- xc[0] = 1;
75
- } else {
76
- xc[0] = x.e = 0;
77
- }
78
- } else if (sd < xc.length) {
79
- more = rm === 1 && xc[sd] >= 5 || rm === 2 && (xc[sd] > 5 || xc[sd] === 5 && (more || xc[sd + 1] !== UNDEFINED || xc[sd - 1] & 1)) || rm === 3 && (more || !!xc[0]);
80
- xc.length = sd;
81
- if (more) {
82
- for (; ++xc[--sd] > 9; ) {
83
- xc[sd] = 0;
84
- if (sd === 0) {
85
- ++x.e;
86
- xc.unshift(1);
87
- break;
88
- }
89
- }
90
- }
91
- for (sd = xc.length; !xc[--sd]; ) xc.pop();
92
- }
93
- return x;
94
- }
95
- function stringify(x, doExponential, isNonzero) {
96
- var e = x.e, s = x.c.join(""), n = s.length;
97
- if (doExponential) {
98
- s = s.charAt(0) + (n > 1 ? "." + s.slice(1) : "") + (e < 0 ? "e" : "e+") + e;
99
- } else if (e < 0) {
100
- for (; ++e; ) s = "0" + s;
101
- s = "0." + s;
102
- } else if (e > 0) {
103
- if (++e > n) {
104
- for (e -= n; e--; ) s += "0";
105
- } else if (e < n) {
106
- s = s.slice(0, e) + "." + s.slice(e);
107
- }
108
- } else if (n > 1) {
109
- s = s.charAt(0) + "." + s.slice(1);
110
- }
111
- return x.s < 0 && isNonzero ? "-" + s : s;
112
- }
113
- P.abs = function() {
114
- var x = new this.constructor(this);
115
- x.s = 1;
116
- return x;
117
- };
118
- P.cmp = function(y) {
119
- var isneg, x = this, xc = x.c, yc = (y = new x.constructor(y)).c, i = x.s, j = y.s, k = x.e, l = y.e;
120
- if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i;
121
- if (i != j) return i;
122
- isneg = i < 0;
123
- if (k != l) return k > l ^ isneg ? 1 : -1;
124
- j = (k = xc.length) < (l = yc.length) ? k : l;
125
- for (i = -1; ++i < j; ) {
126
- if (xc[i] != yc[i]) return xc[i] > yc[i] ^ isneg ? 1 : -1;
127
- }
128
- return k == l ? 0 : k > l ^ isneg ? 1 : -1;
129
- };
130
- P.div = function(y) {
131
- var x = this, Big2 = x.constructor, a = x.c, b = (y = new Big2(y)).c, k = x.s == y.s ? 1 : -1, dp = Big2.DP;
132
- if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
133
- throw Error(INVALID_DP);
134
- }
135
- if (!b[0]) {
136
- throw Error(DIV_BY_ZERO);
137
- }
138
- if (!a[0]) {
139
- y.s = k;
140
- y.c = [y.e = 0];
141
- return y;
142
- }
143
- var bl, bt, n, cmp, ri, bz = b.slice(), ai = bl = b.length, al = a.length, r = a.slice(0, bl), rl = r.length, q = y, qc = q.c = [], qi = 0, p = dp + (q.e = x.e - y.e) + 1;
144
- q.s = k;
145
- k = p < 0 ? 0 : p;
146
- bz.unshift(0);
147
- for (; rl++ < bl; ) r.push(0);
148
- do {
149
- for (n = 0; n < 10; n++) {
150
- if (bl != (rl = r.length)) {
151
- cmp = bl > rl ? 1 : -1;
152
- } else {
153
- for (ri = -1, cmp = 0; ++ri < bl; ) {
154
- if (b[ri] != r[ri]) {
155
- cmp = b[ri] > r[ri] ? 1 : -1;
156
- break;
157
- }
158
- }
159
- }
160
- if (cmp < 0) {
161
- for (bt = rl == bl ? b : bz; rl; ) {
162
- if (r[--rl] < bt[rl]) {
163
- ri = rl;
164
- for (; ri && !r[--ri]; ) r[ri] = 9;
165
- --r[ri];
166
- r[rl] += 10;
167
- }
168
- r[rl] -= bt[rl];
169
- }
170
- for (; !r[0]; ) r.shift();
171
- } else {
172
- break;
173
- }
174
- }
175
- qc[qi++] = cmp ? n : ++n;
176
- if (r[0] && cmp) r[rl] = a[ai] || 0;
177
- else r = [a[ai]];
178
- } while ((ai++ < al || r[0] !== UNDEFINED) && k--);
179
- if (!qc[0] && qi != 1) {
180
- qc.shift();
181
- q.e--;
182
- p--;
183
- }
184
- if (qi > p) round(q, p, Big2.RM, r[0] !== UNDEFINED);
185
- return q;
186
- };
187
- P.eq = function(y) {
188
- return this.cmp(y) === 0;
189
- };
190
- P.gt = function(y) {
191
- return this.cmp(y) > 0;
192
- };
193
- P.gte = function(y) {
194
- return this.cmp(y) > -1;
195
- };
196
- P.lt = function(y) {
197
- return this.cmp(y) < 0;
198
- };
199
- P.lte = function(y) {
200
- return this.cmp(y) < 1;
201
- };
202
- P.minus = P.sub = function(y) {
203
- var i, j, t, xlty, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
204
- if (a != b) {
205
- y.s = -b;
206
- return x.plus(y);
207
- }
208
- var xc = x.c.slice(), xe = x.e, yc = y.c, ye = y.e;
209
- if (!xc[0] || !yc[0]) {
210
- if (yc[0]) {
211
- y.s = -b;
212
- } else if (xc[0]) {
213
- y = new Big2(x);
214
- } else {
215
- y.s = 1;
216
- }
217
- return y;
218
- }
219
- if (a = xe - ye) {
220
- if (xlty = a < 0) {
221
- a = -a;
222
- t = xc;
223
- } else {
224
- ye = xe;
225
- t = yc;
226
- }
227
- t.reverse();
228
- for (b = a; b--; ) t.push(0);
229
- t.reverse();
230
- } else {
231
- j = ((xlty = xc.length < yc.length) ? xc : yc).length;
232
- for (a = b = 0; b < j; b++) {
233
- if (xc[b] != yc[b]) {
234
- xlty = xc[b] < yc[b];
235
- break;
236
- }
237
- }
238
- }
239
- if (xlty) {
240
- t = xc;
241
- xc = yc;
242
- yc = t;
243
- y.s = -y.s;
244
- }
245
- if ((b = (j = yc.length) - (i = xc.length)) > 0) for (; b--; ) xc[i++] = 0;
246
- for (b = i; j > a; ) {
247
- if (xc[--j] < yc[j]) {
248
- for (i = j; i && !xc[--i]; ) xc[i] = 9;
249
- --xc[i];
250
- xc[j] += 10;
251
- }
252
- xc[j] -= yc[j];
253
- }
254
- for (; xc[--b] === 0; ) xc.pop();
255
- for (; xc[0] === 0; ) {
256
- xc.shift();
257
- --ye;
258
- }
259
- if (!xc[0]) {
260
- y.s = 1;
261
- xc = [ye = 0];
262
- }
263
- y.c = xc;
264
- y.e = ye;
265
- return y;
266
- };
267
- P.mod = function(y) {
268
- var ygtx, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
269
- if (!y.c[0]) {
270
- throw Error(DIV_BY_ZERO);
271
- }
272
- x.s = y.s = 1;
273
- ygtx = y.cmp(x) == 1;
274
- x.s = a;
275
- y.s = b;
276
- if (ygtx) return new Big2(x);
277
- a = Big2.DP;
278
- b = Big2.RM;
279
- Big2.DP = Big2.RM = 0;
280
- x = x.div(y);
281
- Big2.DP = a;
282
- Big2.RM = b;
283
- return this.minus(x.times(y));
284
- };
285
- P.neg = function() {
286
- var x = new this.constructor(this);
287
- x.s = -x.s;
288
- return x;
289
- };
290
- P.plus = P.add = function(y) {
291
- var e, k, t, x = this, Big2 = x.constructor;
292
- y = new Big2(y);
293
- if (x.s != y.s) {
294
- y.s = -y.s;
295
- return x.minus(y);
296
- }
297
- var xe = x.e, xc = x.c, ye = y.e, yc = y.c;
298
- if (!xc[0] || !yc[0]) {
299
- if (!yc[0]) {
300
- if (xc[0]) {
301
- y = new Big2(x);
302
- } else {
303
- y.s = x.s;
304
- }
305
- }
306
- return y;
307
- }
308
- xc = xc.slice();
309
- if (e = xe - ye) {
310
- if (e > 0) {
311
- ye = xe;
312
- t = yc;
313
- } else {
314
- e = -e;
315
- t = xc;
316
- }
317
- t.reverse();
318
- for (; e--; ) t.push(0);
319
- t.reverse();
320
- }
321
- if (xc.length - yc.length < 0) {
322
- t = yc;
323
- yc = xc;
324
- xc = t;
325
- }
326
- e = yc.length;
327
- for (k = 0; e; xc[e] %= 10) k = (xc[--e] = xc[e] + yc[e] + k) / 10 | 0;
328
- if (k) {
329
- xc.unshift(k);
330
- ++ye;
331
- }
332
- for (e = xc.length; xc[--e] === 0; ) xc.pop();
333
- y.c = xc;
334
- y.e = ye;
335
- return y;
336
- };
337
- P.pow = function(n) {
338
- var x = this, one = new x.constructor("1"), y = one, isneg = n < 0;
339
- if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
340
- throw Error(INVALID + "exponent");
341
- }
342
- if (isneg) n = -n;
343
- for (; ; ) {
344
- if (n & 1) y = y.times(x);
345
- n >>= 1;
346
- if (!n) break;
347
- x = x.times(x);
348
- }
349
- return isneg ? one.div(y) : y;
350
- };
351
- P.prec = function(sd, rm) {
352
- if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
353
- throw Error(INVALID + "precision");
354
- }
355
- return round(new this.constructor(this), sd, rm);
356
- };
357
- P.round = function(dp, rm) {
358
- if (dp === UNDEFINED) dp = 0;
359
- else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) {
360
- throw Error(INVALID_DP);
361
- }
362
- return round(new this.constructor(this), dp + this.e + 1, rm);
363
- };
364
- P.sqrt = function() {
365
- var r, c, t, x = this, Big2 = x.constructor, s = x.s, e = x.e, half = new Big2("0.5");
366
- if (!x.c[0]) return new Big2(x);
367
- if (s < 0) {
368
- throw Error(NAME + "No square root");
369
- }
370
- s = Math.sqrt(+stringify(x, true, true));
371
- if (s === 0 || s === 1 / 0) {
372
- c = x.c.join("");
373
- if (!(c.length + e & 1)) c += "0";
374
- s = Math.sqrt(c);
375
- e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
376
- r = new Big2((s == 1 / 0 ? "5e" : (s = s.toExponential()).slice(0, s.indexOf("e") + 1)) + e);
377
- } else {
378
- r = new Big2(s + "");
379
- }
380
- e = r.e + (Big2.DP += 4);
381
- do {
382
- t = r;
383
- r = half.times(t.plus(x.div(t)));
384
- } while (t.c.slice(0, e).join("") !== r.c.slice(0, e).join(""));
385
- return round(r, (Big2.DP -= 4) + r.e + 1, Big2.RM);
386
- };
387
- P.times = P.mul = function(y) {
388
- var c, x = this, Big2 = x.constructor, xc = x.c, yc = (y = new Big2(y)).c, a = xc.length, b = yc.length, i = x.e, j = y.e;
389
- y.s = x.s == y.s ? 1 : -1;
390
- if (!xc[0] || !yc[0]) {
391
- y.c = [y.e = 0];
392
- return y;
393
- }
394
- y.e = i + j;
395
- if (a < b) {
396
- c = xc;
397
- xc = yc;
398
- yc = c;
399
- j = a;
400
- a = b;
401
- b = j;
402
- }
403
- for (c = new Array(j = a + b); j--; ) c[j] = 0;
404
- for (i = b; i--; ) {
405
- b = 0;
406
- for (j = a + i; j > i; ) {
407
- b = c[j] + yc[i] * xc[j - i - 1] + b;
408
- c[j--] = b % 10;
409
- b = b / 10 | 0;
410
- }
411
- c[j] = b;
412
- }
413
- if (b) ++y.e;
414
- else c.shift();
415
- for (i = c.length; !c[--i]; ) c.pop();
416
- y.c = c;
417
- return y;
418
- };
419
- P.toExponential = function(dp, rm) {
420
- var x = this, n = x.c[0];
421
- if (dp !== UNDEFINED) {
422
- if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
423
- throw Error(INVALID_DP);
424
- }
425
- x = round(new x.constructor(x), ++dp, rm);
426
- for (; x.c.length < dp; ) x.c.push(0);
427
- }
428
- return stringify(x, true, !!n);
429
- };
430
- P.toFixed = function(dp, rm) {
431
- var x = this, n = x.c[0];
432
- if (dp !== UNDEFINED) {
433
- if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
434
- throw Error(INVALID_DP);
435
- }
436
- x = round(new x.constructor(x), dp + x.e + 1, rm);
437
- for (dp = dp + x.e + 1; x.c.length < dp; ) x.c.push(0);
438
- }
439
- return stringify(x, false, !!n);
440
- };
441
- P.toJSON = P.toString = function() {
442
- var x = this, Big2 = x.constructor;
443
- return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, !!x.c[0]);
444
- };
445
- if (typeof Symbol !== "undefined") {
446
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toJSON;
447
- }
448
- P.toNumber = function() {
449
- var n = +stringify(this, true, true);
450
- if (this.constructor.strict === true && !this.eq(n.toString())) {
451
- throw Error(NAME + "Imprecise conversion");
452
- }
453
- return n;
454
- };
455
- P.toPrecision = function(sd, rm) {
456
- var x = this, Big2 = x.constructor, n = x.c[0];
457
- if (sd !== UNDEFINED) {
458
- if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
459
- throw Error(INVALID + "precision");
460
- }
461
- x = round(new Big2(x), sd, rm);
462
- for (; x.c.length < sd; ) x.c.push(0);
463
- }
464
- return stringify(x, sd <= x.e || x.e <= Big2.NE || x.e >= Big2.PE, !!n);
465
- };
466
- P.valueOf = function() {
467
- var x = this, Big2 = x.constructor;
468
- if (Big2.strict === true) {
469
- throw Error(NAME + "valueOf disallowed");
470
- }
471
- return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, true);
472
- };
473
- var Big = _Big_();
474
- const Big$1 = Big;
475
- const compare = (value, limit, operator) => {
476
- switch (operator) {
477
- case ">":
478
- return value.gt(limit);
479
- case "<":
480
- return value.lt(limit);
481
- case ">=":
482
- return value.gte(limit);
483
- case "<=":
484
- return value.lte(limit);
485
- case "multiple":
486
- return value.mod(limit).eq(0);
487
- default:
488
- return false;
489
- }
490
- };
491
- const bigint = function(joi2) {
492
- return {
493
- type: "bigint",
494
- base: joi2.any(),
495
- coerce: {
496
- from: ["string", "number"],
497
- method(value, helpers) {
498
- if ("bigint" === typeof value) {
499
- return { value };
500
- }
501
- try {
502
- const asBig = Big$1(value.toString());
503
- if (asBig.eq(asBig.round(0))) {
504
- return { value: BigInt(asBig.toString()) };
505
- } else {
506
- return {
507
- value,
508
- errors: [
509
- helpers.error("bigint.base", {
510
- value: String(value)
511
- })
512
- ]
513
- };
514
- }
515
- } catch {
516
- return {
517
- value,
518
- errors: [
519
- helpers.error("bigint.base", {
520
- value: String(value)
521
- })
522
- ]
523
- };
524
- }
525
- }
526
- },
527
- messages: {
528
- "bigint.base": '"{{#label}}" must be a valid bigint',
529
- "bigint.greater": '"{{#label}}" must be greater than {{#limit}}',
530
- "bigint.less": '"{{#label}}" must be less than {{#limit}}',
531
- "bigint.max": '"{{#label}}" must be less than or equal to {{#limit}}',
532
- "bigint.min": '"{{#label}}" must be greater than or equal to {{#limit}}',
533
- "bigint.multiple": '"{{#label}}" must be a multiple of {{#limit}}',
534
- "bigint.negative": '"{{#label}}" must be a negative bigint',
535
- "bigint.positive": '"{{#label}}" must be a positive bigint'
536
- },
537
- validate(value, { error }) {
538
- if (typeof value === "bigint") {
539
- return { value };
540
- }
541
- return {
542
- value,
543
- errors: error("bigint.base", {
544
- value: String(value)
545
- })
546
- };
547
- },
548
- rules: {
549
- compare: {
550
- method: false,
551
- validate(value, helpers, { limit }, { name, operator }) {
552
- const big = Big$1(value.toString());
553
- const threshold = Big$1(limit.toString());
554
- const valid = compare(big, threshold, operator);
555
- if (valid) {
556
- return value;
557
- }
558
- return helpers.error("bigint." + name, {
559
- limit: limit.toString(),
560
- value: value.toString()
561
- });
562
- },
563
- args: [
564
- {
565
- name: "limit",
566
- ref: true,
567
- assert: (value) => typeof value === "bigint",
568
- message: "must be a bigint"
569
- }
570
- ]
571
- },
572
- /**
573
- * Validates that the BigInt is greater than the specified threshold
574
- * @param limit - The threshold value to compare against
575
- */
576
- greater: {
577
- method(limit) {
578
- return this.$_addRule({
579
- name: "greater",
580
- // @ts-ignore
581
- method: "compare",
582
- args: { limit },
583
- operator: ">"
584
- });
585
- }
586
- },
587
- /**
588
- * Validates that the BigInt is less than the specified threshold
589
- * @param limit - The threshold value to compare against
590
- */
591
- less: {
592
- method(limit) {
593
- return this.$_addRule({ name: "less", method: "compare", args: { limit }, operator: "<" });
594
- }
595
- },
596
- /**
597
- * Validates that the BigInt is less than or equal to the specified maximum
598
- * @param limit - The maximum allowed value
599
- */
600
- max: {
601
- method(limit) {
602
- return this.$_addRule({ name: "max", method: "compare", args: { limit }, operator: "<=" });
603
- }
604
- },
605
- /**
606
- * Validates that the BigInt is greater than or equal to the specified minimum
607
- * @param limit - The minimum allowed value
608
- */
609
- min: {
610
- method(limit) {
611
- return this.$_addRule({ name: "min", method: "compare", args: { limit }, operator: ">=" });
612
- }
613
- },
614
- /**
615
- * Validates that the BigInt is a multiple of the specified factor
616
- * @param limit - The factor that the value must be a multiple of
617
- */
618
- multiple: {
619
- method(limit) {
620
- return this.$_addRule({
621
- name: "multiple",
622
- // @ts-ignore
623
- method: "compare",
624
- args: { limit },
625
- operator: "multiple"
626
- });
627
- }
628
- },
629
- /**
630
- * Validates that the BigInt is negative (less than zero)
631
- */
632
- negative: {
633
- method() {
634
- return this.$_addRule("negative");
635
- },
636
- validate(value, helpers) {
637
- if (value >= 0n) {
638
- return helpers.error("bigint.negative", { value: value.toString() });
639
- }
640
- return value;
641
- }
642
- },
643
- /**
644
- * Validates that the BigInt is positive (greater than zero)
645
- */
646
- positive: {
647
- method() {
648
- return this.$_addRule("positive");
649
- },
650
- validate(value, helpers) {
651
- if (value <= 0n) {
652
- return helpers.error("bigint.positive", { value: value.toString() });
653
- }
654
- return value;
655
- }
656
- }
657
- },
658
- cast: {
659
- string: {
660
- from: (value) => typeof value === "bigint",
661
- to(value) {
662
- return value.toString();
663
- }
664
- }
665
- }
666
- };
667
- };
668
- const joi = Joi.extend(bigint);
669
- exports.joi = joi;
670
- //# sourceMappingURL=index-Cv6KC1rC.cjs.map