Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 242aa28d5e |
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
import z, { type ZodTypeAny, type output as ZodOutput } from "zod";
|
||||
import { type RuntimeErrorRequestParams } from "./rpc.js";
|
||||
export * from "./rpc.js";
|
||||
export * from "./validation.js";
|
||||
export type PayloadMode = "snapshot" | "delta";
|
||||
export type SchemaAnnotation = {
|
||||
type: string;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
@@ -7,6 +7,7 @@ import WebSocket from "ws";
|
||||
import z, {} from "zod";
|
||||
import { BootRequestParamsSchema, CallRequestParamsSchema, ContextCloseRequestParamsSchema, ContextOpenRequestParamsSchema, EventSubscribeRequestParamsSchema, EventUnsubscribeRequestParamsSchema, ServerMessageSchema, TargetContextOpenRequestParamsSchema, ValueGetRequestParamsSchema, ValueUnwatchRequestParamsSchema, ValueWatchRequestParamsSchema, parseJson, sendClientMessage, } from "./rpc.js";
|
||||
export * from "./rpc.js";
|
||||
export * from "./validation.js";
|
||||
export const QUIXOS_MEDIA_JSON_SCHEMA_KEY = "x-quixos-media";
|
||||
const readSchemaMeta = (schema) => {
|
||||
try {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import type { ZodError } from "zod";
|
||||
export type WireValidationErrorSummary = {
|
||||
publicMessage: string;
|
||||
debugMessage: string;
|
||||
fields: string[];
|
||||
};
|
||||
export declare const summarizeZodErrorForWire: (error: ZodError, { label, maxIssues, }?: {
|
||||
label?: string;
|
||||
maxIssues?: number;
|
||||
}) => WireValidationErrorSummary;
|
||||
//# sourceMappingURL=validation.d.ts.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,KAAK,CAAC;AAc9C,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,OAAO,QAAQ,EACf,wBAGG;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,KACL,0BAcF,CAAC"}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
const DEFAULT_MAX_ISSUES = 6;
|
||||
const issuePath = (issue) => {
|
||||
const path = issue.path
|
||||
.map((segment) => String(segment))
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(".");
|
||||
return path.length > 0 ? path : "<root>";
|
||||
};
|
||||
const unique = (values) => [...new Set(values)];
|
||||
export const summarizeZodErrorForWire = (error, { label = "message", maxIssues = DEFAULT_MAX_ISSUES, } = {}) => {
|
||||
const issues = error.issues.slice(0, maxIssues);
|
||||
const fields = unique(issues.map(issuePath));
|
||||
const fieldSummary = fields.length > 0 ? fields.join(", ") : "<unknown>";
|
||||
const suffix = error.issues.length > maxIssues ? ", ..." : "";
|
||||
const debugIssues = issues
|
||||
.map((issue) => `${issuePath(issue)}:${issue.code}`)
|
||||
.join(", ");
|
||||
return {
|
||||
publicMessage: `Invalid ${label}: invalid or missing field(s): ${fieldSummary}${suffix}`,
|
||||
debugMessage: `Invalid ${label}: ${debugIssues}${suffix}`,
|
||||
fields,
|
||||
};
|
||||
};
|
||||
//# sourceMappingURL=validation.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,MAAM,SAAS,GAAG,CAAC,KAAe,EAAE,EAAE;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI;SACpB,GAAG,CAAC,CAAC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AY,EAAE,WAAW,KAAK,KAAK,WAAW,GAAG,MAAM,EAAE;QACzD,MAAM;KACP,CAAC;AACJ,CAAC,CAAC"}
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from "./rpc.js";
|
||||
|
||||
export * from "./rpc.js";
|
||||
export * from "./validation.js";
|
||||
|
||||
export type PayloadMode = "snapshot" | "delta";
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { ZodError, ZodIssue } from "zod";
|
||||
|
||||
const DEFAULT_MAX_ISSUES = 6;
|
||||
|
||||
const issuePath = (issue: ZodIssue) => {
|
||||
const path = issue.path
|
||||
.map((segment) => String(segment))
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(".");
|
||||
return path.length > 0 ? path : "<root>";
|
||||
};
|
||||
|
||||
const unique = (values: string[]) => [...new Set(values)];
|
||||
|
||||
export type WireValidationErrorSummary = {
|
||||
publicMessage: string;
|
||||
debugMessage: string;
|
||||
fields: string[];
|
||||
};
|
||||
|
||||
export const summarizeZodErrorForWire = (
|
||||
error: ZodError,
|
||||
{
|
||||
label = "message",
|
||||
maxIssues = DEFAULT_MAX_ISSUES,
|
||||
}: {
|
||||
label?: string;
|
||||
maxIssues?: number;
|
||||
} = {},
|
||||
): WireValidationErrorSummary => {
|
||||
const issues = error.issues.slice(0, maxIssues);
|
||||
const fields = unique(issues.map(issuePath));
|
||||
const fieldSummary = fields.length > 0 ? fields.join(", ") : "<unknown>";
|
||||
const suffix = error.issues.length > maxIssues ? ", ..." : "";
|
||||
const debugIssues = issues
|
||||
.map((issue) => `${issuePath(issue)}:${issue.code}`)
|
||||
.join(", ");
|
||||
|
||||
return {
|
||||
publicMessage: `Invalid ${label}: invalid or missing field(s): ${fieldSummary}${suffix}`,
|
||||
debugMessage: `Invalid ${label}: ${debugIssues}${suffix}`,
|
||||
fields,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user