@nightintelligence/cloudflare-workers-utils 0.35.0-patch2 → 0.35.0-patch3

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 (53) hide show
  1. package/dist/browser.mjs +2 -2
  2. package/dist/browser.mjs.map +1 -1
  3. package/dist/chunk-PAWJFY3S.mjs +6 -0
  4. package/dist/{chunk-6LYDFTTF.mjs.map → chunk-PAWJFY3S.mjs.map} +1 -1
  5. package/dist/compatibility-date.mjs +42 -2
  6. package/dist/compatibility-date.mjs.map +1 -1
  7. package/dist/compliance.mjs +2 -7
  8. package/dist/compliance.mjs.map +1 -1
  9. package/dist/docker-path.mjs +11 -3
  10. package/dist/docker-path.mjs.map +1 -1
  11. package/dist/errors.mjs +61 -2
  12. package/dist/errors.mjs.map +1 -1
  13. package/dist/fs-helpers.mjs +33 -2
  14. package/dist/fs-helpers.mjs.map +1 -1
  15. package/dist/global-wrangler-config-path.mjs +28 -3
  16. package/dist/global-wrangler-config-path.mjs.map +1 -1
  17. package/dist/index.mjs +54 -26124
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/local-env.mjs +5 -80
  20. package/dist/local-env.mjs.map +1 -1
  21. package/dist/metafile-esm.json +1 -1
  22. package/dist/prometheus-metrics.mjs +51 -2
  23. package/dist/prometheus-metrics.mjs.map +1 -1
  24. package/dist/test-helpers/index.mjs +7 -308
  25. package/dist/test-helpers/index.mjs.map +1 -1
  26. package/dist/zod-format.mjs +235 -2
  27. package/dist/zod-format.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/chunk-3D4BXUZX.mjs +0 -54
  30. package/dist/chunk-3D4BXUZX.mjs.map +0 -1
  31. package/dist/chunk-4RE36JUD.mjs +0 -3160
  32. package/dist/chunk-4RE36JUD.mjs.map +0 -1
  33. package/dist/chunk-6LYDFTTF.mjs +0 -40
  34. package/dist/chunk-CPLEE7LH.mjs +0 -64
  35. package/dist/chunk-CPLEE7LH.mjs.map +0 -1
  36. package/dist/chunk-G5FCNCLK.mjs +0 -47
  37. package/dist/chunk-G5FCNCLK.mjs.map +0 -1
  38. package/dist/chunk-IGC3TZGH.mjs +0 -157
  39. package/dist/chunk-IGC3TZGH.mjs.map +0 -1
  40. package/dist/chunk-NXPJWJ2B.mjs +0 -180
  41. package/dist/chunk-NXPJWJ2B.mjs.map +0 -1
  42. package/dist/chunk-OPAKTV2K.mjs +0 -75
  43. package/dist/chunk-OPAKTV2K.mjs.map +0 -1
  44. package/dist/chunk-VKFVZ67V.mjs +0 -35
  45. package/dist/chunk-VKFVZ67V.mjs.map +0 -1
  46. package/dist/chunk-W7DIL5J2.mjs +0 -267
  47. package/dist/chunk-W7DIL5J2.mjs.map +0 -1
  48. package/dist/chunk-ZLUHKBEC.mjs +0 -44
  49. package/dist/chunk-ZLUHKBEC.mjs.map +0 -1
  50. package/dist/chunk-ZQ2EZEOC.mjs +0 -477
  51. package/dist/chunk-ZQ2EZEOC.mjs.map +0 -1
  52. package/dist/open-OYMIZX6T.mjs +0 -609
  53. package/dist/open-OYMIZX6T.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"zod-format.mjs"}
