Options
All
  • Public
  • Public/Protected
  • All
Menu

Module repository

Index

Type aliases

FeedOpts

FeedOpts<TSearch>: Search<TSearch> & IInterval

Type parameters

  • TSearch

Functions

changed

  • changed<TRepo, TEntity, TSearch>(repo: TRepo, search: Search<TSearch>, fromVersion?: number): Observable<IFeedResult<TEntity>>
  • Fetches changed records since last request. Feed result can contain only-new or updated and new records depending on the entity type.

    see

    https://geotab.github.io/sdk/software/guides/data-feed/#active-vs-calculated for details on which feeds will return udpated results.

    example

    Log new driver changes to console:

    import { interval } from "rxjs";
    import { switchMap, mergeMap } from "rxjs/operators";
    import { Geotab } from "geotab-rx";
    import { changes } from "geotab-rx/repository/changes";
    
    function monitorChanges(geotab: Geotab, id: string) {
      interval(1000)
        .pipe(
           switchMap(_ =>
             changed(
               geotab.driverChanges,
               { deviceSearch: { id } }
             )
           ),
           mergeMap(feed => feed.data),
        )
        .subscribe(change => console.log(`New driver '${change.driver.id}'!`));
    }
    
    remarks

    It may be required to provide an entity search using from date to "back-fill" or "seed" data from a date in the past. Providing a from date guarantees that the feed will start at a version with all entities that have a date greater than or equal to the date provided. However, it is possible that the feed will return entities before the provided date. Searching using from date should be used independent of fromVersion and only on the first request.

    Type parameters

    • TRepo: Repo<TEntity, TSearch, TRepo>

    • TEntity = RepoEntity<TRepo>

    • TSearch = RepoSearch<TRepo>

    Parameters

    • repo: TRepo

      The repository to search for entities in.

    • search: Search<TSearch>

      The search object for the type of data to return.

    • Optional fromVersion: number

      The Last retrieved version. All new data that has arrived after this version will be returned in this call, up to a maximum of resultsLimit data records. The FeedResult returned by the feed method will contain the highest version for subsequent calls. When starting a new feed, if this value is not provided, the call will return only the toVersion (last version in the system). The start date can be specified in the search argument.

    Returns Observable<IFeedResult<TEntity>>

count

  • count<TRepo>(repo: Repo<TRepo>): Observable<number>
  • Gets the count of entities in the supplied repository. Entities that are currently inactive (the Entity's ActiveTo date is before the current time) are counted as well.

    example

    Log number of users in database:

    import { Geotab } from "geotab-rx";
    import { count } from "geotab-rx/repository/count";
    
    function logNumberOfUsers(geotab: Geotab) {
      count(geotab.users)
        .subscribe(count =>
          console.log(`Number of users = '${count}'`)
        );
    }
    

    Type parameters

    • TRepo: Repo<unknown, unknown, TRepo>

    Parameters

    • repo: Repo<TRepo>

      The repository to get size of.

    Returns Observable<number>

    Number of entities in supplied repository.

create

  • create<TRepo, TEntity>(repo: TRepo, entity: Partial<TEntity>): Observable<string>
  • Adds a new entity to the database. In most cases, the entity being added will need to be fully constructed. In other words, all its properties need to be defined. These requirements are defined in each entity definition.

    example

    Create a driver change record:

    import { Geotab } from "geotab-rx";
    import { create } from "geotab-rx/repository/create";
    import { IUser } from "geotab-rx/models/user";
    import { IDevice } from "geotab-rx/models/device";
    
    function assignDriverToDevice(geotab: Geotab, driver: IUser, device: IDevice) {
      create(geotab.driverChanges, {
        type: "Driver",
        driver,
        device,
        dateTime: new Date(),
      })
        .subscribe(changeId =>
          console.log(`Created driver change with id = '${changeId}'`)
        )
    }
    

    Type parameters

    • TRepo: Repo<TEntity, unknown, TRepo>

    • TEntity = RepoEntity<TRepo>

    Parameters

    • repo: TRepo

      The repository to add entity to.

    • entity: Partial<TEntity>

      The entity to create.

    Returns Observable<string>

    • The newly created entity id.

feedInterval

  • feedInterval<TRepo, TEntity, TSearch>(repo: TRepo, opts: FeedOpts<TSearch>): Observable<TEntity>
  • Type parameters

    • TRepo: Repo<TEntity, TSearch, TRepo>

    • TEntity = RepoEntity<TRepo>

    • TSearch = RepoSearch<TRepo>

    Parameters

    Returns Observable<TEntity>

find

  • find<TRepo, TEntity, TSearch>(repo: TRepo, search?: Search<TSearch>): Observable<TEntity>
  • Find entities using supplied parameters.

    remarks

    {@link Search.limit} determines how many records should be returned. The default is all records.

    Type parameters

    • TRepo: Repo<TEntity, TSearch, TRepo>

    • TEntity = RepoEntity<TRepo>

    • TSearch = RepoSearch<TRepo>

    Parameters

    • repo: TRepo

      The repo to find entities in.

    • Optional search: Search<TSearch>

      The search conditions.

    Returns Observable<TEntity>

    Observable collection of entities found.

remove

  • remove<TRepo, TEntity>(repo: TRepo, entity: Partial<TEntity> & Pick<TEntity, "id">): Observable<void>
  • Permanently removes an entity and it's associated data from supplied repository. The entity must have an id field, remaining fields are optional.

    remarks

    This can trigger cascading removal of all depanent objects associated with the entity. For example removing a {@link Device} would remove all {@link LogRecord}s associated with it.

    Type parameters

    • TRepo: Repo<TEntity, unknown, TRepo>

    • TEntity: IEntity = RepoEntity<TRepo>

    Parameters

    • repo: TRepo

      The repo to remove entity from.

    • entity: Partial<TEntity> & Pick<TEntity, "id">

      The entity to remove.

    Returns Observable<void>

    Squat.

update

  • update<TRepo, TEntity>(repo: TRepo, entity: Partial<TEntity> & Pick<TEntity, "id">): Observable<string>
  • Update supplied entity in supplied repo.

    Type parameters

    • TRepo: Repo<TEntity, unknown, TRepo>

    • TEntity: IEntity = RepoEntity<TRepo>

    Parameters

    • repo: TRepo

      The repository to update entity in.

    • entity: Partial<TEntity> & Pick<TEntity, "id">

      The entity to update.

    Returns Observable<string>

    Observable of updated entity.

Generated using TypeDoc