How to use the tableschema.Table.load function in tableschema

To help you get started, we’ve selected a few tableschema 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 datopian / datahub-client / lib / validate.js View on Github external
async validateData(descriptor, absPath) {
    // TODO: handle inlined data resources
    let options = {schema: descriptor.schema}
    if (descriptor.dialect) {
      Object.assign(options, descriptor.dialect)
    }
    const table = await Table.load(absPath, options)
    try {
      await table.read()
    } catch (err) {
      err.resource = descriptor.name
      err.path = absPath
      throw err
    }
    return true
  }
github datopian / data-cli / lib / validate.js View on Github external
async function validateData(schema, absPath) {
  // TODO: handle inlined data resources
  const table = await Table.load(absPath, {schema})
  await table.read()
  return true
}
github medialab / ricardo_data / importApp / src / components / ReferenceResourceForm.js View on Github external
newReference: this.state.newReference,
        newRefReference: this.state.newRefReference
      }

      // TODO: hardcoded
      if (resourceDescriptor.name === 'currencies' && !this.state.newReference) {
        const source = [keys(payload.newResource.data[0])].concat([values(payload.newResource.data[0])]);
        const relations = {
          exchange_rates: referenceTables['exchange_rates']
        };
        let table;
        const prefixedValues = {
          "modified_currency": this.state.newResource['modified_currency'].value
        }
        try {
          table = await Table.load(source, {schema});
          const rows = await table.read({forceCast: true, relations});
          const errors = rows.filter((row) => row.errors);
          if (errors.length) {
            this.setState({
              prefixedValues,
              resourceValid: {
                valid: false,
                message: errors[0].errors[0].errors[0].message
              }
            });
          } else {
            this.setState({
              resourceValid: {valid: true}
            })
            this.props.onAddNew(payload)
          }
github medialab / ricardo_data / importApp / src / redux / modules / schemaValidation.js View on Github external
try {
      const tableLength = source.length;
      const chunk = DEFAULT_CHUNK_SIZE;
      let i = 0
      let errors = []
      for(i; i < tableLength; i += chunk) {
        dispatch({
          type: VALIDATE_TABLE_REQUEST,
          payload: {  
            status: 'loading',
            loader: `validating ${i} rows`
          }
        })
        const offset = i / chunk
        const chunkTable = [source[0]].concat(source.slice(i+1-offset, i+chunk-offset))
        const table = await Table.load(chunkTable, {schema});
        const rows = await table.read({forceCast: true, relations});
        const chunkErrors = rows.filter((row) => row.errors)
        if (chunkErrors.length) {
          chunkErrors.forEach((error) => {
            error.rowNumber = error.rowNumber + chunk * offset - offset
          });
          errors = errors.concat(chunkErrors)
        }
      }
      // const table = await Table.load(source, {schema});
      // const rows = await table.read({forceCast: true});
      // const errors = rows.filter((row) => row.errors)
      if (errors.length) {
        dispatch({
          type: VALIDATE_TABLE_FAILURE,
          payload: {
github datopian / data-cli / dist / validate.js View on Github external
var _ref2 = (0, _asyncToGenerator3.default)(function* (schema, absPath) {
    // TODO: handle inlined data resources
    const table = yield Table.load(absPath, { schema });
    yield table.read();
    return true;
  });
github medialab / ricardo_data / importApp / src / redux / modules / schemaValidation.js View on Github external
dispatch(async() => {
    let table;
    try {
      table = await Table.load(source.slice(0,2), {schema});
      await table.read({limit: 1});
      dispatch({
        type: VALIDATE_HEADER_SUCCESS,
        payload: {
          status: 'done',
          valid: true,
          headers: table.headers
        }
      })
    } catch (error) {
      console.error(error)
      if (error.type !== 'ERROR_HEADER') {
        dispatch({
          type: VALIDATE_HEADER_SUCCESS,
          payload: {
            status: 'done',
github medialab / ricardo_data / importApp / src / redux / modules / schemaValidation.js View on Github external
dispatch(async() => {
    let table;
    try {
      table = await Table.load(source, {schema});
      const rows = await table.read({forceCast: true, relations});
      const errors = rows.filter((row) => row.errors);

      if (errors.length) {
        dispatch({
          type: REVALIDATE_ROWS_FAILURE,
          payload: {
            status: 'done',
            valid: false,
            rowNumbers,
            originalValue,
            fixedValues
          }
        })
      } else {
        dispatch({
github frictionlessdata / datapackage-ui / src / components / EditorResource.js View on Github external
dispatch(async () => {
          const table = await Table.load(descriptor.path)
          const rows = await table.read({limit: config.EDITOR_UPLOAD_ROWS_LIMIT})
          const headers = table.headers
          dispatch({
            type: 'UPLOAD_DATA',
            rows,
            headers,
            resourceIndex,
          })
        })
      } else {
github frictionlessdata / datapackage-ui / src / components / EditorResource.js View on Github external
dispatch(async () => {
        const text = await readFile(ev.target.files[0])
        const stream = new Readable()
        stream.push(text)
        stream.push(null)
        const table = await Table.load(stream)
        const rows = await table.read({limit: config.EDITOR_UPLOAD_ROWS_LIMIT})
        const headers = table.headers
        dispatch({
          type: 'UPLOAD_DATA',
          rows,
          headers,
          resourceIndex,
        })
      })
    },

tableschema

A library for working with Table Schema in Javascript.

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis