@flusys/nestjs-core 7.0.2 → 8.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/config/index.d.ts +1 -1
- package/constants/index.d.ts +1 -1
- package/docs/docs.config.d.ts +1 -1
- package/docs/index.d.ts +1 -1
- package/fesm/229.js +729 -0
- package/fesm/config/index.js +126 -1
- package/fesm/constants/index.js +29 -1
- package/fesm/docs/index.js +288 -1
- package/fesm/index.js +124 -5
- package/fesm/interfaces/index.js +18 -4
- package/fesm/migration/cli.js +19 -2
- package/fesm/migration/index.js +45 -3
- package/fesm/runtime.js +85 -0
- package/fesm/utils/index.js +131 -1
- package/index.d.ts +5 -5
- package/interfaces/app-config.interfaces.d.ts +2 -1
- package/interfaces/database.interface.d.ts +1 -0
- package/interfaces/index.d.ts +4 -4
- package/interfaces/migration.interface.d.ts +2 -2
- package/migration/cli.d.ts +0 -1
- package/migration/datasource.factory.d.ts +1 -1
- package/migration/index.d.ts +3 -3
- package/migration/migration.cli.d.ts +1 -1
- package/migration/migration.runner.d.ts +1 -1
- package/package.json +25 -33
- package/utils/datasource-config.builder.d.ts +2 -2
- package/utils/index.d.ts +1 -1
- package/cjs/config/env-config.service.js +0 -162
- package/cjs/config/env-config.service.spec.js +0 -325
- package/cjs/config/index.js +0 -18
- package/cjs/constants/database.constants.js +0 -20
- package/cjs/constants/index.js +0 -18
- package/cjs/docs/docs.config.js +0 -276
- package/cjs/docs/docs.config.spec.js +0 -923
- package/cjs/docs/index.js +0 -18
- package/cjs/index.js +0 -23
- package/cjs/interfaces/app-config.interfaces.js +0 -4
- package/cjs/interfaces/base-entity.interface.js +0 -9
- package/cjs/interfaces/database.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -21
- package/cjs/interfaces/migration.interface.js +0 -4
- package/cjs/migration/cli.js +0 -10
- package/cjs/migration/datasource.factory.js +0 -43
- package/cjs/migration/datasource.factory.spec.js +0 -113
- package/cjs/migration/index.js +0 -45
- package/cjs/migration/migration.cli.js +0 -231
- package/cjs/migration/migration.cli.spec.js +0 -293
- package/cjs/migration/migration.runner.js +0 -276
- package/cjs/migration/migration.runner.spec.js +0 -268
- package/cjs/utils/datasource-config.builder.js +0 -103
- package/cjs/utils/datasource-config.builder.spec.js +0 -232
- package/cjs/utils/index.js +0 -18
- package/fesm/config/env-config.service.js +0 -112
- package/fesm/config/env-config.service.spec.js +0 -321
- package/fesm/constants/database.constants.js +0 -2
- package/fesm/docs/docs.config.js +0 -258
- package/fesm/docs/docs.config.spec.js +0 -919
- package/fesm/interfaces/app-config.interfaces.js +0 -1
- package/fesm/interfaces/base-entity.interface.js +0 -6
- package/fesm/interfaces/database.interface.js +0 -1
- package/fesm/interfaces/migration.interface.js +0 -1
- package/fesm/migration/datasource.factory.js +0 -25
- package/fesm/migration/datasource.factory.spec.js +0 -109
- package/fesm/migration/migration.cli.js +0 -180
- package/fesm/migration/migration.cli.spec.js +0 -289
- package/fesm/migration/migration.runner.js +0 -202
- package/fesm/migration/migration.runner.spec.js +0 -264
- package/fesm/utils/datasource-config.builder.js +0 -84
- package/fesm/utils/datasource-config.builder.spec.js +0 -228
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { buildDataSourceOptions, getMigrationsFolderPath, getMigrationsGlobPattern, getDatabaseForTenant, resolveDatabaseConnection, resolveEntities, getActiveTenants } from './datasource-config.builder';
|
|
2
|
-
describe('datasource-config.builder', ()=>{
|
|
3
|
-
describe('buildDataSourceOptions', ()=>{
|
|
4
|
-
it('should build options with synchronize disabled', ()=>{
|
|
5
|
-
const config = {
|
|
6
|
-
type: 'postgres',
|
|
7
|
-
host: 'localhost',
|
|
8
|
-
port: 5432,
|
|
9
|
-
username: 'root',
|
|
10
|
-
password: 'pw',
|
|
11
|
-
database: 'flusys'
|
|
12
|
-
};
|
|
13
|
-
const options = buildDataSourceOptions(config, [
|
|
14
|
-
Object
|
|
15
|
-
], 'migrations/default', 'custom_migrations');
|
|
16
|
-
expect(options).toEqual({
|
|
17
|
-
type: 'postgres',
|
|
18
|
-
host: 'localhost',
|
|
19
|
-
port: 5432,
|
|
20
|
-
username: 'root',
|
|
21
|
-
password: 'pw',
|
|
22
|
-
database: 'flusys',
|
|
23
|
-
entities: [
|
|
24
|
-
Object
|
|
25
|
-
],
|
|
26
|
-
migrations: [
|
|
27
|
-
'migrations/default'
|
|
28
|
-
],
|
|
29
|
-
migrationsTableName: 'custom_migrations',
|
|
30
|
-
synchronize: false
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
it('should default database to an empty string and table name to "migrations"', ()=>{
|
|
34
|
-
const config = {
|
|
35
|
-
type: 'sqlite'
|
|
36
|
-
};
|
|
37
|
-
const options = buildDataSourceOptions(config, [], 'migrations/default');
|
|
38
|
-
expect(options.database).toBe('');
|
|
39
|
-
expect(options.migrationsTableName).toBe('migrations');
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('getMigrationsFolderPath', ()=>{
|
|
43
|
-
it('should use "default" when no tenantId is given', ()=>{
|
|
44
|
-
expect(getMigrationsFolderPath('migrations')).toBe('migrations/default');
|
|
45
|
-
});
|
|
46
|
-
it('should namespace the folder by tenant', ()=>{
|
|
47
|
-
expect(getMigrationsFolderPath('migrations', 'tenant-a')).toBe('migrations/tenant-a');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('getMigrationsGlobPattern', ()=>{
|
|
51
|
-
it('should build a glob matching ts and js migration files', ()=>{
|
|
52
|
-
expect(getMigrationsGlobPattern('migrations', 'tenant-a')).toBe('migrations/tenant-a/*{.ts,.js}');
|
|
53
|
-
});
|
|
54
|
-
it('should fall back to the default folder', ()=>{
|
|
55
|
-
expect(getMigrationsGlobPattern('migrations')).toBe('migrations/default/*{.ts,.js}');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe('getDatabaseForTenant', ()=>{
|
|
59
|
-
const baseConfig = {
|
|
60
|
-
defaultDatabaseConfig: {
|
|
61
|
-
type: 'postgres',
|
|
62
|
-
database: 'flusys_default'
|
|
63
|
-
},
|
|
64
|
-
migrationsPath: 'migrations',
|
|
65
|
-
entities: []
|
|
66
|
-
};
|
|
67
|
-
it('should return the default tenant config when tenantId is omitted', ()=>{
|
|
68
|
-
const result = getDatabaseForTenant(baseConfig);
|
|
69
|
-
expect(result.database).toBe('flusys_default');
|
|
70
|
-
expect(result.tenant).toBeUndefined();
|
|
71
|
-
expect(result.tenantConfig).toEqual({
|
|
72
|
-
id: 'default',
|
|
73
|
-
database: 'flusys_default',
|
|
74
|
-
enableCompanyFeature: false,
|
|
75
|
-
permissionMode: 'FULL'
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it('should apply bootstrap feature flags to the default tenant config', ()=>{
|
|
79
|
-
const config = {
|
|
80
|
-
...baseConfig,
|
|
81
|
-
bootstrapAppConfig: {
|
|
82
|
-
databaseMode: 'single',
|
|
83
|
-
enableCompanyFeature: true,
|
|
84
|
-
permissionMode: 'RBAC'
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const result = getDatabaseForTenant(config);
|
|
88
|
-
expect(result.tenantConfig.enableCompanyFeature).toBe(true);
|
|
89
|
-
expect(result.tenantConfig.permissionMode).toBe('RBAC');
|
|
90
|
-
});
|
|
91
|
-
it('should resolve an explicit tenant by id', ()=>{
|
|
92
|
-
const config = {
|
|
93
|
-
...baseConfig,
|
|
94
|
-
tenants: [
|
|
95
|
-
{
|
|
96
|
-
id: 'tenant-a',
|
|
97
|
-
database: 'db_a'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: 'tenant-b',
|
|
101
|
-
database: 'db_b'
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
};
|
|
105
|
-
const result = getDatabaseForTenant(config, 'tenant-b');
|
|
106
|
-
expect(result.database).toBe('db_b');
|
|
107
|
-
expect(result.tenant?.id).toBe('tenant-b');
|
|
108
|
-
expect(result.tenantConfig.id).toBe('tenant-b');
|
|
109
|
-
});
|
|
110
|
-
it('should throw a descriptive error for an unknown tenant id', ()=>{
|
|
111
|
-
const config = {
|
|
112
|
-
...baseConfig,
|
|
113
|
-
tenants: [
|
|
114
|
-
{
|
|
115
|
-
id: 'tenant-a',
|
|
116
|
-
database: 'db_a'
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
};
|
|
120
|
-
expect(()=>getDatabaseForTenant(config, 'unknown')).toThrow("Tenant 'unknown' not found. Available: tenant-a");
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('resolveDatabaseConnection', ()=>{
|
|
124
|
-
const baseConfig = {
|
|
125
|
-
defaultDatabaseConfig: {
|
|
126
|
-
type: 'postgres',
|
|
127
|
-
host: 'default-host',
|
|
128
|
-
port: 5432,
|
|
129
|
-
username: 'default-user',
|
|
130
|
-
password: 'default-pw',
|
|
131
|
-
database: 'flusys_default'
|
|
132
|
-
},
|
|
133
|
-
migrationsPath: 'migrations',
|
|
134
|
-
entities: []
|
|
135
|
-
};
|
|
136
|
-
it('should return the default connection when no tenant matches', ()=>{
|
|
137
|
-
const result = resolveDatabaseConnection(baseConfig);
|
|
138
|
-
expect(result).toEqual(baseConfig.defaultDatabaseConfig);
|
|
139
|
-
});
|
|
140
|
-
it('should overlay tenant-specific fields onto the default connection', ()=>{
|
|
141
|
-
const config = {
|
|
142
|
-
...baseConfig,
|
|
143
|
-
tenants: [
|
|
144
|
-
{
|
|
145
|
-
id: 'tenant-a',
|
|
146
|
-
database: 'db_a',
|
|
147
|
-
host: 'tenant-host'
|
|
148
|
-
}
|
|
149
|
-
]
|
|
150
|
-
};
|
|
151
|
-
const result = resolveDatabaseConnection(config, 'tenant-a');
|
|
152
|
-
expect(result).toEqual({
|
|
153
|
-
type: 'postgres',
|
|
154
|
-
host: 'tenant-host',
|
|
155
|
-
port: 5432,
|
|
156
|
-
username: 'default-user',
|
|
157
|
-
password: 'default-pw',
|
|
158
|
-
database: 'db_a'
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
it('should fall back to default connection fields when tenant omits them', ()=>{
|
|
162
|
-
const config = {
|
|
163
|
-
...baseConfig,
|
|
164
|
-
tenants: [
|
|
165
|
-
{
|
|
166
|
-
id: 'tenant-a',
|
|
167
|
-
database: 'db_a'
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
};
|
|
171
|
-
const result = resolveDatabaseConnection(config, 'tenant-a');
|
|
172
|
-
expect(result.host).toBe('default-host');
|
|
173
|
-
expect(result.port).toBe(5432);
|
|
174
|
-
expect(result.username).toBe('default-user');
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe('resolveEntities', ()=>{
|
|
178
|
-
it('should return the entities array directly when not a function', ()=>{
|
|
179
|
-
const config = {
|
|
180
|
-
entities: [
|
|
181
|
-
Object,
|
|
182
|
-
String
|
|
183
|
-
]
|
|
184
|
-
};
|
|
185
|
-
expect(resolveEntities(config)).toEqual([
|
|
186
|
-
Object,
|
|
187
|
-
String
|
|
188
|
-
]);
|
|
189
|
-
});
|
|
190
|
-
it('should invoke the resolver function with tenant config', ()=>{
|
|
191
|
-
const resolver = jest.fn().mockReturnValue([
|
|
192
|
-
Number
|
|
193
|
-
]);
|
|
194
|
-
const config = {
|
|
195
|
-
entities: resolver
|
|
196
|
-
};
|
|
197
|
-
const tenantConfig = {
|
|
198
|
-
id: 'tenant-a',
|
|
199
|
-
database: 'db_a'
|
|
200
|
-
};
|
|
201
|
-
const result = resolveEntities(config, tenantConfig);
|
|
202
|
-
expect(resolver).toHaveBeenCalledWith(tenantConfig);
|
|
203
|
-
expect(result).toEqual([
|
|
204
|
-
Number
|
|
205
|
-
]);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
describe('getActiveTenants', ()=>{
|
|
209
|
-
it('should return an empty array when no tenants are configured', ()=>{
|
|
210
|
-
const config = {
|
|
211
|
-
tenants: undefined
|
|
212
|
-
};
|
|
213
|
-
expect(getActiveTenants(config)).toEqual([]);
|
|
214
|
-
});
|
|
215
|
-
it('should return the configured tenants', ()=>{
|
|
216
|
-
const tenants = [
|
|
217
|
-
{
|
|
218
|
-
id: 'a',
|
|
219
|
-
database: 'db_a'
|
|
220
|
-
}
|
|
221
|
-
];
|
|
222
|
-
const config = {
|
|
223
|
-
tenants
|
|
224
|
-
};
|
|
225
|
-
expect(getActiveTenants(config)).toBe(tenants);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|