How to use the @wireapp/store-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-web-storage / src / WebStorageEngine.ts View on Github external
public async create(
    tableName: string,
    primaryKey: PrimaryKey,
    entity: EntityType,
  ): Promise {
    if (!entity) {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new StoreEngineError.RecordTypeError(message);
    }

    const internalPrimaryKey: any = this.createKey(tableName, primaryKey);

    try {
      await this.read(tableName, primaryKey);
      const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
      throw new StoreEngineError.RecordAlreadyExistsError(message);
    } catch (error) {
      if (!(error instanceof StoreEngineError.RecordNotFoundError)) {
        throw error;
      }
    }

    if (typeof entity === 'string') {
      this.webStorage.setItem(`${internalPrimaryKey}`, entity);
github wireapp / wire-web-packages / packages / store-engine-dexie / src / index.ts View on Github external
return this.db![tableName].get(primaryKey).then((record: any) => {
      if (typeof record === 'string') {
        record += additions;
      } else {
        const message = `Cannot append text to record "${primaryKey}" because it's not a string.`;
        throw new StoreEngineError.RecordTypeError(message);
      }
      return this.updateOrCreate(tableName, primaryKey, record);
    });
  }
github wireapp / wire-web-packages / packages / store-engine-bro-fs / src / index.ts View on Github external
async create(
    tableName: string,
    primaryKey: PrimaryKey,
    entity: EntityType,
  ): Promise {
    if (!entity) {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new StoreEngineError.RecordTypeError(message);
    }

    if (primaryKey === undefined) {
      primaryKey = (this.autoIncrementedPrimaryKey as unknown) as PrimaryKey;
      this.autoIncrementedPrimaryKey += 1;
    }

    const filePath = this.createFilePath(tableName, primaryKey);
    const isExistent = await fs.exists(filePath);

    if (isExistent) {
      const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
      throw new StoreEngineError.RecordAlreadyExistsError(message);
    } else {
      let data: string;
      try {
github wireapp / wire-web-packages / packages / store-engine-web-storage / src / WebStorageEngine.ts View on Github external
public async append(
    tableName: string,
    primaryKey: PrimaryKey,
    additions: string,
  ): Promise {
    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 StoreEngineError.RecordTypeError(message);
    }
    const key = this.createKey(tableName, primaryKey);
    this.webStorage.setItem(`${key}`, record);
    return primaryKey;
  }
github wireapp / wire-web-packages / packages / store-engine-dexie / src / index.ts View on Github external
public create(tableName: string, primaryKey: string, entity: T): Promise {
    if (entity) {
      return this.db![tableName].add(entity, primaryKey).catch((error: Dexie.DexieError) => {
        throw this.mapDatabaseError(error, tableName, primaryKey);
      });
    }
    const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
    return Promise.reject(new StoreEngineError.RecordTypeError(message));
  }
github wireapp / wire-web-packages / packages / store-engine-fs / src / index.ts View on Github external
try {
        await fs.writeFile(filePath, newEntity, {flag: 'wx'});
        return primaryKey;
      } catch (error) {
        if (error.code === 'ENOENT') {
          await fs.outputFile(filePath, newEntity);
          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 StoreEngineError.RecordAlreadyExistsError(message);
        }
        throw error;
      }
    } else {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new StoreEngineError.RecordTypeError(message);
    }
  }
github wireapp / wire-web-packages / packages / store-engine-web-storage / src / WebStorageEngine.ts View on Github external
public async create(
    tableName: string,
    primaryKey: PrimaryKey,
    entity: EntityType,
  ): Promise {
    if (!entity) {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new StoreEngineError.RecordTypeError(message);
    }

    const internalPrimaryKey: any = this.createKey(tableName, primaryKey);

    try {
      await this.read(tableName, primaryKey);
      const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
      throw new StoreEngineError.RecordAlreadyExistsError(message);
    } catch (error) {
      if (!(error instanceof StoreEngineError.RecordNotFoundError)) {
        throw error;
      }
    }

    if (typeof entity === 'string') {
      this.webStorage.setItem(`${internalPrimaryKey}`, entity);