Class TypedStorageService<T, ModelType>

class: TypedStorageService

  • wrap id with type + id.

Type Parameters

  • T extends CoreModel<ModelType>

  • ModelType extends string

Hierarchy

  • TypedStorageService

Implements

Constructors

Properties

storage: ProxyStorageService<T, ModelType>
type: ModelType

Methods

  • using lock(), guard func with auto lock & release.

    const res = await storage.guard(async ()=>{
    return 'abc';
    });
    // res === 'abc'

    Type Parameters

    • T

    Parameters

    • id: string | number
    • handler: (() => T | Promise<T>)
        • (): T | Promise<T>
        • Returns T | Promise<T>

    • Optional tick: number
    • Optional interval: number

    Returns Promise<any>

  • update model (or it will create automatically)

    //before: { count: 1 };
    const res = await storage.increment(1, { count: 2 }, { total: 2 });
    //after : { count: 3, total: 2 }

    Parameters

    • id: string | number

      node-id

    • $increments: T

      model only with numbers

    • Optional $update: T

    Returns Promise<T>

  • lock data-entry by type+id w/ limited time tick

    • WARN! must release lock by release(id)

    total-waited-time = tick * interval (msec)

    [UPDATES]

    1. read original node (or, throw 404 error)
    2. use internal lock.

    Parameters

    • id: string | number

      model-id to lock

    • Optional tick: number

      tick count to wait.

    • Optional interval: number

      timeout interval per each tick (in msec, default 1000 = 1sec)

    Returns Promise<boolean>

  • get next auto-sequence id in number like 1000003.

    Parameters

    • Optional step: number

      (optional) next step value (must be >0) (0 means getting the current value)

    Returns Promise<number>

  • save model by checking origin node.

    • use doSave() rather than doUpdate() for both create & update.
    • if $create is null, throw 404 error it if not found.

    Parameters

    • id: string | number

      node-id

    • model: T
    • Optional $create: T

      (optional) initial creation model.

    Returns Promise<T>

  • update model (or it will create automatically)

    Parameters

    • id: string | number

      node-id

    • model: T

      model to update

    • Optional incrementals: T

      (optional) fields to increment.

    Returns Promise<T>

Generated using TypeDoc