How to use the sp2.updateAndRestore function in sp2

To help you get started, we’ve selected a few sp2 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 phenyl / phenyl / modules / memory-db / src / kvs-client.ts View on Github external
async create(value: PreEntity): Promise {
    if (value.id != null) {
      if (this.pool[value.id] != null) {
        throw new Error(
          `The given id "${value.id}" already exists in memory pool.`
        );
      }
      // @ts-ignore value.id exists
      return this.set(value);
    }

    const newValue = updateAndRestore(value, { id: randomString() });
    // @ts-ignore value.id exists
    return this.set(newValue);
  }
github phenyl / phenyl / modules / memory-db / src / kvs-client.ts View on Github external
async set(value: T): Promise {
    this.pool = updateAndRestore(this.pool, { $set: { [value.id]: value } });
    return value;
  }
github phenyl / phenyl / modules / memory-db / src / kvs-client.ts View on Github external
async delete(id?: string | null): Promise {
    if (id == null || this.pool[id] == null) {
      return false;
    }
    this.pool = updateAndRestore(this.pool, { $unset: { [id]: "" } });
    return true;
  }
}