@fintekkers/ledger-models 1.1.42 → 1.1.43
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/node/wrappers/models/transaction/transaction_price_rules.test.d.ts +1 -0
- package/node/wrappers/models/transaction/transaction_price_rules.test.js +118 -0
- package/node/wrappers/models/transaction/transaction_price_rules.test.js.map +1 -0
- package/node/wrappers/models/transaction/transaction_price_rules.test.ts +103 -0
- package/node/wrappers/models/transaction/transaction_rules.d.ts +9 -1
- package/node/wrappers/models/transaction/transaction_rules.js +28 -8
- package/node/wrappers/models/transaction/transaction_rules.js.map +1 -1
- package/node/wrappers/models/transaction/transaction_rules.ts +28 -6
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// LM-463: trade-price rule. The same fixture
|
|
3
|
+
// (test-fixtures/transaction-price/cases.json) runs in Java, Python and Rust.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const price_pb_1 = require("../../../fintekkers/models/price/price_pb");
|
|
31
|
+
const price_type_pb_1 = require("../../../fintekkers/models/price/price_type_pb");
|
|
32
|
+
const transaction_pb_1 = require("../../../fintekkers/models/transaction/transaction_pb");
|
|
33
|
+
const uuid_1 = require("../utils/uuid");
|
|
34
|
+
const transaction_rules_1 = require("./transaction_rules");
|
|
35
|
+
const FIXTURE = path.resolve(__dirname, '../../../../../test-fixtures/transaction-price/cases.json');
|
|
36
|
+
const CASES = JSON.parse(fs.readFileSync(FIXTURE, 'utf-8')).cases;
|
|
37
|
+
const byName = (name) => CASES.find(c => c.name === name);
|
|
38
|
+
const FIELD = `${transaction_rules_1.PRICE_PREFIX}price_type`;
|
|
39
|
+
function price(p) {
|
|
40
|
+
const out = new price_pb_1.PriceProto();
|
|
41
|
+
if (p.uuid !== undefined)
|
|
42
|
+
out.setUuid(new uuid_1.UUID(uuid_1.UUID.fromString(p.uuid)).toUUIDProto());
|
|
43
|
+
if (p.link)
|
|
44
|
+
out.setIsLink(true);
|
|
45
|
+
if (typeof p.price_type === 'number') {
|
|
46
|
+
// A number is the raw wire value.
|
|
47
|
+
out.setPriceType(p.price_type);
|
|
48
|
+
}
|
|
49
|
+
else if (p.price_type !== undefined) {
|
|
50
|
+
out.setPriceType(price_type_pb_1.PriceTypeProto[p.price_type]);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function transaction(t) {
|
|
55
|
+
const out = new transaction_pb_1.TransactionProto().setUuid(new uuid_1.UUID(uuid_1.UUID.fromString(t.uuid)).toUUIDProto());
|
|
56
|
+
if (t.price)
|
|
57
|
+
out.setPrice(price(t.price));
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
const onPriceType = (vs) => vs.filter(v => v.getField() === FIELD).map(v => v.getMessage());
|
|
61
|
+
describe('transaction_rules.validate: trade price (LM-463)', () => {
|
|
62
|
+
test('fixture has every case, including the metric cases', () => {
|
|
63
|
+
const names = CASES.map(c => c.name);
|
|
64
|
+
expect(new Set(names).size).toBe(names.length);
|
|
65
|
+
expect(names).toEqual(expect.arrayContaining([
|
|
66
|
+
'inline_unknown', 'inline_unknown_no_uuid', 'inline_absolute', 'inline_percentage', 'inline_rate',
|
|
67
|
+
'inline_unrecognised_value', 'link_no_price_type', 'link_unknown_explicit', 'no_price',
|
|
68
|
+
]));
|
|
69
|
+
});
|
|
70
|
+
test('every fixture case runs and matches', () => {
|
|
71
|
+
let ran = 0;
|
|
72
|
+
for (const c of CASES) {
|
|
73
|
+
const actual = (0, transaction_rules_1.validate)(transaction(c.transaction));
|
|
74
|
+
expect([c.name, actual.map(v => v.getField())]).toEqual([c.name, c.violations.map(v => v.field)]);
|
|
75
|
+
c.violations.forEach((want, i) => {
|
|
76
|
+
var _a;
|
|
77
|
+
const got = actual[i];
|
|
78
|
+
expect(got.getMessage()).toBe(want.message);
|
|
79
|
+
if (want.object_id === null)
|
|
80
|
+
expect(got.hasObjectId()).toBe(false);
|
|
81
|
+
else
|
|
82
|
+
expect((_a = uuid_1.UUID.fromUUIDProto(got.getObjectId())) === null || _a === void 0 ? void 0 : _a.toString()).toBe(want.object_id);
|
|
83
|
+
});
|
|
84
|
+
ran++;
|
|
85
|
+
}
|
|
86
|
+
expect(ran).toBe(CASES.length);
|
|
87
|
+
});
|
|
88
|
+
test('inline_unknown gives exactly one violation on price.price_type', () => {
|
|
89
|
+
const actual = (0, transaction_rules_1.validate)(transaction(byName('inline_unknown').transaction));
|
|
90
|
+
expect(actual).toHaveLength(1);
|
|
91
|
+
expect(actual[0].getField()).toBe('price.price_type');
|
|
92
|
+
expect(actual[0].getMessage()).toContain('price_type');
|
|
93
|
+
expect(actual[0].getMessage()).toBe(transaction_rules_1.UNKNOWN_TRADE_PRICE_TYPE);
|
|
94
|
+
});
|
|
95
|
+
test.each(['inline_absolute', 'inline_percentage', 'inline_rate'])('%s gives no violation', name => {
|
|
96
|
+
expect(onPriceType((0, transaction_rules_1.validate)(transaction(byName(name).transaction)))).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
test.each(['link_no_price_type', 'link_unknown_explicit'])('%s is never checked', name => {
|
|
99
|
+
expect(onPriceType((0, transaction_rules_1.validate)(transaction(byName(name).transaction)))).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
test('an unrecognised raw value passes', () => {
|
|
102
|
+
const proto = new transaction_pb_1.TransactionProto().setPrice(new price_pb_1.PriceProto().setPriceType(999));
|
|
103
|
+
expect((0, transaction_rules_1.validate)(proto)).toEqual([]);
|
|
104
|
+
});
|
|
105
|
+
test('every named price type except UNKNOWN_PRICE_TYPE passes', () => {
|
|
106
|
+
const visited = [];
|
|
107
|
+
for (const value of Object.values(price_type_pb_1.PriceTypeProto)) {
|
|
108
|
+
if (typeof value !== 'number' || value === price_type_pb_1.PriceTypeProto.UNKNOWN_PRICE_TYPE)
|
|
109
|
+
continue;
|
|
110
|
+
const proto = new transaction_pb_1.TransactionProto().setPrice(new price_pb_1.PriceProto().setPriceType(value));
|
|
111
|
+
expect([value, (0, transaction_rules_1.validate)(proto)]).toEqual([value, []]);
|
|
112
|
+
visited.push(value);
|
|
113
|
+
}
|
|
114
|
+
expect(visited.length).toBeGreaterThanOrEqual(5);
|
|
115
|
+
expect(visited).toContain(price_type_pb_1.PriceTypeProto.RATE);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=transaction_price_rules.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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Q,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,8BAAc,CAAC,EAAE;YAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,8BAAc,CAAC,kBAAkB;gBAAE,SAAS;YACvF,MAAM,KAAK,GAAG,IAAI,iCAAgB,EAAE,CAAC,QAAQ,CAAC,IAAI,qBAAU,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACpF,MAAM,CAAC,CAAC,KAAK,EAAE,IAAA,4BAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACvB;QACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;QACjD,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,8BAAc,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// LM-463: trade-price rule. The same fixture
|
|
2
|
+
// (test-fixtures/transaction-price/cases.json) runs in Java, Python and Rust.
|
|
3
|
+
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { PriceProto } from '../../../fintekkers/models/price/price_pb';
|
|
7
|
+
import { PriceTypeProto } from '../../../fintekkers/models/price/price_type_pb';
|
|
8
|
+
import { TransactionProto } from '../../../fintekkers/models/transaction/transaction_pb';
|
|
9
|
+
import { FieldViolationProto } from '../../../fintekkers/requests/util/errors/field_violation_pb';
|
|
10
|
+
import { UUID } from '../utils/uuid';
|
|
11
|
+
import { PRICE_PREFIX, UNKNOWN_TRADE_PRICE_TYPE, validate } from './transaction_rules';
|
|
12
|
+
|
|
13
|
+
interface PriceSpec { uuid?: string; link?: boolean; price_type?: string | number }
|
|
14
|
+
interface TransactionSpec { uuid: string; price?: PriceSpec }
|
|
15
|
+
interface Violation { field: string; object_id: string | null; message: string }
|
|
16
|
+
interface Case { name: string; transaction: TransactionSpec; violations: Violation[] }
|
|
17
|
+
|
|
18
|
+
const FIXTURE = path.resolve(__dirname, '../../../../../test-fixtures/transaction-price/cases.json');
|
|
19
|
+
const CASES: Case[] = JSON.parse(fs.readFileSync(FIXTURE, 'utf-8')).cases;
|
|
20
|
+
const byName = (name: string): Case => CASES.find(c => c.name === name)!;
|
|
21
|
+
const FIELD = `${PRICE_PREFIX}price_type`;
|
|
22
|
+
|
|
23
|
+
function price(p: PriceSpec): PriceProto {
|
|
24
|
+
const out = new PriceProto();
|
|
25
|
+
if (p.uuid !== undefined) out.setUuid(new UUID(UUID.fromString(p.uuid)).toUUIDProto());
|
|
26
|
+
if (p.link) out.setIsLink(true);
|
|
27
|
+
if (typeof p.price_type === 'number') {
|
|
28
|
+
// A number is the raw wire value.
|
|
29
|
+
out.setPriceType(p.price_type as PriceTypeProto);
|
|
30
|
+
} else if (p.price_type !== undefined) {
|
|
31
|
+
out.setPriceType(PriceTypeProto[p.price_type as keyof typeof PriceTypeProto]);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function transaction(t: TransactionSpec): TransactionProto {
|
|
37
|
+
const out = new TransactionProto().setUuid(new UUID(UUID.fromString(t.uuid)).toUUIDProto());
|
|
38
|
+
if (t.price) out.setPrice(price(t.price));
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const onPriceType = (vs: FieldViolationProto[]): string[] =>
|
|
43
|
+
vs.filter(v => v.getField() === FIELD).map(v => v.getMessage());
|
|
44
|
+
|
|
45
|
+
describe('transaction_rules.validate: trade price (LM-463)', () => {
|
|
46
|
+
test('fixture has every case, including the metric cases', () => {
|
|
47
|
+
const names = CASES.map(c => c.name);
|
|
48
|
+
expect(new Set(names).size).toBe(names.length);
|
|
49
|
+
expect(names).toEqual(expect.arrayContaining([
|
|
50
|
+
'inline_unknown', 'inline_unknown_no_uuid', 'inline_absolute', 'inline_percentage', 'inline_rate',
|
|
51
|
+
'inline_unrecognised_value', 'link_no_price_type', 'link_unknown_explicit', 'no_price',
|
|
52
|
+
]));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('every fixture case runs and matches', () => {
|
|
56
|
+
let ran = 0;
|
|
57
|
+
for (const c of CASES) {
|
|
58
|
+
const actual = validate(transaction(c.transaction));
|
|
59
|
+
expect([c.name, actual.map(v => v.getField())]).toEqual([c.name, c.violations.map(v => v.field)]);
|
|
60
|
+
c.violations.forEach((want, i) => {
|
|
61
|
+
const got = actual[i];
|
|
62
|
+
expect(got.getMessage()).toBe(want.message);
|
|
63
|
+
if (want.object_id === null) expect(got.hasObjectId()).toBe(false);
|
|
64
|
+
else expect(UUID.fromUUIDProto(got.getObjectId())?.toString()).toBe(want.object_id);
|
|
65
|
+
});
|
|
66
|
+
ran++;
|
|
67
|
+
}
|
|
68
|
+
expect(ran).toBe(CASES.length);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('inline_unknown gives exactly one violation on price.price_type', () => {
|
|
72
|
+
const actual = validate(transaction(byName('inline_unknown').transaction));
|
|
73
|
+
expect(actual).toHaveLength(1);
|
|
74
|
+
expect(actual[0].getField()).toBe('price.price_type');
|
|
75
|
+
expect(actual[0].getMessage()).toContain('price_type');
|
|
76
|
+
expect(actual[0].getMessage()).toBe(UNKNOWN_TRADE_PRICE_TYPE);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test.each(['inline_absolute', 'inline_percentage', 'inline_rate'])('%s gives no violation', name => {
|
|
80
|
+
expect(onPriceType(validate(transaction(byName(name).transaction)))).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test.each(['link_no_price_type', 'link_unknown_explicit'])('%s is never checked', name => {
|
|
84
|
+
expect(onPriceType(validate(transaction(byName(name).transaction)))).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('an unrecognised raw value passes', () => {
|
|
88
|
+
const proto = new TransactionProto().setPrice(new PriceProto().setPriceType(999 as PriceTypeProto));
|
|
89
|
+
expect(validate(proto)).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('every named price type except UNKNOWN_PRICE_TYPE passes', () => {
|
|
93
|
+
const visited: number[] = [];
|
|
94
|
+
for (const value of Object.values(PriceTypeProto)) {
|
|
95
|
+
if (typeof value !== 'number' || value === PriceTypeProto.UNKNOWN_PRICE_TYPE) continue;
|
|
96
|
+
const proto = new TransactionProto().setPrice(new PriceProto().setPriceType(value));
|
|
97
|
+
expect([value, validate(proto)]).toEqual([value, []]);
|
|
98
|
+
visited.push(value);
|
|
99
|
+
}
|
|
100
|
+
expect(visited.length).toBeGreaterThanOrEqual(5);
|
|
101
|
+
expect(visited).toContain(PriceTypeProto.RATE);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -11,7 +11,13 @@ import { FieldViolationProto } from '../../../fintekkers/requests/util/errors/fi
|
|
|
11
11
|
* `child_transactions[1].child_transactions[0]`) and its object_id is the
|
|
12
12
|
* UUID of the transaction that owns the list. A child with no UUID, or an
|
|
13
13
|
* empty one, is never a duplicate. A child whose security is a link is not
|
|
14
|
-
* counted as cash: hydrate it first.
|
|
14
|
+
* counted as cash: hydrate it first.
|
|
15
|
+
*
|
|
16
|
+
* Trade price (LM-463): an inline `price` (not is_link) whose raw price_type
|
|
17
|
+
* is UNKNOWN_PRICE_TYPE gives one violation on `price.price_type`, with
|
|
18
|
+
* object_id the price's UUID. Every other value passes, including an
|
|
19
|
+
* unrecognised number. A link price is never checked, and child
|
|
20
|
+
* transactions' prices are not checked. The Transaction wrapper does not call
|
|
15
21
|
* these rules, so stored rows that break them still load; writers call
|
|
16
22
|
* `validate` / `requireValid` before sending.
|
|
17
23
|
*/
|
|
@@ -19,6 +25,8 @@ export declare const SECURITY_PREFIX = "security.";
|
|
|
19
25
|
export declare const CHILD_TRANSACTIONS = "child_transactions";
|
|
20
26
|
export declare const SECOND_CASH_CHILD = "second cash child";
|
|
21
27
|
export declare const DUPLICATE_CHILD_ID = "duplicate child id";
|
|
28
|
+
export declare const PRICE_PREFIX = "price.";
|
|
29
|
+
export declare const UNKNOWN_TRADE_PRICE_TYPE = "price_type is UNKNOWN_PRICE_TYPE on an inline trade price";
|
|
22
30
|
/** Returns every field-level violation on this transaction, or an empty array when it is valid. */
|
|
23
31
|
export declare function validate(proto: TransactionProto): FieldViolationProto[];
|
|
24
32
|
/** Throws ModelValidationError carrying every violation if `validate` finds any. */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireValid = exports.validate = exports.DUPLICATE_CHILD_ID = exports.SECOND_CASH_CHILD = exports.CHILD_TRANSACTIONS = exports.SECURITY_PREFIX = void 0;
|
|
3
|
+
exports.requireValid = exports.validate = exports.UNKNOWN_TRADE_PRICE_TYPE = exports.PRICE_PREFIX = exports.DUPLICATE_CHILD_ID = exports.SECOND_CASH_CHILD = exports.CHILD_TRANSACTIONS = exports.SECURITY_PREFIX = void 0;
|
|
4
|
+
const price_type_pb_1 = require("../../../fintekkers/models/price/price_type_pb");
|
|
4
5
|
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
5
6
|
const errors_1 = require("../errors");
|
|
7
|
+
const price_rules_1 = require("../price/price_rules");
|
|
6
8
|
const security_rules_1 = require("../security/security_rules");
|
|
7
9
|
const uuid_1 = require("../utils/uuid");
|
|
8
10
|
/**
|
|
@@ -16,7 +18,13 @@ const uuid_1 = require("../utils/uuid");
|
|
|
16
18
|
* `child_transactions[1].child_transactions[0]`) and its object_id is the
|
|
17
19
|
* UUID of the transaction that owns the list. A child with no UUID, or an
|
|
18
20
|
* empty one, is never a duplicate. A child whose security is a link is not
|
|
19
|
-
* counted as cash: hydrate it first.
|
|
21
|
+
* counted as cash: hydrate it first.
|
|
22
|
+
*
|
|
23
|
+
* Trade price (LM-463): an inline `price` (not is_link) whose raw price_type
|
|
24
|
+
* is UNKNOWN_PRICE_TYPE gives one violation on `price.price_type`, with
|
|
25
|
+
* object_id the price's UUID. Every other value passes, including an
|
|
26
|
+
* unrecognised number. A link price is never checked, and child
|
|
27
|
+
* transactions' prices are not checked. The Transaction wrapper does not call
|
|
20
28
|
* these rules, so stored rows that break them still load; writers call
|
|
21
29
|
* `validate` / `requireValid` before sending.
|
|
22
30
|
*/
|
|
@@ -24,6 +32,8 @@ exports.SECURITY_PREFIX = 'security.';
|
|
|
24
32
|
exports.CHILD_TRANSACTIONS = 'child_transactions';
|
|
25
33
|
exports.SECOND_CASH_CHILD = 'second cash child';
|
|
26
34
|
exports.DUPLICATE_CHILD_ID = 'duplicate child id';
|
|
35
|
+
exports.PRICE_PREFIX = 'price.';
|
|
36
|
+
exports.UNKNOWN_TRADE_PRICE_TYPE = 'price_type is UNKNOWN_PRICE_TYPE on an inline trade price';
|
|
27
37
|
/** Returns every field-level violation on this transaction, or an empty array when it is valid. */
|
|
28
38
|
function validate(proto) {
|
|
29
39
|
const out = [];
|
|
@@ -36,6 +46,7 @@ function validate(proto) {
|
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
addChildViolations(proto, '', out);
|
|
49
|
+
addPriceViolation(proto, out);
|
|
39
50
|
return out;
|
|
40
51
|
}
|
|
41
52
|
exports.validate = validate;
|
|
@@ -47,13 +58,13 @@ function requireValid(proto) {
|
|
|
47
58
|
}
|
|
48
59
|
exports.requireValid = requireValid;
|
|
49
60
|
function addChildViolations(parent, prefix, out) {
|
|
50
|
-
const parentId = idOf(parent);
|
|
61
|
+
const parentId = idOf(parent.getUuid());
|
|
51
62
|
let seenCash = false;
|
|
52
63
|
let firstCashId;
|
|
53
64
|
const seenIds = new Set();
|
|
54
65
|
parent.getChildtransactionsList().forEach((child, i) => {
|
|
55
66
|
const field = `${prefix}${exports.CHILD_TRANSACTIONS}[${i}]`;
|
|
56
|
-
const childId = idOf(child);
|
|
67
|
+
const childId = idOf(child.getUuid());
|
|
57
68
|
if (isCash(child)) {
|
|
58
69
|
if (seenCash) {
|
|
59
70
|
out.push((0, errors_1.violation)(field, parentId, `${exports.SECOND_CASH_CHILD}: transaction ${display(parentId)} already has cash child `
|
|
@@ -74,6 +85,16 @@ function addChildViolations(parent, prefix, out) {
|
|
|
74
85
|
addChildViolations(child, `${field}.`, out);
|
|
75
86
|
});
|
|
76
87
|
}
|
|
88
|
+
/** LM-463: an inline trade price must have a price_type; a link price is never checked. */
|
|
89
|
+
function addPriceViolation(proto, out) {
|
|
90
|
+
const price = proto.getPrice();
|
|
91
|
+
if (!price || price.getIsLink())
|
|
92
|
+
return;
|
|
93
|
+
// Raw number, so an unrecognised value is not rejected.
|
|
94
|
+
if (price.getPriceType() === price_type_pb_1.PriceTypeProto.UNKNOWN_PRICE_TYPE) {
|
|
95
|
+
out.push((0, errors_1.violation)(exports.PRICE_PREFIX + price_rules_1.PRICE_TYPE, idOf(price.getUuid()), exports.UNKNOWN_TRADE_PRICE_TYPE));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
77
98
|
/** Same test as Java Security.isCash() on an inline security; a link is not cash. */
|
|
78
99
|
function isCash(child) {
|
|
79
100
|
const security = child.getSecurity();
|
|
@@ -81,10 +102,9 @@ function isCash(child) {
|
|
|
81
102
|
return false;
|
|
82
103
|
return security.getProductType() === product_type_pb_1.ProductTypeProto.CURRENCY || security.hasCashDetails();
|
|
83
104
|
}
|
|
84
|
-
/** The
|
|
85
|
-
function idOf(
|
|
86
|
-
|
|
87
|
-
const raw = (_a = proto.getUuid()) === null || _a === void 0 ? void 0 : _a.getRawUuid_asU8();
|
|
105
|
+
/** The UUID, or undefined when it is unset or not 16 bytes. */
|
|
106
|
+
function idOf(uuid) {
|
|
107
|
+
const raw = uuid === null || uuid === void 0 ? void 0 : uuid.getRawUuid_asU8();
|
|
88
108
|
return raw && raw.length === 16 ? uuid_1.UUID.fromU8Array(raw) : undefined;
|
|
89
109
|
}
|
|
90
110
|
function display(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction_rules.js","sourceRoot":"","sources":["transaction_rules.ts"],"names":[],"mappings":";;;AAAA,yFAAuF;
|
|
1
|
+
{"version":3,"file":"transaction_rules.js","sourceRoot":"","sources":["transaction_rules.ts"],"names":[],"mappings":";;;AAAA,kFAAgF;AAChF,yFAAuF;AAIvF,sCAA4D;AAC5D,sDAAkD;AAClD,+DAA0E;AAC1E,wCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEU,QAAA,eAAe,GAAG,WAAW,CAAC;AAC9B,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAC1C,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AACxC,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAC1C,QAAA,YAAY,GAAG,QAAQ,CAAC;AACxB,QAAA,wBAAwB,GAAG,2DAA2D,CAAC;AAEpG,mGAAmG;AACnG,SAAgB,QAAQ,CAAC,KAAuB;IAC5C,MAAM,GAAG,GAA0B,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,QAAQ,EAAE;QACV,KAAK,MAAM,CAAC,IAAI,IAAA,yBAAgB,EAAC,QAAQ,CAAC,EAAE;YACxC,MAAM,QAAQ,GAAG,CAAC,CAAC,YAAY,EAAE,CAAC;YAClC,QAAQ,CAAC,QAAQ,CAAC,uBAAe,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;YAClD,GAAG,CAA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CAAC;AAChG,CAAC;AAED,+DAA+D;AAC/D,SAAS,IAAI,CAAC,IAA2B;IACrC,MAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe,EAAE,CAAC;IACpC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC;AAED,SAAS,OAAO,CAAC,EAAoB;IACjC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AACvC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { PriceTypeProto } from '../../../fintekkers/models/price/price_type_pb';
|
|
1
2
|
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
2
3
|
import { TransactionProto } from '../../../fintekkers/models/transaction/transaction_pb';
|
|
4
|
+
import { UUIDProto } from '../../../fintekkers/models/util/uuid_pb';
|
|
3
5
|
import { FieldViolationProto } from '../../../fintekkers/requests/util/errors/field_violation_pb';
|
|
4
6
|
import { ModelValidationError, violation } from '../errors';
|
|
7
|
+
import { PRICE_TYPE } from '../price/price_rules';
|
|
5
8
|
import { validate as validateSecurity } from '../security/security_rules';
|
|
6
9
|
import { UUID } from '../utils/uuid';
|
|
7
10
|
|
|
@@ -16,7 +19,13 @@ import { UUID } from '../utils/uuid';
|
|
|
16
19
|
* `child_transactions[1].child_transactions[0]`) and its object_id is the
|
|
17
20
|
* UUID of the transaction that owns the list. A child with no UUID, or an
|
|
18
21
|
* empty one, is never a duplicate. A child whose security is a link is not
|
|
19
|
-
* counted as cash: hydrate it first.
|
|
22
|
+
* counted as cash: hydrate it first.
|
|
23
|
+
*
|
|
24
|
+
* Trade price (LM-463): an inline `price` (not is_link) whose raw price_type
|
|
25
|
+
* is UNKNOWN_PRICE_TYPE gives one violation on `price.price_type`, with
|
|
26
|
+
* object_id the price's UUID. Every other value passes, including an
|
|
27
|
+
* unrecognised number. A link price is never checked, and child
|
|
28
|
+
* transactions' prices are not checked. The Transaction wrapper does not call
|
|
20
29
|
* these rules, so stored rows that break them still load; writers call
|
|
21
30
|
* `validate` / `requireValid` before sending.
|
|
22
31
|
*/
|
|
@@ -25,6 +34,8 @@ export const SECURITY_PREFIX = 'security.';
|
|
|
25
34
|
export const CHILD_TRANSACTIONS = 'child_transactions';
|
|
26
35
|
export const SECOND_CASH_CHILD = 'second cash child';
|
|
27
36
|
export const DUPLICATE_CHILD_ID = 'duplicate child id';
|
|
37
|
+
export const PRICE_PREFIX = 'price.';
|
|
38
|
+
export const UNKNOWN_TRADE_PRICE_TYPE = 'price_type is UNKNOWN_PRICE_TYPE on an inline trade price';
|
|
28
39
|
|
|
29
40
|
/** Returns every field-level violation on this transaction, or an empty array when it is valid. */
|
|
30
41
|
export function validate(proto: TransactionProto): FieldViolationProto[] {
|
|
@@ -38,6 +49,7 @@ export function validate(proto: TransactionProto): FieldViolationProto[] {
|
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
addChildViolations(proto, '', out);
|
|
52
|
+
addPriceViolation(proto, out);
|
|
41
53
|
return out;
|
|
42
54
|
}
|
|
43
55
|
|
|
@@ -48,13 +60,13 @@ export function requireValid(proto: TransactionProto): void {
|
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
function addChildViolations(parent: TransactionProto, prefix: string, out: FieldViolationProto[]): void {
|
|
51
|
-
const parentId = idOf(parent);
|
|
63
|
+
const parentId = idOf(parent.getUuid());
|
|
52
64
|
let seenCash = false;
|
|
53
65
|
let firstCashId: UUID | undefined;
|
|
54
66
|
const seenIds = new Set<string>();
|
|
55
67
|
parent.getChildtransactionsList().forEach((child, i) => {
|
|
56
68
|
const field = `${prefix}${CHILD_TRANSACTIONS}[${i}]`;
|
|
57
|
-
const childId = idOf(child);
|
|
69
|
+
const childId = idOf(child.getUuid());
|
|
58
70
|
if (isCash(child)) {
|
|
59
71
|
if (seenCash) {
|
|
60
72
|
out.push(violation(field, parentId,
|
|
@@ -77,6 +89,16 @@ function addChildViolations(parent: TransactionProto, prefix: string, out: Field
|
|
|
77
89
|
});
|
|
78
90
|
}
|
|
79
91
|
|
|
92
|
+
/** LM-463: an inline trade price must have a price_type; a link price is never checked. */
|
|
93
|
+
function addPriceViolation(proto: TransactionProto, out: FieldViolationProto[]): void {
|
|
94
|
+
const price = proto.getPrice();
|
|
95
|
+
if (!price || price.getIsLink()) return;
|
|
96
|
+
// Raw number, so an unrecognised value is not rejected.
|
|
97
|
+
if (price.getPriceType() === PriceTypeProto.UNKNOWN_PRICE_TYPE) {
|
|
98
|
+
out.push(violation(PRICE_PREFIX + PRICE_TYPE, idOf(price.getUuid()), UNKNOWN_TRADE_PRICE_TYPE));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
/** Same test as Java Security.isCash() on an inline security; a link is not cash. */
|
|
81
103
|
function isCash(child: TransactionProto): boolean {
|
|
82
104
|
const security = child.getSecurity();
|
|
@@ -84,9 +106,9 @@ function isCash(child: TransactionProto): boolean {
|
|
|
84
106
|
return security.getProductType() === ProductTypeProto.CURRENCY || security.hasCashDetails();
|
|
85
107
|
}
|
|
86
108
|
|
|
87
|
-
/** The
|
|
88
|
-
function idOf(
|
|
89
|
-
const raw =
|
|
109
|
+
/** The UUID, or undefined when it is unset or not 16 bytes. */
|
|
110
|
+
function idOf(uuid: UUIDProto | undefined): UUID | undefined {
|
|
111
|
+
const raw = uuid?.getRawUuid_asU8();
|
|
90
112
|
return raw && raw.length === 16 ? UUID.fromU8Array(raw) : undefined;
|
|
91
113
|
}
|
|
92
114
|
|