Skip to content

Commit

Permalink
refactor: datasource refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hubert committed Oct 11, 2024
1 parent 505e8e2 commit 05195d7
Show file tree
Hide file tree
Showing 124 changed files with 1,879 additions and 1,968 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"sanitize-html": "^2.11.0",
"sequelize": "^6.19.0",
"sequelize": "^6.30.0",
"statuses": "^2.0.1",
"tedious": "^15.1.0",
"wildcard": "^2.0.1"
Expand Down
7 changes: 4 additions & 3 deletions servers/identity-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ const logger = new Logger('AppModule', { timestamp: true });
isGlobal: true,
useFactory: async (config: ConfigService, storageOptions: StorageOptions) => ({
debug: config.get('debug', false),
issuer: `${config.getOrThrow('server.origin')}${normalizeRoutePath(
config.get<string>('server.globalPrefixUri', ''),
)}`,
issuer: 'http://fakeissuer.com',
// `${config.getOrThrow('server.origin')}${normalizeRoutePath(
// config.get<string>('server.globalPrefixUri', ''),
// )}`,
path: normalizeRoutePath(config.get('OIDC_PATH', '/oidc')),
jwks: await getJWKS(config.get('PRIVATE_KEY')),
storage: storageOptions.use,
Expand Down
2 changes: 1 addition & 1 deletion servers/identity-server/src/datasource/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const IDENTITY_OPTIONS = 'IDENTITY_OPTIONS';
export const IDENTITY_DATASOURCE_OPTIONS = 'IDENTITY_DATASOURCE_OPTIONS';
20 changes: 11 additions & 9 deletions servers/identity-server/src/datasource/datasource.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
IdentityDatasourceAsyncOptions,
IdentityDatasourceOptionsFactory,
} from './interfaces/identity-datasource-options.interface';
import { dataSources } from './sequelize';
import * as DataSources from './sequelize/datasources';
import { IdentityDatasourceService } from './datasource.service';
import { IDENTITY_OPTIONS } from './constants';
import { IDENTITY_DATASOURCE_OPTIONS } from './constants';

const dataSources = Object.values(DataSources);

@Module({})
export class IdentityDatasourceModule {
Expand All @@ -22,13 +24,13 @@ export class IdentityDatasourceModule {
global: isGlobal,
providers: [
{
provide: IDENTITY_OPTIONS,
provide: IDENTITY_DATASOURCE_OPTIONS,
useValue: restOptions,
},
...dataSources,
IdentityDatasourceService,
...dataSources,
],
exports: [IDENTITY_OPTIONS, ...dataSources, IdentityDatasourceService],
exports: [IDENTITY_DATASOURCE_OPTIONS, IdentityDatasourceService, ...dataSources],
};
}

Expand All @@ -37,8 +39,8 @@ export class IdentityDatasourceModule {
module: IdentityDatasourceModule,
global: options.isGlobal,
imports: options.imports,
providers: [...this.createAsyncProviders(options), ...dataSources, IdentityDatasourceService],
exports: [IDENTITY_OPTIONS, ...dataSources, IdentityDatasourceService],
providers: [...this.createAsyncProviders(options), IdentityDatasourceService, ...dataSources],
exports: [IDENTITY_DATASOURCE_OPTIONS, IdentityDatasourceService, ...dataSources],
};
}

Expand All @@ -58,7 +60,7 @@ export class IdentityDatasourceModule {
private static createAsyncOptionsProvider(options: IdentityDatasourceAsyncOptions): Provider {
if (options.useFactory) {
return {
provide: IDENTITY_OPTIONS,
provide: IDENTITY_DATASOURCE_OPTIONS,
useFactory: async (...args: any[]) => {
const moduleOptions = await options.useFactory!(...args);
// check connection config
Expand All @@ -69,7 +71,7 @@ export class IdentityDatasourceModule {
};
}
return {
provide: IDENTITY_OPTIONS,
provide: IDENTITY_DATASOURCE_OPTIONS,
useFactory: async (optionsFactory: IdentityDatasourceOptionsFactory) => {
const moduleOptions = await optionsFactory.createSequlizeOptions();
// check connection config
Expand Down
Loading

0 comments on commit 05195d7

Please sign in to comment.