• A class decorator that defines an injectable datastore

    Type Parameters

    • T

      Type of the datastore values

    Parameters

    • container: {} = defaultContainer

      Object that stores injectables

      Returns ClassDecorator<Class<AnnotatedDatastore<T>>>

      See

      AnnotatedDatastore for interface definition

      Example

      import { AnnotatedDatastore, Datastore } from "@fork-git-it/annotatedjs";

      @Datastore()
      class TestDatastore implements AnnotatedDatastore<string> {
      private map = new Map<string, string>();

      length: number = 0;

      async clear(): Promise<undefined> {
      this.map.clear();
      this.length = 0;
      }

      async getItem(keyName: string): Promise<string | null> {
      return this.map.get(keyName) || null;
      }

      async key(index: number): Promise<string | null> {
      return [...this.map.keys()].at(index) || null;
      }

      async removeItem(keyName: string): Promise<undefined> {
      const keyExisted = this.map.has(keyName);

      this.map.delete(keyName);

      if (!keyExisted) {
      this.length--;
      }
      }

      async setItem(keyName: string, value: string): Promise<undefined> {
      const keyExisted = this.map.has(keyName);

      this.map.set(keyName, value);

      if (!keyExisted) {
      this.length++;
      }
      }
      }

    Generated using TypeDoc