{
  "$meta": {
    "package": "@walkeros/server-transformer-cache",
    "version": "3.1.0",
    "type": "transformer",
    "platform": [
      "server"
    ],
    "docs": "https://www.walkeros.io/docs/transformers/cache",
    "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/server/transformers/cache/src"
  },
  "schemas": {
    "settings": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "maxSize": {
          "description": "Maximum cache size in bytes. Default: 10MB",
          "type": "number",
          "exclusiveMinimum": 0
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "match": {
                "anyOf": [
                  {
                    "$ref": "#/definitions/__schema0"
                  },
                  {
                    "type": "string",
                    "const": "*"
                  }
                ],
                "description": "Match expression or \"*\" to match all events"
              },
              "key": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Event property paths used to build the cache key"
              },
              "ttl": {
                "type": "number",
                "exclusiveMinimum": 0,
                "description": "Time-to-live in seconds for cached entries"
              },
              "headers": {
                "description": "HTTP response headers to include with cached responses",
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {
                  "type": "string"
                }
              }
            },
            "required": [
              "match",
              "key",
              "ttl"
            ],
            "additionalProperties": false,
            "description": "Cache rule: defines which events to cache, key composition, and TTL"
          },
          "description": "Cache rules evaluated in order. First matching rule wins."
        }
      },
      "required": [
        "rules"
      ],
      "additionalProperties": false,
      "description": "Cache transformer: caches event responses by match rules with TTL",
      "definitions": {
        "__schema0": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "description": "Property path to match against"
                },
                "operator": {
                  "type": "string",
                  "enum": [
                    "eq",
                    "contains",
                    "prefix",
                    "suffix",
                    "regex",
                    "gt",
                    "lt",
                    "exists"
                  ],
                  "description": "Match operator"
                },
                "value": {
                  "type": "string",
                  "description": "Value to compare against"
                },
                "not": {
                  "description": "Negate the condition",
                  "type": "boolean"
                }
              },
              "required": [
                "key",
                "operator",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "and": {
                  "type": "array",
                  "items": {
                    "allOf": [
                      {
                        "$ref": "#/definitions/__schema0"
                      }
                    ]
                  }
                }
              },
              "required": [
                "and"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "or": {
                  "type": "array",
                  "items": {
                    "allOf": [
                      {
                        "$ref": "#/definitions/__schema0"
                      }
                    ]
                  }
                }
              },
              "required": [
                "or"
              ],
              "additionalProperties": false
            }
          ]
        }
      }
    }
  },
  "examples": {
    "step": {
      "cacheHit": {
        "in": {
          "name": "page view",
          "data": {
            "url": "/api/events"
          },
          "id": "1700000601-gr0up-2",
          "trigger": "load",
          "entity": "page",
          "action": "view",
          "timestamp": 1700000601,
          "group": "gr0up",
          "count": 2,
          "version": {
            "tagging": 1
          },
          "source": {
            "type": "server",
            "id": "",
            "previous_id": ""
          }
        },
        "out": false
      },
      "cacheMiss": {
        "in": {
          "name": "page view",
          "data": {
            "url": "/api/events"
          },
          "id": "1700000600-gr0up-1",
          "trigger": "load",
          "entity": "page",
          "action": "view",
          "timestamp": 1700000600,
          "group": "gr0up",
          "count": 1,
          "version": {
            "tagging": 1
          },
          "source": {
            "type": "server",
            "id": "",
            "previous_id": ""
          }
        },
        "out": {
          "respond": true
        }
      },
      "differentCacheKeys": {
        "description": "POST to the same path produces a separate cache entry (key includes HTTP method)",
        "in": {
          "name": "page view",
          "data": {
            "url": "/api/events"
          },
          "id": "1700000602-gr0up-3",
          "trigger": "load",
          "entity": "page",
          "action": "view",
          "timestamp": 1700000602,
          "group": "gr0up",
          "count": 3,
          "version": {
            "tagging": 1
          },
          "source": {
            "type": "server",
            "id": "",
            "previous_id": ""
          }
        },
        "out": {
          "respond": true
        }
      }
    }
  }
}