|
1 | 1 | import type { LogLevelNames } from 'loglevel'
|
2 |
| -import type { |
3 |
| - ButtonProps, |
4 |
| - DialogProps, |
5 |
| - DividerProps, |
6 |
| - Grid2Props, |
7 |
| - SxProps, |
8 |
| - TypographyProps, |
9 |
| -} from '@mui/material' |
| 2 | +import type { DialogProps } from '@mui/material' |
10 | 3 | import type { UiconsIndex } from 'uicons.js'
|
| 4 | + |
11 | 5 | import { Props as ImgProps } from '@components/Img'
|
12 | 6 |
|
| 7 | +import type { CustomComponent } from './blocks' |
13 | 8 | import config = require('server/src/configs/default.json')
|
14 | 9 | import example = require('server/src/configs/local.example.json')
|
15 | 10 |
|
16 | 11 | import type { Schema } from './server'
|
17 |
| -import { OnlyType, DeepMerge, ComparisonReport } from './utility' |
| 12 | +import { |
| 13 | + OnlyType, |
| 14 | + DeepMerge, |
| 15 | + ComparisonReport, |
| 16 | + Paths, |
| 17 | + ObjectPathValue, |
| 18 | +} from './utility' |
18 | 19 |
|
19 | 20 | type BaseConfig = typeof config
|
20 | 21 | type ExampleConfig = typeof example
|
@@ -54,12 +55,8 @@ export type Config<Client extends boolean = false> = DeepMerge<
|
54 | 55 | methods: string[]
|
55 | 56 | strategies: {
|
56 | 57 | trialPeriod: {
|
57 |
| - start: { |
58 |
| - js: Date |
59 |
| - } |
60 |
| - end: { |
61 |
| - js: Date |
62 |
| - } |
| 58 | + start: TrialPeriodDate |
| 59 | + end: TrialPeriodDate |
63 | 60 | roles: string[]
|
64 | 61 | }
|
65 | 62 | allowedGuilds: string[]
|
@@ -151,6 +148,20 @@ export interface Icons extends Omit<BaseConfig['icons'], 'styles'> {
|
151 | 148 | defaultIcons: Record<string, string>
|
152 | 149 | }
|
153 | 150 |
|
| 151 | +type BaseTrial = |
| 152 | + BaseConfig['authentication']['strategies'][number]['trialPeriod']['start'] |
| 153 | + |
| 154 | +export interface TrialPeriodDate extends BaseTrial { |
| 155 | + year?: number |
| 156 | + month?: number |
| 157 | + day?: number |
| 158 | + hour?: number |
| 159 | + minute?: number |
| 160 | + second?: number |
| 161 | + millisecond?: number |
| 162 | + js?: Date |
| 163 | +} |
| 164 | + |
154 | 165 | export interface ExtraField {
|
155 | 166 | name: string
|
156 | 167 | database: string
|
@@ -181,150 +192,8 @@ export interface GridSizes {
|
181 | 192 | xl?: number
|
182 | 193 | }
|
183 | 194 |
|
184 |
| -export interface BaseBlock { |
185 |
| - gridSizes?: GridSizes |
186 |
| - gridStyle?: React.CSSProperties |
187 |
| - gridSx?: SxProps |
188 |
| - donorOnly?: boolean |
189 |
| - freeloaderOnly?: boolean |
190 |
| - loggedInOnly?: boolean |
191 |
| - loggedOutOnly?: boolean |
192 |
| - text?: string | null |
193 |
| - content?: string | null |
194 |
| - link?: string | null |
195 |
| - href?: string | null |
196 |
| -} |
197 |
| -export interface CustomText |
198 |
| - extends Omit<OnlyType<TypographyProps, Function, false>>, |
199 |
| - BaseBlock { |
200 |
| - type: 'text' |
201 |
| -} |
202 |
| - |
203 |
| -export interface CustomDivider |
204 |
| - extends Omit<OnlyDType<DividerProps, Function, false>>, |
205 |
| - BaseBlock { |
206 |
| - type: 'divider' |
207 |
| -} |
208 |
| - |
209 |
| -export interface CustomButton |
210 |
| - extends Omit<OnlyType<ButtonProps, Function, false>>, |
211 |
| - BaseBlock { |
212 |
| - type: 'button' |
213 |
| -} |
214 |
| - |
215 |
| -export interface CustomImg extends ImgProps, BaseBlock { |
216 |
| - type: 'img' |
217 |
| -} |
218 |
| - |
219 |
| -export interface CustomDiscord extends BaseBlock { |
220 |
| - type: 'discord' |
221 |
| - link: string |
222 |
| -} |
223 |
| - |
224 |
| -export interface CustomTelegram extends BaseBlock { |
225 |
| - type: 'telegram' |
226 |
| - telegramBotName: string |
227 |
| - telegramAuthUrl: string |
228 |
| -} |
229 |
| - |
230 |
| -export interface CustomLocal extends BaseBlock { |
231 |
| - type: 'localLogin' |
232 |
| - localAuthUrl: string |
233 |
| - link: string |
234 |
| - style: React.CSSProperties |
235 |
| -} |
236 |
| - |
237 |
| -export interface CustomLocale extends BaseBlock { |
238 |
| - type: 'localeSelection' |
239 |
| -} |
240 |
| - |
241 |
| -export interface ParentBlock extends BaseBlock, Grid2Props { |
242 |
| - type: 'parent' |
243 |
| - components: CustomComponent[] |
244 |
| -} |
245 |
| - |
246 |
| -export type CustomComponent = |
247 |
| - | CustomText |
248 |
| - | CustomDivider |
249 |
| - | CustomButton |
250 |
| - | CustomImg |
251 |
| - | CustomDiscord |
252 |
| - | CustomTelegram |
253 |
| - | CustomLocal |
254 |
| - | CustomLocale |
255 |
| - | ParentBlock |
256 |
| - |
257 |
| -export type DeepKeys<T, P extends string = ''> = { |
258 |
| - [K in keyof T]-?: K extends string |
259 |
| - ? P extends '' |
260 |
| - ? `${K}` | `${K}.${DeepKeys<T[K], K>}` |
261 |
| - : `${P}.${K}.${DeepKeys<T[K], P & K>}` |
262 |
| - : never |
263 |
| -}[keyof T] |
264 |
| - |
265 |
| -export type ConfigPaths<T extends object> = DeepKeys<T> |
266 |
| - |
267 |
| -export type PathValue<T, P> = P extends `${infer K}.${infer Rest}` |
268 |
| - ? K extends keyof T |
269 |
| - ? Rest extends DeepKeys<T[K]> |
270 |
| - ? PathValue<T[K], Rest> |
271 |
| - : never |
272 |
| - : never |
273 |
| - : P extends keyof T |
274 |
| - ? T[P] |
275 |
| - : never |
276 |
| - |
277 |
| -export type ConfigPathValue< |
278 |
| - T extends object, |
279 |
| - P extends ConfigPaths<T>, |
280 |
| -> = PathValue<T, P> |
281 |
| - |
282 |
| -export type Join<K, P> = K extends string | number |
283 |
| - ? P extends string | number |
284 |
| - ? `${K}${'' extends P ? '' : '.'}${P}` |
285 |
| - : never |
286 |
| - : never |
287 |
| - |
288 |
| -export type Prev = [ |
289 |
| - never, |
290 |
| - 0, |
291 |
| - 1, |
292 |
| - 2, |
293 |
| - 3, |
294 |
| - 4, |
295 |
| - 5, |
296 |
| - 6, |
297 |
| - 7, |
298 |
| - 8, |
299 |
| - 9, |
300 |
| - 10, |
301 |
| - 11, |
302 |
| - 12, |
303 |
| - 13, |
304 |
| - 14, |
305 |
| - 15, |
306 |
| - 16, |
307 |
| - 17, |
308 |
| - 18, |
309 |
| - 19, |
310 |
| - 20, |
311 |
| - ...0[], |
312 |
| -] |
313 |
| - |
314 |
| -export type Paths<T, D extends number = 10> = [D] extends [never] |
315 |
| - ? never |
316 |
| - : T extends object |
317 |
| - ? { |
318 |
| - [K in keyof T]-?: K extends string | number |
319 |
| - ? `${K}` | Join<K, Paths<T[K], Prev[D]>> |
320 |
| - : never |
321 |
| - }[keyof T] |
322 |
| - : '' |
323 |
| - |
324 |
| -export type NestedObjectPaths = Paths<Config> |
325 |
| - |
326 |
| -export type GetSafeConfig = <P extends NestedObjectPaths>( |
| 195 | +export type GetSafeConfig = <P extends Paths<Config>>( |
327 | 196 | path: P,
|
328 |
| -) => ConfigPathValue<Config, P> |
| 197 | +) => ObjectPathValue<Config, P> |
329 | 198 |
|
330 | 199 | export type ConfigEqualReport = ComparisonReport<Omit<Config, 'areas'>>
|
0 commit comments