How to use the @wireapp/store-engine/dist/commonjs/engine/error/.RecordTypeError function in @wireapp/store-engine

To help you get started, we’ve selected a few @wireapp/store-engine 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 wireapp / wire-web-packages / packages / store-engine-fs / src / index.ts View on Github external
public async append(tableName: string, primaryKey: string, additions: string): Promise {
    const file = this.resolvePath(tableName, primaryKey);
    let record = await this.read(tableName, primaryKey);
    if (typeof record === 'string') {
      record += additions;
    } else {
      const message = `Cannot append text to record "${primaryKey}" because it's not a string.`;
      throw new RecordTypeError(message);
    }
    const updatedRecord = record;
    await fs.outputFile(file, updatedRecord);
    return primaryKey;
  }
github wireapp / wire-web-packages / packages / store-engine-fs / src / index.ts View on Github external
try {
        await fs.writeFile(filePath, entity, {flag: 'wx'});
        return primaryKey;
      } catch (error) {
        if (error.code === 'ENOENT') {
          await fs.outputFile(filePath, entity);
          return primaryKey;
        } else if (error.code === 'EEXIST') {
          const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
          throw new RecordAlreadyExistsError(message);
        }
        throw error;
      }
    } else {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new RecordTypeError(message);
    }
  }