@sonamu-kit/react-components 0.5.3 → 0.6.0

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.
@@ -1,6 +1,18 @@
1
1
  import { z } from 'zod';
2
2
  import { FilterPropType } from '../../../lib/types';
3
3
  import { FieldMeta, FilterFieldMetadata } from './types';
4
+ declare module "zod" {
5
+ /**
6
+ * Sonamu 생성 코드가 zod 기본 레지스트리 메타에 싣는 표식 중 필터가 읽는 키입니다.
7
+ * sonamu 패키지의 같은 선언과 맞춰 둡니다.
8
+ */
9
+ interface GlobalMeta {
10
+ /** 생성된 enum의 ID. `enum.{EnumId}.{값}` 라벨 키를 만들 때 씁니다. */
11
+ SonamuEnumId?: string;
12
+ /** numeric 칸 표시 */
13
+ SonamuPropType?: "numeric";
14
+ }
15
+ }
4
16
  type UnwrappedZodType = {
5
17
  innerType: z.core.$ZodType;
6
18
  nullable: boolean;
@@ -33,8 +33,8 @@ function s(t) {
33
33
  }
34
34
  function c(e, t) {
35
35
  if (!i(e)) return;
36
- let n = Array.from(e.options), a = r.globalRegistry.get(e)?.description, o = {};
37
- if (a) for (let e of n) o[e] = t(`enum.${a}.${e}`);
36
+ let n = Array.from(e.options), a = r.globalRegistry.get(e)?.SonamuEnumId, o = {};
37
+ for (let e of n) o[e] = a ? t(`enum.${a}.${e}`) : e;
38
38
  return {
39
39
  options: n,
40
40
  labels: o
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["isEnumLike","zodType","getZodType","isObject","typeName","isString","unwrapZodType","current","nullable","z","zodTypeNameToPropType","zodTypeToFilterPropTypeMap","extractEnumData","zodEnum","options","enumDescription","labels","option","SD","extractFieldMetaFromSchema","fieldDefinitions","schema","\"shape\"","fieldMeta","fieldName","zodSchema","propType","innerType"],"sources":["../../../../src/components/ui/sonamu-filter/utils.ts"],"sourcesContent":["import { isObject, isString } from \"radashi\";\nimport { z } from \"zod\";\n\nimport { type FilterPropType } from \"../../../lib/types\";\nimport { zodTypeToFilterPropTypeMap } from \"./constants\";\nimport { type FieldMeta, type FilterFieldMetadata } from \"./types\";\n\ntype UnwrappedZodType = {\n innerType: z.core.$ZodType;\n nullable: boolean;\n};\n\ntype EnumLike = z.core.$ZodType & {\n options: readonly string[];\n};\n\nfunction isEnumLike(zodType: z.core.$ZodType): zodType is EnumLike {\n return \"options\" in zodType && Array.isArray(zodType.options);\n}\n\nfunction getZodType(zodType: z.core.$ZodType): string {\n if (\"def\" in zodType && isObject(zodType.def) && \"type\" in zodType.def) {\n const typeName = zodType.def.type;\n if (isString(typeName)) return typeName;\n }\n return \"unknown\";\n}\n\n/**\n * ZodNullable, ZodOptional 등의 래퍼를 벗겨내고 내부 타입을 반환\n * nullable/optional 여부도 함께 반환\n */\nexport function unwrapZodType(zodType: z.ZodTypeAny): UnwrappedZodType {\n let current: z.core.$ZodType = zodType;\n let nullable = false;\n\n while (current instanceof z.ZodNullable || current instanceof z.ZodOptional) {\n if (current instanceof z.ZodNullable) {\n nullable = true;\n }\n current = current.def.innerType;\n }\n\n return { innerType: current, nullable };\n}\n\n/**\n * Zod 타입 이름을 FilterPropType으로 변환\n */\nexport function zodTypeNameToPropType(typeName: string): FilterPropType {\n switch (typeName) {\n case \"number\":\n return zodTypeToFilterPropTypeMap.number;\n case \"boolean\":\n return zodTypeToFilterPropTypeMap.boolean;\n case \"date\":\n return zodTypeToFilterPropTypeMap.date;\n case \"enum\":\n return zodTypeToFilterPropTypeMap.enum;\n case \"array\":\n return zodTypeToFilterPropTypeMap.array;\n case \"object\":\n return zodTypeToFilterPropTypeMap.object;\n default:\n return zodTypeToFilterPropTypeMap.string;\n }\n}\n\n/**\n * Zod enum에서 options와 labels를 추출\n * SD 함수를 사용하여 enum.{EnumName}.{value} 형태로 라벨 조회\n */\nexport function extractEnumData(\n zodEnum: z.core.$ZodType,\n SD: (key: string) => string,\n): FieldMeta[\"enumData\"] {\n // options 추출\n if (!isEnumLike(zodEnum)) {\n return undefined;\n }\n const options = Array.from(zodEnum.options);\n\n // labels 추출 (SD 함수 사용: enum.{EnumName}.{value})\n const enumDescription = z.globalRegistry.get(zodEnum)?.description;\n const labels: Record<string, string> = {};\n\n if (enumDescription) {\n for (const option of options) {\n const dictKey = `enum.${enumDescription}.${option}`;\n labels[option] = SD(dictKey);\n }\n }\n\n return { options, labels };\n}\n\n/**\n * Zod 스키마에서 각 필드의 타입 정보를 추출하여 FieldMeta 형태로 변환\n */\nexport function extractFieldMetaFromSchema(\n schema: z.ZodObject,\n SD: (key: string) => string,\n): FilterFieldMetadata {\n const fieldDefinitions = schema[\"shape\"];\n const fieldMeta: FilterFieldMetadata = {};\n\n for (const [fieldName, zodSchema] of Object.entries(fieldDefinitions)) {\n // virtual, textsearchable로 시작하는 필드는 제외\n if (fieldName.startsWith(\"virtual\") || fieldName.startsWith(\"textsearchable\")) {\n continue;\n }\n\n // nullable/optional 벗겨내기\n const { innerType, nullable } = unwrapZodType(zodSchema);\n\n // 메타 SonamuPropType 체크 (numeric 등)\n const metadata = zodSchema.meta();\n const sonamuPropType = metadata?.SonamuPropType;\n const isNumeric = sonamuPropType === \"numeric\";\n\n // propType 결정\n const propType: FilterPropType = isNumeric\n ? \"numeric\"\n : zodTypeNameToPropType(getZodType(innerType));\n\n // enum 타입인 경우 추가 정보 추출\n const enumData = propType === \"enum\" ? extractEnumData(innerType, SD) : undefined;\n\n fieldMeta[fieldName] = {\n propType,\n nullable,\n enumData,\n };\n }\n\n return fieldMeta;\n}\n"],"mappings":";;;;AAgBA,SAASA,EAAW,GAA+C;CACjE,OAAO,aAAaC,KAAW,MAAM,QAAQA,EAAQ,OAAO;AAC9D;AAEA,SAASC,EAAW,GAAkC;CACpD,IAAI,SAASD,KAAWE,EAASF,EAAQ,GAAG,KAAK,UAAUA,EAAQ,KAAK;EACtE,IAAMG,IAAWH,EAAQ,IAAI;EAC7B,IAAII,EAASD,CAAQ,GAAG,OAAOA;CACjC;CACA,OAAO;AACT;AAMA,SAAgBE,EAAc,GAA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;CAEA,OAAOK;AACT"}
1
+ {"version":3,"file":"utils.js","names":["isEnumLike","zodType","getZodType","isObject","typeName","isString","unwrapZodType","current","nullable","z","zodTypeNameToPropType","zodTypeToFilterPropTypeMap","extractEnumData","zodEnum","options","enumId","labels","option","SD","extractFieldMetaFromSchema","fieldDefinitions","schema","\"shape\"","fieldMeta","fieldName","zodSchema","propType","innerType"],"sources":["../../../../src/components/ui/sonamu-filter/utils.ts"],"sourcesContent":["import { isObject, isString } from \"radashi\";\nimport { z } from \"zod\";\n\nimport { type FilterPropType } from \"../../../lib/types\";\nimport { zodTypeToFilterPropTypeMap } from \"./constants\";\nimport { type FieldMeta, type FilterFieldMetadata } from \"./types\";\n\ndeclare module \"zod\" {\n /**\n * Sonamu 생성 코드가 zod 기본 레지스트리 메타에 싣는 표식 중 필터가 읽는 키입니다.\n * sonamu 패키지의 같은 선언과 맞춰 둡니다.\n */\n interface GlobalMeta {\n /** 생성된 enum의 ID. `enum.{EnumId}.{값}` 라벨 키를 만들 때 씁니다. */\n SonamuEnumId?: string;\n /** numeric 칸 표시 */\n SonamuPropType?: \"numeric\";\n }\n}\n\ntype UnwrappedZodType = {\n innerType: z.core.$ZodType;\n nullable: boolean;\n};\n\ntype EnumLike = z.core.$ZodType & {\n options: readonly string[];\n};\n\nfunction isEnumLike(zodType: z.core.$ZodType): zodType is EnumLike {\n return \"options\" in zodType && Array.isArray(zodType.options);\n}\n\nfunction getZodType(zodType: z.core.$ZodType): string {\n if (\"def\" in zodType && isObject(zodType.def) && \"type\" in zodType.def) {\n const typeName = zodType.def.type;\n if (isString(typeName)) return typeName;\n }\n return \"unknown\";\n}\n\n/**\n * ZodNullable, ZodOptional 등의 래퍼를 벗겨내고 내부 타입을 반환\n * nullable/optional 여부도 함께 반환\n */\nexport function unwrapZodType(zodType: z.ZodTypeAny): UnwrappedZodType {\n let current: z.core.$ZodType = zodType;\n let nullable = false;\n\n while (current instanceof z.ZodNullable || current instanceof z.ZodOptional) {\n if (current instanceof z.ZodNullable) {\n nullable = true;\n }\n current = current.def.innerType;\n }\n\n return { innerType: current, nullable };\n}\n\n/**\n * Zod 타입 이름을 FilterPropType으로 변환\n */\nexport function zodTypeNameToPropType(typeName: string): FilterPropType {\n switch (typeName) {\n case \"number\":\n return zodTypeToFilterPropTypeMap.number;\n case \"boolean\":\n return zodTypeToFilterPropTypeMap.boolean;\n case \"date\":\n return zodTypeToFilterPropTypeMap.date;\n case \"enum\":\n return zodTypeToFilterPropTypeMap.enum;\n case \"array\":\n return zodTypeToFilterPropTypeMap.array;\n case \"object\":\n return zodTypeToFilterPropTypeMap.object;\n default:\n return zodTypeToFilterPropTypeMap.string;\n }\n}\n\n/**\n * Zod enum에서 options와 labels를 추출\n * SD 함수를 사용하여 enum.{EnumName}.{value} 형태로 라벨 조회\n */\nexport function extractEnumData(\n zodEnum: z.core.$ZodType,\n SD: (key: string) => string,\n): FieldMeta[\"enumData\"] {\n // options 추출\n if (!isEnumLike(zodEnum)) {\n return undefined;\n }\n const options = Array.from(zodEnum.options);\n\n // labels 추출 (SD 함수 사용: enum.{EnumId}.{value})\n // Sonamu 생성 코드가 `.meta({ SonamuEnumId })`로 실어 둔 enum ID를 읽습니다.\n const enumId = z.globalRegistry.get(zodEnum)?.SonamuEnumId;\n const labels: Record<string, string> = {};\n\n for (const option of options) {\n // enum ID가 없으면(직접 만든 enum 등) 라벨 키를 만들 수 없으므로 값을 그대로 라벨로 씁니다.\n labels[option] = enumId ? SD(`enum.${enumId}.${option}`) : option;\n }\n\n return { options, labels };\n}\n\n/**\n * Zod 스키마에서 각 필드의 타입 정보를 추출하여 FieldMeta 형태로 변환\n */\nexport function extractFieldMetaFromSchema(\n schema: z.ZodObject,\n SD: (key: string) => string,\n): FilterFieldMetadata {\n const fieldDefinitions = schema[\"shape\"];\n const fieldMeta: FilterFieldMetadata = {};\n\n for (const [fieldName, zodSchema] of Object.entries(fieldDefinitions)) {\n // virtual, textsearchable로 시작하는 필드는 제외\n if (fieldName.startsWith(\"virtual\") || fieldName.startsWith(\"textsearchable\")) {\n continue;\n }\n\n // nullable/optional 벗겨내기\n const { innerType, nullable } = unwrapZodType(zodSchema);\n\n // 메타 SonamuPropType 체크 (numeric 등)\n const metadata = zodSchema.meta();\n const sonamuPropType = metadata?.SonamuPropType;\n const isNumeric = sonamuPropType === \"numeric\";\n\n // propType 결정\n const propType: FilterPropType = isNumeric\n ? \"numeric\"\n : zodTypeNameToPropType(getZodType(innerType));\n\n // enum 타입인 경우 추가 정보 추출\n const enumData = propType === \"enum\" ? extractEnumData(innerType, SD) : undefined;\n\n fieldMeta[fieldName] = {\n propType,\n nullable,\n enumData,\n };\n }\n\n return fieldMeta;\n}\n"],"mappings":";;;;AA6BA,SAASA,EAAW,GAA+C;CACjE,OAAO,aAAaC,KAAW,MAAM,QAAQA,EAAQ,OAAO;AAC9D;AAEA,SAASC,EAAW,GAAkC;CACpD,IAAI,SAASD,KAAWE,EAASF,EAAQ,GAAG,KAAK,UAAUA,EAAQ,KAAK;EACtE,IAAMG,IAAWH,EAAQ,IAAI;EAC7B,IAAII,EAASD,CAAQ,GAAG,OAAOA;CACjC;CACA,OAAO;AACT;AAMA,SAAgBE,EAAc,GAAyC;CACrE,IAAIC,IAA2BN,GAC3BO,IAAW;CAEf,OAAOD,aAAmBE,EAAE,eAAeF,aAAmBE,EAAE,cAI9D,AAHIF,aAAmBE,EAAE,gBACvB,IAAW,KAEb,IAAUF,EAAQ,IAAI;CAGxB,OAAO;EAAE,WAAWA;EAAS;CAAS;AACxC;AAKA,SAAgBG,EAAsB,GAAkC;CACtE,QAAQN,GAAR;EACE,KAAK,UACH,OAAOO,EAA2B;EACpC,KAAK,WACH,OAAOA,EAA2B;EACpC,KAAK,QACH,OAAOA,EAA2B;EACpC,KAAK,QACH,OAAOA,EAA2B;EACpC,KAAK,SACH,OAAOA,EAA2B;EACpC,KAAK,UACH,OAAOA,EAA2B;EACpC,SACE,OAAOA,EAA2B;CACtC;AACF;AAMA,SAAgBC,EACd,GACA,GACuB;CAEvB,IAAI,CAACZ,EAAWa,CAAO,GACrB;CAEF,IAAMC,IAAU,MAAM,KAAKD,EAAQ,OAAO,GAIpCE,IAASN,EAAE,eAAe,IAAII,CAAO,CAAC,EAAE,cACxCG,IAAiC,CAAC;CAExC,KAAK,IAAMC,KAAUH,GAEnB,EAAOG,KAAUF,IAASG,EAAG,QAAQH,EAAO,GAAGE,GAAQ,IAAIA;CAG7D,OAAO;EAAE;EAAS;CAAO;AAC3B;AAKA,SAAgBE,EACd,GACA,GACqB;CACrB,IAAMC,IAAmBC,EAAOC,OAC1BC,IAAiC,CAAC;CAExC,KAAK,IAAM,CAACC,GAAWC,MAAc,OAAO,QAAQL,CAAgB,GAAG;EAErE,IAAII,EAAU,WAAW,SAAS,KAAKA,EAAU,WAAW,gBAAgB,GAC1E;EAIF,IAAM,EAAE,cAAW,gBAAalB,EAAcmB,CAAS,GAQjDC,IALWD,EAAU,KACJ,CAAA,EAAU,mBACI,YAIjC,YACAf,EAAsBR,EAAWyB,CAAS,CAAC;EAK/C,EAAUH,KAAa;GACrB;GACA;GACA,UALeE,MAAa,SAASd,EAAgBe,GAAWT,CAAE,IAAI,KAAA;EAMxE;CACF;CAEA,OAAOK;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonamu-kit/react-components",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "author": "CartaNova <dev@cartanova.ai>",
6
6
  "repository": {