hanzio 1.2.0 → 2.0.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.
Files changed (145) hide show
  1. package/README.md +786 -239
  2. package/dist/api-wrapper/builders.d.ts +4 -3
  3. package/dist/api-wrapper/create-client.d.ts +1 -1
  4. package/dist/api-wrapper/describe.d.ts +16 -0
  5. package/dist/api-wrapper/endpoint.d.ts +18 -0
  6. package/dist/api-wrapper/errors.d.ts +39 -2
  7. package/dist/api-wrapper/index.d.ts +5 -0
  8. package/dist/api-wrapper/otel.d.ts +44 -0
  9. package/dist/api-wrapper/paginate.d.ts +12 -0
  10. package/dist/api-wrapper/redaction.d.ts +2 -0
  11. package/dist/api-wrapper/shared.d.ts +16 -2
  12. package/dist/api-wrapper/testing.d.ts +23 -0
  13. package/dist/api-wrapper/transport.d.ts +4 -5
  14. package/dist/api-wrapper/types.d.ts +103 -18
  15. package/dist/array/index.d.ts +50 -4
  16. package/dist/cache/createCache.d.ts +31 -0
  17. package/dist/cache/index.d.ts +19 -2
  18. package/dist/color/contrast.d.ts +40 -0
  19. package/dist/color/index.d.ts +2 -0
  20. package/dist/{math → color}/metricsSeriesColors.d.ts +14 -7
  21. package/dist/cool-console-log/index.d.ts +34 -5
  22. package/dist/crypto/encoding.d.ts +18 -0
  23. package/dist/crypto/hash.d.ts +33 -0
  24. package/dist/crypto/index.d.ts +4 -0
  25. package/dist/crypto/sealer.d.ts +25 -0
  26. package/dist/crypto/webhook.d.ts +20 -0
  27. package/dist/date/index.d.ts +46 -2
  28. package/dist/emitter/index.d.ts +21 -0
  29. package/dist/error/index.d.ts +12 -0
  30. package/dist/format/index.d.ts +102 -0
  31. package/dist/function/index.d.ts +60 -0
  32. package/dist/guard/index.d.ts +20 -0
  33. package/dist/i18n/index.d.ts +37 -0
  34. package/dist/index-0zvtcbzy.js +224 -0
  35. package/dist/index-181e6vfw.js +29 -0
  36. package/dist/index-8r2vdzjg.js +87 -0
  37. package/dist/index-hy7kbb99.js +157 -0
  38. package/dist/{src/secrets/infisical.js → index-j1ybktbr.js} +500 -538
  39. package/dist/index-k9yx6bne.js +89 -0
  40. package/dist/index-kj1phgrx.js +169 -0
  41. package/dist/index-mnkcfyx8.js +78 -0
  42. package/dist/{p-queue/index.js → index-pwt0dz63.js} +7 -11
  43. package/dist/index-rp5pqghz.js +157 -0
  44. package/dist/index-srt06xd2.js +15 -0
  45. package/dist/index-wjyb9bsd.js +263 -0
  46. package/dist/index.d.ts +7 -7
  47. package/dist/jwt/index.d.ts +50 -2
  48. package/dist/math/index.d.ts +2 -2
  49. package/dist/math/linearRegressionTrend.d.ts +14 -1
  50. package/dist/math/scale.d.ts +8 -0
  51. package/dist/object/index.d.ts +19 -0
  52. package/dist/p-queue/index.d.ts +1 -1
  53. package/dist/promise/index.d.ts +97 -2
  54. package/dist/sitemap/index.d.ts +48 -6
  55. package/dist/src/api-wrapper/index.js +60 -1130
  56. package/dist/src/api-wrapper/testing.js +20 -0
  57. package/dist/{cool-console-log → src/cool-console-log}/index.js +80 -33
  58. package/dist/src/crypto/index.js +195 -0
  59. package/dist/src/format/index.js +211 -0
  60. package/dist/src/i18n/index.js +36 -0
  61. package/dist/src/index.js +739 -3145
  62. package/dist/src/jwt/index.js +138 -92
  63. package/dist/src/p-queue/index.js +9 -437
  64. package/dist/src/secrets/index.js +44 -1428
  65. package/dist/src/secrets/vite.js +6 -39
  66. package/dist/src/secrets/worker.js +10 -273
  67. package/dist/src/sitemap/index.js +183 -511
  68. package/dist/src/storage/index.js +119 -0
  69. package/dist/src/zod/index.js +340 -167
  70. package/dist/state/index.d.ts +21 -0
  71. package/dist/storage/index.d.ts +58 -0
  72. package/dist/string/index.d.ts +75 -2
  73. package/dist/typedswitch/index.d.ts +31 -24
  74. package/dist/types/index.d.ts +11 -0
  75. package/dist/url/index.d.ts +50 -1
  76. package/dist/zod/index.d.ts +32 -3
  77. package/dist/zod/introspect.d.ts +19 -0
  78. package/dist/zod/jsonToZodSchemaMapper.d.ts +3 -1
  79. package/dist/zod/zodMinMaxFilter.d.ts +22 -3
  80. package/dist/zod/zodToTypeString.d.ts +8 -3
  81. package/package.json +78 -7
  82. package/src/api-wrapper/actions-impl.ts +11 -72
  83. package/src/api-wrapper/builders.ts +32 -25
  84. package/src/api-wrapper/create-client.ts +171 -41
  85. package/src/api-wrapper/describe.ts +157 -0
  86. package/src/api-wrapper/endpoint.ts +26 -0
  87. package/src/api-wrapper/error-reporting.ts +7 -1
  88. package/src/api-wrapper/errors.ts +107 -2
  89. package/src/api-wrapper/headers.ts +11 -6
  90. package/src/api-wrapper/index.ts +5 -0
  91. package/src/api-wrapper/otel.ts +139 -0
  92. package/src/api-wrapper/paginate.ts +28 -0
  93. package/src/api-wrapper/redaction.ts +42 -0
  94. package/src/api-wrapper/shared.ts +21 -2
  95. package/src/api-wrapper/testing.ts +48 -0
  96. package/src/api-wrapper/transport.ts +41 -43
  97. package/src/api-wrapper/types.ts +185 -18
  98. package/src/array/index.ts +195 -42
  99. package/src/cache/createCache.ts +157 -0
  100. package/src/cache/index.ts +132 -147
  101. package/src/color/contrast.ts +163 -0
  102. package/src/color/index.ts +22 -0
  103. package/src/{math → color}/metricsSeriesColors.ts +47 -49
  104. package/src/cool-console-log/index.ts +128 -41
  105. package/src/crypto/encoding.ts +83 -0
  106. package/src/crypto/hash.ts +170 -0
  107. package/src/crypto/index.ts +26 -0
  108. package/src/crypto/sealer.ts +168 -0
  109. package/src/crypto/webhook.ts +86 -0
  110. package/src/date/index.ts +109 -34
  111. package/src/emitter/index.ts +82 -0
  112. package/src/error/index.ts +63 -0
  113. package/src/format/index.ts +389 -0
  114. package/src/function/index.ts +201 -0
  115. package/src/guard/index.ts +80 -0
  116. package/src/i18n/index.ts +125 -0
  117. package/src/index.ts +11 -7
  118. package/src/jwt/index.ts +199 -125
  119. package/src/math/index.ts +5 -10
  120. package/src/math/linearRegressionTrend.ts +33 -8
  121. package/src/math/scale.ts +17 -0
  122. package/src/object/index.ts +99 -0
  123. package/src/p-queue/index.ts +2 -0
  124. package/src/promise/index.ts +304 -9
  125. package/src/sitemap/index.ts +293 -130
  126. package/src/state/index.ts +133 -81
  127. package/src/storage/index.ts +187 -0
  128. package/src/string/index.ts +261 -23
  129. package/src/typedswitch/index.ts +58 -38
  130. package/src/types/index.ts +14 -0
  131. package/src/url/index.ts +146 -1
  132. package/src/zod/index.ts +105 -9
  133. package/src/zod/introspect.ts +103 -0
  134. package/src/zod/jsonToZodSchemaMapper.ts +44 -21
  135. package/src/zod/zodMinMaxFilter.ts +37 -13
  136. package/src/zod/zodToTypeString.ts +184 -181
  137. package/dist/api-wrapper/index.js +0 -250
  138. package/dist/gzip/index.d.ts +0 -2
  139. package/dist/gzip/index.js +0 -16
  140. package/dist/index.js +0 -1823
  141. package/dist/jwt/index.js +0 -19
  142. package/dist/sitemap/index.js +0 -552
  143. package/dist/src/gzip/index.js +0 -16
  144. package/dist/src/secrets/loaders.js +0 -1529
  145. package/dist/zod/index.js +0 -210
