11import { BatchConfig } from "." ;
2- import { type z } from "zod" ;
32import { DOMAttributes } from "react" ;
43import type { DebounceConfig } from "./utils/debounce" ;
54import type { ThrottleConfig } from "./utils/throttle" ;
@@ -14,9 +13,11 @@ export type SetContext<TContext extends Context = Context> = (
1413export type EventNames = "onImpression" | "onPageView" | DOMEventNames ;
1514
1615/** EventParams */
17- export type SchemaParams < TSchemas extends Schemas = Schemas , TKey extends keyof TSchemas = keyof TSchemas > = z . infer <
18- TSchemas [ TKey ]
19- > ;
16+ export type SchemaParams <
17+ TSchemas extends Schemas = Schemas ,
18+ TKey extends keyof TSchemas = keyof TSchemas ,
19+ > = StandardSchemaV1 . InferOutput < TSchemas [ TKey ] > ;
20+
2021export type EventParams = Record < string , any > ;
2122export type EventParamsWithSchema <
2223 TContext extends Context = Context ,
@@ -101,12 +102,12 @@ export interface PageViewConfig<
101102}
102103
103104/** Schema */
104- export type Schemas = Record < string , z . ZodObject < any > > ;
105+ export type Schemas = Record < string , StandardSchemaV1 < any , any > > ;
105106export interface SchemaConfig < TSchemas extends Schemas = Schemas > {
106107 /** A record of schemas */
107108 schemas : TSchemas ;
108109 /** A function to handle schema errors */
109- onSchemaError ?: ( error : z . ZodError ) => void ;
110+ onSchemaError ?: ( error : ReadonlyArray < StandardSchemaV1 . Issue > ) => void ;
110111 /** If true, abort the event execution if a schema error occurs */
111112 abortOnError ?: boolean ;
112113}
@@ -198,3 +199,69 @@ export type TrackingOptions<TContext extends Context = Context, TEventParams ext
198199 | { throttle : ThrottleConfig ; debounce ?: never }
199200 | { debounce ?: never ; throttle ?: never }
200201) ;
202+
203+ // standard schema
204+ /** The Standard Schema interface. */
205+ export interface StandardSchemaV1 < Input = unknown , Output = Input > {
206+ /** The Standard Schema properties. */
207+ readonly "~standard" : StandardSchemaV1 . Props < Input , Output > ;
208+ }
209+
210+ export declare namespace StandardSchemaV1 {
211+ /** The Standard Schema properties interface. */
212+ export interface Props < Input = unknown , Output = Input > {
213+ /** The version number of the standard. */
214+ readonly version : 1 ;
215+ /** The vendor name of the schema library. */
216+ readonly vendor : string ;
217+ /** Validates unknown input values. */
218+ readonly validate : ( value : unknown ) => Result < Output > | Promise < Result < Output > > ;
219+ /** Inferred types associated with the schema. */
220+ readonly types ?: Types < Input , Output > | undefined ;
221+ }
222+
223+ /** The result interface of the validate function. */
224+ export type Result < Output > = SuccessResult < Output > | FailureResult ;
225+
226+ /** The result interface if validation succeeds. */
227+ export interface SuccessResult < Output > {
228+ /** The typed output value. */
229+ readonly value : Output ;
230+ /** The non-existent issues. */
231+ readonly issues ?: undefined ;
232+ }
233+
234+ /** The result interface if validation fails. */
235+ export interface FailureResult {
236+ /** The issues of failed validation. */
237+ readonly issues : ReadonlyArray < Issue > ;
238+ }
239+
240+ /** The issue interface of the failure output. */
241+ export interface Issue {
242+ /** The error message of the issue. */
243+ readonly message : string ;
244+ /** The path of the issue, if any. */
245+ readonly path ?: ReadonlyArray < PropertyKey | PathSegment > | undefined ;
246+ }
247+
248+ /** The path segment interface of the issue. */
249+ export interface PathSegment {
250+ /** The key representing a path segment. */
251+ readonly key : PropertyKey ;
252+ }
253+
254+ /** The Standard Schema types interface. */
255+ export interface Types < Input = unknown , Output = Input > {
256+ /** The input type of the schema. */
257+ readonly input : Input ;
258+ /** The output type of the schema. */
259+ readonly output : Output ;
260+ }
261+
262+ /** Infers the input type of a Standard Schema. */
263+ export type InferInput < Schema extends StandardSchemaV1 > = NonNullable < Schema [ "~standard" ] [ "types" ] > [ "input" ] ;
264+
265+ /** Infers the output type of a Standard Schema. */
266+ export type InferOutput < Schema extends StandardSchemaV1 > = NonNullable < Schema [ "~standard" ] [ "types" ] > [ "output" ] ;
267+ }
0 commit comments