canonical_id: "filter"
display_name: "過濾陣列"
category: "logic"
version: "v1"
wasi_target: "preview1"
stability: "floating"
runtime_compat:
  - "cf-workers"
  - "workerd"
  - "wazero"
constraints:
  max_size_kb: 2048
  max_cold_start_ms: 50
  no_network_syscall: true
  no_filesystem_syscall: true
  io_model: "stdin_stdout_json"
input_schema:
  type: object
  required: [items, condition]
  properties:
    items:
      type: array
      description: 要過濾的陣列
    condition:
      type: object
      required: [key, op, value]
      properties:
        key:
          type: string
          description: 要比較的欄位名稱
        op:
          type: string
          enum: [eq, ne, gt, lt, contains]
        value:
          type: string
          description: 比較值
output_schema:
  type: object
  properties:
    success:
      type: boolean
    data:
      type: object
      properties:
        items:
          type: array
        count:
          type: number
gherkin_tests:
  - scenario: "過濾 status=active 的元素"
    given: '{"items":[{"status":"active"},{"status":"inactive"}],"condition":{"key":"status","op":"eq","value":"active"}}'
    then_contains: '{"success":true'
  - scenario: "空陣列輸入"
    given: '{"items":[],"condition":{"key":"status","op":"eq","value":"active"}}'
    then_contains: '{"success":true'
  - scenario: "缺少 condition.key"
    given: '{"items":[],"condition":{"op":"eq","value":"x"}}'
    then_contains: '{"success":false'
tags: [builtin, filter, array, condition]
description: "依條件過濾陣列，回傳符合條件的元素。支援 eq/ne/gt/lt/contains 運算子。"
config_example: |
  my_filter:                          # 節點名稱（可自訂）
    items: "{{upstream.results}}"     # 要過濾的陣列（必填）
    condition:                        # 過濾條件（必填）
      key: status                     # 要比較的欄位名稱（必填）
      op: eq                          # 運算子：eq / ne / gt / lt / contains（必填）
      value: active                   # 比較值（必填）