@@ -0,0 +1,89 @@
1
+ // src/cache/createCache.ts
2
+ function createCache2(options = {}) {
3
+ const {
4
+ defaultTtlMs,
5
+ staleMarginMs: defaultStaleMarginMs = 0,
6
+ maxEntries,
7
+ now = Date.now
8
+ } = options;
9
+ const store = new Map;
10
+ const fill = (entry, value, startedAt, setOptions = {}) => {
11
+ const { ttlMs = defaultTtlMs, staleMarginMs = defaultStaleMarginMs } = setOptions;
12
+ const ttl = typeof ttlMs === "function" ? ttlMs(value) : ttlMs;
13
+ entry.value = value;
14
+ entry.hasValue = true;
15
+ entry.expiresAt = ttl === undefined ? undefined : startedAt + ttl;
16
+ entry.refreshAt = entry.expiresAt === undefined ? undefined : entry.expiresAt - staleMarginMs;
17
+ return entry;
18
+ };
19
+ const isExpired = (entry) => entry.expiresAt !== undefined && entry.expiresAt <= now();
20
+ const hasFreshValue = (entry) => entry?.hasValue === true && !isExpired(entry);
21
+ const touch = (key, entry) => {
22
+ store.delete(key);
23
+ store.set(key, entry);
24
+ if (maxEntries !== undefined) {
25
+ while (store.size > maxEntries) {
26
+ store.delete(store.keys().next().value);
27
+ }
28
+ }
29
+ };
30
+ const read = (key) => {
31
+ const entry = store.get(key);
32
+ if (!entry)
33
+ return;
34
+ if (isExpired(entry) && !entry.inflight) {
35
+ store.delete(key);
36
+ return;
37
+ }
38
+ touch(key, entry);
39
+ return entry;
40
+ };
41
+ return {
42
+ async getOrSet(key, fn, setOptions) {
43
+ const existing = read(key);
44
+ if (existing?.inflight)
45
+ return existing.inflight;
46
+ const isStale = existing?.refreshAt !== undefined && existing.refreshAt <= now();
47
+ if (existing?.hasValue && !isStale)
48
+ return existing.value;
49
+ const entry = existing ?? { hasValue: false };
50
+ const startedAt = now();
51
+ const promise = (async () => fn())();
52
+ entry.inflight = promise;
53
+ touch(key, entry);
54
+ try {
55
+ const value = await promise;
56
+ fill(entry, value, startedAt, setOptions);
57
+ return value;
58
+ } catch (error) {
59
+ if (!hasFreshValue(entry) && store.get(key) === entry) {
60
+ store.delete(key);
61
+ }
62
+ throw error;
63
+ } finally {
64
+ entry.inflight = undefined;
65
+ }
66
+ },
67
+ get(key) {
68
+ const entry = read(key);
69
+ return hasFreshValue(entry) ? entry?.value : undefined;
70
+ },
71
+ has(key) {
72
+ return hasFreshValue(read(key));
73
+ },
74
+ set(key, value, setOptions) {
75
+ touch(key, fill({ hasValue: false }, value, now(), setOptions));
76
+ },
77
+ delete(key) {
78
+ store.delete(key);
79
+ },
80
+ clear() {
81
+ store.clear();
82
+ },
83
+ get size() {
84
+ return store.size;
85
+ }
86
+ };
87
+ }
88
+
89
+ export { createCache2 };
@@ -0,0 +1,169 @@
1
+ // src/string/index.ts
2
+ function extractNumber2(value, options = {}) {
3
+ const { decimalSeparator = "." } = options;
4
+ const decimal = decimalSeparator === "." ? "\\." : ",";
5
+ const thousands = decimalSeparator === "." ? "," : "\\.";
6
+ const token = value?.match(new RegExp(`-?(?:\\d+(?:(?:${thousands}|\\s)\\d{3}(?!\\d))*(?:${decimal}\\d+)?|${decimal}\\d+)`))?.[0];
7
+ if (!token)
8
+ return;
9
+ const parsedNumber = Number.parseFloat(token.replace(/\s/g, "").replaceAll(decimalSeparator === "." ? "," : ".", "").replace(decimalSeparator, "."));
10
+ return Number.isNaN(parsedNumber) ? undefined : parsedNumber;
11
+ }
12
+ function generateId2(input) {
13
+ const data = normalizeIdInput(input);
14
+ let hash = 0;
15
+ for (let index = 0;index < data.length; index++) {
16
+ const char = data.charCodeAt(index);
17
+ hash = (hash << 5) - hash + char;
18
+ hash |= 0;
19
+ }
20
+ return Math.abs(hash).toString(16).padStart(8, "0");
21
+ }
22
+ async function sha256Id2(input, length = 16) {
23
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(normalizeIdInput(input)));
24
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, length);
25
+ }
26
+ var UNDECOMPOSED_LETTERS = {
27
+ æ: "ae",
28
+ Æ: "AE",
29
+ ø: "o",
30
+ Ø: "O",
31
+ œ: "oe",
32
+ Œ: "OE",
33
+ ß: "ss",
34
+ ẞ: "SS",
35
+ đ: "d",
36
+ Đ: "D",
37
+ ł: "l",
38
+ Ł: "L",
39
+ þ: "th",
40
+ Þ: "TH",
41
+ ð: "d",
42
+ Ð: "D"
43
+ };
44
+ function stripAccents(value) {
45
+ return value.normalize("NFKD").replace(/\p{M}/gu, "").replace(/[æøœßđłþðÆØŒẞĐŁÞÐ]/g, (letter) => UNDECOMPOSED_LETTERS[letter] ?? "");
46
+ }
47
+ function slugify2(value, options = {}) {
48
+ const { separator = "-", lowercase = true, maxLength } = options;
49
+ const slug = stripAccents(value).replace(/&/g, " and ").replace(/[\s\-_/,:;·]+/g, " ").replace(/[^a-zA-Z0-9 ]/g, "").trim().split(/ +/).join(separator);
50
+ const cased = lowercase ? slug.toLowerCase() : slug;
51
+ if (maxLength === undefined || cased.length <= maxLength)
52
+ return cased;
53
+ return cased.slice(0, maxLength).replace(/[^a-zA-Z0-9]+$/, "");
54
+ }
55
+ function stableStringify2(value) {
56
+ return JSON.stringify(value, (_key, item) => {
57
+ if (typeof item === "bigint")
58
+ return `${item}n`;
59
+ if (item instanceof Map)
60
+ return { $map: [...item.entries()] };
61
+ if (item instanceof Set)
62
+ return { $set: [...item] };
63
+ if (item && typeof item === "object" && !Array.isArray(item)) {
64
+ const record = item;
65
+ return Object.fromEntries(Object.keys(record).sort().map((key) => [key, record[key]]));
66
+ }
67
+ return item;
68
+ }) ?? "undefined";
69
+ }
70
+ function truncate2(text, maxLength, options = {}) {
71
+ const { ellipsis = "…", wordBoundary = false } = options;
72
+ const characters = graphemes(text);
73
+ if (characters.length <= maxLength)
74
+ return text;
75
+ const ellipsisCharacters = graphemes(ellipsis);
76
+ const room = maxLength - ellipsisCharacters.length;
77
+ if (room <= 0)
78
+ return ellipsisCharacters.slice(0, maxLength).join("");
79
+ let cut = characters.slice(0, room).join("");
80
+ if (wordBoundary && !/^\s/.test(characters[room] ?? "")) {
81
+ const lastSpace = cut.search(/\s\S*$/);
82
+ if (lastSpace > 0)
83
+ cut = cut.slice(0, lastSpace);
84
+ }
85
+ return cut.trimEnd() + ellipsis;
86
+ }
87
+ function normalizeWhitespace2(text) {
88
+ return text.replace(/\s+/g, " ").trim();
89
+ }
90
+ function escapeRegExp2(text) {
91
+ return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&").replace(/-/g, "\\x2d");
92
+ }
93
+ function foldForSearch2(text) {
94
+ return stripAccents(text).toLowerCase();
95
+ }
96
+ function matchesSearch2(query, ...fields) {
97
+ const haystack = foldForSearch2(fields.filter(Boolean).join(`
98
+ `));
99
+ return foldForSearch2(query).split(/\s+/).every((term) => haystack.includes(term));
100
+ }
101
+ var HAS_LETTER = /\p{L}/u;
102
+ function initials2(name, options = {}) {
103
+ const { max = 2 } = options;
104
+ const trimmed = name?.trim() ?? "";
105
+ const source = /^[^\s@]+@[^\s@]+$/.test(trimmed) ? (trimmed.split("@")[0] ?? "").replace(/\+.*$/, "").replace(/[._-]+/g, " ") : trimmed;
106
+ const words = source.split(/\s+/).filter((word) => HAS_LETTER.test(word));
107
+ const first = words[0];
108
+ if (!first)
109
+ return "";
110
+ if (words.length === 1)
111
+ return fromFirstLetter(first, max).toUpperCase();
112
+ const head = words.slice(0, Math.max(1, max - 1));
113
+ const picked = words.length > max ? [...head, words.at(-1) ?? first].slice(0, max) : words;
114
+ return picked.map((word) => fromFirstLetter(word, 1)).join("").toUpperCase();
115
+ }
116
+ function safeJsonParse2(text) {
117
+ try {
118
+ return { ok: true, data: JSON.parse(text), error: null };
119
+ } catch (error) {
120
+ return { ok: false, data: null, error };
121
+ }
122
+ }
123
+ function fromFirstLetter(word, count) {
124
+ const characters = graphemes(word);
125
+ const start = characters.findIndex((character) => HAS_LETTER.test(character));
126
+ if (start === -1)
127
+ return "";
128
+ return characters.slice(start, start + count).join("");
129
+ }
130
+ var segmenter;
131
+ function graphemes(text) {
132
+ if (typeof Intl === "undefined" || !("Segmenter" in Intl))
133
+ return [...text];
134
+ segmenter ??= new Intl.Segmenter;
135
+ return Array.from(segmenter.segment(text), ({ segment }) => segment);
136
+ }
137
+ function normalizeIdInput(input) {
138
+ if (input === undefined)
139
+ return "undefined";
140
+ if (input === null)
141
+ return "null";
142
+ if (typeof input === "string") {
143
+ return safeDecodeURIComponent(input).split("&").sort().join("&");
144
+ }
145
+ if (typeof input === "number" || typeof input === "boolean") {
146
+ return input.toString();
147
+ }
148
+ return JSON.stringify(sortJsonValue(input));
149
+ }
150
+ function sortJsonValue(value) {
151
+ if (value === undefined)
152
+ return null;
153
+ if (Array.isArray(value)) {
154
+ return value.map((item) => sortJsonValue(item));
155
+ }
156
+ if (typeof value === "object" && value !== null) {
157
+ return Object.fromEntries(Object.entries(value).filter(([, itemValue]) => itemValue !== undefined).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)).map(([key, itemValue]) => [key, sortJsonValue(itemValue)]));
158
+ }
159
+ return value;
160
+ }
161
+ function safeDecodeURIComponent(value) {
162
+ try {
163
+ return decodeURIComponent(value);
164
+ } catch {
165
+ return value;
166
+ }
167
+ }
168
+
169
+ export { extractNumber2, generateId2, sha256Id2, slugify2, stableStringify2, truncate2, normalizeWhitespace2, escapeRegExp2, foldForSearch2, matchesSearch2, initials2, safeJsonParse2 };
@@ -0,0 +1,78 @@
1
+ // src/url/index.ts
2
+ function buildQueryString2(params, options = {}) {
3
+ const pairs = [];
4
+ for (const [key, value] of Object.entries(params)) {
5
+ const values = Array.isArray(value) ? value : [value];
6
+ for (const item of values) {
7
+ if (item != null)
8
+ pairs.push([key, String(item)]);
9
+ }
10
+ }
11
+ if (options.encode === false) {
12
+ return pairs.map(([key, value]) => `${key}=${value}`).join("&");
13
+ }
14
+ return new URLSearchParams(pairs).toString();
15
+ }
16
+ function replacePathParams2(path, params = {}) {
17
+ return path.replace(/:([A-Za-z_]\w*)/g, (_, key) => {
18
+ const value = params[key];
19
+ if (value === undefined) {
20
+ throw new Error(`Missing required path parameter: ${key}`);
21
+ }
22
+ return encodeURIComponent(String(value));
23
+ });
24
+ }
25
+ function buildUrl2(base, path = "", options = {}) {
26
+ const joined = path ? `${trimTrailingSlash2(base)}/${path.replace(/^\/+/, "")}` : base;
27
+ const url = replacePathParams2(joined, options.params);
28
+ const query = options.query ? buildQueryString2(options.query) : "";
29
+ if (!query)
30
+ return url;
31
+ return `${url}${url.includes("?") ? "&" : "?"}${query}`;
32
+ }
33
+ function normalizeDomain2(input) {
34
+ const trimmed = input.trim();
35
+ const withScheme = /^[a-z][a-z\d+.-]*:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
36
+ return new URL(withScheme).origin;
37
+ }
38
+ function getDomainFaviconUrl2(domainOrUrl, size = 128) {
39
+ let domain = domainOrUrl;
40
+ try {
41
+ if (/^[a-z][a-z\d+.-]*:\/\//i.test(domainOrUrl)) {
42
+ domain = new URL(domainOrUrl).hostname;
43
+ }
44
+ } catch {}
45
+ return `https://www.google.com/s2/favicons?domain=${encodeURIComponent(domain)}&sz=${size}`;
46
+ }
47
+ function trimTrailingSlash2(url) {
48
+ return url.replace(/\/+$/, "");
49
+ }
50
+ function ensureLeadingSlash2(path) {
51
+ return path.startsWith("/") ? path : `/${path}`;
52
+ }
53
+ function buildMailto2(options) {
54
+ const { to, cc, bcc, subject, body } = options;
55
+ const headers = Object.entries({
56
+ cc: cc && recipients(cc),
57
+ bcc: bcc && recipients(bcc),
58
+ subject: subject && encodeURIComponent(subject),
59
+ body: body && encodeURIComponent(body.replace(/\r?\n/g, `\r
60
+ `))
61
+ }).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
62
+ return `mailto:${to ? recipients(to) : ""}${headers ? `?${headers}` : ""}`;
63
+ }
64
+ function recipients(value) {
65
+ return (typeof value === "string" ? [value] : value).map((address) => encodeURIComponent(address.trim()).replace(/%40/g, "@")).join(",");
66
+ }
67
+ function parseRetryAfter2(value, now = Date.now()) {
68
+ const trimmed = value?.trim();
69
+ if (!trimmed)
70
+ return;
71
+ if (/^-?\d*\.?\d+$/.test(trimmed)) {
72
+ return Math.max(0, Number(trimmed) * 1000);
73
+ }
74
+ const date = Date.parse(trimmed);
75
+ return Number.isNaN(date) ? undefined : Math.max(0, date - now);
76
+ }
77
+
78
+ export { buildQueryString2, replacePathParams2, buildUrl2, normalizeDomain2, getDomainFaviconUrl2, trimTrailingSlash2, ensureLeadingSlash2, buildMailto2, parseRetryAfter2 };
@@ -1,12 +1,12 @@
1
1
  // src/p-queue/index.ts
