UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

57 lines • 2.52 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { z } from 'zod'; import { parseLimit } from "../../utils/size.js"; import { parseConfigWithSchema, refuseRepeatedFields } from "../../vfs/secrets.js"; export const CacheType = Object.freeze({ RAM: 'ram', REDIS: 'redis', }); // The type is any registered one: `registerFileCacheStore` takes names // this module does not list, and the registry names a missing factory. const CacheConfig = z.object({ type: z.custom((value) => typeof value === 'string').optional(), limit: z.union([z.string(), z.number()]).optional(), maxDrainBytes: z.number().nullable().optional(), }); const RedisCacheConfig = CacheConfig.extend({ url: z.string().optional(), // Absent scopes the keys to the workspace; a prefix shares them with // every workspace that names it. keyPrefix: z.string().optional(), }); /** * Check a cache config the way python's `CacheConfig` checks one on * construction, and camelize its keys. * * The fields are picked by `type`, where python picks them by class: a * RAM cache takes no connection fields, and any other type takes the * redis set its registered factory receives. One field named in both * spellings is refused, as python refuses the camelCase one. * * @param config the cache config as the caller passed it. * @throws Error when `limit` is not a size. * @returns the checked config with every key in its camelCase spelling. */ export function normalizeCacheConfig(config) { const input = config; refuseRepeatedFields(input); const parsed = (input.type ?? CacheType.RAM) === CacheType.RAM ? parseConfigWithSchema(CacheConfig, input) : parseConfigWithSchema(RedisCacheConfig, input); if (parsed.limit !== undefined) parseLimit(parsed.limit, 'limit'); return parsed; } //# sourceMappingURL=config.js.map