Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,59 @@ function parseAstChunkingConfig(value) {
}
// Like parsePositiveInt but allows 0. Used for fields where 0 is a meaningful
// "disabled" sentinel (e.g. autoRecallBadRecallDecayMs=0 disables decay).
function parseNonNegativeInt(value) {
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
return Math.floor(value);
function parseNonNegativeInt(value, fieldPath) {
// Missing: optional field — return undefined so caller's ?? default applies
if (value === undefined)
return undefined;
if (typeof value === "number") {
if (!Number.isFinite(value)) {
const msg = `must be a finite number, got ${String(value)}`;
if (fieldPath)
throw new Error(`${fieldPath}: ${msg}`);
return undefined;
}
if (!Number.isInteger(value)) {
const msg = `must be an integer, got ${value}`;
if (fieldPath)
throw new Error(`${fieldPath}: ${msg}`);
return undefined;
}
if (value < 0) {
const msg = `must be >= 0, got ${value}`;
if (fieldPath)
throw new Error(`${fieldPath}: ${msg}`);
return undefined;
}
return value;
}
if (typeof value === "string") {
const s = value.trim();
if (!s)
if (!s) {
if (fieldPath)
throw new Error(`${fieldPath}: must be a non-negative integer`);
return undefined;
}
const resolved = resolveEnvVars(s);
// When fieldPath is provided, only accept env-var reference strings
// (e.g. "${MY_VAR}"). Plain numeric strings are rejected — the config
// schema already catches them at the gateway level.
if (fieldPath && resolved === s) {
const n = Number(resolved);
if (Number.isFinite(n) && n >= 0 && Number.isInteger(n))
throw new Error(`${fieldPath}: must be a number, got string "${s}"`);
throw new Error(`${fieldPath}: must be a non-negative integer`);
}
const n = Number(resolved);
if (Number.isFinite(n) && n >= 0)
return Math.floor(n);
if (Number.isFinite(n) && n >= 0 && Number.isInteger(n))
return n;
if (fieldPath)
throw new Error(`${fieldPath}: must be a non-negative integer`);
return undefined;
}
// Reject all other types when fieldPath provided (null, boolean, object, array)
const msg = `must be a non-negative integer, got ${typeof value}`;
if (fieldPath)
throw new Error(`${fieldPath}: ${msg}`);
return undefined;
}
function clampInt(value, min, max) {
Expand Down Expand Up @@ -4983,7 +5023,7 @@ export function parsePluginConfig(value) {
const storageAutoCleanupRaw = typeof storageMaintenanceRaw?.autoCleanup === "object" && storageMaintenanceRaw.autoCleanup !== null
? storageMaintenanceRaw.autoCleanup
: null;
const readConsistencyIntervalSecondsRaw = parseNonNegativeInt(storageMaintenanceRaw?.readConsistencyIntervalSeconds);
const readConsistencyIntervalSecondsRaw = parseNonNegativeInt(storageMaintenanceRaw?.readConsistencyIntervalSeconds, "plugins.entries.memory-lancedb-pro.config.storageMaintenance.readConsistencyIntervalSeconds");
const lockingRaw = typeof cfg.locking === "object" && cfg.locking !== null
? cfg.locking
: null;
Expand Down
Loading