Gathering detailed insights and metrics for base-repo
Gathering detailed insights and metrics for base-repo
Gathering detailed insights and metrics for base-repo
Gathering detailed insights and metrics for base-repo
npm install base-repo
Typescript
Module System
Node Version
NPM Version
54.1
Supply Chain
89.4
Quality
74.2
Maintenance
50
Vulnerability
0
License
TypeScript (97.22%)
JavaScript (2.78%)
Total Downloads
34,343
Last Day
18
Last Week
94
Last Month
757
Last Year
8,930
4 Stars
232 Commits
1 Forks
1 Watchers
5 Branches
2 Contributors
Updated on Oct 23, 2024
Minified
Minified + Gzipped
Latest Version
3.1.13
Package Id
base-repo@3.1.13
Unpacked Size
191.72 kB
Size
54.67 kB
File Count
56
NPM Version
10.2.3
Node Version
20.10.0
Published on
Jun 04, 2024
Cumulative downloads
Total Downloads
Last Day
-5.3%
18
Compared to previous day
Last Week
13.3%
94
Compared to previous week
Last Month
1.6%
757
Compared to previous month
Last Year
9.9%
8,930
Compared to previous year
2
21
Cache Invalidation at model level extended features for sequelize-typescript (v2.1.0 or later)
1$ npm install base-repo sequelize@^6.x.x sequelize-typescript@^2.x.x
Your tsconfig.json
needs the following flags:
1"target": "es6", // or a more recent ecmascript version 2"experimentalDecorators": true, 3"emitDecoratorMetadata": true
make sure defined all model of sequelize at this level and
1@Module({ 2 ... 3 imports: [ 4 RedisModule.register(cacheConfig() as RedisModuleOptions), 5 6 SequelizeCacheModule.register({ 7 defaultTTL: 5, // DEFINE TTL FOR ALL PROJECT seconds 8 // DEFINE HOW TO GET CACHE FROM GIVEN KEY 9 callbackGet: async ({ key }) => CacheConfigModule.store.get(key), 10 // DEFINE HOW TO INVALIDATE CACHE FROM GIVEN KEY 11 callbackInvalidate: ({ key }) => (CacheConfigModule?.store?.del?.(key) || null), 12 // DEFINE HOW TO SET CACHE FROM GIVEN KEY VALUE AND TTL 13 callbackSet: async ({ key, value, ttl }) => CacheConfigModule.store.set(key, value, { ttl }), 14 callbackGetKey: async ({ keyPattern }) => CacheConfigModule.store.keys?.(`${process.env.CACHE_PREFIX}${keyPattern}`) || [], 15 }), 16 17 SequelizeModule.forRoot({ 18 ...DBOptions, 19 }), 20 ... 21 ], 22}) 23 24export class CacheConfigModule { 25 static store: Store; 26 27 constructor(@Inject(CACHE_MANAGER) private store: Store) { 28 CacheConfigModule.store = this.store; 29 } 30}
@Cache(options)
the @Cache is used for defined ttl and cache for findOne and automatically invalidate findOneCache/findByPkCache
@Cache
API OptionsOptions | Description |
---|---|
options.ttl | set TTL for this model, this will override ttl at module (Optional) |
1@Cache({ 2 ttl: 100, 3}) 4@Table() 5export class DmCourse extends BaseModel {}
BaseModel
1@Cache({ 2 ttl: 100, 3}) 4@Table() 5export class DmCourse extends BaseModel { 6 // default `{modelName} data not found' 7 static notFoundMessage = 'your model not found message'; 8 9 /** 10 * @default `updatedAt` 11 * @description `this is for checking newest updated timestamp for cached list.` 12 */ 13 static onUpdateAttribute = 'modifiedAt' 14 15 @UpdatedAt 16 @Column({ field: 'UpdatedAt' }) 17 modifiedAt: Date; 18}
the Model need to extends BaseModel
1interface DmCourseAtt { 2 id: number 3 name: string; 4 type: number; 5} 6 7interface DmCreateAtt extends DmCourseAtt Omit<DmCourseAtt, 'id'> 8 9@Cache({ 10 ttl: 100, 11}) 12@Table() 13export class DmCourse extends BaseModel<DmCourseAtt, DmCreateAtt> {}
for strict type that can used at default function from sequelize-typescript can be planted at generic type 2 and 3 sequelize-typescript strict
Model.findOneCache(cacheOptions)
cacheOptions : FindOptions
limited findOptions from sequelize-typescript1// file: DmCourse.ts
2
3@Cache() //default ttl module
4@Table()
5export class DmCourse extends BaseModel<DmCourseAtt, DmCreateAtt> {}
6
7...
8
9// file: Course.controller.ts
10
11class CourseController {
12 async getCourse() {
13 const course = await DmCourse.findOneCache({
14 where: {
15 isDeleted: false,
16 name: 'Math',
17 },
18 rejectOnEmpty: true, // use model default throw, or use use throw Exception
19 // rejectOnEmpty: new BadRequestException('message')
20 })
21 }
22}
byIsDeletedAndName
findOneCache
API OptionsOptions | Description |
---|---|
cacheOptions | some function from Sequelize FindOptions |
cacheOptions.ttl | set TTL for this cache key, this will override ttl at module and model (Optional) , (Required) when has include Query |
cacheOptions.rejectOnEmpty | will throw error when set true (Optional) |
Model.findByPkCache(id, options)
1class CourseController { 2 async getCourse() { 3 const course = await DmCourse.findByPkCache(1, { 4 ttl: 100, 5 }); 6 } 7}
findByPkCache
API OptionsOptions | Description |
---|---|
id | value of id |
cacheOptions | some function from Sequelize FindOptions |
cacheOptions.ttl | set TTL for this cache key, this will override ttl at module and model (Optional) , (Required) when has include Query |
cacheOptions.rejectOnEmpty | will throw error when set true (Optional) |
Model.findAllCache(cacheOptions)
1class CourseController { 2 async getCourse() { 3 const course = await DmCourse.findAllCache({ 4 ttl: 100, 5 attributes: ['id','name','type'] 6 where: { 7 isDeleted: false, 8 }, 9 order: [ 10 ['id','desc'] 11 ], 12 include: [ 13 { 14 // any association 15 } 16 ], 17 limit: 10, 18 }) 19 } 20}
findAllCache
API OptionsOptions | Description |
---|---|
cacheOptions.ttl | set TTL for this cache key, this will override ttl at module and model (Optional), (Required) when has include Query |
{...cacheOptions} | is same with FindOptions from sequelize-typescript |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
26 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-12
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More