metriclistingrep.ts•14 kB
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
Access,
Access$inboundSchema,
Access$Outbound,
Access$outboundSchema,
} from "./access.js";
import {
Filter,
Filter$inboundSchema,
Filter$Outbound,
Filter$outboundSchema,
} from "./filter.js";
import {
Link,
Link$inboundSchema,
Link$Outbound,
Link$outboundSchema,
} from "./link.js";
import {
MemberSummary,
MemberSummary$inboundSchema,
MemberSummary$Outbound,
MemberSummary$outboundSchema,
} from "./membersummary.js";
import {
MetricEventDefaultRep,
MetricEventDefaultRep$inboundSchema,
MetricEventDefaultRep$Outbound,
MetricEventDefaultRep$outboundSchema,
} from "./metriceventdefaultrep.js";
import {
Modification,
Modification$inboundSchema,
Modification$Outbound,
Modification$outboundSchema,
} from "./modification.js";
/**
* The kind of event the metric tracks
*/
export const MetricListingRepKind = {
Pageview: "pageview",
Click: "click",
Custom: "custom",
} as const;
/**
* The kind of event the metric tracks
*/
export type MetricListingRepKind = ClosedEnum<typeof MetricListingRepKind>;
/**
* For custom metrics, the success criteria
*/
export const MetricListingRepSuccessCriteria = {
HigherThanBaseline: "HigherThanBaseline",
LowerThanBaseline: "LowerThanBaseline",
} as const;
/**
* For custom metrics, the success criteria
*/
export type MetricListingRepSuccessCriteria = ClosedEnum<
typeof MetricListingRepSuccessCriteria
>;
/**
* The method by which multiple unit event values are aggregated
*/
export const MetricListingRepUnitAggregationType = {
Average: "average",
Sum: "sum",
} as const;
/**
* The method by which multiple unit event values are aggregated
*/
export type MetricListingRepUnitAggregationType = ClosedEnum<
typeof MetricListingRepUnitAggregationType
>;
/**
* The method for analyzing metric events
*/
export const MetricListingRepAnalysisType = {
Mean: "mean",
Percentile: "percentile",
} as const;
/**
* The method for analyzing metric events
*/
export type MetricListingRepAnalysisType = ClosedEnum<
typeof MetricListingRepAnalysisType
>;
export type MetricListingRep = {
/**
* The number of experiments using this metric
*/
experimentCount?: number | undefined;
/**
* The number of metric groups using this metric
*/
metricGroupCount?: number | undefined;
/**
* The ID of this metric
*/
id: string;
/**
* The version ID of the metric
*/
versionId: string;
/**
* A unique key to reference the metric
*/
key: string;
/**
* A human-friendly name for the metric
*/
name: string;
/**
* The kind of event the metric tracks
*/
kind: MetricListingRepKind;
/**
* The number of feature flags currently attached to this metric
*/
attachedFlagCount?: number | undefined;
/**
* The location and content type of related resources
*/
links: { [k: string]: Link };
site?: Link | undefined;
access?: Access | undefined;
/**
* Tags for the metric
*/
tags: Array<string>;
creationDate: number;
lastModified?: Modification | undefined;
/**
* The ID of the member who maintains this metric
*/
maintainerId?: string | undefined;
maintainer?: MemberSummary | undefined;
/**
* Description of the metric
*/
description?: string | undefined;
/**
* The category of the metric
*/
category?: string | undefined;
/**
* For custom metrics, whether to track numeric changes in value against a baseline (<code>true</code>) or to track a conversion when an end user takes an action (<code>false</code>).
*/
isNumeric?: boolean | undefined;
/**
* For custom metrics, the success criteria
*/
successCriteria?: MetricListingRepSuccessCriteria | undefined;
/**
* For numeric custom metrics, the unit of measure
*/
unit?: string | undefined;
/**
* For custom metrics, the event key to use in your code
*/
eventKey?: string | undefined;
/**
* An array of randomization units allowed for this metric
*/
randomizationUnits?: Array<string> | undefined;
filters?: Filter | undefined;
/**
* The method by which multiple unit event values are aggregated
*/
unitAggregationType?: MetricListingRepUnitAggregationType | undefined;
/**
* The method for analyzing metric events
*/
analysisType?: MetricListingRepAnalysisType | undefined;
/**
* The percentile for the analysis method. An integer denoting the target percentile between 0 and 100. Required when <code>analysisType</code> is <code>percentile</code>.
*/
percentileValue?: number | undefined;
eventDefault?: MetricEventDefaultRep | undefined;
};
/** @internal */
export const MetricListingRepKind$inboundSchema: z.ZodNativeEnum<
typeof MetricListingRepKind
> = z.nativeEnum(MetricListingRepKind);
/** @internal */
export const MetricListingRepKind$outboundSchema: z.ZodNativeEnum<
typeof MetricListingRepKind
> = MetricListingRepKind$inboundSchema;
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace MetricListingRepKind$ {
/** @deprecated use `MetricListingRepKind$inboundSchema` instead. */
export const inboundSchema = MetricListingRepKind$inboundSchema;
/** @deprecated use `MetricListingRepKind$outboundSchema` instead. */
export const outboundSchema = MetricListingRepKind$outboundSchema;
}
/** @internal */
export const MetricListingRepSuccessCriteria$inboundSchema: z.ZodNativeEnum<
typeof MetricListingRepSuccessCriteria
> = z.nativeEnum(MetricListingRepSuccessCriteria);
/** @internal */
export const MetricListingRepSuccessCriteria$outboundSchema: z.ZodNativeEnum<
typeof MetricListingRepSuccessCriteria
> = MetricListingRepSuccessCriteria$inboundSchema;
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace MetricListingRepSuccessCriteria$ {
/** @deprecated use `MetricListingRepSuccessCriteria$inboundSchema` instead. */
export const inboundSchema = MetricListingRepSuccessCriteria$inboundSchema;
/** @deprecated use `MetricListingRepSuccessCriteria$outboundSchema` instead. */
export const outboundSchema = MetricListingRepSuccessCriteria$outboundSchema;
}
/** @internal */
export const MetricListingRepUnitAggregationType$inboundSchema: z.ZodNativeEnum<
typeof MetricListingRepUnitAggregationType
> = z.nativeEnum(MetricListingRepUnitAggregationType);
/** @internal */
export const MetricListingRepUnitAggregationType$outboundSchema:
z.ZodNativeEnum<typeof MetricListingRepUnitAggregationType> =
MetricListingRepUnitAggregationType$inboundSchema;
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace MetricListingRepUnitAggregationType$ {
/** @deprecated use `MetricListingRepUnitAggregationType$inboundSchema` instead. */
export const inboundSchema =
MetricListingRepUnitAggregationType$inboundSchema;
/** @deprecated use `MetricListingRepUnitAggregationType$outboundSchema` instead. */
export const outboundSchema =
MetricListingRepUnitAggregationType$outboundSchema;
}
/** @internal */
export const MetricListingRepAnalysisType$inboundSchema: z.ZodNativeEnum<
typeof MetricListingRepAnalysisType
> = z.nativeEnum(MetricListingRepAnalysisType);
/** @internal */
export const MetricListingRepAnalysisType$outboundSchema: z.ZodNativeEnum<
typeof MetricListingRepAnalysisType
> = MetricListingRepAnalysisType$inboundSchema;
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace MetricListingRepAnalysisType$ {
/** @deprecated use `MetricListingRepAnalysisType$inboundSchema` instead. */
export const inboundSchema = MetricListingRepAnalysisType$inboundSchema;
/** @deprecated use `MetricListingRepAnalysisType$outboundSchema` instead. */
export const outboundSchema = MetricListingRepAnalysisType$outboundSchema;
}
/** @internal */
export const MetricListingRep$inboundSchema: z.ZodType<
MetricListingRep,
z.ZodTypeDef,
unknown
> = z.object({
experimentCount: z.number().int().optional(),
metricGroupCount: z.number().int().optional(),
_id: z.string(),
_versionId: z.string(),
key: z.string(),
name: z.string(),
kind: MetricListingRepKind$inboundSchema,
_attachedFlagCount: z.number().int().optional(),
_links: z.record(Link$inboundSchema),
_site: Link$inboundSchema.optional(),
_access: Access$inboundSchema.optional(),
tags: z.array(z.string()),
_creationDate: z.number().int(),
lastModified: Modification$inboundSchema.optional(),
maintainerId: z.string().optional(),
_maintainer: MemberSummary$inboundSchema.optional(),
description: z.string().optional(),
category: z.string().optional(),
isNumeric: z.boolean().optional(),
successCriteria: MetricListingRepSuccessCriteria$inboundSchema.optional(),
unit: z.string().optional(),
eventKey: z.string().optional(),
randomizationUnits: z.array(z.string()).optional(),
filters: Filter$inboundSchema.optional(),
unitAggregationType: MetricListingRepUnitAggregationType$inboundSchema
.optional(),
analysisType: MetricListingRepAnalysisType$inboundSchema.optional(),
percentileValue: z.number().int().optional(),
eventDefault: MetricEventDefaultRep$inboundSchema.optional(),
}).transform((v) => {
return remap$(v, {
"_id": "id",
"_versionId": "versionId",
"_attachedFlagCount": "attachedFlagCount",
"_links": "links",
"_site": "site",
"_access": "access",
"_creationDate": "creationDate",
"_maintainer": "maintainer",
});
});
/** @internal */
export type MetricListingRep$Outbound = {
experimentCount?: number | undefined;
metricGroupCount?: number | undefined;
_id: string;
_versionId: string;
key: string;
name: string;
kind: string;
_attachedFlagCount?: number | undefined;
_links: { [k: string]: Link$Outbound };
_site?: Link$Outbound | undefined;
_access?: Access$Outbound | undefined;
tags: Array<string>;
_creationDate: number;
lastModified?: Modification$Outbound | undefined;
maintainerId?: string | undefined;
_maintainer?: MemberSummary$Outbound | undefined;
description?: string | undefined;
category?: string | undefined;
isNumeric?: boolean | undefined;
successCriteria?: string | undefined;
unit?: string | undefined;
eventKey?: string | undefined;
randomizationUnits?: Array<string> | undefined;
filters?: Filter$Outbound | undefined;
unitAggregationType?: string | undefined;
analysisType?: string | undefined;
percentileValue?: number | undefined;
eventDefault?: MetricEventDefaultRep$Outbound | undefined;
};
/** @internal */
export const MetricListingRep$outboundSchema: z.ZodType<
MetricListingRep$Outbound,
z.ZodTypeDef,
MetricListingRep
> = z.object({
experimentCount: z.number().int().optional(),
metricGroupCount: z.number().int().optional(),
id: z.string(),
versionId: z.string(),
key: z.string(),
name: z.string(),
kind: MetricListingRepKind$outboundSchema,
attachedFlagCount: z.number().int().optional(),
links: z.record(Link$outboundSchema),
site: Link$outboundSchema.optional(),
access: Access$outboundSchema.optional(),
tags: z.array(z.string()),
creationDate: z.number().int(),
lastModified: Modification$outboundSchema.optional(),
maintainerId: z.string().optional(),
maintainer: MemberSummary$outboundSchema.optional(),
description: z.string().optional(),
category: z.string().optional(),
isNumeric: z.boolean().optional(),
successCriteria: MetricListingRepSuccessCriteria$outboundSchema.optional(),
unit: z.string().optional(),
eventKey: z.string().optional(),
randomizationUnits: z.array(z.string()).optional(),
filters: Filter$outboundSchema.optional(),
unitAggregationType: MetricListingRepUnitAggregationType$outboundSchema
.optional(),
analysisType: MetricListingRepAnalysisType$outboundSchema.optional(),
percentileValue: z.number().int().optional(),
eventDefault: MetricEventDefaultRep$outboundSchema.optional(),
}).transform((v) => {
return remap$(v, {
id: "_id",
versionId: "_versionId",
attachedFlagCount: "_attachedFlagCount",
links: "_links",
site: "_site",
access: "_access",
creationDate: "_creationDate",
maintainer: "_maintainer",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace MetricListingRep$ {
/** @deprecated use `MetricListingRep$inboundSchema` instead. */
export const inboundSchema = MetricListingRep$inboundSchema;
/** @deprecated use `MetricListingRep$outboundSchema` instead. */
export const outboundSchema = MetricListingRep$outboundSchema;
/** @deprecated use `MetricListingRep$Outbound` instead. */
export type Outbound = MetricListingRep$Outbound;
}
export function metricListingRepToJSON(
metricListingRep: MetricListingRep,
): string {
return JSON.stringify(
MetricListingRep$outboundSchema.parse(metricListingRep),
);
}
export function metricListingRepFromJSON(
jsonString: string,
): SafeParseResult<MetricListingRep, SDKValidationError> {
return safeParse(
jsonString,
(x) => MetricListingRep$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'MetricListingRep' from JSON`,
);
}