@wisemen/address 0.1.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/.env.test +1 -0
- package/README.md +83 -0
- package/dist/address-column.d.ts +2 -0
- package/dist/address-column.js +27 -0
- package/dist/address-column.js.map +1 -0
- package/dist/address-command.builder.d.ts +14 -0
- package/dist/address-command.builder.js +39 -0
- package/dist/address-command.builder.js.map +1 -0
- package/dist/address-command.d.ts +14 -0
- package/dist/address-command.js +104 -0
- package/dist/address-command.js.map +1 -0
- package/dist/address-response.d.ts +14 -0
- package/dist/address-response.js +72 -0
- package/dist/address-response.js.map +1 -0
- package/dist/address.builder.d.ts +16 -0
- package/dist/address.builder.js +47 -0
- package/dist/address.builder.js.map +1 -0
- package/dist/address.d.ts +12 -0
- package/dist/address.js +12 -0
- package/dist/address.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/is-address.validator.d.ts +11 -0
- package/dist/is-address.validator.js +52 -0
- package/dist/is-address.validator.js.map +1 -0
- package/dist/tests/address-column.integration.test.d.ts +1 -0
- package/dist/tests/address-column.integration.test.js +109 -0
- package/dist/tests/address-column.integration.test.js.map +1 -0
- package/dist/tests/is-address.validator.unit.test.d.ts +1 -0
- package/dist/tests/is-address.validator.unit.test.js +129 -0
- package/dist/tests/is-address.validator.unit.test.js.map +1 -0
- package/dist/tests/sql/address-test.entity.d.ts +5 -0
- package/dist/tests/sql/address-test.entity.js +28 -0
- package/dist/tests/sql/address-test.entity.js.map +1 -0
- package/dist/tests/sql/datasource.d.ts +2 -0
- package/dist/tests/sql/datasource.js +15 -0
- package/dist/tests/sql/datasource.js.map +1 -0
- package/eslint.config.js +17 -0
- package/lib/address-column.ts +31 -0
- package/lib/address-command.builder.ts +56 -0
- package/lib/address-command.ts +78 -0
- package/lib/address-response.ts +46 -0
- package/lib/address.builder.ts +68 -0
- package/lib/address.ts +13 -0
- package/lib/index.ts +7 -0
- package/lib/is-address.validator.ts +82 -0
- package/lib/tests/address-column.integration.test.ts +163 -0
- package/lib/tests/is-address.validator.unit.test.ts +144 -0
- package/lib/tests/sql/address-test.entity.ts +12 -0
- package/lib/tests/sql/datasource.ts +15 -0
- package/package.json +44 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { after, before, describe, it } from 'node:test';
|
|
2
|
+
import { expect } from 'expect';
|
|
3
|
+
import { Coordinates } from '@wisemen/coordinates';
|
|
4
|
+
import { AddressBuilder } from '../address.builder.js';
|
|
5
|
+
import { dataSource } from './sql/datasource.js';
|
|
6
|
+
import { AddressTest } from './sql/address-test.entity.js';
|
|
7
|
+
describe('AddressColumn', () => {
|
|
8
|
+
before(async () => {
|
|
9
|
+
await dataSource.initialize();
|
|
10
|
+
await dataSource.synchronize(true);
|
|
11
|
+
});
|
|
12
|
+
after(async () => {
|
|
13
|
+
await dataSource.destroy();
|
|
14
|
+
});
|
|
15
|
+
describe('serialization and deserialization', () => {
|
|
16
|
+
it('stores and retrieves a complete address with all fields', async () => {
|
|
17
|
+
const address = new AddressBuilder()
|
|
18
|
+
.withPlaceName('Main Office')
|
|
19
|
+
.withPlaceId('place123')
|
|
20
|
+
.withCountry('Belgium')
|
|
21
|
+
.withCity('Brussels')
|
|
22
|
+
.withPostalCode('1000')
|
|
23
|
+
.withStreetName('Grand Place')
|
|
24
|
+
.withStreetNumber('1')
|
|
25
|
+
.withUnit('A')
|
|
26
|
+
.withCoordinates(new Coordinates(50.8503, 4.3517))
|
|
27
|
+
.build();
|
|
28
|
+
await dataSource.manager.upsert(AddressTest, { id: 1, address }, { conflictPaths: { id: true } });
|
|
29
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 1 });
|
|
30
|
+
expect(test.address).not.toBeNull();
|
|
31
|
+
expect(test.address?.placeName).toBe('Main Office');
|
|
32
|
+
expect(test.address?.placeId).toBe('place123');
|
|
33
|
+
expect(test.address?.country).toBe('Belgium');
|
|
34
|
+
expect(test.address?.city).toBe('Brussels');
|
|
35
|
+
expect(test.address?.postalCode).toBe('1000');
|
|
36
|
+
expect(test.address?.streetName).toBe('Grand Place');
|
|
37
|
+
expect(test.address?.streetNumber).toBe('1');
|
|
38
|
+
expect(test.address?.unit).toBe('A');
|
|
39
|
+
expect(test.address?.coordinates?.latitude).toBe(50.8503);
|
|
40
|
+
expect(test.address?.coordinates?.longitude).toBe(4.3517);
|
|
41
|
+
});
|
|
42
|
+
it('stores and retrieves an address with partial fields', async () => {
|
|
43
|
+
const address = new AddressBuilder()
|
|
44
|
+
.withCountry('Belgium')
|
|
45
|
+
.withCity('Antwerp')
|
|
46
|
+
.withPostalCode('2000')
|
|
47
|
+
.build();
|
|
48
|
+
await dataSource.manager.upsert(AddressTest, { id: 2, address }, { conflictPaths: { id: true } });
|
|
49
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 2 });
|
|
50
|
+
expect(test.address).not.toBeNull();
|
|
51
|
+
expect(test.address?.country).toBe('Belgium');
|
|
52
|
+
expect(test.address?.city).toBe('Antwerp');
|
|
53
|
+
expect(test.address?.postalCode).toBe('2000');
|
|
54
|
+
expect(test.address?.streetName).toBeUndefined();
|
|
55
|
+
expect(test.address?.streetNumber).toBeUndefined();
|
|
56
|
+
expect(test.address?.unit).toBeUndefined();
|
|
57
|
+
expect(test.address?.coordinates).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
it('stores and retrieves an address with coordinates only', async () => {
|
|
60
|
+
const address = new AddressBuilder()
|
|
61
|
+
.withCoordinates(new Coordinates(51.2194, 4.4025))
|
|
62
|
+
.build();
|
|
63
|
+
await dataSource.manager.upsert(AddressTest, { id: 3, address }, { conflictPaths: { id: true } });
|
|
64
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 3 });
|
|
65
|
+
expect(test.address).not.toBeNull();
|
|
66
|
+
expect(test.address?.coordinates?.latitude).toBe(51.2194);
|
|
67
|
+
expect(test.address?.coordinates?.longitude).toBe(4.4025);
|
|
68
|
+
expect(test.address?.country).toBeUndefined();
|
|
69
|
+
expect(test.address?.city).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
it('stores and retrieves a null address', async () => {
|
|
72
|
+
await dataSource.manager.upsert(AddressTest, { id: 4, address: null }, { conflictPaths: { id: true } });
|
|
73
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 4 });
|
|
74
|
+
expect(test.address).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
it('stores and retrieves an address with null coordinates', async () => {
|
|
77
|
+
const address = new AddressBuilder()
|
|
78
|
+
.withCountry('Netherlands')
|
|
79
|
+
.withCity('Amsterdam')
|
|
80
|
+
.withCoordinates(null)
|
|
81
|
+
.build();
|
|
82
|
+
await dataSource.manager.upsert(AddressTest, { id: 5, address }, { conflictPaths: { id: true } });
|
|
83
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 5 });
|
|
84
|
+
expect(test.address).not.toBeNull();
|
|
85
|
+
expect(test.address?.country).toBe('Netherlands');
|
|
86
|
+
expect(test.address?.city).toBe('Amsterdam');
|
|
87
|
+
expect(test.address?.coordinates).toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
it('updates an existing address', async () => {
|
|
90
|
+
const initialAddress = new AddressBuilder()
|
|
91
|
+
.withCountry('France')
|
|
92
|
+
.withCity('Paris')
|
|
93
|
+
.build();
|
|
94
|
+
await dataSource.manager.upsert(AddressTest, { id: 6, address: initialAddress }, { conflictPaths: { id: true } });
|
|
95
|
+
const updatedAddress = new AddressBuilder()
|
|
96
|
+
.withCountry('France')
|
|
97
|
+
.withCity('Lyon')
|
|
98
|
+
.withPostalCode('69000')
|
|
99
|
+
.build();
|
|
100
|
+
await dataSource.manager.upsert(AddressTest, { id: 6, address: updatedAddress }, { conflictPaths: { id: true } });
|
|
101
|
+
const test = await dataSource.manager.findOneByOrFail(AddressTest, { id: 6 });
|
|
102
|
+
expect(test.address).not.toBeNull();
|
|
103
|
+
expect(test.address?.country).toBe('France');
|
|
104
|
+
expect(test.address?.city).toBe('Lyon');
|
|
105
|
+
expect(test.address?.postalCode).toBe('69000');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=address-column.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-column.integration.test.js","sourceRoot":"","sources":["../../lib/tests/address-column.integration.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;QAC7B,MAAM,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,KAAK,IAAI,EAAE;QACf,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACjD,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;YACvE,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE;iBACjC,aAAa,CAAC,aAAa,CAAC;iBAC5B,WAAW,CAAC,UAAU,CAAC;iBACvB,WAAW,CAAC,SAAS,CAAC;iBACtB,QAAQ,CAAC,UAAU,CAAC;iBACpB,cAAc,CAAC,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CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { describe, it } from 'node:test';
|
|
11
|
+
import { validate } from 'class-validator';
|
|
12
|
+
import { expect } from 'expect';
|
|
13
|
+
import { plainToInstance } from 'class-transformer';
|
|
14
|
+
import { AddressCommand } from '../address-command.js';
|
|
15
|
+
import { IsAddress } from '../is-address.validator.js';
|
|
16
|
+
class TestClass {
|
|
17
|
+
address;
|
|
18
|
+
}
|
|
19
|
+
__decorate([
|
|
20
|
+
IsAddress(),
|
|
21
|
+
__metadata("design:type", AddressCommand)
|
|
22
|
+
], TestClass.prototype, "address", void 0);
|
|
23
|
+
class TestClassWithRequiredFields {
|
|
24
|
+
address;
|
|
25
|
+
}
|
|
26
|
+
__decorate([
|
|
27
|
+
IsAddress({
|
|
28
|
+
countryRequired: true,
|
|
29
|
+
cityRequired: true,
|
|
30
|
+
postalCodeRequired: true,
|
|
31
|
+
streetNameRequired: true
|
|
32
|
+
}),
|
|
33
|
+
__metadata("design:type", AddressCommand)
|
|
34
|
+
], TestClassWithRequiredFields.prototype, "address", void 0);
|
|
35
|
+
describe('IsAddress decorator test', () => {
|
|
36
|
+
it('should pass validation when the address has all fields', async () => {
|
|
37
|
+
const testInstance = new TestClass();
|
|
38
|
+
const addressCommand = new AddressCommand();
|
|
39
|
+
addressCommand.country = 'Belgium';
|
|
40
|
+
addressCommand.city = 'Brussels';
|
|
41
|
+
addressCommand.postalCode = '1000';
|
|
42
|
+
addressCommand.streetName = 'Main Street';
|
|
43
|
+
addressCommand.streetNumber = '123';
|
|
44
|
+
addressCommand.unit = null;
|
|
45
|
+
addressCommand.placeName = null;
|
|
46
|
+
addressCommand.placeId = null;
|
|
47
|
+
addressCommand.coordinates = null;
|
|
48
|
+
testInstance.address = addressCommand;
|
|
49
|
+
const errors = await validate(testInstance);
|
|
50
|
+
expect(errors.length).toBe(0);
|
|
51
|
+
});
|
|
52
|
+
it('should pass validation when the address has only some fields', async () => {
|
|
53
|
+
const testInstance = new TestClass();
|
|
54
|
+
const addressCommand = new AddressCommand();
|
|
55
|
+
addressCommand.country = 'Belgium';
|
|
56
|
+
addressCommand.city = null;
|
|
57
|
+
addressCommand.postalCode = null;
|
|
58
|
+
addressCommand.streetName = null;
|
|
59
|
+
addressCommand.streetNumber = null;
|
|
60
|
+
addressCommand.unit = null;
|
|
61
|
+
addressCommand.placeName = null;
|
|
62
|
+
addressCommand.placeId = null;
|
|
63
|
+
addressCommand.coordinates = null;
|
|
64
|
+
testInstance.address = addressCommand;
|
|
65
|
+
const errors = await validate(testInstance);
|
|
66
|
+
expect(errors.length).toBe(0);
|
|
67
|
+
});
|
|
68
|
+
it('should fail validation when required fields are missing', async () => {
|
|
69
|
+
const testInstance = new TestClassWithRequiredFields();
|
|
70
|
+
const addressCommand = new AddressCommand();
|
|
71
|
+
addressCommand.country = null;
|
|
72
|
+
addressCommand.city = null;
|
|
73
|
+
addressCommand.postalCode = null;
|
|
74
|
+
addressCommand.streetName = null;
|
|
75
|
+
addressCommand.streetNumber = null;
|
|
76
|
+
addressCommand.unit = null;
|
|
77
|
+
addressCommand.placeName = null;
|
|
78
|
+
addressCommand.placeId = null;
|
|
79
|
+
addressCommand.coordinates = null;
|
|
80
|
+
testInstance.address = addressCommand;
|
|
81
|
+
const errors = await validate(testInstance);
|
|
82
|
+
expect(errors.length).toBe(1);
|
|
83
|
+
expect(errors[0].constraints?.isAddress).toContain('countryRequired');
|
|
84
|
+
expect(errors[0].constraints?.isAddress).toContain('cityRequired');
|
|
85
|
+
expect(errors[0].constraints?.isAddress).toContain('postalCodeRequired');
|
|
86
|
+
expect(errors[0].constraints?.isAddress).toContain('streetNameRequired');
|
|
87
|
+
});
|
|
88
|
+
it('should pass validation when all required fields are provided', async () => {
|
|
89
|
+
const testInstance = new TestClassWithRequiredFields();
|
|
90
|
+
const addressCommand = new AddressCommand();
|
|
91
|
+
addressCommand.country = 'Belgium';
|
|
92
|
+
addressCommand.city = 'Brussels';
|
|
93
|
+
addressCommand.postalCode = '1000';
|
|
94
|
+
addressCommand.streetName = 'Main Street';
|
|
95
|
+
addressCommand.streetNumber = null;
|
|
96
|
+
addressCommand.unit = null;
|
|
97
|
+
addressCommand.placeName = null;
|
|
98
|
+
addressCommand.placeId = null;
|
|
99
|
+
addressCommand.coordinates = null;
|
|
100
|
+
testInstance.address = addressCommand;
|
|
101
|
+
const errors = await validate(testInstance);
|
|
102
|
+
expect(errors.length).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
it('should fail validation when some required fields are missing', async () => {
|
|
105
|
+
const testInstance = new TestClassWithRequiredFields();
|
|
106
|
+
const addressCommand = new AddressCommand();
|
|
107
|
+
addressCommand.country = 'Belgium';
|
|
108
|
+
addressCommand.city = 'Brussels';
|
|
109
|
+
addressCommand.postalCode = null;
|
|
110
|
+
addressCommand.streetName = null;
|
|
111
|
+
addressCommand.streetNumber = null;
|
|
112
|
+
addressCommand.unit = null;
|
|
113
|
+
addressCommand.placeName = null;
|
|
114
|
+
addressCommand.placeId = null;
|
|
115
|
+
addressCommand.coordinates = null;
|
|
116
|
+
testInstance.address = addressCommand;
|
|
117
|
+
const errors = await validate(testInstance);
|
|
118
|
+
expect(errors.length).toBe(1);
|
|
119
|
+
expect(errors[0].constraints?.isAddress).toContain('postalCodeRequired');
|
|
120
|
+
expect(errors[0].constraints?.isAddress).toContain('streetNameRequired');
|
|
121
|
+
});
|
|
122
|
+
it('should fail validation when the address is not an AddressCommand instance', async () => {
|
|
123
|
+
const testInstance = new TestClass();
|
|
124
|
+
testInstance.address = plainToInstance(AddressCommand, { country: 'Belgium' });
|
|
125
|
+
const errors = await validate(testInstance);
|
|
126
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=is-address.validator.unit.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-address.validator.unit.test.js","sourceRoot":"","sources":["../../lib/tests/is-address.validator.unit.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEtD,MAAM,SAAS;IAEb,OAAO,CAAgB;CACxB;AADC;IADC,SAAS,EAAE;8BACH,cAAc;0CAAA;AAGzB,MAAM,2BAA2B;IAO/B,OAAO,CAAgB;CACxB;AADC;IANC,SAAS,CAAC;QACT,eAAe,EAAE,IAAI;QACrB,YAAY,EAAE,IAAI;QAClB,kBAAkB,EAAE,IAAI;QACxB,kBAAkB,EAAE,IAAI;KACzB,CAA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= arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Entity, PrimaryColumn } from 'typeorm';
|
|
11
|
+
import { AddressColumn } from '../../address-column.js';
|
|
12
|
+
let AddressTest = class AddressTest {
|
|
13
|
+
id;
|
|
14
|
+
address;
|
|
15
|
+
};
|
|
16
|
+
__decorate([
|
|
17
|
+
PrimaryColumn(),
|
|
18
|
+
__metadata("design:type", Number)
|
|
19
|
+
], AddressTest.prototype, "id", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
AddressColumn({ nullable: true }),
|
|
22
|
+
__metadata("design:type", Object)
|
|
23
|
+
], AddressTest.prototype, "address", void 0);
|
|
24
|
+
AddressTest = __decorate([
|
|
25
|
+
Entity()
|
|
26
|
+
], AddressTest);
|
|
27
|
+
export { AddressTest };
|
|
28
|
+
//# sourceMappingURL=address-test.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-test.entity.js","sourceRoot":"","sources":["../../../lib/tests/sql/address-test.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAIhD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEtB,EAAE,CAAQ;IAGV,OAAO,CAAgB;CACxB,CAAA;AAJC;IADC,aAAa,EAAE;;uCACN;AAGV;IADC,aAAa,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;;4CACT;AALZ,WAAW;IADvB,MAAM,EAAE;GACI,WAAW,CAMvB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
export const dataSource = new DataSource({
|
|
3
|
+
name: 'default',
|
|
4
|
+
type: 'postgres',
|
|
5
|
+
url: process.env.DATABASE_URI,
|
|
6
|
+
ssl: false,
|
|
7
|
+
extra: { max: 50 },
|
|
8
|
+
logging: true,
|
|
9
|
+
synchronize: false,
|
|
10
|
+
migrationsRun: true,
|
|
11
|
+
entities: [
|
|
12
|
+
'dist/**/*.entity.js'
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=datasource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../../lib/tests/sql/datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IACvC,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;IAC7B,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;IAClB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,KAAK;IAClB,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE;QACR,qBAAqB;KACtB;CACF,CAAC,CAAA"}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import eslintNestJSConfig from '@wisemen/eslint-config-nestjs'
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...eslintNestJSConfig,
|
|
5
|
+
{
|
|
6
|
+
rules: {
|
|
7
|
+
'import-typescript/no-relative-parent-imports': 'off'
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.test.ts'],
|
|
12
|
+
rules: {
|
|
13
|
+
'@typescript-eslint/unbound-method': 'off',
|
|
14
|
+
'@typescript-eslint/no-floating-promises': 'off'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { plainToInstance } from 'class-transformer'
|
|
2
|
+
import { ColumnOptions, Column } from 'typeorm'
|
|
3
|
+
import { Coordinates } from '@wisemen/coordinates'
|
|
4
|
+
import { Address } from './address.js'
|
|
5
|
+
|
|
6
|
+
export function AddressColumn (options?: Omit<ColumnOptions, 'type' | 'transformer'>) {
|
|
7
|
+
return Column({
|
|
8
|
+
...options,
|
|
9
|
+
type: 'jsonb',
|
|
10
|
+
transformer: {
|
|
11
|
+
from (address: Address | null): Address | null {
|
|
12
|
+
if (address === null) {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const addressInstance = plainToInstance(Address, address)
|
|
17
|
+
const coordinates = address.coordinates
|
|
18
|
+
|
|
19
|
+
if (coordinates) {
|
|
20
|
+
addressInstance.coordinates = new Coordinates(coordinates.latitude, coordinates.longitude)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return addressInstance
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
to (address: Address | null | undefined): Address | null | undefined {
|
|
27
|
+
return address
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CoordinatesCommand } from '@wisemen/coordinates'
|
|
2
|
+
import { AddressCommand } from './address-command.js'
|
|
3
|
+
|
|
4
|
+
export class AddressCommandBuilder {
|
|
5
|
+
private command: AddressCommand
|
|
6
|
+
|
|
7
|
+
constructor () {
|
|
8
|
+
this.command = new AddressCommand()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
withCountry (country: string): this {
|
|
12
|
+
this.command.country = country
|
|
13
|
+
|
|
14
|
+
return this
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
withCity (city: string): this {
|
|
18
|
+
this.command.city = city
|
|
19
|
+
|
|
20
|
+
return this
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
withPostalCode (postalCode: string): this {
|
|
24
|
+
this.command.postalCode = postalCode
|
|
25
|
+
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
withStreetName (streetName: string): this {
|
|
30
|
+
this.command.streetName = streetName
|
|
31
|
+
|
|
32
|
+
return this
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
withStreetNumber (streetNumber: string): this {
|
|
36
|
+
this.command.streetNumber = streetNumber
|
|
37
|
+
|
|
38
|
+
return this
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
withUnit (unit: string): this {
|
|
42
|
+
this.command.unit = unit
|
|
43
|
+
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
withCoordinates (coordinates: CoordinatesCommand): this {
|
|
48
|
+
this.command.coordinates = coordinates
|
|
49
|
+
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
build (): AddressCommand {
|
|
54
|
+
return this.command
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IsNotEmpty, IsObject, IsString, ValidateNested } from 'class-validator'
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger'
|
|
3
|
+
import { Type } from 'class-transformer'
|
|
4
|
+
import { IsNullable } from '@wisemen/validators'
|
|
5
|
+
import { CoordinatesCommand } from '@wisemen/coordinates'
|
|
6
|
+
import { AddressBuilder } from './address.builder.js'
|
|
7
|
+
import { Address } from './address.js'
|
|
8
|
+
|
|
9
|
+
export class AddressCommand {
|
|
10
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
11
|
+
@IsNullable()
|
|
12
|
+
@IsString()
|
|
13
|
+
@IsNotEmpty()
|
|
14
|
+
placeName: string | null
|
|
15
|
+
|
|
16
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
17
|
+
@IsNullable()
|
|
18
|
+
@IsString()
|
|
19
|
+
@IsNotEmpty()
|
|
20
|
+
placeId: string | null
|
|
21
|
+
|
|
22
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
23
|
+
@IsNullable()
|
|
24
|
+
@IsString()
|
|
25
|
+
@IsNotEmpty()
|
|
26
|
+
country: string | null
|
|
27
|
+
|
|
28
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
29
|
+
@IsNullable()
|
|
30
|
+
@IsString()
|
|
31
|
+
@IsNotEmpty()
|
|
32
|
+
city: string | null
|
|
33
|
+
|
|
34
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
35
|
+
@IsNullable()
|
|
36
|
+
@IsString()
|
|
37
|
+
@IsNotEmpty()
|
|
38
|
+
postalCode: string | null
|
|
39
|
+
|
|
40
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
41
|
+
@IsNullable()
|
|
42
|
+
@IsString()
|
|
43
|
+
@IsNotEmpty()
|
|
44
|
+
streetName: string | null
|
|
45
|
+
|
|
46
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
47
|
+
@IsNullable()
|
|
48
|
+
@IsString()
|
|
49
|
+
@IsNotEmpty()
|
|
50
|
+
streetNumber: string | null
|
|
51
|
+
|
|
52
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
53
|
+
@IsNullable()
|
|
54
|
+
@IsString()
|
|
55
|
+
@IsNotEmpty()
|
|
56
|
+
unit: string | null
|
|
57
|
+
|
|
58
|
+
@ApiProperty({ type: CoordinatesCommand, nullable: true })
|
|
59
|
+
@IsNullable()
|
|
60
|
+
@IsObject()
|
|
61
|
+
@Type(() => CoordinatesCommand)
|
|
62
|
+
@ValidateNested()
|
|
63
|
+
coordinates: CoordinatesCommand | null
|
|
64
|
+
|
|
65
|
+
parse (): Address {
|
|
66
|
+
return new AddressBuilder()
|
|
67
|
+
.withPlaceId(this.placeId)
|
|
68
|
+
.withPlaceName(this.placeName)
|
|
69
|
+
.withCountry(this.country)
|
|
70
|
+
.withCity(this.city)
|
|
71
|
+
.withPostalCode(this.postalCode)
|
|
72
|
+
.withStreetName(this.streetName)
|
|
73
|
+
.withStreetNumber(this.streetNumber)
|
|
74
|
+
.withUnit(this.unit)
|
|
75
|
+
.withCoordinates(this.coordinates ? this.coordinates.toCoordinates() : null)
|
|
76
|
+
.build()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger'
|
|
2
|
+
import { CoordinatesResponse } from '@wisemen/coordinates'
|
|
3
|
+
import { Address } from './address.js'
|
|
4
|
+
|
|
5
|
+
export class AddressResponse {
|
|
6
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
7
|
+
placeName: string | null
|
|
8
|
+
|
|
9
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
10
|
+
placeId: string | null
|
|
11
|
+
|
|
12
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
13
|
+
country: string | null
|
|
14
|
+
|
|
15
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
16
|
+
city: string | null
|
|
17
|
+
|
|
18
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
19
|
+
postalCode: string | null
|
|
20
|
+
|
|
21
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
22
|
+
streetName: string | null
|
|
23
|
+
|
|
24
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
25
|
+
streetNumber: string | null
|
|
26
|
+
|
|
27
|
+
@ApiProperty({ type: 'string', nullable: true })
|
|
28
|
+
unit: string | null
|
|
29
|
+
|
|
30
|
+
@ApiProperty({ type: CoordinatesResponse, nullable: true })
|
|
31
|
+
coordinates: CoordinatesResponse | null
|
|
32
|
+
|
|
33
|
+
constructor (address: Address) {
|
|
34
|
+
this.placeName = address.placeName ?? null
|
|
35
|
+
this.placeId = address.placeId ?? null
|
|
36
|
+
this.country = address.country ?? null
|
|
37
|
+
this.city = address.city ?? null
|
|
38
|
+
this.postalCode = address.postalCode ?? null
|
|
39
|
+
this.streetName = address.streetName ?? null
|
|
40
|
+
this.streetNumber = address.streetNumber ?? null
|
|
41
|
+
this.unit = address.unit ?? null
|
|
42
|
+
this.coordinates = address.coordinates != null
|
|
43
|
+
? new CoordinatesResponse(address.coordinates)
|
|
44
|
+
: null
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Coordinates } from '@wisemen/coordinates'
|
|
2
|
+
import { Address } from './address.js'
|
|
3
|
+
|
|
4
|
+
export class AddressBuilder {
|
|
5
|
+
private readonly address: Address
|
|
6
|
+
|
|
7
|
+
constructor () {
|
|
8
|
+
this.address = new Address()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
withPlaceName (name?: string | null): this {
|
|
12
|
+
this.address.placeName = name ?? undefined
|
|
13
|
+
|
|
14
|
+
return this
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
withPlaceId (id?: string | null): this {
|
|
18
|
+
this.address.placeId = id ?? undefined
|
|
19
|
+
|
|
20
|
+
return this
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
withCountry (country?: string | null): this {
|
|
24
|
+
this.address.country = country ?? undefined
|
|
25
|
+
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
withCity (city?: string | null): this {
|
|
30
|
+
this.address.city = city ?? undefined
|
|
31
|
+
|
|
32
|
+
return this
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
withPostalCode (zipCode?: string | null): this {
|
|
36
|
+
this.address.postalCode = zipCode ?? undefined
|
|
37
|
+
|
|
38
|
+
return this
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
withStreetName (streetName?: string | null): this {
|
|
42
|
+
this.address.streetName = streetName ?? undefined
|
|
43
|
+
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
withStreetNumber (streetNumber?: string | null): this {
|
|
48
|
+
this.address.streetNumber = streetNumber ?? undefined
|
|
49
|
+
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
withUnit (unit?: string | null): this {
|
|
54
|
+
this.address.unit = unit ?? undefined
|
|
55
|
+
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
withCoordinates (coordinates?: Coordinates | null): this {
|
|
60
|
+
this.address.coordinates = coordinates ?? undefined
|
|
61
|
+
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
build (): Address {
|
|
66
|
+
return this.address
|
|
67
|
+
}
|
|
68
|
+
}
|
package/lib/address.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Coordinates } from '@wisemen/coordinates'
|
|
2
|
+
|
|
3
|
+
export class Address {
|
|
4
|
+
placeName?: string | null
|
|
5
|
+
placeId?: string | null
|
|
6
|
+
country?: string | null
|
|
7
|
+
city?: string | null
|
|
8
|
+
postalCode?: string | null
|
|
9
|
+
streetName?: string | null
|
|
10
|
+
streetNumber?: string | null
|
|
11
|
+
unit?: string | null
|
|
12
|
+
coordinates?: Coordinates | null
|
|
13
|
+
}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Address } from './address.js'
|
|
2
|
+
export { AddressBuilder } from './address.builder.js'
|
|
3
|
+
export { AddressCommand } from './address-command.js'
|
|
4
|
+
export { AddressCommandBuilder } from './address-command.builder.js'
|
|
5
|
+
export { AddressResponse } from './address-response.js'
|
|
6
|
+
export { AddressColumn } from './address-column.js'
|
|
7
|
+
export { IsAddress, type IsAddressValidationOptions } from './is-address.validator.js'
|