@fintekkers/ledger-models 0.1.71 → 0.1.73
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 +1 -1
- package/node/wrappers/models/position/field.js +27 -0
- package/node/wrappers/models/position/field.js.map +1 -0
- package/node/wrappers/models/position/field.test.js +63 -0
- package/node/wrappers/models/position/field.test.js.map +1 -0
- package/node/wrappers/models/position/field.test.ts +13 -0
- package/node/wrappers/models/position/field.ts +25 -0
- package/node/wrappers/models/position/hardcoded.position.js +10 -4
- package/node/wrappers/models/position/hardcoded.position.js.map +1 -1
- package/node/wrappers/models/position/hardcoded.position.ts +12 -79
- package/node/wrappers/models/position/position.js +16 -14
- package/node/wrappers/models/position/position.js.map +1 -1
- package/node/wrappers/models/position/position.test copy.js +107 -0
- package/node/wrappers/models/position/position.test copy.js.map +1 -0
- package/node/wrappers/models/position/position.test.js +40 -44
- package/node/wrappers/models/position/position.test.js.map +1 -1
- package/node/wrappers/models/position/position.test.ts +34 -66
- package/node/wrappers/models/position/position.ts +17 -18
- package/node/wrappers/models/utils/date.js +4 -1
- package/node/wrappers/models/utils/date.js.map +1 -1
- package/node/wrappers/models/utils/date.ts +5 -1
- package/node/wrappers/models/utils/protoEnum.js +50 -0
- package/node/wrappers/models/utils/protoEnum.js.map +1 -0
- package/node/wrappers/models/utils/protoEnum.test.js +21 -0
- package/node/wrappers/models/utils/protoEnum.test.js.map +1 -0
- package/node/wrappers/models/utils/protoEnum.test.ts +23 -0
- package/node/wrappers/models/utils/protoEnum.ts +54 -0
- package/node/wrappers/models/utils/serialization.js +7 -0
- package/node/wrappers/models/utils/serialization.js.map +1 -1
- package/node/wrappers/models/utils/serialization.ts +7 -0
- package/node/wrappers/services/portfolio-service/portfolio.test.js +0 -1
- package/node/wrappers/services/portfolio-service/portfolio.test.js.map +1 -1
- package/node/wrappers/services/portfolio-service/portfolio.test.ts +0 -1
- package/node/wrappers/services/position-service/PositionService.js +2 -2
- package/node/wrappers/services/position-service/PositionService.js.map +1 -1
- package/node/wrappers/services/position-service/PositionService.ts +1 -1
- package/node/wrappers/services/position-service/position.test.js +18 -63
- package/node/wrappers/services/position-service/position.test.js.map +1 -1
- package/node/wrappers/services/position-service/position.test.ts +8 -73
- package/node/wrappers/services/security-service/security.maturityLadder.test.js +0 -1
- package/node/wrappers/services/security-service/security.maturityLadder.test.js.map +1 -1
- package/node/wrappers/services/security-service/security.maturityLadder.test.ts +0 -2
- package/node/wrappers/services/transaction-service/transaction.search.test.js +0 -1
- package/node/wrappers/services/transaction-service/transaction.search.test.js.map +1 -1
- package/node/wrappers/services/transaction-service/transaction.search.test.ts +0 -2
- package/package.json +2 -2
|
@@ -36,8 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
|
|
40
|
-
var serialization_1 = require("../utils/serialization");
|
|
41
39
|
var uuid_1 = require("../utils/uuid");
|
|
42
40
|
var any_pb_1 = require("google-protobuf/google/protobuf/any_pb");
|
|
43
41
|
var decimal_value_pb_1 = require("../../../fintekkers/models/util/decimal_value_pb");
|
|
@@ -47,65 +45,63 @@ var field_pb_1 = require("../../../fintekkers/models/position/field_pb");
|
|
|
47
45
|
var measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
|
|
48
46
|
var security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
49
47
|
var portfolio_pb_1 = require("../../../fintekkers/models/portfolio/portfolio_pb");
|
|
50
|
-
var
|
|
48
|
+
var position_1 = require("./position");
|
|
49
|
+
var date_1 = require("../utils/date");
|
|
50
|
+
var position_status_pb_1 = require("../../../fintekkers/models/position/position_status_pb");
|
|
51
51
|
test('test the position wrapper', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
var isTrue;
|
|
52
53
|
return __generator(this, function (_a) {
|
|
53
|
-
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, testSerialization()];
|
|
56
|
+
case 1:
|
|
57
|
+
isTrue = _a.sent();
|
|
58
|
+
expect(isTrue).toBe(true);
|
|
59
|
+
return [2 /*return*/];
|
|
60
|
+
}
|
|
54
61
|
});
|
|
55
62
|
}); });
|
|
56
63
|
function testSerialization() {
|
|
57
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var fields, security, portfolio, tradeDate, productType, id, measure, measureValue,
|
|
65
|
+
var fields, security, portfolio, tradeDate, productType, id, measure, measureValue, tradeDatePacked, idPacked, positionProto, position, tradeDatePosition, securityPosition, portfolioPosition, positionID;
|
|
59
66
|
return __generator(this, function (_a) {
|
|
60
67
|
fields = [field_pb_1.FieldProto.ID, field_pb_1.FieldProto.TRADE_DATE, field_pb_1.FieldProto.PRODUCT_TYPE, field_pb_1.FieldProto.PORTFOLIO, field_pb_1.FieldProto.SECURITY];
|
|
61
68
|
security = new security_pb_1.SecurityProto().setAssetClass("Test");
|
|
62
69
|
portfolio = new portfolio_pb_1.PortfolioProto().setPortfolioName("Test portfolio");
|
|
63
|
-
tradeDate =
|
|
70
|
+
tradeDate = date_1.LocalDate.today().toDate();
|
|
64
71
|
productType = "Test product type";
|
|
65
72
|
id = new uuid_1.UUID(uuid_1.UUID.random().toBytes());
|
|
66
73
|
measure = measure_pb_1.MeasureProto.DIRECTED_QUANTITY;
|
|
67
74
|
measureValue = new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue("1.0");
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
tradeDatePacked = new any_pb_1.Any();
|
|
76
|
+
tradeDatePacked.setTypeUrl("Doesn't matter");
|
|
77
|
+
tradeDatePacked.setValue(date_1.LocalDate.from(tradeDate).toProto().serializeBinary());
|
|
78
|
+
idPacked = new any_pb_1.Any();
|
|
79
|
+
idPacked.setTypeUrl("Doesn't matter");
|
|
80
|
+
idPacked.setValue(id.toUUIDProto().serializeBinary());
|
|
74
81
|
positionProto = new position_pb_1.PositionProto();
|
|
75
|
-
positionProto.
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
positionProto.setFieldsList([
|
|
83
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.TRADE_DATE).setFieldValuePacked(tradeDatePacked),
|
|
84
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.SECURITY).setFieldValuePacked(security),
|
|
85
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.PORTFOLIO).setFieldValuePacked(portfolio),
|
|
86
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.POSITION_STATUS).setEnumValue(position_status_pb_1.PositionStatusProto.EXECUTED),
|
|
87
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.PRODUCT_TYPE).setStringValue(productType),
|
|
88
|
+
new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.ID).setFieldValuePacked(idPacked),
|
|
89
|
+
]);
|
|
90
|
+
position = new position_1.Position(positionProto);
|
|
91
|
+
tradeDatePosition = position.getFieldValue(field_pb_1.FieldProto.TRADE_DATE);
|
|
92
|
+
expect(tradeDate.getFullYear()).toBe(tradeDatePosition.getFullYear());
|
|
93
|
+
expect(tradeDate.getMonth()).toBe(tradeDatePosition.getMonth());
|
|
94
|
+
expect(tradeDate.getDay()).toBe(tradeDatePosition.getDay());
|
|
95
|
+
securityPosition = position.getFieldValue(field_pb_1.FieldProto.SECURITY);
|
|
96
|
+
expect(securityPosition.getAssetClass()).toBe(security.getAssetClass());
|
|
97
|
+
portfolioPosition = position.getFieldValue(field_pb_1.FieldProto.PORTFOLIO);
|
|
98
|
+
expect(portfolioPosition.getPortfolioName()).toBe(portfolio.getPortfolioName());
|
|
99
|
+
expect(position.getFieldValue(field_pb_1.FieldProto.PRODUCT_TYPE)).toBe(productType);
|
|
100
|
+
positionID = position.getFieldValue(field_pb_1.FieldProto.ID);
|
|
101
|
+
expect(positionID.toString()).toBe(id.toString());
|
|
102
|
+
expect(position.getFieldValue(field_pb_1.FieldProto.POSITION_STATUS)).toBe(position_status_pb_1.PositionStatusProto.EXECUTED);
|
|
78
103
|
return [2 /*return*/, true];
|
|
79
104
|
});
|
|
80
105
|
});
|
|
81
106
|
}
|
|
82
|
-
function pack() {
|
|
83
|
-
var message = new position_pb_1.PositionProto();
|
|
84
|
-
// Create a value of any type (in this case, a string)
|
|
85
|
-
// const stringValue = "Hello, Any!";
|
|
86
|
-
// const anyValue = new Any();
|
|
87
|
-
// anyValue.pack(stringValue, "type.googleapis.com/google.protobuf.StringValue");
|
|
88
|
-
// message.setValue(anyValue);
|
|
89
|
-
// // Serialize the message to a binary buffer
|
|
90
|
-
// const serialized = message.serializeBinary();
|
|
91
|
-
// // Deserialize the binary buffer
|
|
92
|
-
// const deserializedMessage = PositionProto.deserializeBinary(serialized);
|
|
93
|
-
// const deserializedValue = deserializedMessage.getFieldsList()[0];
|
|
94
|
-
// if (deserializedValue.is(string)) {
|
|
95
|
-
// const unpackedValue = deserializedValue.unpack(StringValue.deserializeBinary);
|
|
96
|
-
// console.log(unpackedValue.getValue()); // Output: Hello, Any!
|
|
97
|
-
// }
|
|
98
|
-
}
|
|
99
|
-
function dummyPosition() {
|
|
100
|
-
var field = new position_util_pb_1.FieldMapEntry()
|
|
101
|
-
.setField(field_pb_1.FieldProto.TRANSACTION_TYPE);
|
|
102
|
-
// .setFieldValuePacked
|
|
103
|
-
return new position_pb_1.PositionProto();
|
|
104
|
-
// new TransactionProto()
|
|
105
|
-
// .setObjectClass('Transaction').setVersion('0.0.1').setUuid(UUID.random().toUUIDProto())
|
|
106
|
-
// .setTradeDate(new LocalDateProto().setYear(2021).setMonth(1).setDay(1))
|
|
107
|
-
// .setTransactionType(TransactionTypeProto.BUY)
|
|
108
|
-
// .setQuantity(new DecimalValueProto().setArbitraryPrecisionValue('1000.00'))
|
|
109
|
-
// .setSettlementDate(new LocalDateProto().setYear(2021).setMonth(1).setDay(1)));
|
|
110
|
-
}
|
|
111
107
|
//# sourceMappingURL=position.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.test.js","sourceRoot":"","sources":["position.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"position.test.js","sourceRoot":"","sources":["position.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAqC;AACrC,iEAA6D;AAI7D,qFAAqF;AACrF,+EAAgF;AAChF,yFAAqF;AACrF,yEAA0E;AAC1E,6EAA8E;AAC9E,+EAAgF;AAChF,kFAAmF;AACnF,uCAAsC;AACtC,sCAA0C;AAC1C,6FAA6F;AAE7F,IAAI,CAAC,2BAA2B,EAAE;;;;oBACf,qBAAM,iBAAiB,EAAE,EAAA;;gBAAlC,MAAM,GAAG,SAAyB;gBACxC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;KAC7B,CAAC,CAAC;AAEH,SAAe,iBAAiB;;;;YACxB,MAAM,GAAG,CAAC,qBAAU,CAAC,EAAE,EAAE,qBAAU,CAAC,UAAU,EAAE,qBAAU,CAAC,YAAY,EAAE,qBAAU,CAAC,SAAS,EAAE,qBAAU,CAAC,QAAQ,CAAC,CAAC;YAEpH,QAAQ,GAAG,IAAI,2BAAa,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACrD,SAAS,GAAG,IAAI,6BAAc,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;YACpE,SAAS,GAAG,gBAAS,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC;YACvC,WAAW,GAAG,mBAAmB,CAAC;YAClC,EAAE,GAAG,IAAI,WAAI,CAAC,W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BAAU,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,wCAAmB,CAAC,QAAQ,CAAC,CAAC;YAE9F,sBAAO,IAAI,EAAC;;;CACf"}
|
|
@@ -1,36 +1,22 @@
|
|
|
1
|
-
import { LocalDateProto } from '../../../fintekkers/models/util/local_date_pb';
|
|
2
|
-
import { UUIDProto } from '../../../fintekkers/models/util/uuid_pb';
|
|
3
|
-
import { ProtoSerializationUtil } from '../utils/serialization';
|
|
4
1
|
import { UUID } from '../utils/uuid';
|
|
5
2
|
import { Any } from 'google-protobuf/google/protobuf/any_pb';
|
|
6
3
|
|
|
7
4
|
import assert = require('assert');
|
|
8
|
-
import Transaction from '../transaction/transaction';
|
|
9
|
-
import { TransactionProto } from '../../../fintekkers/models/transaction/transaction_pb';
|
|
10
|
-
import { TransactionTypeProto } from '../../../fintekkers/models/transaction/transaction_type_pb';
|
|
11
|
-
import { LocalTimestampProto } from '../../../fintekkers/models/util/local_timestamp_pb';
|
|
12
5
|
|
|
13
|
-
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
|
|
14
6
|
import { DecimalValueProto } from '../../../fintekkers/models/util/decimal_value_pb';
|
|
15
|
-
import {
|
|
16
|
-
import { PositionProto, PositionTypeProto, PositionViewProto } from '../../../fintekkers/models/position/position_pb';
|
|
7
|
+
import { PositionProto } from '../../../fintekkers/models/position/position_pb';
|
|
17
8
|
import { FieldMapEntry } from '../../../fintekkers/models/position/position_util_pb';
|
|
18
9
|
import { FieldProto } from '../../../fintekkers/models/position/field_pb';
|
|
19
|
-
import { PositionService } from '../../services/position-service/PositionService';
|
|
20
|
-
import { PositionFilter } from './positionfilter';
|
|
21
|
-
import { QueryPositionRequestProto } from '../../../fintekkers/requests/position/query_position_request_pb';
|
|
22
|
-
import { ZonedDateTime } from '../utils/datetime';
|
|
23
10
|
import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
|
|
24
11
|
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
25
12
|
import { PortfolioProto } from '../../../fintekkers/models/portfolio/portfolio_pb';
|
|
26
|
-
import { Position } from './
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
import { Position } from './position';
|
|
14
|
+
import { LocalDate } from '../utils/date';
|
|
15
|
+
import { PositionStatusProto } from '../../../fintekkers/models/position/position_status_pb';
|
|
29
16
|
|
|
30
17
|
test('test the position wrapper', async () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
const isTrue = await testSerialization();
|
|
19
|
+
expect(isTrue).toBe(true);
|
|
34
20
|
});
|
|
35
21
|
|
|
36
22
|
async function testSerialization(): Promise<boolean> {
|
|
@@ -38,67 +24,49 @@ async function testSerialization(): Promise<boolean> {
|
|
|
38
24
|
|
|
39
25
|
let security = new SecurityProto().setAssetClass("Test");
|
|
40
26
|
let portfolio = new PortfolioProto().setPortfolioName("Test portfolio");
|
|
41
|
-
let tradeDate =
|
|
27
|
+
let tradeDate = LocalDate.today().toDate();
|
|
42
28
|
let productType = "Test product type";
|
|
43
29
|
let id = new UUID(UUID.random().toBytes());
|
|
44
30
|
|
|
45
31
|
let measure = MeasureProto.DIRECTED_QUANTITY;
|
|
46
32
|
let measureValue = new DecimalValueProto().setArbitraryPrecisionValue("1.0");
|
|
47
33
|
|
|
34
|
+
const tradeDatePacked = new Any();
|
|
35
|
+
tradeDatePacked.setTypeUrl(`Doesn't matter`);
|
|
36
|
+
tradeDatePacked.setValue(LocalDate.from(tradeDate).toProto().serializeBinary());
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const binaryMessage = security.serializeBinary();
|
|
53
|
-
anyMessage.setTypeUrl(typeUrl);
|
|
54
|
-
anyMessage.setValue(binaryMessage);
|
|
38
|
+
const idPacked = new Any();
|
|
39
|
+
idPacked.setTypeUrl(`Doesn't matter`);
|
|
40
|
+
idPacked.setValue(id.toUUIDProto().serializeBinary());
|
|
55
41
|
|
|
56
42
|
let positionProto = new PositionProto();
|
|
57
|
-
positionProto.
|
|
58
|
-
|
|
43
|
+
positionProto.setFieldsList([
|
|
44
|
+
new FieldMapEntry().setField(FieldProto.TRADE_DATE).setFieldValuePacked(tradeDatePacked),
|
|
45
|
+
new FieldMapEntry().setField(FieldProto.SECURITY).setFieldValuePacked(security),
|
|
46
|
+
new FieldMapEntry().setField(FieldProto.PORTFOLIO).setFieldValuePacked(portfolio),
|
|
47
|
+
new FieldMapEntry().setField(FieldProto.POSITION_STATUS).setEnumValue(PositionStatusProto.EXECUTED),
|
|
48
|
+
new FieldMapEntry().setField(FieldProto.PRODUCT_TYPE).setStringValue(productType),
|
|
49
|
+
new FieldMapEntry().setField(FieldProto.ID).setFieldValuePacked(idPacked),
|
|
50
|
+
]);
|
|
59
51
|
let position = new Position(positionProto);
|
|
60
52
|
|
|
61
|
-
position.getFieldValue(FieldProto.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function pack() {
|
|
67
|
-
const message = new PositionProto();
|
|
68
|
-
|
|
69
|
-
// Create a value of any type (in this case, a string)
|
|
70
|
-
// const stringValue = "Hello, Any!";
|
|
71
|
-
// const anyValue = new Any();
|
|
72
|
-
// anyValue.pack(stringValue, "type.googleapis.com/google.protobuf.StringValue");
|
|
53
|
+
let tradeDatePosition = position.getFieldValue(FieldProto.TRADE_DATE);
|
|
54
|
+
expect(tradeDate.getFullYear()).toBe(tradeDatePosition.getFullYear());
|
|
55
|
+
expect(tradeDate.getMonth()).toBe(tradeDatePosition.getMonth());
|
|
56
|
+
expect(tradeDate.getDay()).toBe(tradeDatePosition.getDay());
|
|
73
57
|
|
|
74
|
-
|
|
58
|
+
let securityPosition: SecurityProto = position.getFieldValue(FieldProto.SECURITY);
|
|
59
|
+
expect(securityPosition.getAssetClass()).toBe(security.getAssetClass());
|
|
75
60
|
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
let portfolioPosition: PortfolioProto = position.getFieldValue(FieldProto.PORTFOLIO);
|
|
62
|
+
expect(portfolioPosition.getPortfolioName()).toBe(portfolio.getPortfolioName());
|
|
78
63
|
|
|
79
|
-
|
|
80
|
-
// const deserializedMessage = PositionProto.deserializeBinary(serialized);
|
|
81
|
-
// const deserializedValue = deserializedMessage.getFieldsList()[0];
|
|
64
|
+
expect(position.getFieldValue(FieldProto.PRODUCT_TYPE)).toBe(productType);
|
|
82
65
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// console.log(unpackedValue.getValue()); // Output: Hello, Any!
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
|
-
}
|
|
66
|
+
let positionID = position.getFieldValue(FieldProto.ID);
|
|
67
|
+
expect(positionID.toString()).toBe(id.toString());
|
|
89
68
|
|
|
90
|
-
|
|
91
|
-
let field = new FieldMapEntry()
|
|
92
|
-
.setField(FieldProto.TRANSACTION_TYPE);
|
|
93
|
-
// .setFieldValuePacked
|
|
69
|
+
expect(position.getFieldValue(FieldProto.POSITION_STATUS)).toBe(PositionStatusProto.EXECUTED);
|
|
94
70
|
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
// new TransactionProto()
|
|
98
|
-
// .setObjectClass('Transaction').setVersion('0.0.1').setUuid(UUID.random().toUUIDProto())
|
|
99
|
-
// .setTradeDate(new LocalDateProto().setYear(2021).setMonth(1).setDay(1))
|
|
100
|
-
// .setTransactionType(TransactionTypeProto.BUY)
|
|
101
|
-
// .setQuantity(new DecimalValueProto().setArbitraryPrecisionValue('1000.00'))
|
|
102
|
-
// .setSettlementDate(new LocalDateProto().setYear(2021).setMonth(1).setDay(1)));
|
|
71
|
+
return true;
|
|
103
72
|
}
|
|
104
|
-
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Note: Some classes and functions have been omitted or simplified due to lack of context.
|
|
2
2
|
|
|
3
|
-
import { Any } from "@grpc/grpc-js/build/src/generated/google/protobuf/Any";
|
|
4
3
|
import { FieldProto } from "../../../fintekkers/models/position/field_pb";
|
|
5
4
|
import { PositionProto } from "../../../fintekkers/models/position/position_pb";
|
|
6
5
|
import { FieldMapEntry, MeasureMapEntry } from "../../../fintekkers/models/position/position_util_pb";
|
|
@@ -10,12 +9,9 @@ import { UUIDProto } from "../../../fintekkers/models/util/uuid_pb";
|
|
|
10
9
|
import { LocalTimestampProto } from "../../../fintekkers/models/util/local_timestamp_pb";
|
|
11
10
|
import { LocalDateProto } from "../../../fintekkers/models/util/local_date_pb";
|
|
12
11
|
import { IdentifierProto } from "../../../fintekkers/models/security/identifier/identifier_pb";
|
|
13
|
-
import { UUID } from "../utils/uuid";
|
|
14
12
|
import { MeasureProto } from "../../../fintekkers/models/position/measure_pb";
|
|
15
13
|
import Decimal from "decimal.js";
|
|
16
14
|
import { ProtoSerializationUtil } from "../utils/serialization";
|
|
17
|
-
import { SecurityProto } from "../../../fintekkers/models/security/security_pb";
|
|
18
|
-
import { PortfolioProto } from "../../../fintekkers/models/portfolio/portfolio_pb";
|
|
19
15
|
import { StringValue } from 'google-protobuf/google/protobuf/wrappers_pb';
|
|
20
16
|
|
|
21
17
|
export class Position {
|
|
@@ -23,12 +19,6 @@ export class Position {
|
|
|
23
19
|
|
|
24
20
|
constructor(positionProto: PositionProto) {
|
|
25
21
|
this.proto = positionProto;
|
|
26
|
-
|
|
27
|
-
// //For each field, put into a map
|
|
28
|
-
// this.proto.getFieldsList().forEach(field => {
|
|
29
|
-
// console.log(field);
|
|
30
|
-
// });
|
|
31
|
-
|
|
32
22
|
}
|
|
33
23
|
|
|
34
24
|
public getFieldValue(field: FieldProto): any {
|
|
@@ -38,16 +28,25 @@ export class Position {
|
|
|
38
28
|
public getField(fieldToGet: FieldMapEntry): any {
|
|
39
29
|
for (const tmpField of this.proto.getFieldsList()) {
|
|
40
30
|
if (tmpField.getField() === fieldToGet.getField()) {
|
|
31
|
+
|
|
32
|
+
if (tmpField.getStringValue() !== undefined && tmpField.getStringValue().length > 0) {
|
|
33
|
+
return tmpField.getStringValue();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (tmpField.getEnumValue() > 0) {
|
|
37
|
+
// let fieldName: string = new Field(fieldToGet.getField()).getName();
|
|
38
|
+
// let proto: ProtoEnum = ProtoEnum.fromEnumName(fieldName, tmpField.getEnumValue());
|
|
39
|
+
return tmpField.getEnumValue();//proto.enumDescriptor['EXECUTED'];
|
|
40
|
+
}
|
|
41
|
+
|
|
41
42
|
const unpackedValue = Position.unpackField(tmpField);
|
|
42
43
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
// const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[fieldToGet.field];
|
|
46
|
-
// return new ProtoEnum(descriptor, unpackedValue.enumValue);
|
|
44
|
+
if (FieldProto.SECURITY == fieldToGet.getField()) {
|
|
45
|
+
return new Security(unpackedValue);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
if (
|
|
50
|
-
return unpackedValue;
|
|
48
|
+
if (FieldProto.PORTFOLIO == fieldToGet.getField()) {
|
|
49
|
+
return new Portfolio(unpackedValue);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
return ProtoSerializationUtil.deserialize(unpackedValue);
|
|
@@ -141,9 +140,9 @@ export class Position {
|
|
|
141
140
|
case FieldProto.ASSET_CLASS:
|
|
142
141
|
return StringValue.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
|
|
143
142
|
case FieldProto.PORTFOLIO:
|
|
144
|
-
return
|
|
143
|
+
return fieldToUnpack.getFieldValuePacked();
|
|
145
144
|
case FieldProto.SECURITY:
|
|
146
|
-
return
|
|
145
|
+
return fieldToUnpack.getFieldValuePacked();
|
|
147
146
|
default:
|
|
148
147
|
throw new Error(`Field not found. Could not unpack ${FieldProto[fieldToUnpack.getField()]}`);
|
|
149
148
|
}
|
|
@@ -21,7 +21,10 @@ var LocalDate = /** @class */ (function () {
|
|
|
21
21
|
};
|
|
22
22
|
LocalDate.today = function () {
|
|
23
23
|
var today = new Date();
|
|
24
|
-
return
|
|
24
|
+
return this.from(today);
|
|
25
|
+
};
|
|
26
|
+
LocalDate.from = function (date) {
|
|
27
|
+
return new LocalDate(new local_date_pb_1.LocalDateProto().setYear(date.getFullYear()).setMonth(date.getMonth() + 1).setDay(date.getDate()));
|
|
25
28
|
};
|
|
26
29
|
return LocalDate;
|
|
27
30
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["date.ts"],"names":[],"mappings":";;;AACA,+EAA+E;AAC/E,iDAAyD;AAEzD;IAGE,mBAAY,KAAqB;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,0BAAM,GAAN;QACE,sEAAsE;QACtE,gFAAgF;QAChF,4EAA4E;QAC5E,OAAO,sCAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,4BAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACxF,CAAC;IAED,2BAAO,GAAP;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEM,eAAK,GAAZ;QACE,IAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,SAAS,CAClB,IAAI,8BAAc,EAAE,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["date.ts"],"names":[],"mappings":";;;AACA,+EAA+E;AAC/E,iDAAyD;AAEzD;IAGE,mBAAY,KAAqB;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,0BAAM,GAAN;QACE,sEAAsE;QACtE,gFAAgF;QAChF,4EAA4E;QAC5E,OAAO,sCAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,4BAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACxF,CAAC;IAED,2BAAO,GAAP;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEM,eAAK,GAAZ;QACE,IAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAEM,cAAI,GAAX,UAAY,IAAU;QACpB,OAAO,IAAI,SAAS,CAClB,IAAI,8BAAc,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CACtG,CAAC;IACJ,CAAC;IACH,gBAAC;AAAD,CAAC,AAhCD,IAgCC;AAEQ,8BAAS"}
|
|
@@ -26,8 +26,12 @@ class LocalDate {
|
|
|
26
26
|
|
|
27
27
|
static today(): LocalDate {
|
|
28
28
|
const today = new Date();
|
|
29
|
+
return this.from(today);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static from(date: Date): LocalDate {
|
|
29
33
|
return new LocalDate(
|
|
30
|
-
new LocalDateProto().setYear(
|
|
34
|
+
new LocalDateProto().setYear(date.getFullYear()).setMonth(date.getMonth() + 1).setDay(date.getDate())
|
|
31
35
|
);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProtoEnum = void 0;
|
|
4
|
+
var transaction_type_pb_1 = require("../../../fintekkers/models/transaction/transaction_type_pb");
|
|
5
|
+
var position_status_pb_1 = require("../../../fintekkers/models/position/position_status_pb");
|
|
6
|
+
var field_pb_1 = require("../../../fintekkers/models/position/field_pb");
|
|
7
|
+
var ProtoEnum = /** @class */ (function () {
|
|
8
|
+
function ProtoEnum(enumDescriptor, enumValue) {
|
|
9
|
+
this.enumValue = enumValue;
|
|
10
|
+
this.enumDescriptor = enumDescriptor;
|
|
11
|
+
}
|
|
12
|
+
ProtoEnum.fromEnumName = function (enumName, enumValue) {
|
|
13
|
+
return new ProtoEnum(ProtoEnum.getFieldDescriptorFromName(enumName), enumValue);
|
|
14
|
+
};
|
|
15
|
+
ProtoEnum.getFieldDescriptorFromName = function (enumName) {
|
|
16
|
+
if (enumName === "TRANSACTION_TYPE") {
|
|
17
|
+
return transaction_type_pb_1.TransactionTypeProto;
|
|
18
|
+
}
|
|
19
|
+
if (enumName === "POSITION_STATUS") {
|
|
20
|
+
return position_status_pb_1.PositionStatusProto;
|
|
21
|
+
}
|
|
22
|
+
if (enumName === "FIELD") {
|
|
23
|
+
return field_pb_1.FieldProto;
|
|
24
|
+
}
|
|
25
|
+
throw new Error("Enum has not been mapped: ".concat(enumName));
|
|
26
|
+
};
|
|
27
|
+
ProtoEnum.prototype.getEnumName = function () {
|
|
28
|
+
// Assuming your enumDescriptor has a name property or similar
|
|
29
|
+
return this.enumDescriptor.name;
|
|
30
|
+
};
|
|
31
|
+
ProtoEnum.prototype.getEnumValue = function () {
|
|
32
|
+
return this.enumValue;
|
|
33
|
+
};
|
|
34
|
+
ProtoEnum.prototype.getEnumValueName = function () {
|
|
35
|
+
var _this = this;
|
|
36
|
+
// In TypeScript/JS, enum values can be accessed directly if you know the value
|
|
37
|
+
// Assuming your enums are simple objects or as generated by protobuf ts
|
|
38
|
+
var enumKey = Object.keys(this.enumDescriptor).find(function (key) { return _this.enumDescriptor[key] === _this.enumValue; });
|
|
39
|
+
if (!enumKey) {
|
|
40
|
+
return 'UNKNOWN'; // Or handle as appropriate
|
|
41
|
+
}
|
|
42
|
+
return enumKey;
|
|
43
|
+
};
|
|
44
|
+
ProtoEnum.prototype.toString = function () {
|
|
45
|
+
return this.getEnumValueName();
|
|
46
|
+
};
|
|
47
|
+
return ProtoEnum;
|
|
48
|
+
}());
|
|
49
|
+
exports.ProtoEnum = ProtoEnum;
|
|
50
|
+
//# sourceMappingURL=protoEnum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protoEnum.js","sourceRoot":"","sources":["protoEnum.ts"],"names":[],"mappings":";;;AACA,kGAAkG;AAClG,6FAA6F;AAC7F,yEAA0E;AAE1E;IAII,mBAAY,cAAmB,EAAE,SAAiB;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAEM,sBAAY,GAAnB,UAAoB,QAAgB,EAAE,SAAiB;QACnD,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;IAEc,oCAA0B,GAAzC,UAA0C,QAAgB;QACtD,IAAI,QAAQ,KAAK,kBAAkB,EAAE,CAAC;YAClC,OAAO,0CAAoB,CAAC;QAChC,CAAC;QACD,IAAI,QAAQ,KAAK,iBAAiB,EAAE,CAAC;YACjC,OAAO,wCAAmB,CAAC;QAC/B,CAAC;QACD,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YACvB,OAAO,qBAAU,CAAC;QACtB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,oCAA6B,QAAQ,CAAE,CAAC,CAAC;IAC7D,CAAC;IAED,+BAAW,GAAX;QACI,8DAA8D;QAC9D,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IACpC,CAAC;IAED,gCAAY,GAAZ;QACI,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,oCAAgB,GAAhB;QAAA,iBAQC;QAPG,+EAA+E;QAC/E,wEAAwE;QACxE,IAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG,IAAI,OAAA,KAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAI,CAAC,SAAS,EAA3C,CAA2C,CAAC,CAAC;QAC1G,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,SAAS,CAAC,CAAC,2BAA2B;QACjD,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,4BAAQ,GAAR;QACI,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACnC,CAAC;IACL,gBAAC;AAAD,CAAC,AAhDD,IAgDC;AAhDY,8BAAS"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ProtoEnum.test.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
var position_status_pb_1 = require("../../../fintekkers/models/position/position_status_pb");
|
|
5
|
+
var transaction_type_pb_1 = require("../../../fintekkers/models/transaction/transaction_type_pb");
|
|
6
|
+
var protoEnum_1 = require("./protoEnum");
|
|
7
|
+
describe('ProtoEnum', function () {
|
|
8
|
+
it('should correctly identify the name of the enum value for TransactionTypeProto', function () {
|
|
9
|
+
var protoEnum = new protoEnum_1.ProtoEnum(transaction_type_pb_1.TransactionTypeProto, 1);
|
|
10
|
+
expect(protoEnum.getEnumValueName()).toEqual('BUY');
|
|
11
|
+
});
|
|
12
|
+
it('should correctly return the enum value for PositionStatusProto', function () {
|
|
13
|
+
var protoEnum = new protoEnum_1.ProtoEnum(position_status_pb_1.PositionStatusProto.INTENDED, 2);
|
|
14
|
+
expect(protoEnum.getEnumValue()).toEqual(2);
|
|
15
|
+
});
|
|
16
|
+
it('should throw an error for an unmapped enum name', function () {
|
|
17
|
+
expect(function () { return protoEnum_1.ProtoEnum.fromEnumName('UNMAPPED_ENUM', 0); }).toThrow('Enum has not been mapped: UNMAPPED_ENUM');
|
|
18
|
+
});
|
|
19
|
+
// Add more tests as necessary to cover your use cases
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=protoEnum.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protoEnum.test.js","sourceRoot":"","sources":["protoEnum.test.ts"],"names":[],"mappings":";AAAA,oBAAoB;;AAEpB,6FAA6F;AAC7F,kGAAkG;AAClG,yCAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE;IAClB,EAAE,CAAC,+EAA+E,EAAE;QAChF,IAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,0CAAoB,EAAE,CAAC,CAAC,CAAC;QACzD,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE;QACjE,IAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,wCAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACjE,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE;QAClD,MAAM,CAAC,cAAM,OAAA,qBAAS,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC,CAAC,EAA1C,CAA0C,CAAC,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC;IAChH,CAAC,CAAC,CAAC;IAEH,sDAAsD;AAC1D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ProtoEnum.test.ts
|
|
2
|
+
|
|
3
|
+
import { PositionStatusProto } from '../../../fintekkers/models/position/position_status_pb';
|
|
4
|
+
import { TransactionTypeProto } from '../../../fintekkers/models/transaction/transaction_type_pb';
|
|
5
|
+
import { ProtoEnum } from './protoEnum';
|
|
6
|
+
|
|
7
|
+
describe('ProtoEnum', () => {
|
|
8
|
+
it('should correctly identify the name of the enum value for TransactionTypeProto', () => {
|
|
9
|
+
const protoEnum = new ProtoEnum(TransactionTypeProto, 1);
|
|
10
|
+
expect(protoEnum.getEnumValueName()).toEqual('BUY');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should correctly return the enum value for PositionStatusProto', () => {
|
|
14
|
+
const protoEnum = new ProtoEnum(PositionStatusProto.INTENDED, 2);
|
|
15
|
+
expect(protoEnum.getEnumValue()).toEqual(2);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should throw an error for an unmapped enum name', () => {
|
|
19
|
+
expect(() => ProtoEnum.fromEnumName('UNMAPPED_ENUM', 0)).toThrow('Enum has not been mapped: UNMAPPED_ENUM');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Add more tests as necessary to cover your use cases
|
|
23
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import { TransactionTypeProto } from '../../../fintekkers/models/transaction/transaction_type_pb';
|
|
3
|
+
import { PositionStatusProto } from '../../../fintekkers/models/position/position_status_pb';
|
|
4
|
+
import { FieldProto } from '../../../fintekkers/models/position/field_pb';
|
|
5
|
+
|
|
6
|
+
export class ProtoEnum {
|
|
7
|
+
private enumValue: number;
|
|
8
|
+
private enumDescriptor: any; // Use appropriate type for enum descriptor
|
|
9
|
+
|
|
10
|
+
constructor(enumDescriptor: any, enumValue: number) {
|
|
11
|
+
this.enumValue = enumValue;
|
|
12
|
+
this.enumDescriptor = enumDescriptor;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static fromEnumName(enumName: string, enumValue: number): ProtoEnum {
|
|
16
|
+
return new ProtoEnum(ProtoEnum.getFieldDescriptorFromName(enumName), enumValue);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private static getFieldDescriptorFromName(enumName: string): any {
|
|
20
|
+
if (enumName === "TRANSACTION_TYPE") {
|
|
21
|
+
return TransactionTypeProto;
|
|
22
|
+
}
|
|
23
|
+
if (enumName === "POSITION_STATUS") {
|
|
24
|
+
return PositionStatusProto;
|
|
25
|
+
}
|
|
26
|
+
if (enumName === "FIELD") {
|
|
27
|
+
return FieldProto;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Enum has not been mapped: ${enumName}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getEnumName(): string {
|
|
33
|
+
// Assuming your enumDescriptor has a name property or similar
|
|
34
|
+
return this.enumDescriptor.name;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getEnumValue(): number {
|
|
38
|
+
return this.enumValue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getEnumValueName(): string {
|
|
42
|
+
// In TypeScript/JS, enum values can be accessed directly if you know the value
|
|
43
|
+
// Assuming your enums are simple objects or as generated by protobuf ts
|
|
44
|
+
const enumKey = Object.keys(this.enumDescriptor).find(key => this.enumDescriptor[key] === this.enumValue);
|
|
45
|
+
if (!enumKey) {
|
|
46
|
+
return 'UNKNOWN'; // Or handle as appropriate
|
|
47
|
+
}
|
|
48
|
+
return enumKey;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toString(): string {
|
|
52
|
+
return this.getEnumValueName();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -7,6 +7,7 @@ var local_timestamp_pb_1 = require("../../../fintekkers/models/util/local_timest
|
|
|
7
7
|
var uuid_pb_1 = require("../../../fintekkers/models/util/uuid_pb");
|
|
8
8
|
var datetime_1 = require("./datetime");
|
|
9
9
|
var uuid_1 = require("./uuid");
|
|
10
|
+
var wrappers_pb_1 = require("google-protobuf/google/protobuf/wrappers_pb");
|
|
10
11
|
var ProtoSerializationUtil = /** @class */ (function () {
|
|
11
12
|
function ProtoSerializationUtil() {
|
|
12
13
|
}
|
|
@@ -26,6 +27,9 @@ var ProtoSerializationUtil = /** @class */ (function () {
|
|
|
26
27
|
if (typeof obj === "number") {
|
|
27
28
|
return new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue(obj.toString());
|
|
28
29
|
}
|
|
30
|
+
if (obj instanceof String) {
|
|
31
|
+
return wrappers_pb_1.StringValue.of(obj);
|
|
32
|
+
}
|
|
29
33
|
throw new Error("Could not serialize object of type ".concat(typeof obj, ". Value: ").concat(obj));
|
|
30
34
|
};
|
|
31
35
|
ProtoSerializationUtil.deserialize = function (obj) {
|
|
@@ -46,6 +50,9 @@ var ProtoSerializationUtil = /** @class */ (function () {
|
|
|
46
50
|
if (obj instanceof decimal_value_pb_1.DecimalValueProto) {
|
|
47
51
|
return parseFloat(obj.getArbitraryPrecisionValue());
|
|
48
52
|
}
|
|
53
|
+
if (obj instanceof wrappers_pb_1.StringValue) {
|
|
54
|
+
return obj.toString();
|
|
55
|
+
}
|
|
49
56
|
throw new Error("Could not deserialize object of type ".concat(typeof obj, ". Value: ").concat(obj));
|
|
50
57
|
};
|
|
51
58
|
return ProtoSerializationUtil;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["serialization.ts"],"names":[],"mappings":";;;AAAA,qFAAqF;AACrF,+EAA+E;AAC/E,yFAAyF;AACzF,mEAAoE;AACpE,uCAA2C;AAC3C,+BAA8B;
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["serialization.ts"],"names":[],"mappings":";;;AAAA,qFAAqF;AACrF,+EAA+E;AAC/E,yFAAyF;AACzF,mEAAoE;AACpE,uCAA2C;AAC3C,+BAA8B;AAC9B,2EAA0E;AAO1E;IAAA;IAgDA,CAAC;IA/CQ,gCAAS,GAAhB,UAAiB,GAAQ;QACvB,IAAI,GAAG,YAAY,WAAI,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,GAAG,YAAY,IAAI,EAAE,CAAC;YACxB,OAAO,IAAI,8BAAc,EAAE;iBACxB,OAAO,CAAC,GAAG,CAAC,WA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,SAAS,KAAK,kBAAkB,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC,CAAA,uCAAuC;QACrD,CAAC;QACD,IAAI,GAAG,YAAY,oCAAiB,EAAE,CAAC;YACrC,OAAO,UAAU,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,GAAG,YAAY,yBAAW,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;QACxB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,+CAAwC,OAAO,GAAG,sBAAY,GAAG,CAAE,CAAC,CAAC;IACvF,CAAC;IACH,6BAAC;AAAD,CAAC,AAhDD,IAgDC;AAhDY,wDAAsB"}
|
|
@@ -4,6 +4,7 @@ import { LocalTimestampProto } from "../../../fintekkers/models/util/local_times
|
|
|
4
4
|
import { UUIDProto } from "../../../fintekkers/models/util/uuid_pb";
|
|
5
5
|
import { ZonedDateTime } from "./datetime";
|
|
6
6
|
import { UUID } from "./uuid";
|
|
7
|
+
import { StringValue } from 'google-protobuf/google/protobuf/wrappers_pb';
|
|
7
8
|
|
|
8
9
|
interface EnumValueDescriptor {
|
|
9
10
|
name: string;
|
|
@@ -27,6 +28,9 @@ export class ProtoSerializationUtil {
|
|
|
27
28
|
if (typeof obj === "number") {
|
|
28
29
|
return new DecimalValueProto().setArbitraryPrecisionValue(obj.toString());
|
|
29
30
|
}
|
|
31
|
+
if (obj instanceof String) {
|
|
32
|
+
return StringValue.of(obj);
|
|
33
|
+
}
|
|
30
34
|
|
|
31
35
|
throw new Error(`Could not serialize object of type ${typeof obj}. Value: ${obj}`);
|
|
32
36
|
}
|
|
@@ -49,6 +53,9 @@ export class ProtoSerializationUtil {
|
|
|
49
53
|
if (obj instanceof DecimalValueProto) {
|
|
50
54
|
return parseFloat(obj.getArbitraryPrecisionValue());
|
|
51
55
|
}
|
|
56
|
+
if (obj instanceof StringValue) {
|
|
57
|
+
return obj.toString();
|
|
58
|
+
}
|
|
52
59
|
|
|
53
60
|
throw new Error(`Could not deserialize object of type ${typeof obj}. Value: ${obj}`);
|
|
54
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portfolio.test.js","sourceRoot":"","sources":["portfolio.test.ts"],"names":[],"mappings":";AAAA,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAET,cAAc;AACd,yEAA0E;AAC1E,8CAAgD;AAChD,gDAAkD;AAElD,qBAAqB;AACrB,uDAAsD;AACtD,kFAAmF;AAEnF,uEAAsE;AAGtE,IAAI,CAAC,4EAA4E,EAAE;;;;;gBAC3E,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC;gBAC5C,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;gBAE7B,gBAAgB,GAAG,IAAI,mCAAgB,EAAE,CAAC;gBAE1C,SAAS,GAAG,IAAI,6BAAc,EAAE,CAAC;gBACvC,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;gBACtC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBAC9B,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC5B,SAAS,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;gBAC7C,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;gBAET,qBAAM,gBAAgB,CAAC,uBAAuB,CAAC,SAAS,CAAC,EAAA;;gBAA7E,iBAAiB,GAAG,SAAyD;gBACjF,MAAM,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAEG,qBAAM,gBAAgB,CAAC,eAAe,CAAC,SAAS,CAAC,EAAA;;gBAAzG,uBAAuB,GAAiC,SAAiD;gBAC7G,MAAM,CAAC,uBAAuB,CAAC,wBAAwB,EAAE,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