2
- class TimeoutError extends Error {
2
+ class TimeoutError2 extends Error {
3
3
  constructor(message) {
4
4
  super(message);
5
5
  this.name = "TimeoutError";
6
6
  }
7
7
  }
8
8
 
9
- class PriorityQueue {
9
+ class PriorityQueue2 {
10
10
  #queue = [];
11
11
  enqueue(run, options = {}) {
12
12
  const element = {
@@ -28,7 +28,7 @@ class PriorityQueue {
28
28
  return this.#queue.filter((item) => Object.entries(options).every(([key, value]) => item[key] === value)).map((item) => item.run);
29
29
  }
30
30
  setPriority(id, priority) {
31
- const index = this.#queue.findIndex((item2) => item2.id === id);
31
+ const index = this.#queue.findIndex((item) => item.id === id);
32
32
  if (index === -1) {
33
33
  throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
34
34
  }
@@ -46,7 +46,7 @@ class PriorityQueue {
46
46
  }
47
47
  }
48
48
 
49
- class PQueue {
49
+ class PQueue2 {
50
50
  #listeners = new Map;
51
51
  #queue;
52
52
  #queueClass;
@@ -69,7 +69,7 @@ class PQueue {
69
69
  const {
70
70
  concurrency = Number.POSITIVE_INFINITY,
71
71
  autoStart = true,
72
- queueClass = PriorityQueue,
72
+ queueClass = PriorityQueue2,
73
73
  intervalCap = Number.POSITIVE_INFINITY,
74
74
  interval = 0,
75
75
  carryoverIntervalCount,
@@ -321,7 +321,7 @@ class PQueue {
321
321
  if (options.timeout) {
322
322
  races.push(new Promise((_resolve, reject) => {
323
323
  timeoutId = setTimeout(() => {
324
- reject(new TimeoutError(`Task timed out after ${options.timeout}ms`));
324
+ reject(new TimeoutError2(`Task timed out after ${options.timeout}ms`));
325
325
  }, options.timeout);
326
326
  }));
327
327
  }
@@ -432,8 +432,4 @@ class PQueue {
432
432
  }
433
433
  }
434
434
  }
435
- export {
436
- PQueue as default,
437
- TimeoutError,
438
- PriorityQueue
439
- };
435
+ export { TimeoutError2, PriorityQueue2, PQueue2 };
@@ -0,0 +1,157 @@
1
+ // src/crypto/encoding.ts
2
+ var BYTE_CHUNK_SIZE = 32768;
3
+ var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
4
+ var BASE64URL = /^[A-Za-z0-9_-]*={0,2}$/;
5
+ var HEX = /^(?:[0-9a-fA-F]{2})*$/;
6
+ var textEncoder = new TextEncoder;
7
+ var textDecoder = new TextDecoder;
8
+ function utf8Encode2(value) {
9
+ return textEncoder.encode(value);
10
+ }
11
+ function utf8Decode2(bytes) {
12
+ return textDecoder.decode(bytes);
13
+ }
14
+ function encodeBase642(bytes) {
15
+ const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
16
+ let binary = "";
17
+ for (let offset = 0;offset < view.length; offset += BYTE_CHUNK_SIZE) {
18
+ binary += String.fromCharCode(...view.subarray(offset, offset + BYTE_CHUNK_SIZE));
19
+ }
20
+ return btoa(binary);
21
+ }
22
+ function decodeBase642(value) {
23
+ if (!BASE64.test(value))
24
+ throw new TypeError("Invalid base64 string");
25
+ const unpadded = value.replace(/=+$/, "");
26
+ if (unpadded.length % 4 === 1)
27
+ throw new TypeError("Invalid base64 string");
28
+ const binary = atob(unpadded.padEnd(Math.ceil(unpadded.length / 4) * 4, "="));
29
+ const bytes = new Uint8Array(binary.length);
30
+ for (let index = 0;index < binary.length; index += 1) {
31
+ bytes[index] = binary.charCodeAt(index);
32
+ }
33
+ return bytes;
34
+ }
35
+ function encodeBase64Url2(bytes) {
36
+ return encodeBase642(bytes).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
37
+ }
38
+ function decodeBase64Url2(value) {
39
+ if (!BASE64URL.test(value))
40
+ throw new TypeError("Invalid base64url string");
41
+ return decodeBase642(value.replaceAll("-", "+").replaceAll("_", "/"));
42
+ }
43
+ function bytesToHex2(bytes) {
44
+ const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
45
+ let hex = "";
46
+ for (const byte of view)
47
+ hex += byte.toString(16).padStart(2, "0");
48
+ return hex;
49
+ }
50
+ function hexToBytes2(value) {
51
+ if (!HEX.test(value))
52
+ throw new TypeError("Invalid hex string");
53
+ const bytes = new Uint8Array(value.length / 2);
54
+ for (let index = 0;index < bytes.length; index += 1) {
55
+ bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
56
+ }
57
+ return bytes;
58
+ }
59
+ function toBytes(data) {
60
+ if (typeof data === "string")
61
+ return utf8Encode2(data);
62
+ return data instanceof Uint8Array ? new Uint8Array(data) : new Uint8Array(data.slice(0));
63
+ }
64
+
65
+ // src/crypto/hash.ts
66
+ var HMAC_ALGORITHMS = ["SHA-256", "SHA-384", "SHA-512"];
67
+ var RANDOM_CHUNK_SIZE = 65536;
68
+ var ENCODERS = {
69
+ hex: bytesToHex2,
70
+ base64: encodeBase642,
71
+ base64url: encodeBase64Url2
72
+ };
73
+ var DECODERS = { hex: hexToBytes2, base64: decodeBase642, base64url: decodeBase64Url2 };
74
+ function safeEqual2(a, b) {
75
+ const left = typeof a === "string" ? utf8Encode2(a) : a;
76
+ const right = typeof b === "string" ? utf8Encode2(b) : b;
77
+ const length = Math.max(left.length, right.length);
78
+ let diff = left.length ^ right.length;
79
+ for (let index = 0;index < length; index += 1) {
80
+ diff |= (left[index] ?? 0) ^ (right[index] ?? 0);
81
+ }
82
+ return diff === 0;
83
+ }
84
+ function randomBytes2(byteLength) {
85
+ if (!Number.isSafeInteger(byteLength) || byteLength < 0) {
86
+ throw new RangeError("byteLength must be a non-negative integer");
87
+ }
88
+ const cryptoApi = globalThis.crypto;
89
+ if (!cryptoApi?.getRandomValues) {
90
+ throw new Error("Web Crypto is not available in this runtime");
91
+ }
92
+ const bytes = new Uint8Array(byteLength);
93
+ for (let offset = 0;offset < byteLength; offset += RANDOM_CHUNK_SIZE) {
94
+ cryptoApi.getRandomValues(bytes.subarray(offset, offset + RANDOM_CHUNK_SIZE));
95
+ }
96
+ return bytes;
97
+ }
98
+ function randomToken2(byteLength = 32) {
99
+ if (!Number.isSafeInteger(byteLength) || byteLength < 1) {
100
+ throw new RangeError("byteLength must be a positive integer");
101
+ }
102
+ return encodeBase64Url2(randomBytes2(byteLength));
103
+ }
104
+ async function sha2562(data) {
105
+ return new Uint8Array(await getSubtleCrypto().digest("SHA-256", toBytes(data)));
106
+ }
107
+ async function sha256Hex2(data) {
108
+ return bytesToHex2(await sha2562(data));
109
+ }
110
+ async function hmacSign2(secret, data, options = {}) {
111
+ const { algorithm = "SHA-256", encoding = "hex" } = options;
112
+ assertEncoding(encoding);
113
+ const key = await importHmacKey(secret, algorithm, "sign");
114
+ const signature = await getSubtleCrypto().sign("HMAC", key, toBytes(data));
115
+ return ENCODERS[encoding](new Uint8Array(signature));
116
+ }
117
+ async function verifyHmacSignature2(secret, data, signature, options = {}) {
118
+ const { algorithm = "SHA-256", encoding = "hex", prefix } = options;
119
+ assertEncoding(encoding);
120
+ const key = await importHmacKey(secret, algorithm, "verify");
121
+ let encoded = signature;
122
+ if (prefix !== undefined) {
123
+ if (!signature.startsWith(prefix))
124
+ return false;
125
+ encoded = signature.slice(prefix.length);
126
+ }
127
+ let received;
128
+ try {
129
+ received = DECODERS[encoding](encoded);
130
+ } catch (_error) {
131
+ return false;
132
+ }
133
+ return getSubtleCrypto().verify("HMAC", key, received, toBytes(data));
134
+ }
135
+ function importHmacKey(secret, algorithm, usage) {
136
+ if (!HMAC_ALGORITHMS.includes(algorithm)) {
137
+ throw new TypeError(`Unsupported HMAC algorithm: ${algorithm}`);
138
+ }
139
+ const keyBytes = toBytes(secret);
140
+ if (keyBytes.length === 0)
141
+ throw new TypeError("HMAC secret must not be empty");
142
+ return getSubtleCrypto().importKey("raw", keyBytes, { name: "HMAC", hash: algorithm }, false, [usage]);
143
+ }
144
+ function assertEncoding(encoding) {
145
+ if (!Object.hasOwn(ENCODERS, encoding)) {
146
+ throw new TypeError(`Unsupported signature encoding: ${encoding}`);
147
+ }
148
+ }
149
+ function getSubtleCrypto() {
150
+ const subtle = globalThis.crypto?.subtle;
151
+ if (!subtle) {
152
+ throw new Error("Web Crypto is not available in this runtime");
153
+ }
154
+ return subtle;
155
+ }
156
+
157
+ export { utf8Encode2, utf8Decode2, encodeBase642, decodeBase642, encodeBase64Url2, decodeBase64Url2, bytesToHex2, hexToBytes2, toBytes, safeEqual2, randomBytes2, randomToken2, sha2562, sha256Hex2, hmacSign2, verifyHmacSignature2, getSubtleCrypto };
@@ -0,0 +1,15 @@
1
+ // src/secrets/errors.ts
2
+ class SecretLoadError2 extends Error {
3
+ code;
4
+ operation;
5
+ status;
6
+ constructor(code, message, details = {}) {
7
+ super(message);
8
+ this.name = "SecretLoadError";
9
+ this.code = code;
10
+ this.operation = details.operation;
11
+ this.status = details.status;
12
+ }
13
+ }
14
+
15
+ export { SecretLoadError2 };