All files / schemas/trellis/rules configured.schema.cts

100% Statements 116/116
100% Branches 0/0
100% Functions 0/0
100% Lines 116/116

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 1171x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * @license
 * Copyright 2022 Open Ag Data Alliance
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 */
 
import type { JSONSchema8 as Schema } from 'jsonschema8';
 
const schema: Schema = {
  $id: 'https://formats.openag.io/trellis/rules/configured.schema.json',
  $schema: 'http://json-schema.org/draft-07/schema#',
  description: 'Representation of a constructed OADA rule for rules engine',
  properties: {
    enabled: {
      description: 'Wether this rule should be active',
      type: 'boolean',
      default: true,
    },
    services: {
      description: 'Array of the names of the services involved in this rule',
      $comment: 'Should this be here?',
      type: 'array',
      items: {
        type: 'string',
      },
      uniqueItems: true,
    },
    type: {
      description: 'Content-type this rule applies to',
      type: 'string',
    },
    on: {
      $comment: 'Where should this definiton live?',
      description: 'Whether to trigger on new item, changed item, etc.',
      oneOf: [
        {
          description: 'Trigger on a new item being added',
          enum: ['new'],
        },
        {
          description: 'Trigger on any change to an item',
          enum: ['change'],
        },
      ],
      default: 'new',
    },
    path: {
      description: 'The path to an OADA list to which to apply this rule',
      $ref: '../../oada.schema.json#/definitions/path',
    },
    conditions: {
      description: 'List of conditions involved in this rule',
      additionalProperties: {
        description: 'Particular condition involved in this rule',
        type: 'object',
        properties: {
          condition: {
            description: 'A link to the condition document',
            $ref: '../../oada/link/v1.schema.json#/definitions/versioned',
          },
          options: {
            description: 'Parameter values for this condition',
            type: 'object',
          },
        },
        required: ['condition'],
      },
    },
    actions: {
      description: 'List of actions involved in this rule',
      additionalProperties: {
        description: 'Particular action involved in this rule',
        type: 'object',
        properties: {
          action: {
            description: 'A link to the action document',
            $ref: '../../oada/link/v1.schema.json#/definitions/versioned',
          },
          options: {
            description: 'Parameter values for this action',
            type: 'object',
          },
        },
        required: ['action'],
      },
    },
  },
  required: ['type', 'path', 'conditions', 'actions'],
  examples: [
    {
      type: 'application/json',
      enabled: true,
      path: '/bookmarks/foo',
      on: 'new',
      services: ['test-service'],
      actions: {
        'test-action': {
          action: {
            _id: 'resources/foo',
            _rev: 1,
          },
          options: {
            foo: 1,
            bar: 'a',
          },
        },
      },
      conditions: {},
    },
  ],
};
 
export = schema;