1.1.4 • Published 2 years ago

@khalitovadel/abstract-repository v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Repositories templates

Example:

import { AbstractCachedRepository } from '@khalitovadel/abstract-repository';

export class MyEntity {
   private readonly id!: string;
   private readonly fullName: string;
   private otherField?: string;
   private userId: string;

   constructor(fullName: string) {
       this.fullName = fullName;
   }
}

export interface ObjectFromDb {
   _id: string;
   fullName: string;
   userId: string;
}

export class MyEntityRepository extends AbstractCachedRepository<string, ObjectFromDb, MyEntity, MyEntity> {
   protected decrypt(value: ObjectFromDb): MyEntity {

       const instance = Object.create(Object.getPrototypeOf(MyEntity));
       Object.assign(instance, {
           id: String(value._id),
           fullName: value.fullName,
           otherField: '',
           userId: value.userId,
       })
       return instance;
   }

   protected create(value: MyEntity): Promise<[string, ObjectFromDb]> {
       // your implementation
   }

   protected update(value: MyEntity): Promise<[string, ObjectFromDb]> {
       // your implementation
   }

   protected findByIds(ids: string[]): Promise<Map<string, ObjectFromDb>> {
       // your implementation
   }

   /**
    * New Method of repository
    * Here I call my db, to find entity by index
    * Mongodb example:
    * const result: {userId: string, _id: string}[] = model.find({ userId }, {_id: 1, userId: 1});
    * Our base goal find that data only by index
    * To prevent the database from trying to read file documents
    * then:
    * return this.list(result.map(el => el._id));
    * 
    * As result we have very fast methods,
    * who get all data from cache, in the correct sequence (If there are necessary sortings)
    * if not exists repository set it to cache
    */
   public findEntityByRelatedUser(userId: string) {
       // your implementation
   }
}
acornacorn-jsxansi-colorsansi-regexajvarray-includesansi-stylesargparsebalanced-matcharray.prototype.flatbrace-expansionbracescall-bindarray-unioncallsiteschalkcolor-nameconcat-mapcross-spawncolor-convertdebugdeep-isdefine-propertiesdir-globdiff-sequencesdoctrineenquireres-abstractes-to-primitiveescape-string-regexpeslint-module-utilseslint-import-resolver-nodeeslint-scopeeslint-utilseslint-visitor-keysespreeesrecurseesqueryestraversefast-deep-equalesutilsfast-difffast-globfast-json-stable-stringifyfast-levenshteinfastqfill-rangefind-upfile-entry-cacheflat-cacheflattedfs.realpathfunction-bindfunctional-red-black-treeget-intrinsicget-symbol-descriptionglobglob-parentglobalsglobbyhashas-bigintshas-flaghas-symbolshas-tostringtagignoreimport-freshimurmurhashinflightinheritsinternal-slotis-bigintis-boolean-objectis-callableis-core-moduleis-date-objectis-extglobis-globis-numberis-negative-zerois-number-objectis-regexis-shared-array-bufferis-symbolis-stringis-weakrefisexejest-diffjest-get-typejs-yamljson-schema-traversejson-stable-stringify-without-jsonifyjson5levnlocate-pathlodash.mergelru-cachemerge2micromatchminimatchminimistmsnatural-compareobject-inspectobject-keysobject.assignobject.valuesonceoptionatorp-limitp-locatep-tryparent-modulepath-existspath-is-absolutepath-keypath-parsepath-typepicomatchpkg-dirprelude-lsprettier-linter-helperspretty-formatprogresspunycodequeue-microtaskreact-isregexppresolveresolve-fromreusifyrimrafrun-parallelsemvershebang-commandshebang-regexside-channelslashstring.prototype.trimendstring.prototype.trimstartstrip-ansistrip-bomstrip-json-commentssupports-colortext-tableto-regex-rangetsconfig-pathstslibtsutilstype-checktype-festunbox-primitiveuri-jsv8-compile-cachewhichwhich-boxed-primitiveword-wrapwrappyyallist
1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago