Function overrideStorage

  • Overrides an existing storage schema in the swarm system with a new or partial schema. This function updates the configuration of a storage identified by its storageName, applying the provided schema properties. It operates outside any existing method or execution contexts to ensure isolation, leveraging beginContext for a clean execution scope. Logs the override operation if logging is enabled in the global configuration.

    Type Parameters

    Parameters

    • OptionalstorageSchema: TStorageSchema<T>

      The schema containing the storage’s unique name and optional properties to override.

      • storageName

        The unique identifier of the storage to override, matching IStorageSchema<T>["storageName"].

    Returns IStorageSchema<T>

    The updated storage schema as applied by the swarm’s storage schema service.

    If the storage schema service encounters an error during the override operation (e.g., invalid storageName or schema).

    // Override a storage’s schema with new properties
    overrideStorage({
    storageName: "UserData",
    persist: true,
    embedding: "TextEmbedding",
    createIndex: (item) => item.id.toString(),
    });
    // Logs the operation (if enabled) and updates the storage schema in the swarm.