Skip to content

Commit

Permalink
fix: merging data-source options (#829)
Browse files Browse the repository at this point in the history
* chore(release): 3.2.0 [skip ci]

# [3.2.0](v3.1.1...v3.2.0) (2023-11-25)

### Bug Fixes

* **deps:** bump @faker-js/faker from 8.2.0 to 8.3.1 ([#782](#782)) ([fa7a114](fa7a114))
* **deps:** bump locter from 1.2.2 to 1.2.3 ([#779](#779)) ([e89daea](e89daea))

### Features

* seeder with non default export ([#776](#776)) ([e1fe651](e1fe651))

* fix: merging env and file data-source options

* test: add test suite for merging data source options

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
  • Loading branch information
tada5hi and semantic-release-bot authored Jan 11, 2024
1 parent 305d0c2 commit 1d0261a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# [3.2.0](https://github.com/tada5hi/typeorm-extension/compare/v3.1.1...v3.2.0) (2023-11-25)


### Bug Fixes

* **deps:** bump @faker-js/faker from 8.2.0 to 8.3.1 ([#782](https://github.com/tada5hi/typeorm-extension/issues/782)) ([fa7a114](https://github.com/tada5hi/typeorm-extension/commit/fa7a114d7508e635377fbf7c19bd9cfbaaf4ab05))
* **deps:** bump locter from 1.2.2 to 1.2.3 ([#779](https://github.com/tada5hi/typeorm-extension/issues/779)) ([e89daea](https://github.com/tada5hi/typeorm-extension/commit/e89daeab5bd2c0d08ee2503dc259b7e601d790c1))


### Features

* seeder with non default export ([#776](https://github.com/tada5hi/typeorm-extension/issues/776)) ([e1fe651](https://github.com/tada5hi/typeorm-extension/commit/e1fe651397b9f217ca5321db407aca255e5ae5ad))

## [3.1.1](https://github.com/tada5hi/typeorm-extension/compare/v3.1.0...v3.1.1) (2023-10-24)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typeorm-extension",
"version": "3.1.1",
"version": "3.2.0",
"description": "A library to create/drop database, simple seeding data sets, ...",
"author": {
"name": "Peter Placzek",
Expand Down
14 changes: 13 additions & 1 deletion src/data-source/options/utils/merge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { merge } from 'smob';
import { createMerger } from 'smob';
import type { DataSourceOptions } from 'typeorm';

const merge = createMerger({
strategy: (target, key, value) => {
if (typeof target[key] === 'undefined') {
target[key] = value;

return target;
}

return undefined;
},
});

export function mergeDataSourceOptions(
target: DataSourceOptions,
source: DataSourceOptions,
Expand Down
32 changes: 32 additions & 0 deletions test/unit/data-source/options/merge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import { mergeDataSourceOptions } from '../../../../src';

describe('src/data-source/options/merge', () => {
it('should merge data source options', () => {
const options = mergeDataSourceOptions({
type: 'postgres',
password: undefined,
}, {
type: 'postgres',
password: 'password',
});

expect(options).toBeDefined();
expect(options.type).toEqual('postgres');
expect((options as PostgresConnectionOptions).password).toEqual('password');
});

it('should not merge data source options', () => {
const options = mergeDataSourceOptions({
type: 'postgres',
password: undefined,
}, {
type: 'mysql',
password: 'password',
});

expect(options).toBeDefined();
expect(options.type).toEqual('postgres');
expect((options as PostgresConnectionOptions).password).toBeUndefined();
});
});

0 comments on commit 1d0261a

Please sign in to comment.