How to use the @ditojs/utils.isArray function in @ditojs/utils

To help you get started, we’ve selected a few @ditojs/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ditojs / dito / packages / server / src / cli / db / createMigration.js View on Github external
const statement = primary
        ? [`table.increments('${column}').primary()`]
        : specificType
          ? [`table.specificType('${column}', '${specificType}')`]
          : [`table.${knexType}('${column}')`]
      statement.push(
        unsigned && 'unsigned()',
        !primary && required && 'notNullable()',
        nullable && 'nullable()',
        unique && 'unique()',
        index && 'index()'
      )
      if (_default !== undefined) {
        let value = defaultValues[_default]
        if (!value) {
          value = isArray(_default) || isObject(_default)
            ? JSON.stringify(_default)
            : _default
          if (isString(value)) {
            value = `'${value}'`
          }
        }
        statement.push(`defaultTo(${value})`)
      }
      if (foreign) {
        for (const relation of Object.values(relations)) {
          // TODO: Support composite keys for foreign references:
          // Use `asArray(from)`, `asArray(to)`
          const { from, to, owner } = relation
          const [fromClass, fromProperty] = from?.split('.') || []
          if (fromProperty === name) {
            if (fromClass !== modelClass.name) {
github ditojs / dito / packages / server / src / schema / properties.js View on Github external
schema = {
      type: 'array',
      items: schema.length > 1 ? schema : schema[0],
      // The array short-forms sets an empty array as the default.
      default: []
    }
  } else if (
    // Expand objects to `type: 'object'`...
    isObject(schema) &&
    !(
      // ...but only if they don't define any of these properties:
      isString(schema.type) ||
      isString(schema.$ref) ||
      isArray(schema.allOf) ||
      isArray(schema.anyOf) ||
      isArray(schema.oneOf) ||
      isObject(schema.not)
    )
  ) {
    schema = {
      type: 'object',
      properties: {
        ...schema
      },
      additionalProperties: false
    }
  }
  return schema
}
github ditojs / dito / packages / admin / src / mixins / SourceMixin.js View on Github external
unwrapListData(data) {
      if (
        this.isListSource &&
        isObject(data) &&
        isNumber(data.total) &&
        isArray(data.results)
      ) {
        // If @ditojs/server sends data in the form of `{ results, total }`
        // replace the value with result, but remember the total in the store.
        this.total = data.total
        this.value = data.results
        return this.value
      }
    },
github ditojs / dito / packages / server / src / query / QueryBuilder.js View on Github external
insert(data, returning) {
    // Only PostgreSQL is able to insert multiple entries at once it seems,
    // all others have to fall back on insertGraph() to do so for now:
    return !this.isPostgreSQL() && isArray(data) && data.length > 1
      ? this.insertGraph(data)
      : super.insert(data, returning)
  }
github ditojs / dito / packages / admin / src / components / DitoSchema.vue View on Github external
filterData(data) {
      // Filters out arrays and objects that are back by data resources
      // themselves, as those are already taking care of through their own API
      // resource end-points and shouldn't be set.
      const copy = {}
      for (const [key, value] of Object.entries(data)) {
        if (isArray(value) || isObject(value)) {
          if (this.getComponent(key)?.providesData) {
            continue
          }
        }
        copy[key] = value
      }
      return copy
    },
github ditojs / dito / packages / admin / src / types / DitoUpload.vue View on Github external
get(accept) {
        return isArray(accept) ? accept.join(',') : accept
      }
    }),
github ditojs / dito / packages / server / src / lib / EventEmitter.js View on Github external
_handle(method, event, callback) {
    if (isString(event)) {
      super[method](event, callback)
    } else if (isArray(event)) {
      for (const ev of event) {
        super[method](ev, callback)
      }
    } else if (isPlainObject(event)) {
      for (const key in event) {
        super[method](key, event[key])
      }
    }
    return this
  }
github ditojs / dito / packages / server / src / app / Validator.js View on Github external
function hasDefaults(obj) {
  if (isArray(obj)) {
    for (const val of obj) {
      if (val && hasDefaults(val)) {
        return true
      }
    }
  } else if (isObject(obj)) {
    for (const [key, val] of Object.entries(obj)) {
      if (key === 'default' || val && hasDefaults(val)) {
        return true
      }
    }
  }
  return false
}