{
  "title": "CodeChunk",
  "@id": "stencila:CodeChunk",
  "extends": "CodeExecutable",
  "category": "code",
  "role": "secondary",
  "status": "unstable",
  "description": "A executable chunk of code.",
  "properties": {
    "type": {
      "@id": "schema:type",
      "description": "The name of the type.",
      "type": "string",
      "enum": [
        "CodeChunk"
      ],
      "default": "CodeChunk",
      "from": "Entity"
    },
    "id": {
      "@id": "schema:id",
      "description": "The identifier for this item.",
      "type": "string",
      "from": "Entity"
    },
    "meta": {
      "@id": "stencila:meta",
      "description": "Metadata associated with this item.",
      "type": "object",
      "from": "Entity"
    },
    "text": {
      "@id": "schema:text",
      "description": "The text of the code.",
      "type": "string",
      "from": "Code"
    },
    "programmingLanguage": {
      "@id": "schema:programmingLanguage",
      "description": "The programming language of the code.",
      "type": "string",
      "from": "Code",
      "isOverride": true
    },
    "mediaType": {
      "@id": "schema:encodingFormat",
      "aliases": [
        "encodingFormat"
      ],
      "description": "Media type, typically expressed using a MIME format, of the code.",
      "$comment": "This property allows the differentiation of formats using the same programming language\nor variants of a programming language. An example is using `programmingLanguage` \"json\" and\n`encodingFormat` \"application/ld+json\" for JSON-LD code examples.\n",
      "type": "string",
      "from": "Code"
    },
    "codeDependencies": {
      "@id": "stencila:codeDependencies",
      "description": "The upstream dependencies of the code.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "CodeChunk.schema.json"
          },
          {
            "$ref": "Parameter.schema.json"
          }
        ]
      },
      "$comment": "Note that this excludes `CodeExpression` nodes since they should not have side effects\n(e.g. assigning variables) that would cause another node to be dependent upon them.\n",
      "from": "CodeExecutable",
      "isArray": true,
      "isPlural": true,
      "aliases": [
        "codeDependencie"
      ]
    },
    "codeDependents": {
      "@id": "stencila:codeDependents",
      "description": "The downstream dependents of the code.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "CodeChunk.schema.json"
          },
          {
            "$ref": "CodeExpression.schema.json"
          }
        ]
      },
      "$comment": "Note that in comparison to `codeDependencies`, this property does not allow for `Parameter`\ndependents (because parameters are never dependent upon others).\n",
      "from": "CodeExecutable",
      "isArray": true,
      "isPlural": true,
      "aliases": [
        "codeDependent"
      ]
    },
    "compileDigest": {
      "@id": "stencila:compileDigest",
      "description": "A digest of the content, semantics and dependencies of the node.",
      "type": "string",
      "from": "CodeExecutable"
    },
    "executeCount": {
      "@id": "stencila:executeCount",
      "description": "A count of the number of times that the node has been executed.",
      "type": "integer",
      "minimum": 0,
      "$comment": "Intended to increment with each successive execution of the node, including across sessions.\nNote that this differs to the `execution_count` in Jupyter Notebook format which is\nthe \"code cell's prompt number\" and which resets at the start of each new session.\n",
      "from": "CodeExecutable"
    },
    "executeDigest": {
      "@id": "stencila:executeDigest",
      "description": "The `compileDigest` of the node when it was last executed.",
      "type": "string",
      "from": "CodeExecutable"
    },
    "executeRequired": {
      "@id": "stencila:executeRequired",
      "description": "Whether, and why, a node requires execution or re-execution.",
      "enum": [
        "No",
        "NeverExecuted",
        "SemanticsChanged",
        "DependenciesChanged",
        "DependenciesFailed"
      ],
      "$comment": "Derived from a comparison of `compileDigest` and `executeDigest` and the `executeStatus`\nof dependencies.\n`No`: no re-execution is required, the semantics of the code and its dependencies has not changed\nsince it was last executed.\n`NeverExecuted`: execution is required because the code has never been executed (or any previous\nexecution was not persisted in its state).\n`SemanticsChanged`: re-execution is required because the semantics of the code has changed since it was\nlast executed.\n`DependenciesChanged`: the semantics of one or more dependencies (including transitive dependencies) \nchanged since it was last executed.\n`DependenciesFailed`: one or more dependencies (including transitive dependencies) failed when it was\nlast executed.\n",
      "from": "CodeExecutable"
    },
    "executeStatus": {
      "@id": "stencila:executeStatus",
      "description": "Status of the most recent, including any current, execution of the code.",
      "enum": [
        "Scheduled",
        "ScheduledPreviouslyFailed",
        "Running",
        "RunningPreviouslyFailed",
        "Succeeded",
        "Failed",
        "Cancelled"
      ],
      "from": "CodeExecutable"
    },
    "executeEnded": {
      "@id": "stencila:executeEnded",
      "description": "The date-time that the the last execution of the code ended.",
      "$ref": "Date.schema.json",
      "from": "CodeExecutable"
    },
    "executeDuration": {
      "@id": "stencila:executeDuration",
      "description": "Duration in seconds of the last execution of the code.",
      "type": "number",
      "minimum": 0,
      "from": "CodeExecutable"
    },
    "errors": {
      "@id": "stencila:errors",
      "description": "Errors when compiling (e.g. syntax errors) or executing the chunk.",
      "type": "array",
      "items": {
        "$ref": "CodeError.schema.json"
      },
      "from": "CodeExecutable",
      "isArray": true,
      "isPlural": true,
      "aliases": [
        "error"
      ]
    },
    "label": {
      "@id": "stencila:label",
      "description": "A short label for the CodeChunk.",
      "type": "string",
      "from": "CodeChunk"
    },
    "caption": {
      "@id": "schema:caption",
      "description": "A caption for the CodeChunk.",
      "$comment": "An array of nodes or, to be compatible with https://schema.org/caption, a string.\n",
      "anyOf": [
        {
          "type": "array",
          "items": {
            "$ref": "BlockContent.schema.json"
          }
        },
        {
          "type": "string"
        }
      ],
      "from": "CodeChunk"
    },
    "executeAuto": {
      "@id": "stencila:executeAuto",
      "description": "Under which circumstances the node should be automatically executed.",
      "enum": [
        "Never",
        "Needed",
        "Always"
      ],
      "default": "Needed",
      "$comment": "`Never`: Never automatically execute the code chunk. Only execute when the user explicitly runs\nthe code (or its containing document).\n`Needed`: Automatically execute the code chunk if needed. Execute the code chunk if it is an \nupstream dependency of a node that has been executed, or is a downstream dependent of a node that\nhas been executed.\n`Always`: Always execute the code, even if it, or its dependencies, are unchanged since the \nlast time it was executed.\n",
      "from": "CodeChunk"
    },
    "executePure": {
      "@id": "stencila:executePure",
      "description": "Whether the code should be treated as side-effect free when executed.",
      "type": "boolean",
      "from": "CodeChunk"
    },
    "outputs": {
      "@id": "stencila:outputs",
      "description": "Outputs from executing the chunk.",
      "type": "array",
      "items": {
        "$ref": "Node.schema.json"
      },
      "from": "CodeChunk",
      "isArray": true,
      "isPlural": true,
      "aliases": [
        "output"
      ]
    }
  },
  "examples": [
    {
      "type": "CodeChunk",
      "programmingLanguage": "python",
      "text": "print('Hello world!')"
    }
  ],
  "file": "CodeChunk.schema.yaml",
  "children": [],
  "descendants": [],
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.stenci.la/v1/CodeChunk.schema.json",
  "source": "https://github.com/stencila/schema/blob/master/schema/CodeChunk.schema.yaml",
  "type": "object",
  "propertyAliases": {
    "encodingFormat": "mediaType",
    "codeDependencie": "codeDependencies",
    "codeDependent": "codeDependents",
    "error": "errors",
    "output": "outputs"
  },
  "additionalProperties": false,
  "required": [
    "type",
    "text",
    "programmingLanguage"
  ]
}
