mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix NestKeys type
This commit is contained in:
2 files changed
+14
-5
No files matched your search
@@ -2,7 +2,7 @@ import yaml from 'js-yaml';
|
||||
import { nanoid } from 'nanoid';
|
||||
import Schema from 'schemastery';
|
||||
import { Logger } from './logger';
|
||||
import { NestKeys } from './typeutils';
|
||||
import { Flatten } from './typeutils';
|
||||
|
||||
const defaultPath = process.env.CI ? '/tmp/file'
|
||||
: process.env.DEFAULT_STORE_PATH || '/data/file/hydro';
|
||||
@@ -80,7 +80,7 @@ export async function setConfig(key: string, value: any) {
|
||||
|
||||
export function requestConfig<T, S>(s: Schema<T, S>): {
|
||||
config: ReturnType<Schema<T, S>>,
|
||||
setConfig: (key: NestKeys<ReturnType<Schema<T, S>>>, value: any) => Promise<void>,
|
||||
setConfig: (key: keyof Flatten<ReturnType<Schema<T, S>>> & string, value: any) => Promise<void>,
|
||||
} {
|
||||
SystemSettings.push(s);
|
||||
let curValue = s(systemConfig);
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
/* eslint-disable @typescript-eslint/indent */
|
||||
export type Atomic = number | string | boolean | bigint | symbol | Date | any[];
|
||||
export type Values<S> = S[keyof S];
|
||||
export type Intersect<U> = (U extends any ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never;
|
||||
export type NumberKeys<O> = {
|
||||
[K in keyof O]: number extends O[K] ? K : never
|
||||
}[keyof O];
|
||||
export type ArrayKeys<O, P = any> = {
|
||||
[K in keyof O]: P[] extends O[K] ? K : never
|
||||
}[keyof O];
|
||||
export type NestKeys<O, T = any, S = any[]> = O extends object ? O extends S ? never : {
|
||||
[K in keyof O]: (O[K] extends T ? K : never) | `${K & string}.${NestKeys<O[K], T, S | O>}`
|
||||
}[keyof O] & string : never;
|
||||
type FlatWrap<S, T, P extends string> = { [K in P]?: S } | (S extends T ? never // rule out atomic / recursive types
|
||||
: S extends any[] ? never // rule out array types
|
||||
: string extends keyof S ? never // rule out dict / infinite types
|
||||
: FlatMap<S, T, `${P}.`>);
|
||||
type FlatMap<S, T = Atomic, P extends string = ''> = Values<{
|
||||
[K in keyof S & string as `${P}${K}`]: FlatWrap<S[K], S | T, `${P}${K}`>
|
||||
}>;
|
||||
export type Flatten<S> = Intersect<FlatMap<S>>;
|
||||
export type Value<O, V = ''> = {
|
||||
[K in keyof O]: V
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user