File tree Expand file tree Collapse file tree 7 files changed +119
-5
lines changed
services/feature-toggle-service Expand file tree Collapse file tree 7 files changed +119
-5
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,21 @@ npm i @sourceloop/feature-toggle-service
4949- Start the application
5050 ` npm start `
5151
52+ ### Using with Sequelize
53+
54+ This service supports Sequelize as the underlying ORM using [ @loopback/sequelize ] ( https://www.npmjs.com/package/@loopback/sequelize ) extension. And in order to use it, you'll need to do following changes.
55+
56+ 1 . To use Sequelize in your application, add following to application.ts:
57+
58+ ``` ts
59+ this .bind (ChatServiceBindings .Config ).to ({
60+ useCustomSequence: false ,
61+ useSequelize: true ,
62+ });
63+ ```
64+
65+ 2 . Use the ` SequelizeDataSource ` in your audit datasource as the parent class. Refer [ this] ( https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource ) for more.
66+
5267### Asymmetric Token Signing and Verification
5368
5469If you are using asymmetric token signing and verification, you need to create a datasource for auth database. Example datasource file for auth:-
Original file line number Diff line number Diff line change 9696 "typescript" : " ^5.4.5" ,
9797 "widdershins" : " ^4.0.1"
9898 },
99+ "optionalDependencies" : {
100+ "@loopback/sequelize" : " ^0.6.9"
101+ },
99102 "peerDependencies" : {
100103 "db-migrate" : " ^1.0.0-beta.21" ,
101104 "db-migrate-pg" : " ^1.3.0"
Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ import {
3838 FeatureValuesRepository ,
3939 StrategyRepository ,
4040} from './repositories' ;
41+ import {
42+ FeatureRepository as FeatureSequelizeRepository ,
43+ FeatureValuesRepository as FeatureValuesSequelizeRepository ,
44+ StrategyRepository as StrategySequelizeRepository ,
45+ } from './repositories/sequelize' ;
4146import { IToggleServiceConfig } from './types' ;
4247
4348export class FeatureToggleServiceComponent implements Component {
@@ -70,11 +75,19 @@ export class FeatureToggleServiceComponent implements Component {
7075 // Mount default sequence if needed
7176 this . setupSequence ( ) ;
7277 }
73- this . repositories = [
74- FeatureRepository ,
75- FeatureValuesRepository ,
76- StrategyRepository ,
77- ] ;
78+ if ( this . config ?. useSequelize ) {
79+ this . repositories = [
80+ FeatureSequelizeRepository ,
81+ FeatureValuesSequelizeRepository ,
82+ StrategySequelizeRepository ,
83+ ] ;
84+ } else {
85+ this . repositories = [
86+ FeatureRepository ,
87+ FeatureValuesRepository ,
88+ StrategyRepository ,
89+ ] ;
90+ }
7891 this . models = [ Feature , FeatureValues , Strategy ] ;
7992
8093 this . controllers = [
Original file line number Diff line number Diff line change 1+ import { Getter , inject } from '@loopback/core' ;
2+ import { IAuthUserWithPermissions } from '@sourceloop/core' ;
3+ import { AuthenticationBindings } from 'loopback4-authentication' ;
4+ import { FeatureValues } from '../../models' ;
5+ import { FeatureToggleDbName } from '../../types' ;
6+ import { SequelizeSoftCrudRepository } from 'loopback4-soft-delete/sequelize' ;
7+ import { SequelizeDataSource } from '@loopback/sequelize' ;
8+ export class FeatureValuesRepository extends SequelizeSoftCrudRepository <
9+ FeatureValues ,
10+ typeof FeatureValues . prototype . id
11+ > {
12+ constructor (
13+ @inject ( `datasources.${ FeatureToggleDbName } ` )
14+ dataSource : SequelizeDataSource ,
15+ @inject . getter ( AuthenticationBindings . CURRENT_USER )
16+ protected readonly getCurrentUser : Getter <
17+ IAuthUserWithPermissions | undefined
18+ > ,
19+ ) {
20+ super ( FeatureValues , dataSource , getCurrentUser ) ;
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Sourcefuse Technologies
2+ //
3+ // This software is released under the MIT License.
4+ // https://opensource.org/licenses/MIT
5+ import { Getter , inject } from '@loopback/core' ;
6+ import { IAuthUserWithPermissions } from '@sourceloop/core' ;
7+ import { SequelizeSoftCrudRepository } from 'loopback4-soft-delete/sequelize' ;
8+ import { SequelizeDataSource } from '@loopback/sequelize' ;
9+ import { AuthenticationBindings } from 'loopback4-authentication' ;
10+ import { Feature } from '../../models' ;
11+ import { FeatureToggleDbName } from '../../types' ;
12+
13+ export class FeatureRepository extends SequelizeSoftCrudRepository <
14+ Feature ,
15+ typeof Feature . prototype . name
16+ > {
17+ constructor (
18+ @inject ( `datasources.${ FeatureToggleDbName } ` )
19+ dataSource : SequelizeDataSource ,
20+ @inject . getter ( AuthenticationBindings . CURRENT_USER )
21+ protected readonly getCurrentUser : Getter <
22+ IAuthUserWithPermissions | undefined
23+ > ,
24+ ) {
25+ super ( Feature , dataSource , getCurrentUser ) ;
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Sourcefuse Technologies
2+ //
3+ // This software is released under the MIT License.
4+ // https://opensource.org/licenses/MIT
5+ export * from './feature-values.repository' ;
6+ export * from './feature.repository' ;
7+ export * from './strategy.repository' ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Sourcefuse Technologies
2+ //
3+ // This software is released under the MIT License.
4+ // https://opensource.org/licenses/MIT
5+ import { Getter , inject } from '@loopback/core' ;
6+ import { IAuthUserWithPermissions } from '@sourceloop/core' ;
7+ import { SequelizeSoftCrudRepository } from 'loopback4-soft-delete/sequelize' ;
8+ import { SequelizeDataSource } from '@loopback/sequelize' ;
9+ import { AuthenticationBindings } from 'loopback4-authentication' ;
10+ import { Strategy } from '../../models' ;
11+ import { FeatureToggleDbName } from '../../types' ;
12+
13+ export class StrategyRepository extends SequelizeSoftCrudRepository <
14+ Strategy ,
15+ typeof Strategy . prototype . name
16+ > {
17+ constructor (
18+ @inject ( `datasources.${ FeatureToggleDbName } ` )
19+ dataSource : SequelizeDataSource ,
20+ @inject . getter ( AuthenticationBindings . CURRENT_USER )
21+ protected readonly getCurrentUser : Getter <
22+ IAuthUserWithPermissions | undefined
23+ > ,
24+ ) {
25+ super ( Strategy , dataSource , getCurrentUser ) ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments