@cloudflare/workers-utils 0.41.0 → 0.41.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/{chunk-JTB7VJSC.mjs → chunk-IKXB77SR.mjs} +405 -454
- package/dist/chunk-OWXQB7GP.mjs +14968 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +318 -15276
- package/dist/metafile-esm.json +1 -1
- package/dist/test-helpers/index.mjs +1 -1
- package/dist/zod-format.d.mts +3 -3
- package/dist/zod-format.mjs +1 -1
- package/package.json +5 -6
- package/dist/chunk-7AX24RFK.mjs +0 -265
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatConfigSnippet, PATH_TO_DEPLOY_CONFIG, parseTOML, parseJSONC } from '../chunk-
|
|
1
|
+
import { formatConfigSnippet, PATH_TO_DEPLOY_CONFIG, parseTOML, parseJSONC } from '../chunk-IKXB77SR.mjs';
|
|
2
2
|
import '../chunk-MCNIGVAF.mjs';
|
|
3
3
|
import '../chunk-WO2IAW6M.mjs';
|
|
4
4
|
import { removeDir } from '../chunk-53IMCORZ.mjs';
|
package/dist/zod-format.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
declare function formatZodError(error: z.
|
|
3
|
+
/** Formats a Zod validation error for CLI output. */
|
|
4
|
+
declare function formatZodError(error: Parameters<typeof z.prettifyError>[0]): string;
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { formatZodError };
|
package/dist/zod-format.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { formatZodError } from './chunk-OWXQB7GP.mjs';
|
|
2
2
|
import './chunk-Q72B4Q5Z.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/workers-utils",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.2",
|
|
4
4
|
"description": "Internal utility package for workers-sdk. Not intended for external use — APIs may change without notice.",
|
|
5
5
|
"homepage": "https://github.com/cloudflare/workers-sdk/tree/main/packages/workers-utils#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -81,11 +81,10 @@
|
|
|
81
81
|
"dotenv-expand": "13.0.0",
|
|
82
82
|
"empathic": "^2.0.0",
|
|
83
83
|
"jsonc-parser": "3.2.0",
|
|
84
|
-
"kleur": "^4.1.5",
|
|
85
84
|
"minimatch": "^5.1.0",
|
|
86
85
|
"open": "11.0.0",
|
|
87
86
|
"signal-exit": "4.1.0",
|
|
88
|
-
"smol-toml": "1.
|
|
87
|
+
"smol-toml": "1.8.0",
|
|
89
88
|
"ts-dedent": "^2.2.0",
|
|
90
89
|
"tsdown": "^0.15.9",
|
|
91
90
|
"tsup": "8.3.0",
|
|
@@ -94,9 +93,9 @@
|
|
|
94
93
|
"vitest": "4.1.0",
|
|
95
94
|
"xdg-app-paths": "^8.3.0",
|
|
96
95
|
"zod": "4.4.3",
|
|
97
|
-
"@cloudflare/workers-shared": "0.
|
|
98
|
-
"@cloudflare/
|
|
99
|
-
"@cloudflare/
|
|
96
|
+
"@cloudflare/workers-shared": "0.20.0",
|
|
97
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
98
|
+
"@cloudflare/workflows-shared": "0.14.0"
|
|
100
99
|
},
|
|
101
100
|
"peerDependencies": {
|
|
102
101
|
"vitest": "^4.1.0"
|
package/dist/chunk-7AX24RFK.mjs
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { __name } from './chunk-Q72B4Q5Z.mjs';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import util from 'node:util';
|
|
4
|
-
|
|
5
|
-
// ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs
|
|
6
|
-
var FORCE_COLOR;
|
|
7
|
-
var NODE_DISABLE_COLORS;
|
|
8
|
-
var NO_COLOR;
|
|
9
|
-
var TERM;
|
|
10
|
-
var isTTY = true;
|
|
11
|
-
if (typeof process !== "undefined") {
|
|
12
|
-
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
13
|
-
isTTY = process.stdout && process.stdout.isTTY;
|
|
14
|
-
}
|
|
15
|
-
var $ = {
|
|
16
|
-
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY)
|
|
17
|
-
};
|
|
18
|
-
function init(x, y) {
|
|
19
|
-
let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
|
|
20
|
-
let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
|
|
21
|
-
return function(txt) {
|
|
22
|
-
if (!$.enabled || txt == null) return txt;
|
|
23
|
-
return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
__name(init, "init");
|
|
27
|
-
var dim = init(2, 22);
|
|
28
|
-
var red = init(31, 39);
|
|
29
|
-
var green = init(32, 39);
|
|
30
|
-
var yellow = init(33, 39);
|
|
31
|
-
var blue = init(34, 39);
|
|
32
|
-
var magenta = init(35, 39);
|
|
33
|
-
var cyan = init(36, 39);
|
|
34
|
-
|
|
35
|
-
// src/zod-format.ts
|
|
36
|
-
var originalEnabled = $.enabled;
|
|
37
|
-
function _forceColour(enabled = originalEnabled) {
|
|
38
|
-
$.enabled = enabled;
|
|
39
|
-
}
|
|
40
|
-
__name(_forceColour, "_forceColour");
|
|
41
|
-
var kMessages = Symbol("kMessages");
|
|
42
|
-
var kActual = Symbol("kActual");
|
|
43
|
-
var kGroupId = Symbol("kGroupId");
|
|
44
|
-
var groupColours = [
|
|
45
|
-
yellow,
|
|
46
|
-
/* (green) */
|
|
47
|
-
cyan,
|
|
48
|
-
blue,
|
|
49
|
-
magenta,
|
|
50
|
-
green
|
|
51
|
-
];
|
|
52
|
-
var GroupCountsMap = Map;
|
|
53
|
-
function isAnnotation(value) {
|
|
54
|
-
return typeof value === "object" && value !== null && kMessages in value && kActual in value;
|
|
55
|
-
}
|
|
56
|
-
__name(isAnnotation, "isAnnotation");
|
|
57
|
-
function isRecord(value) {
|
|
58
|
-
return typeof value === "object" && value !== null;
|
|
59
|
-
}
|
|
60
|
-
__name(isRecord, "isRecord");
|
|
61
|
-
function arrayShallowEqual(a, b) {
|
|
62
|
-
if (a.length !== b.length) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
for (let i = 0; i < a.length; i++) {
|
|
66
|
-
if (a[i] !== b[i]) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
__name(arrayShallowEqual, "arrayShallowEqual");
|
|
73
|
-
function issueEqual(a, b) {
|
|
74
|
-
return a.message === b.message && arrayShallowEqual(a.path, b.path);
|
|
75
|
-
}
|
|
76
|
-
__name(issueEqual, "issueEqual");
|
|
77
|
-
function hasMultipleDistinctMessages(issues, atDepth) {
|
|
78
|
-
let firstIssue;
|
|
79
|
-
for (const issue of issues) {
|
|
80
|
-
if (issue.path.length < atDepth) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (firstIssue === void 0) {
|
|
84
|
-
firstIssue = issue;
|
|
85
|
-
} else if (!issueEqual(firstIssue, issue)) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
__name(hasMultipleDistinctMessages, "hasMultipleDistinctMessages");
|
|
92
|
-
function annotate(groupCounts, annotated, input, issue, path, groupId) {
|
|
93
|
-
if (path.length === 0) {
|
|
94
|
-
if (issue.code === "invalid_union") {
|
|
95
|
-
const allBranchIssues = issue.errors;
|
|
96
|
-
const unionIssues = allBranchIssues.flat();
|
|
97
|
-
if (unionIssues.length > 0) {
|
|
98
|
-
const multipleDistinct = hasMultipleDistinctMessages(unionIssues, 1);
|
|
99
|
-
let newGroupId;
|
|
100
|
-
if (isRecord(input) && multipleDistinct) {
|
|
101
|
-
newGroupId = groupCounts.size;
|
|
102
|
-
groupCounts.set(newGroupId, 0);
|
|
103
|
-
}
|
|
104
|
-
for (const branchIssues of allBranchIssues) {
|
|
105
|
-
for (const unionIssue of branchIssues) {
|
|
106
|
-
const unionPath = unionIssue.path;
|
|
107
|
-
if (multipleDistinct && unionPath.length === 0) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
annotated = annotate(
|
|
111
|
-
groupCounts,
|
|
112
|
-
annotated,
|
|
113
|
-
input,
|
|
114
|
-
unionIssue,
|
|
115
|
-
unionPath,
|
|
116
|
-
newGroupId
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return annotated;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const message = issue.message;
|
|
124
|
-
if (annotated !== void 0) {
|
|
125
|
-
if (isAnnotation(annotated) && !annotated[kMessages].includes(message)) {
|
|
126
|
-
annotated[kMessages].push(message);
|
|
127
|
-
}
|
|
128
|
-
return annotated;
|
|
129
|
-
}
|
|
130
|
-
if (groupId !== void 0) {
|
|
131
|
-
const current = groupCounts.get(groupId);
|
|
132
|
-
assert(current !== void 0);
|
|
133
|
-
groupCounts.set(groupId, current + 1);
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
[kMessages]: [message],
|
|
137
|
-
[kActual]: input,
|
|
138
|
-
[kGroupId]: groupId
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
const [head, ...tail] = path;
|
|
142
|
-
assert(isRecord(input), "Expected object/array input for nested issue");
|
|
143
|
-
if (annotated === void 0) {
|
|
144
|
-
if (Array.isArray(input)) {
|
|
145
|
-
annotated = new Array(input.length);
|
|
146
|
-
} else {
|
|
147
|
-
const entries = Object.keys(input).map((key) => [key, void 0]);
|
|
148
|
-
annotated = Object.fromEntries(entries);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
assert(isRecord(annotated), "Expected object/array for nested issue");
|
|
152
|
-
annotated[head] = annotate(
|
|
153
|
-
groupCounts,
|
|
154
|
-
annotated[head],
|
|
155
|
-
input[head],
|
|
156
|
-
issue,
|
|
157
|
-
tail,
|
|
158
|
-
groupId
|
|
159
|
-
);
|
|
160
|
-
return annotated;
|
|
161
|
-
}
|
|
162
|
-
__name(annotate, "annotate");
|
|
163
|
-
function print(inspectOptions, groupCounts, annotated, indent = "", extras) {
|
|
164
|
-
const prefix = extras?.prefix ?? "";
|
|
165
|
-
const suffix = extras?.suffix ?? "";
|
|
166
|
-
if (isAnnotation(annotated)) {
|
|
167
|
-
const prefixIndent = indent + " ".repeat(prefix.length);
|
|
168
|
-
const actual = util.inspect(annotated[kActual], inspectOptions);
|
|
169
|
-
const actualIndented = actual.split("\n").map((line, i) => i > 0 ? prefixIndent + line : line).join("\n");
|
|
170
|
-
let messageColour = red;
|
|
171
|
-
let messagePrefix = prefixIndent + "^";
|
|
172
|
-
let groupOr = "";
|
|
173
|
-
if (annotated[kGroupId] !== void 0) {
|
|
174
|
-
messageColour = groupColours[annotated[kGroupId] % groupColours.length];
|
|
175
|
-
messagePrefix += annotated[kGroupId] + 1;
|
|
176
|
-
const remaining = groupCounts.get(annotated[kGroupId]);
|
|
177
|
-
assert(remaining !== void 0);
|
|
178
|
-
if (remaining > 1) {
|
|
179
|
-
groupOr = " *or*";
|
|
180
|
-
}
|
|
181
|
-
groupCounts.set(annotated[kGroupId], remaining - 1);
|
|
182
|
-
}
|
|
183
|
-
messagePrefix += " ";
|
|
184
|
-
const messageIndent = " ".repeat(messagePrefix.length);
|
|
185
|
-
const messageIndented = annotated[kMessages].flatMap((m) => m.split("\n")).map((line, i) => i > 0 ? messageIndent + line : line).join("\n");
|
|
186
|
-
const error = messageColour(`${messagePrefix}${messageIndented}${groupOr}`);
|
|
187
|
-
return `${indent}${dim(prefix)}${actualIndented}${dim(suffix)}
|
|
188
|
-
${error}`;
|
|
189
|
-
} else if (Array.isArray(annotated)) {
|
|
190
|
-
let result = `${indent}${dim(`${prefix}[`)}
|
|
191
|
-
`;
|
|
192
|
-
const arrayIndent = indent + " ";
|
|
193
|
-
for (let i = 0; i < annotated.length; i++) {
|
|
194
|
-
const value = annotated[i];
|
|
195
|
-
if (value === void 0 && (i === 0 || annotated[i - 1] !== void 0)) {
|
|
196
|
-
result += `${arrayIndent}${dim("...,")}
|
|
197
|
-
`;
|
|
198
|
-
}
|
|
199
|
-
if (value !== void 0) {
|
|
200
|
-
result += print(inspectOptions, groupCounts, value, arrayIndent, {
|
|
201
|
-
prefix: `/* [${i}] */ `,
|
|
202
|
-
suffix: ","
|
|
203
|
-
});
|
|
204
|
-
result += "\n";
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
result += `${indent}${dim(`]${suffix}`)}`;
|
|
208
|
-
return result;
|
|
209
|
-
} else if (isRecord(annotated)) {
|
|
210
|
-
let result = `${indent}${dim(`${prefix}{`)}
|
|
211
|
-
`;
|
|
212
|
-
const objectIndent = indent + " ";
|
|
213
|
-
const entries = Object.entries(annotated);
|
|
214
|
-
for (let i = 0; i < entries.length; i++) {
|
|
215
|
-
const [key, value] = entries[i];
|
|
216
|
-
if (value === void 0 && (i === 0 || entries[i - 1][1] !== void 0)) {
|
|
217
|
-
result += `${objectIndent}${dim("...,")}
|
|
218
|
-
`;
|
|
219
|
-
}
|
|
220
|
-
if (value !== void 0) {
|
|
221
|
-
result += print(inspectOptions, groupCounts, value, objectIndent, {
|
|
222
|
-
prefix: `${key}: `,
|
|
223
|
-
suffix: ","
|
|
224
|
-
});
|
|
225
|
-
result += "\n";
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
result += `${indent}${dim(`}${suffix}`)}`;
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
return "";
|
|
232
|
-
}
|
|
233
|
-
__name(print, "print");
|
|
234
|
-
function formatZodError(error, input) {
|
|
235
|
-
const sortedIssues = Array.from(error.issues).sort((a, b) => {
|
|
236
|
-
if (a.code !== b.code) {
|
|
237
|
-
if (a.code === "invalid_union") {
|
|
238
|
-
return -1;
|
|
239
|
-
}
|
|
240
|
-
if (b.code === "invalid_union") {
|
|
241
|
-
return 1;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return 0;
|
|
245
|
-
});
|
|
246
|
-
let annotated;
|
|
247
|
-
const groupCounts = new GroupCountsMap();
|
|
248
|
-
for (const issue of sortedIssues) {
|
|
249
|
-
annotated = annotate(
|
|
250
|
-
groupCounts,
|
|
251
|
-
annotated,
|
|
252
|
-
input,
|
|
253
|
-
issue,
|
|
254
|
-
issue.path
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
const inspectOptions = {
|
|
258
|
-
depth: 0,
|
|
259
|
-
colors: $.enabled
|
|
260
|
-
};
|
|
261
|
-
return print(inspectOptions, groupCounts, annotated);
|
|
262
|
-
}
|
|
263
|
-
__name(formatZodError, "formatZodError");
|
|
264
|
-
|
|
265
|
-
export { _forceColour, formatZodError };
|