mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
refactor(api): tidy the api and shared packages (#2733)
This commit is contained in:
1 parent
580401d2dc
commit
5afbf67a70
333 files changed
+10180
-7910
No files matched your search
@@ -38,23 +38,14 @@ const noopLogger: IKVLogger = {
|
||||
};
|
||||
|
||||
export function resolveKVClientConfig(config: KVClientConfig | string): ResolvedKVClientConfig {
|
||||
if (typeof config === 'string') {
|
||||
return {
|
||||
url: normalizeUrl(config),
|
||||
mode: 'standalone' as const,
|
||||
clusterNodes: [],
|
||||
clusterNatMap: {},
|
||||
timeoutMs: DEFAULT_KV_TIMEOUT_MS,
|
||||
logger: noopLogger,
|
||||
};
|
||||
}
|
||||
const options: KVClientConfig = typeof config === 'string' ? {url: config} : config;
|
||||
return {
|
||||
url: normalizeUrl(config.url),
|
||||
mode: config.mode ?? 'standalone',
|
||||
clusterNodes: config.clusterNodes ?? [],
|
||||
clusterNatMap: config.clusterNatMap ?? {},
|
||||
timeoutMs: config.timeoutMs ?? DEFAULT_KV_TIMEOUT_MS,
|
||||
logger: config.logger ?? noopLogger,
|
||||
url: normalizeUrl(options.url),
|
||||
mode: options.mode ?? 'standalone',
|
||||
clusterNodes: options.clusterNodes ?? [],
|
||||
clusterNatMap: options.clusterNatMap ?? {},
|
||||
timeoutMs: options.timeoutMs ?? DEFAULT_KV_TIMEOUT_MS,
|
||||
logger: options.logger ?? noopLogger,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,5 +54,9 @@ function normalizeUrl(url: string): string {
|
||||
if (trimmed.length === 0) {
|
||||
throw new Error('KV client URL must not be empty');
|
||||
}
|
||||
const query = new URLSearchParams(trimmed.match(/^[^?#]*(\?[^#]*)/)?.[1]);
|
||||
if (query.has('stringNumbers')) {
|
||||
throw new Error('KV client URLs do not support stringNumbers; numeric replies are required');
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
Reference in new issue
Block a user