mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
Created 11 packagerepo-specific workflow plugins: - auth_verify_jwt - JWT token verification - auth_check_scopes - Scope-based authorization - parse_path - URL path parameter extraction (Express-style) - normalize_entity - Field normalization (trim, lower, unique, sort) - validate_entity - JSON schema validation - kv_get/kv_put - RocksDB key-value operations - blob_put - Filesystem blob storage with SHA-256 hashing - index_upsert - Index entry management - respond_json/respond_error - Response formatting Created string.sha256 plugin: - Compute SHA256 hash of strings/bytes - Optional "sha256:" prefix - Used by packagerepo for content-addressed storage All plugins follow standard pattern: - Class extending NodeExecutor - Factory with create() function - package.json with metadata - Access external state via runtime parameter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""Workflow plugin: put value in RocksDB key-value store."""
|
|
|
|
from typing import Dict, Any
|
|
import json
|
|
|
|
from ...base import NodeExecutor
|
|
|
|
|
|
class KvPut(NodeExecutor):
|
|
"""Put value in RocksDB key-value store."""
|
|
|
|
node_type = "packagerepo.kv_put"
|
|
category = "packagerepo"
|
|
description = "Put value in RocksDB key-value store"
|
|
|
|
def execute(self, inputs: Dict[str, Any], runtime: Any = None) -> Dict[str, Any]:
|
|
"""Put value in KV store."""
|
|
key = inputs.get("key")
|
|
value = inputs.get("value")
|
|
|
|
if not key:
|
|
return {"error": "key is required"}
|
|
|
|
if value is None:
|
|
return {"error": "value is required"}
|
|
|
|
if not runtime or not hasattr(runtime, "kv_store"):
|
|
return {"error": "kv_store not available in runtime"}
|
|
|
|
try:
|
|
# Convert value to bytes
|
|
if isinstance(value, (dict, list)):
|
|
# Serialize JSON objects
|
|
value_bytes = json.dumps(value).encode("utf-8")
|
|
elif isinstance(value, str):
|
|
value_bytes = value.encode("utf-8")
|
|
elif isinstance(value, bytes):
|
|
value_bytes = value
|
|
else:
|
|
# Convert other types to string
|
|
value_bytes = str(value).encode("utf-8")
|
|
|
|
# Put value in KV store
|
|
runtime.kv_store.put(key.encode("utf-8"), value_bytes)
|
|
|
|
return {"result": {"success": True, "key": key}}
|
|
|
|
except Exception as e:
|
|
return {"error": f"failed to put value: {str(e)}", "error_code": "KV_PUT_FAILED"}
|