Skip to content

Commit 40e23ad

Browse files
authored
refactor(cli): zod namespace (#6278)
1 parent ec04b46 commit 40e23ad

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

packages/libraries/cli/src/helpers/config.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { sync as mkdirp } from 'mkdirp';
4-
import * as zod from 'zod';
4+
import { z } from 'zod';
55

6-
const LegacyConfigModel = zod.object({
7-
registry: zod.string().optional(),
8-
token: zod.string().optional(),
6+
const LegacyConfigModel = z.object({
7+
registry: z.string().optional(),
8+
token: z.string().optional(),
99
});
1010

11-
const ConfigModel = zod.object({
12-
registry: zod
11+
const ConfigModel = z.object({
12+
registry: z
1313
.object({
14-
endpoint: zod.string().url().optional(),
15-
accessToken: zod.string().optional(),
14+
endpoint: z.string().url().optional(),
15+
accessToken: z.string().optional(),
1616
})
1717
.optional(),
18-
cdn: zod
18+
cdn: z
1919
.object({
20-
endpoint: zod.string().url().optional(),
21-
accessToken: zod.string().optional(),
20+
endpoint: z.string().url().optional(),
21+
accessToken: z.string().optional(),
2222
})
2323
.optional(),
2424
});
2525

26-
const getAllowedConfigKeys = <TConfig extends zod.ZodObject<any>>(
26+
const getAllowedConfigKeys = <TConfig extends z.ZodObject<any>>(
2727
config: TConfig,
2828
): Set<GetConfigurationKeys<TConfig>> => {
2929
const keys = new Set<GetConfigurationKeys<TConfig>>();
3030

31-
const traverse = (obj: zod.ZodObject<Record<string, any>>, path: Array<string> = []): string => {
32-
if (obj instanceof zod.ZodObject) {
31+
const traverse = (obj: z.ZodObject<Record<string, any>>, path: Array<string> = []): string => {
32+
if (obj instanceof z.ZodObject) {
3333
const shape = obj.shape;
3434
for (const [key, value] of Object.entries(shape)) {
3535
traverse(value, [...path, key]);
@@ -46,22 +46,22 @@ const getAllowedConfigKeys = <TConfig extends zod.ZodObject<any>>(
4646
return keys;
4747
};
4848

49-
export type ConfigModelType = zod.TypeOf<typeof ConfigModel>;
49+
export type ConfigModelType = z.TypeOf<typeof ConfigModel>;
5050

51-
type BuildPropertyPath<TObject extends zod.ZodObject<any>> = `.${GetConfigurationKeys<TObject>}`;
51+
type BuildPropertyPath<TObject extends z.ZodObject<any>> = `.${GetConfigurationKeys<TObject>}`;
5252

5353
type GetConfigurationKeys<
54-
T extends zod.ZodObject<{
55-
[key: string]: zod.ZodType<any, any>;
54+
T extends z.ZodObject<{
55+
[key: string]: z.ZodType<any, any>;
5656
}>,
5757
> =
58-
T extends zod.ZodObject<infer TObjectShape>
58+
T extends z.ZodObject<infer TObjectShape>
5959
? TObjectShape extends Record<infer TKey, infer TObjectPropertyType>
6060
? TKey extends string
61-
? `${TKey}${TObjectPropertyType extends zod.ZodObject<any>
61+
? `${TKey}${TObjectPropertyType extends z.ZodObject<any>
6262
? BuildPropertyPath<TObjectPropertyType>
63-
: TObjectPropertyType extends zod.ZodOptional<infer TOptionalInnerObjectPropertyType>
64-
? TOptionalInnerObjectPropertyType extends zod.ZodObject<any>
63+
: TObjectPropertyType extends z.ZodOptional<infer TOptionalInnerObjectPropertyType>
64+
? TOptionalInnerObjectPropertyType extends z.ZodObject<any>
6565
? BuildPropertyPath<TOptionalInnerObjectPropertyType>
6666
: ''
6767
: ''}`
@@ -71,19 +71,19 @@ type GetConfigurationKeys<
7171

7272
type GetZodValueType<
7373
TString extends string,
74-
ConfigurationModelType extends zod.ZodObject<any>,
74+
ConfigurationModelType extends z.ZodObject<any>,
7575
> = TString extends `${infer TKey}.${infer TNextKey}`
76-
? ConfigurationModelType extends zod.ZodObject<infer InnerType>
77-
? InnerType[TKey] extends zod.ZodObject<any>
76+
? ConfigurationModelType extends z.ZodObject<infer InnerType>
77+
? InnerType[TKey] extends z.ZodObject<any>
7878
? GetZodValueType<TNextKey, InnerType[TKey]>
79-
: InnerType[TKey] extends zod.ZodOptional<infer OptionalInner>
80-
? OptionalInner extends zod.ZodObject<any>
79+
: InnerType[TKey] extends z.ZodOptional<infer OptionalInner>
80+
? OptionalInner extends z.ZodObject<any>
8181
? GetZodValueType<TNextKey, OptionalInner>
8282
: never
8383
: never
8484
: never
85-
: ConfigurationModelType extends zod.ZodObject<infer InnerType>
86-
? zod.TypeOf<InnerType[TString]>
85+
: ConfigurationModelType extends z.ZodObject<infer InnerType>
86+
? z.TypeOf<InnerType[TString]>
8787
: never;
8888

8989
export type GetConfigurationValueType<TString extends string> = GetZodValueType<

0 commit comments

Comments
 (0)