deno.land / x / pothos@release-1713397530 / packages / core / utils / enums.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// @ts-nocheckimport { BaseEnum, EnumValues, PothosEnumValueConfig, SchemaTypes } from '../types/index.ts';export function normalizeEnumValues<Types extends SchemaTypes>(values: EnumValues<SchemaTypes>): Record<string, PothosEnumValueConfig<Types>> { const result: Record<string, PothosEnumValueConfig<Types>> = {}; if (Array.isArray(values)) { values.forEach((key) => { result[String(key)] = { pothosOptions: {}, }; }); } else { Object.entries(values).forEach(([key, value]) => { if (value && typeof value === "object") { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment result[key] = { ...value, pothosOptions: value as PothosSchemaTypes.EnumValueConfig<Types>, }; } else if (typeof value === "string") { result[value] = { pothosOptions: {}, }; } }); } return result;}export function valuesFromEnum<Types extends SchemaTypes>(Enum: BaseEnum, values?: Record<string, Omit<PothosSchemaTypes.EnumValueConfig<Types>, "value">>): Record<string, PothosEnumValueConfig<Types>> { const result: Record<string, PothosEnumValueConfig<Types>> = {}; Object.keys(Enum) .filter((key) => typeof Enum[Enum[key]] !== "number") .forEach((key) => { result[key] = { value: Enum[key], pothosOptions: {}, ...values?.[key], }; }); return result;}
pothos

Version Info

Tagged at
a year ago