1
+ {"version":3,"sources":["../src/zod-format.ts"],"names":["$colors"],"mappings":";;;;;AAkBA,MAAM,kBAAkBA,CAAA,CAAQ,OAAA;AAKzB,SAAS,YAAA,CAAa,UAAU,eAAA,EAAiB;AACvD,EAAAA,CAAA,CAAQ,OAAA,GAAU,OAAA;AACnB;AAFgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;AAuOhB,MAAM,SAAA,GAAY,OAAO,WAAW,CAAA;AACpC,MAAM,OAAA,GAAU,OAAO,SAAS,CAAA;AAChC,MAAM,QAAA,GAAW,OAAO,UAAU,CAAA;AAwBlC,MAAM,YAAA,GAAe;AAAA,EAAC,MAAA;AAAA;AAAA,EAAsB,IAAA;AAAA,EAAM,IAAA;AAAA,EAAM,OAAA;AAAA,EAAS;AAAK,CA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AA;AAAA,MACX,WAAA;AAAA,MACA,SAAA;AAAA,MACA,KAAA;AAAA,MACA,KAAA;AAAA,MACA,KAAA,CAAM;AAAA,KACP;AAAA,EACD;AAKA,EAAA,MAAM,cAAA,GAAsC;AAAA,IAC3C,KAAA,EAAO,CAAA;AAAA,IACP,QAAQA,CAAA,CAAQ;AAAA,GACjB;AACA,EAAA,OAAO,KAAA,CAAM,cAAA,EAAgB,WAAA,EAAa,SAAS,CAAA;AACpD;AApCgB,MAAA,CAAA,cAAA,EAAA,gBAAA,CAAA","file":"zod-format.mjs","sourcesContent":["// noinspection JSUnusedAssignment\n// ^ WebStorm incorrectly thinks some variables might not have been initialised\n// before use without this. TypeScript is better at catching these errors. :)\n\nimport assert from \"node:assert\";\nimport util from \"node:util\";\nimport {\n\t$ as $colors,\n\tblue,\n\tcyan,\n\tdim,\n\tgreen,\n\tmagenta,\n\tred,\n\tyellow,\n} from \"kleur/colors\";\nimport type { z } from \"zod\";\n\nconst originalEnabled = $colors.enabled;\n\n// `kleur` is marked as a dev dependency, so will get bundled. We'd still like\n// to be able to control whether it's enabled in tests though. Therefore, export\n// a function that toggles the enabled state of our bundled version.\nexport function _forceColour(enabled = originalEnabled) {\n\t$colors.enabled = enabled;\n}\n\n// This file contains a `formatZodError(error, input)` function for formatting\n// a Zod `error` that came from parsing a specific `input`. This works by\n// building an \"annotated\" version of the `input`, with roughly the same shape,\n// but including messages from the `error`. This is then printed to a string.\n//\n// When the Zod `error` includes an issue at a specific path, that path is\n// replaced with an `Annotation` in the \"annotated\" version. This `Annotation`,\n// includes any messages for that path, along with the actual value at that\n// path. `Annotation`s may be grouped if they are part of a union. In this case,\n// they'll be printed in a different colour and with a group ID to indicate that\n// only one of the issues needs to be fixed for all issues in the group to be\n// resolved.\n//\n// This is best illustrated with some examples:\n//\n// # Primitive Input\n//\n// ```\n// const schema = z.boolean();\n// const input = 42;\n// const error = schema.safeParse(input).error;\n// ↳ ZodError [\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"boolean\",\n// \"received\": \"number\",\n// \"path\": [],\n// \"message\": \"Expected boolean, received number\"\n// }\n// ]\n//\n// /* Annotated */\n// {\n// [Symbol(kMessages)]: [ 'Expected boolean, received number' ],\n// [Symbol(kActual)]: 42\n// }\n//\n// const formatted = formatZodError(error, input);\n// ↳ 42\n// ^ Expected boolean, received number\n// ```\n//\n// In this example, we only have a single issue, with `\"path\": []`. This path\n// represents the root, so the root of the input has been replaced with an\n// annotation in the annotated version.\n//\n// ### Object Input\n//\n// ````\n// const schema = z.object({ a: z.number(), b: z.number(), c: z.object({ d: z.number() })});\n// const input = { a: false, b: 42, c: { d: \"not a number\" } };\n// const error = schema.safeParse(input).error;\n// ↳ ZodError: [\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"number\",\n// \"received\": \"boolean\",\n// \"path\": [ \"a\" ],\n// \"message\": \"Expected number, received boolean\"\n// },\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"number\",\n// \"received\": \"string\",\n// \"path\": [ \"c\", \"d\" ],\n// \"message\": \"Expected number, received boolean\"\n// }\n// ]\n//\n// /* Annotated after 1st issue */\n// {\n// a: {\n// [Symbol(kMessages)]: [ 'Expected number, received boolean' ],\n// [Symbol(kActual)]: false\n// },\n// b: undefined,\n// c: undefined,\n// }\n//\n// /* Annotated after 2nd issue */\n// {\n// a: {\n// [Symbol(kMessages)]: [ 'Expected number, received boolean' ],\n// [Symbol(kActual)]: false\n// },\n// b: undefined,\n// c: {\n// d: {\n// [Symbol(kMessages)]: [ 'Expected number, received string' ],\n// [Symbol(kActual)]: 'not a number'\n// }\n// }\n// }\n//\n// const formatted = formatZodError(error, input);\n// ↳ {\n// a: false,\n// ^ Expected number, received boolean\n// ...,\n// c: {\n// d: true,\n// ^ Expected number, received boolean\n// },\n// }\n// ````\n//\n// If the error contains multiple issues, we annotate them one at a time.\n// For object inputs, the annotated object starts out with the same keys as\n// the object, just with `undefined` values. Keys with values that are\n// `undefined` at the end of annotation will be printed as \"...\". Annotations\n// are inserted on paths where there are issues. Note annotations are\n// effectively the leaves of the annotated tree.\n//\n// ### Array Input\n//\n// ```\n// const schema = z.array(z.number());\n// const input = [1, 2, false, 4];\n// const error = schema.safeParse(input).error;\n// ↳ ZodError: [\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"number\",\n// \"received\": \"boolean\",\n// \"path\": [ 2 ],\n// \"message\": \"Expected number, received boolean\"\n// }\n// ]\n//\n// /* Annotated */\n// [\n// <2 empty items>,\n// {\n// [Symbol(kMessages)]: [ 'Expected number, received boolean' ],\n// [Symbol(kActual)]: false\n// },\n// <1 empty item>\n// ]\n//\n// const formatted = formatZodError(error, input);\n// ↳ [\n// ...,\n// /* [2] */ false,\n// ^ Expected number, received boolean\n// ...,\n// ]\n// ```\n//\n// In this case the annotated value is now an array, rather than a plain-object,\n// to match the shape of the input. Note it has the same length as the input,\n// including empty items for array indices that don't have errors. Empty items\n// will be coalesced and printed as \"...\".\n//\n// ### Union Schema and Groups\n//\n// ```\n// const schema = z.union([z.object({ a: z.number() }), z.object({ b: z.string() })]);\n// const input = { c: false };\n// const error = schema.safeParse(input).error;\n// ↳ [\n// {\n// \"code\": \"invalid_union\",\n// \"path\": [],\n// \"message\": \"Invalid input\",\n// \"unionErrors\": [\n// {\n// \"name\": \"ZodError\",\n// \"issues\": [\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"number\",\n// \"received\": \"undefined\",\n// \"path\": [ \"a\" ],\n// \"message\": \"Required\"\n// }\n// ]\n// },\n// {\n// \"name\": \"ZodError\",\n// \"issues\": [\n// {\n// \"code\": \"invalid_type\",\n// \"expected\": \"string\",\n// \"received\": \"undefined\",\n// \"path\": [ \"b\" ],\n// \"message\": \"Required\"\n// }\n// ]\n// }\n// ]\n// }\n// ]\n//\n// /* Annotated */\n// {\n// c: undefined,\n// a: {\n// [Symbol(kMessages)]: [ 'Required' ],\n// [Symbol(kActual)]: undefined,\n// [Symbol(kGroupId)]: 0\n// },\n// b: {\n// [Symbol(kMessages)]: [ 'Required' ],\n// [Symbol(kActual)]: undefined,\n// [Symbol(kGroupId)]: 0\n// }\n// }\n//\n// const formatted = formatZodError(error, input);\n// ↳ {\n// ...,\n// a: undefined,\n// ^1 Required *or*\n// b: undefined,\n// ^1 Required\n// }\n// ```\n//\n// In this case, fixing either of the reported issues would solve the problem.\n// To indicate this, we \"group\" issues contained within `unionErrors`. See how\n// annotations have a `[Symbol(kGroupId)]: 0`. Group IDs are 0-indexed\n// internally but 1-indexed when displayed (see \"^1\"). Each group's messages\n// are displayed in a different colour to visually group them. Note the\n// unhelpful \"Invalid input\" message has been hidden. Required options that\n// are not present in the `input` are added to the end of the annotated input.\n//\n\nconst kMessages = Symbol(\"kMessages\");\nconst kActual = Symbol(\"kActual\");\nconst kGroupId = Symbol(\"kGroupId\");\n\n// Set of Zod error messages attached to a specific path in the input\ninterface Annotation {\n\t// Error messages at this specific path in the annotated tree. A path may have\n\t// multiple messages associated with it if the schema is a union/intersection.\n\t[kMessages]: string[];\n\t// The input value at this specific path\n\t[kActual]: unknown;\n\t// Optional 0-indexed group for this annotation. Fixing a single issue in a\n\t// group will usually fix all other issues in the group. Grouped annotations\n\t// are displayed in a different colour with their 1-indexed group ID.\n\t[kGroupId]?: number;\n}\n\n// Object with the same shape as the input, but with undefined at the leaves,\n// or an annotation iff there's an issue at that specific path.\ntype Annotated =\n\t| undefined\n\t| Annotation\n\t| { [key: string]: Annotated }\n\t| Annotated[];\n\n// `green` is a success colour, so only use it for groups if really needed\nconst groupColours = [yellow, /* (green) */ cyan, blue, magenta, green];\n\n// Maps group IDs to the number of annotations in that group. Used to determine\n// whether this isn't the last annotation in a group, and \"or\" should be printed\n// with the message.\nconst GroupCountsMap = Map<number /* [kGroupId] */, number /* count */>;\ntype GroupCountsMap = InstanceType<typeof GroupCountsMap>;\n\nfunction isAnnotation(value: unknown): value is Annotation {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\tkMessages in value &&\n\t\tkActual in value\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string | number, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction arrayShallowEqual<T>(a: T[], b: T[]) {\n\tif (a.length !== b.length) {\n\t\treturn false;\n\t}\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction issueEqual(a: z.core.$ZodIssue, b: z.core.$ZodIssue) {\n\t// We consider issues to be equal if their messages and paths are\n\treturn a.message === b.message && arrayShallowEqual(a.path, b.path);\n}\n\nfunction hasMultipleDistinctMessages(\n\tissues: z.core.$ZodIssue[],\n\tatDepth: number\n) {\n\t// Returns true iff `issues` has issues that aren't \"the same\" at the\n\t// specified depth or below\n\tlet firstIssue: z.core.$ZodIssue | undefined;\n\tfor (const issue of issues) {\n\t\tif (issue.path.length < atDepth) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (firstIssue === undefined) {\n\t\t\tfirstIssue = issue;\n\t\t} else if (!issueEqual(firstIssue, issue)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction annotate(\n\tgroupCounts: GroupCountsMap,\n\tannotated: Annotated,\n\tinput: unknown,\n\tissue: z.core.$ZodIssue,\n\tpath: (string | number)[],\n\tgroupId?: number\n): Annotated {\n\tif (path.length === 0) {\n\t\t// Empty path, `input` has incorrect shape\n\n\t\t// If this is an `invalid_union` error, make sure we include all sub-issues\n\t\tif (issue.code === \"invalid_union\") {\n\t\t\t// In zod v4, `issue.errors` is `$ZodIssue[][]` where each inner\n\t\t\t// array holds the issues for one union branch.\n\t\t\tconst allBranchIssues = issue.errors;\n\t\t\tconst unionIssues = allBranchIssues.flat();\n\n\t\t\t// In zod v4, discriminated unions with an invalid discriminator\n\t\t\t// produce an `invalid_union` issue with an empty `errors` array\n\t\t\t// and the error message on the issue itself. Fall through to\n\t\t\t// treat it as a regular annotation in that case.\n\t\t\tif (unionIssues.length > 0) {\n\t\t\t\t// If the `input` is an object/array with multiple distinct messages,\n\t\t\t\t// annotate it as a group\n\t\t\t\t// In zod v4, branch issue paths are already relative to the union\n\t\t\t\t// issue, so use depth 1 (deeper than current level 0) rather than\n\t\t\t\t// issue.path.length + 1.\n\t\t\t\tconst multipleDistinct = hasMultipleDistinctMessages(unionIssues, 1);\n\n\t\t\t\tlet newGroupId: number | undefined;\n\t\t\t\tif (isRecord(input) && multipleDistinct) {\n\t\t\t\t\tnewGroupId = groupCounts.size;\n\t\t\t\t\tgroupCounts.set(newGroupId, 0);\n\t\t\t\t}\n\n\t\t\t\tfor (const branchIssues of allBranchIssues) {\n\t\t\t\t\tfor (const unionIssue of branchIssues) {\n\t\t\t\t\t\t// In zod v4, branch issue paths are already relative to the\n\t\t\t\t\t\t// union issue (not absolute), so use them directly.\n\t\t\t\t\t\tconst unionPath = unionIssue.path as (string | number)[];\n\t\t\t\t\t\t// If we have multiple distinct messages at deeper levels, and this\n\t\t\t\t\t\t// issue is for the current path, skip it, so we don't end up annotating\n\t\t\t\t\t\t// the current path and sub-paths\n\t\t\t\t\t\tif (multipleDistinct && unionPath.length === 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tannotated = annotate(\n\t\t\t\t\t\t\tgroupCounts,\n\t\t\t\t\t\t\tannotated,\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\tunionIssue,\n\t\t\t\t\t\t\tunionPath,\n\t\t\t\t\t\t\tnewGroupId\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn annotated;\n\t\t\t}\n\t\t}\n\n\t\tconst message = issue.message;\n\t\t// If we've already annotated this path (existing annotation or union)...\n\t\tif (annotated !== undefined) {\n\t\t\t// ...and if this is a new message for an existing annotation...\n\t\t\tif (isAnnotation(annotated) && !annotated[kMessages].includes(message)) {\n\t\t\t\t// ...add it\n\t\t\t\tannotated[kMessages].push(message);\n\t\t\t}\n\t\t\treturn annotated;\n\t\t}\n\n\t\t// Creating a new annotation\n\n\t\t// If this new annotation is part of a group...\n\t\tif (groupId !== undefined) {\n\t\t\t// ...increment that group's count\n\t\t\tconst current = groupCounts.get(groupId);\n\t\t\tassert(current !== undefined);\n\t\t\tgroupCounts.set(groupId, current + 1);\n\t\t}\n\n\t\treturn <Annotation>{\n\t\t\t[kMessages]: [message],\n\t\t\t[kActual]: input,\n\t\t\t[kGroupId]: groupId,\n\t\t};\n\t}\n\n\t// Non-empty path, `input` should be an object or array\n\tconst [head, ...tail] = path;\n\tassert(isRecord(input), \"Expected object/array input for nested issue\");\n\tif (annotated === undefined) {\n\t\t// Initialise `annotated` to look like `input`, with empty slots for keys\n\t\tif (Array.isArray(input)) {\n\t\t\tannotated = new Array(input.length);\n\t\t} else {\n\t\t\tconst entries = Object.keys(input).map((key) => [key, undefined]);\n\t\t\tannotated = Object.fromEntries(entries);\n\t\t}\n\t}\n\tassert(isRecord(annotated), \"Expected object/array for nested issue\");\n\t// Recursively annotate\n\tannotated[head] = annotate(\n\t\tgroupCounts,\n\t\tannotated[head],\n\t\tinput[head],\n\t\tissue,\n\t\ttail,\n\t\tgroupId\n\t);\n\treturn annotated;\n}\n\ninterface PrintExtras {\n\tprefix?: string;\n\tsuffix?: string;\n}\nfunction print(\n\tinspectOptions: util.InspectOptions,\n\tgroupCounts: GroupCountsMap,\n\tannotated: Annotated,\n\tindent = \"\",\n\textras?: PrintExtras\n): string {\n\tconst prefix = extras?.prefix ?? \"\";\n\tconst suffix = extras?.suffix ?? \"\";\n\n\tif (isAnnotation(annotated)) {\n\t\tconst prefixIndent = indent + \" \".repeat(prefix.length);\n\n\t\t// Print actual value\n\t\tconst actual = util.inspect(annotated[kActual], inspectOptions);\n\t\tconst actualIndented = actual\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line, i) => (i > 0 ? prefixIndent + line : line))\n\t\t\t.join(\"\\n\");\n\n\t\t// Print message\n\t\tlet messageColour = red;\n\t\tlet messagePrefix = prefixIndent + \"^\";\n\t\tlet groupOr = \"\";\n\t\tif (annotated[kGroupId] !== undefined) {\n\t\t\t// If this annotation was part of a group, set the message colour based\n\t\t\t// on the group, and include the group ID in the prefix\n\t\t\tmessageColour = groupColours[annotated[kGroupId] % groupColours.length];\n\t\t\tmessagePrefix += annotated[kGroupId] + 1;\n\t\t\tconst remaining = groupCounts.get(annotated[kGroupId]);\n\t\t\tassert(remaining !== undefined);\n\t\t\tif (remaining > 1) {\n\t\t\t\tgroupOr = \" *or*\";\n\t\t\t}\n\t\t\tgroupCounts.set(annotated[kGroupId], remaining - 1);\n\t\t}\n\t\tmessagePrefix += \" \";\n\n\t\tconst messageIndent = \" \".repeat(messagePrefix.length);\n\t\tconst messageIndented = annotated[kMessages]\n\t\t\t.flatMap((m) => m.split(\"\\n\"))\n\t\t\t.map((line, i) => (i > 0 ? messageIndent + line : line))\n\t\t\t.join(\"\\n\");\n\n\t\t// Print final annotation\n\t\tconst error = messageColour(`${messagePrefix}${messageIndented}${groupOr}`);\n\t\treturn `${indent}${dim(prefix)}${actualIndented}${dim(suffix)}\\n${error}`;\n\t} else if (Array.isArray(annotated)) {\n\t\t// Print array recursively\n\t\tlet result = `${indent}${dim(`${prefix}[`)}\\n`;\n\t\tconst arrayIndent = indent + \" \";\n\t\tfor (let i = 0; i < annotated.length; i++) {\n\t\t\tconst value = annotated[i];\n\t\t\t// Add `...` if the last item wasn't an `...`\n\t\t\tif (value === undefined && (i === 0 || annotated[i - 1] !== undefined)) {\n\t\t\t\tresult += `${arrayIndent}${dim(\"...,\")}\\n`;\n\t\t\t}\n\t\t\tif (value !== undefined) {\n\t\t\t\tresult += print(inspectOptions, groupCounts, value, arrayIndent, {\n\t\t\t\t\tprefix: `/* [${i}] */ `,\n\t\t\t\t\tsuffix: \",\",\n\t\t\t\t});\n\t\t\t\tresult += \"\\n\";\n\t\t\t}\n\t\t}\n\t\tresult += `${indent}${dim(`]${suffix}`)}`;\n\t\treturn result;\n\t} else if (isRecord(annotated)) {\n\t\t// Print object recursively\n\t\tlet result = `${indent}${dim(`${prefix}{`)}\\n`;\n\t\tconst objectIndent = indent + \" \";\n\t\tconst entries = Object.entries(annotated);\n\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\tconst [key, value] = entries[i];\n\t\t\t// Add `...` if the last item wasn't an `...`\n\t\t\tif (value === undefined && (i === 0 || entries[i - 1][1] !== undefined)) {\n\t\t\t\tresult += `${objectIndent}${dim(\"...,\")}\\n`;\n\t\t\t}\n\t\t\tif (value !== undefined) {\n\t\t\t\tresult += print(inspectOptions, groupCounts, value, objectIndent, {\n\t\t\t\t\tprefix: `${key}: `,\n\t\t\t\t\tsuffix: \",\",\n\t\t\t\t});\n\t\t\t\tresult += \"\\n\";\n\t\t\t}\n\t\t}\n\t\tresult += `${indent}${dim(`}${suffix}`)}`;\n\t\treturn result;\n\t}\n\n\treturn \"\";\n}\n\nexport function formatZodError(error: z.ZodError, input: unknown): string {\n\t// Shallow copy and sort array, with `invalid_union` errors first, so we don't\n\t// annotate the input with an `invalid_type` error instead\n\tconst sortedIssues = Array.from(error.issues).sort((a, b) => {\n\t\tif (a.code !== b.code) {\n\t\t\tif (a.code === \"invalid_union\") {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (b.code === \"invalid_union\") {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t});\n\n\t// Build annotated input\n\tlet annotated: Annotated;\n\tconst groupCounts = new GroupCountsMap();\n\tfor (const issue of sortedIssues) {\n\t\tannotated = annotate(\n\t\t\tgroupCounts,\n\t\t\tannotated,\n\t\t\tinput,\n\t\t\tissue,\n\t\t\tissue.path as (string | number)[]\n\t\t);\n\t}\n\n\t// Print to pretty string\n\t// Build inspect options on each call to `formatZodError()` so we can toggle\n\t// colours per-call\n\tconst inspectOptions: util.InspectOptions = {\n\t\tdepth: 0,\n\t\tcolors: $colors.enabled,\n\t};\n\treturn print(inspectOptions, groupCounts, annotated);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nightintelligence/cloudflare-workers-utils",
3
- "version": "0.35.0-patch2",
3
+ "version": "0.35.0-patch3",
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": {
@@ -1,54 +0,0 @@
1
- import { __name } from './chunk-6LYDFTTF.mjs';
2
-
3
- // src/prometheus-metrics.ts
4
- var MetricsRegistry = class {
5
- static {
6
- __name(this, "MetricsRegistry");
7
- }
8
- counters = [];
9
- /**
10
- * Create and register a new counter metric.
11
- *
12
- * @param name - The metric name (e.g. "service_request_total")
13
- * @param help - A human-readable description of the metric
14
- * @returns A Counter that can be incremented
15
- */
16
- createCounter(name, help) {
17
- const entry = { name, help, value: 0 };
18
- this.counters.push(entry);
19
- return {
20
- inc: /* @__PURE__ */ __name(() => {
21
- entry.value++;
22
- }, "inc"),
23
- add: /* @__PURE__ */ __name((amount) => {
24
- if (amount < 0) {
25
- throw new Error("Counter value cannot decrease");
26
- }
27
- entry.value += amount;
28
- }, "add")
29
- };
30
- }
31
- /**
32
- * Serialize all registered metrics in Prometheus text exposition format.
33
- *
34
- * @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
35
- */
36
- metrics() {
37
- return this.counters.map((c) => {
38
- let result = "";
39
- if (c.help.length > 0) {
40
- result += `# HELP ${c.name} ${c.help}
41
- `;
42
- }
43
- result += `# TYPE ${c.name} counter
44
- `;
45
- result += `${c.name} ${c.value}
46
- `;
47
- return result;
48
- }).join("");
49
- }
50
- };
51
-
52
- export { MetricsRegistry };
53
- //# sourceMappingURL=chunk-3D4BXUZX.mjs.map
54
- //# sourceMappingURL=chunk-3D4BXUZX.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/prometheus-metrics.ts"],"names":[],"mappings":";;;AAuCO,IAAM,kBAAN,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IAAA,CAAK,EAAE,CAAA;AAAA,EACV;AACD","file":"chunk-3D4BXUZX.mjs","sourcesContent":["/**\n * Lightweight Prometheus metrics registry for push-based counter metrics.\n *\n * Designed for ephemeral per-request usage in Cloudflare Workers that push\n * metrics to a Prometheus push gateway. Replaces the deprecated `promjs` library.\n *\n * @example\n * ```ts\n * const metrics = new MetricsRegistry();\n * const reqCounter = metrics.createCounter(\n * \"service_request_total\",\n * \"Total requests\"\n * );\n * reqCounter.inc();\n *\n * // Push to Prometheus gateway\n * ctx.waitUntil(\n * fetch(prometheusUrl, {\n * method: \"POST\",\n * headers: { Authorization: `Bearer ${token}` },\n * body: metrics.metrics(),\n * })\n * );\n * ```\n */\n\nexport interface Counter {\n\t/** Increment the counter by 1. */\n\tinc(): void;\n\t/** Increment the counter by the given non-negative amount. */\n\tadd(amount: number): void;\n}\n\ninterface CounterEntry {\n\tname: string;\n\thelp: string;\n\tvalue: number;\n}\n\nexport class MetricsRegistry {\n\tprivate counters: CounterEntry[] = [];\n\n\t/**\n\t * Create and register a new counter metric.\n\t *\n\t * @param name - The metric name (e.g. \"service_request_total\")\n\t * @param help - A human-readable description of the metric\n\t * @returns A Counter that can be incremented\n\t */\n\tcreateCounter(name: string, help: string): Counter {\n\t\tconst entry: CounterEntry = { name, help, value: 0 };\n\t\tthis.counters.push(entry);\n\t\treturn {\n\t\t\tinc: () => {\n\t\t\t\tentry.value++;\n\t\t\t},\n\t\t\tadd: (amount: number) => {\n\t\t\t\tif (amount < 0) {\n\t\t\t\t\tthrow new Error(\"Counter value cannot decrease\");\n\t\t\t\t}\n\t\t\t\tentry.value += amount;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Serialize all registered metrics in Prometheus text exposition format.\n\t *\n\t * @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format\n\t */\n\tmetrics(): string {\n\t\treturn this.counters\n\t\t\t.map((c) => {\n\t\t\t\tlet result = \"\";\n\t\t\t\tif (c.help.length > 0) {\n\t\t\t\t\tresult += `# HELP ${c.name} ${c.help}\\n`;\n\t\t\t\t}\n\t\t\t\tresult += `# TYPE ${c.name} counter\\n`;\n\t\t\t\tresult += `${c.name} ${c.value}\\n`;\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.join(\"\");\n\t}\n}\n"]}