Skip to content

Commit 9d48e0e

Browse files
committed
Make className and tenants in tenant related builders mandatory
1 parent 9c68d53 commit 9d48e0e

File tree

8 files changed

+37
-126
lines changed

8 files changed

+37
-126
lines changed

src/batch/journey.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,7 @@ describe('multi tenancy', () => {
546546

547547
it('create Passage classes tenants', () => {
548548
return client.schema
549-
.tenantsCreator()
550-
.withClassName(passageClassName)
551-
.withTenants(tenants)
549+
.tenantsCreator(passageClassName, tenants)
552550
.do()
553551
.then((res) => {
554552
expect(res).toHaveLength(2);
@@ -560,8 +558,7 @@ describe('multi tenancy', () => {
560558

561559
it('get Passage classes tenants', () => {
562560
return client.schema
563-
.tenantsGetter()
564-
.withClassName(passageClassName)
561+
.tenantsGetter(passageClassName)
565562
.do()
566563
.then((res) => {
567564
expect(res).toHaveLength(2);

src/data/journey.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,7 @@ describe('multi tenancy', () => {
12231223
.catch((e) => fail('it should not have errord: ' + e));
12241224

12251225
await client.schema
1226-
.tenantsCreator()
1227-
.withClassName(documentClassName)
1228-
.withTenants(tenants)
1226+
.tenantsCreator(documentClassName, tenants)
12291227
.do()
12301228
.then((res) => expect(res).toHaveLength(3))
12311229
.catch((e) => fail('it should not have errord: ' + e));
@@ -1238,9 +1236,7 @@ describe('multi tenancy', () => {
12381236
.catch((e) => fail('it should not have errord: ' + e));
12391237

12401238
return client.schema
1241-
.tenantsCreator()
1242-
.withClassName(passageClassName)
1243-
.withTenants(tenants)
1239+
.tenantsCreator(passageClassName, tenants)
12441240
.do()
12451241
.then((res) => expect(res).toHaveLength(3))
12461242
.catch((e) => fail('it should not have errord: ' + e));

src/graphql/journey.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,19 +1859,11 @@ const setupDocumentPassageSchema = async (
18591859
await Promise.all([client.schema.classCreator().withClass(passage).do()]);
18601860

18611861
if (tenants) {
1862-
const documentTenants = await client.schema
1863-
.tenantsCreator()
1864-
.withClassName(document.class!)
1865-
.withTenants(tenants)
1866-
.do();
1862+
const documentTenants = await client.schema.tenantsCreator(document.class!, tenants).do();
18671863
expect(documentTenants).toBeDefined();
18681864
expect(documentTenants).toHaveLength(tenants.length);
18691865

1870-
const passageTenants = await client.schema
1871-
.tenantsCreator()
1872-
.withClassName(passage.class!)
1873-
.withTenants(tenants)
1874-
.do();
1866+
const passageTenants = await client.schema.tenantsCreator(passage.class!, tenants).do();
18751867
expect(passageTenants).toBeDefined();
18761868
expect(passageTenants).toHaveLength(tenants.length);
18771869
}

src/schema/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import TenantsCreator from './tenantsCreator';
1111
import TenantsGetter from './tenantsGetter';
1212
import TenantsDeleter from './tenantsDeleter';
1313
import Connection from '../connection';
14+
import { Tenant } from '../openapi/types';
1415

1516
export interface Schema {
1617
classCreator: () => ClassCreator;
@@ -22,9 +23,9 @@ export interface Schema {
2223
shardsGetter: () => ShardsGetter;
2324
shardUpdater: () => ShardUpdater;
2425
shardsUpdater: () => ShardsUpdater;
25-
tenantsCreator: () => TenantsCreator;
26-
tenantsGetter: () => TenantsGetter;
27-
tenantsDeleter: () => TenantsDeleter;
26+
tenantsCreator: (className: string, tenants: Array<Tenant>) => TenantsCreator;
27+
tenantsGetter: (className: string) => TenantsGetter;
28+
tenantsDeleter: (className: string, tenants: Array<string>) => TenantsDeleter;
2829
}
2930

3031
const schema = (client: Connection): Schema => {
@@ -38,9 +39,11 @@ const schema = (client: Connection): Schema => {
3839
shardsGetter: () => new ShardsGetter(client),
3940
shardUpdater: () => new ShardUpdater(client),
4041
shardsUpdater: () => new ShardsUpdater(client),
41-
tenantsCreator: () => new TenantsCreator(client),
42-
tenantsGetter: () => new TenantsGetter(client),
43-
tenantsDeleter: () => new TenantsDeleter(client),
42+
tenantsCreator: (className: string, tenants: Array<Tenant>) =>
43+
new TenantsCreator(client, className, tenants),
44+
tenantsGetter: (className: string) => new TenantsGetter(client, className),
45+
tenantsDeleter: (className: string, tenants: Array<string>) =>
46+
new TenantsDeleter(client, className, tenants),
4447
};
4548
};
4649

src/schema/journey.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,7 @@ describe('multi tenancy', () => {
677677

678678
it('defines tenants for MultiTenancy class', () => {
679679
return client.schema
680-
.tenantsCreator()
681-
.withClassName(classObj.class!)
682-
.withTenants(tenants)
680+
.tenantsCreator(classObj.class!, tenants)
683681
.do()
684682
.then((res: Array<Tenant>) => {
685683
expect(res).toEqual(tenants);
@@ -688,8 +686,7 @@ describe('multi tenancy', () => {
688686

689687
it('gets tenants for MultiTenancy class', () => {
690688
return client.schema
691-
.tenantsGetter()
692-
.withClassName(classObj.class!)
689+
.tenantsGetter(classObj.class!)
693690
.do()
694691
.then((res: Array<Tenant>) => {
695692
expect(res).toHaveLength(3);
@@ -698,9 +695,7 @@ describe('multi tenancy', () => {
698695

699696
it('delete one tenant in MultiTenancy class', () => {
700697
return client.schema
701-
.tenantsDeleter()
702-
.withClassName(classObj.class!)
703-
.withTenants([tenants[0].name!])
698+
.tenantsDeleter(classObj.class!, [tenants[0].name!])
704699
.do()
705700
.then((res) => {
706701
expect(res).toEqual(undefined);
@@ -709,8 +704,7 @@ describe('multi tenancy', () => {
709704

710705
it('get tenants after delete for MultiTenancy class', () => {
711706
return client.schema
712-
.tenantsGetter()
713-
.withClassName(classObj.class!)
707+
.tenantsGetter(classObj.class!)
714708
.do()
715709
.then((res: Array<Tenant>) => {
716710
expect(res).toHaveLength(2);
@@ -735,9 +729,7 @@ describe('multi tenancy', () => {
735729

736730
it('fails to define tenants for NoMultiTenancy class', () => {
737731
return client.schema
738-
.tenantsCreator()
739-
.withClassName(classObjWithoutMultiTenancyConfig.class!)
740-
.withTenants(tenants)
732+
.tenantsCreator(classObjWithoutMultiTenancyConfig.class!, tenants)
741733
.do()
742734
.catch((e: Error) => {
743735
expect(e.message).toContain('multi-tenancy is not enabled for class \\"NoMultiTenancy\\"');

src/schema/tenantsCreator.ts

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,22 @@
1-
import { isValidStringProperty } from '../validation/string';
21
import Connection from '../connection';
32
import { CommandBase } from '../validation/commandBase';
43
import { Tenant } from '../openapi/types';
54

65
export default class TenantsCreator extends CommandBase {
7-
private className?: string;
8-
private tenants?: Array<Tenant>;
6+
private className: string;
7+
private tenants: Array<Tenant>;
98

10-
constructor(client: Connection) {
9+
constructor(client: Connection, className: string, tenants: Array<Tenant>) {
1110
super(client);
12-
}
13-
14-
withClassName = (className: string) => {
1511
this.className = className;
16-
return this;
17-
};
18-
19-
withTenants = (tenants: Array<Tenant>) => {
2012
this.tenants = tenants;
21-
return this;
22-
};
23-
24-
validateClassName = () => {
25-
if (!isValidStringProperty(this.className)) {
26-
this.addError('className must be set - set with .withClassName(className)');
27-
}
28-
};
29-
30-
validateTenants = () => {
31-
if (!this.tenants || this.tenants.length == 0) {
32-
this.addError('tenants must be set - set with .withTenants(tenants)');
33-
}
34-
};
13+
}
3514

3615
validate = () => {
37-
this.validateClassName();
38-
this.validateTenants();
16+
// nothing to validate
3917
};
4018

4119
do = (): Promise<Array<Tenant>> => {
42-
this.validate();
43-
if (this.errors.length > 0) {
44-
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
45-
}
46-
const path = `/schema/${this.className}/tenants`;
47-
return this.client.post(path, this.tenants);
20+
return this.client.post(`/schema/${this.className}/tenants`, this.tenants);
4821
};
4922
}

src/schema/tenantsDeleter.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,20 @@ import { CommandBase } from '../validation/commandBase';
44
import { Tenant } from '../openapi/types';
55

66
export default class TenantsDeleter extends CommandBase {
7-
private className?: string;
8-
private tenants?: Array<string>;
7+
private className: string;
8+
private tenants: Array<string>;
99

10-
constructor(client: Connection) {
10+
constructor(client: Connection, className: string, tenants: Array<string>) {
1111
super(client);
12-
}
13-
14-
withClassName = (className: string) => {
1512
this.className = className;
16-
return this;
17-
};
18-
19-
withTenants = (tenants: Array<string>) => {
2013
this.tenants = tenants;
21-
return this;
22-
};
23-
24-
validateClassName = () => {
25-
if (!isValidStringProperty(this.className)) {
26-
this.addError('className must be set - set with .withClassName(className)');
27-
}
28-
};
29-
30-
validateTenants = () => {
31-
if (!this.tenants || this.tenants.length == 0) {
32-
this.addError('tenants must be set - set with .withTenants(tenants)');
33-
}
34-
};
14+
}
3515

3616
validate = () => {
37-
this.validateClassName();
38-
this.validateTenants();
17+
// nothing to validate
3918
};
4019

4120
do = (): Promise<void> => {
42-
this.validate();
43-
if (this.errors.length > 0) {
44-
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
45-
}
46-
const path = `/schema/${this.className}/tenants`;
47-
return this.client.delete(path, this.tenants, false);
21+
return this.client.delete(`/schema/${this.className}/tenants`, this.tenants, false);
4822
};
4923
}

src/schema/tenantsGetter.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
1-
import { isValidStringProperty } from '../validation/string';
21
import Connection from '../connection';
32
import { CommandBase } from '../validation/commandBase';
43
import { Tenant } from '../openapi/types';
54

65
export default class TenantsGetter extends CommandBase {
7-
private className?: string;
6+
private className: string;
87

9-
constructor(client: Connection) {
8+
constructor(client: Connection, className: string) {
109
super(client);
11-
}
12-
13-
withClassName = (className: string) => {
1410
this.className = className;
15-
return this;
16-
};
17-
18-
validateClassName = () => {
19-
if (!isValidStringProperty(this.className)) {
20-
this.addError('className must be set - set with .withClassName(className)');
21-
}
22-
};
11+
}
2312

2413
validate = () => {
25-
this.validateClassName();
14+
// nothing to validate
2615
};
2716

2817
do = (): Promise<Array<Tenant>> => {
29-
this.validate();
30-
if (this.errors.length > 0) {
31-
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
32-
}
33-
const path = `/schema/${this.className}/tenants`;
34-
return this.client.get(path);
18+
return this.client.get(`/schema/${this.className}/tenants`);
3519
};
3620
}

0 commit comments

Comments
 (0)