text: "use strict";
  // Copyright IBM Corp. 2018,2019. All Rights Reserved.
  // Node module: @loopback/repository-json-schema
  // This file is licensed under the MIT License.
  // License text available at https://opensource.org/licenses/MIT
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  const repository_1 = require("@loopback/repository");
  /**
   * Build a JSON schema describing the format of the "scope" object
   * used to query model instances.
   *
   * Note we don't take the model properties into account yet and return
   * a generic json schema allowing any "where" condition.
   *
   * @param modelCtor - The model constructor to build the filter schema for.
   */
  function getScopeFilterJsonSchemaFor(modelCtor, options = {}) {
      let EmptyModel = class EmptyModel extends repository_1.Model {
      };
      EmptyModel = __decorate([
          repository_1.model({ settings: { strict: false } })
      ], EmptyModel);
      const schema = Object.assign(Object.assign({}, getFilterJsonSchemaFor(EmptyModel, { setTitle: false })), (options.setTitle !== false && {
          title: `${modelCtor.modelName}.ScopeFilter`,
      }));
      return schema;
  }
  exports.getScopeFilterJsonSchemaFor = getScopeFilterJsonSchemaFor;
  /**
   * Build a JSON schema describing the format of the "filter" object
   * used to query model instances.
   *
   * Note we don't take the model properties into account yet and return
   * a generic json schema allowing any "where" condition.
   *
   * @param modelCtor - The model constructor to build the filter schema for.
   */
  function getFilterJsonSchemaFor(modelCtor, options = {}) {
      const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
          title: `${modelCtor.modelName}.Filter`,
      })), { properties: {
              where: getWhereJsonSchemaFor(modelCtor, options),
              fields: getFieldsJsonSchemaFor(modelCtor, options),
              offset: {
                  type: 'integer',
                  minimum: 0,
              },
              limit: {
                  type: 'integer',
                  minimum: 1,
                  examples: [100],
              },
              skip: {
                  type: 'integer',
                  minimum: 0,
              },
              order: {
                  type: 'array',
                  items: {
                      type: 'string',
                  },
              },
          }, additionalProperties: false });
      const modelRelations = repository_1.getModelRelations(modelCtor);
      const hasRelations = Object.keys(modelRelations).length > 0;
      if (hasRelations) {
          schema.properties.include = Object.assign(Object.assign({}, (options.setTitle !== false && {
              title: `${modelCtor.modelName}.IncludeFilter`,
          })), { type: 'array', items: Object.assign(Object.assign({}, (options.setTitle !== false && {
                  title: `${modelCtor.modelName}.IncludeFilter.Items`,
              })), { type: 'object', properties: {
                      // TODO(bajtos) restrict values to relations defined by "model"
                      relation: { type: 'string' },
                      // TODO(bajtos) describe the filter for the relation target model
                      scope: getScopeFilterJsonSchemaFor(modelCtor, options),
                  } }) });
      }
      return schema;
  }
  exports.getFilterJsonSchemaFor = getFilterJsonSchemaFor;
  /**
   * Build a JSON schema describing the format of the "where" object
   * used to filter model instances to query, update or delete.
   *
   * Note we don't take the model properties into account yet and return
   * a generic json schema allowing any "where" condition.
   *
   * @param modelCtor - The model constructor to build the filter schema for.
   */
  function getWhereJsonSchemaFor(modelCtor, options = {}) {
      const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
          title: `${modelCtor.modelName}.WhereFilter`,
      })), { type: 'object', 
          // TODO(bajtos) enumerate "model" properties and operators like "and"
          // See https://github.com/strongloop/loopback-next/issues/1748
          additionalProperties: true });
      return schema;
  }
  exports.getWhereJsonSchemaFor = getWhereJsonSchemaFor;
  /**
   * Build a JSON schema describing the format of the "fields" object
   * used to include or exclude properties of model instances.
   *
   * @param modelCtor - The model constructor to build the filter schema for.
   */
  function getFieldsJsonSchemaFor(modelCtor, options = {}) {
      const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
          title: `${modelCtor.modelName}.Fields`,
      })), { type: 'object', properties: Object.assign({}, ...Object.keys(modelCtor.definition.properties).map(k => ({
              [k]: { type: 'boolean' },
          }))), additionalProperties: modelCtor.definition.settings.strict === false });
      return schema;
  }
  exports.getFieldsJsonSchemaFor = getFieldsJsonSchemaFor;
  //# sourceMappingURL=filter-json-schema.js.map