{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openspatials.com/developers/spec/0.5/state-frame.schema.json",
  "title": "OpenSpatials world state event stream message, version 0.5",
  "description": "0.5 addition (kit support next). Spec: src/spec/core/WORLD-STATE.md sections 4 to 6. One message of a world's event stream (a WebSocket; one JSON object per text frame). From the world: hello first, with its current revision and time; then each change as one event with type, revision (one higher than the event before), time (RFC 3339) and urls (every resource whose representation changed, relative to the state document); resync, with the current revision, when a reader's since asks for events the world no longer keeps. From a reader: auth, the access token as the stream's first message (never in an address). Change types: state_changed, and the Open Spatial Lab's Web of Worlds types user_joined, user_left, node_created, node_updated and node_deleted; a reader handles any type by its urls. Unknown fields are allowed and ignored.",
  "type": "object",
  "required": [
    "type"
  ],
  "properties": {
    "type": {
      "description": "hello, resync, auth, or a change type.",
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,63}$"
    }
  },
  "allOf": [
    {
      "$ref": "#/$defs/noCode"
    },
    {
      "if": {
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "enum": [
              "hello",
              "resync"
            ]
          }
        }
      },
      "then": {
        "$ref": "#/$defs/marker"
      },
      "else": {
        "if": {
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "const": "auth"
            }
          }
        },
        "then": {
          "$ref": "#/$defs/auth"
        },
        "else": {
          "$ref": "#/$defs/change"
        }
      }
    }
  ],
  "$defs": {
    "marker": {
      "description": "hello (the world's first message) or resync: the world's current revision and the time of the change that made it (null before the first change).",
      "type": "object",
      "required": [
        "revision",
        "time"
      ],
      "properties": {
        "revision": {
          "type": "integer",
          "minimum": 0
        },
        "time": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "format": "date-time"
            }
          ]
        }
      }
    },
    "auth": {
      "description": "A reader's first message to a world that requires authorization.",
      "type": "object",
      "required": [
        "token"
      ],
      "properties": {
        "token": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        }
      }
    },
    "change": {
      "description": "One change of the world.",
      "type": "object",
      "required": [
        "revision",
        "time",
        "urls"
      ],
      "properties": {
        "revision": {
          "description": "The world's revision after this change.",
          "type": "integer",
          "minimum": 1
        },
        "time": {
          "description": "The world's UTC time of the change.",
          "type": "string",
          "format": "date-time"
        },
        "urls": {
          "description": "Every resource whose representation changed, relative to the state document (a Web of Worlds world: to its base address).",
          "type": "array",
          "minItems": 1,
          "maxItems": 256,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048,
            "pattern": "^\\S+$"
          }
        },
        "values": {
          "description": "For state_changed: the names of the values that changed (optional).",
          "type": "array",
          "maxItems": 256,
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"
          }
        }
      }
    },
    "noCode": {
      "description": "04 section 1, closed list, at any depth: a key named script, scripts, eval or javascript; a key that is 'on' followed by a capital letter; a string value starting with javascript:, vbscript: or data:text/html (any case, after leading white space).",
      "x-openspatials-reason": "unsafe-file",
      "propertyNames": {
        "not": {
          "pattern": "^(?:script|scripts|eval|javascript|on[A-Z].*)$"
        }
      },
      "additionalProperties": {
        "$ref": "#/$defs/noCode"
      },
      "items": {
        "$ref": "#/$defs/noCode"
      },
      "not": {
        "type": "string",
        "pattern": "^\\s*(?:[Jj][Aa][Vv][Aa][Ss][Cc][Rr][Ii][Pp][Tt]:|[Vv][Bb][Ss][Cc][Rr][Ii][Pp][Tt]:|[Dd][Aa][Tt][Aa]:[Tt][Ee][Xx][Tt]/[Hh][Tt][Mm][Ll])"
      }
    }
  }
}
