@fintekkers/ledger-models 1.1.51 → 1.1.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/index.js +19 -0
- package/index.js.map +1 -1
- package/index.ts +27 -1
- package/node/wrappers/models/security/security.d.ts +29 -0
- package/node/wrappers/models/security/security.js +59 -0
- package/node/wrappers/models/security/security.js.map +1 -1
- package/node/wrappers/models/security/security.ts +63 -0
- package/node/wrappers/models/security/security_metric.d.ts +163 -0
- package/node/wrappers/models/security/security_metric.js +431 -0
- package/node/wrappers/models/security/security_metric.js.map +1 -0
- package/node/wrappers/models/security/security_metric.test.d.ts +1 -0
- package/node/wrappers/models/security/security_metric.test.js +215 -0
- package/node/wrappers/models/security/security_metric.test.js.map +1 -0
- package/node/wrappers/models/security/security_metric.test.ts +223 -0
- package/node/wrappers/models/security/security_metric.ts +514 -0
- package/node/wrappers/services/security-metric-service/SecurityMetricService.d.ts +94 -0
- package/node/wrappers/services/security-metric-service/SecurityMetricService.js +257 -0
- package/node/wrappers/services/security-metric-service/SecurityMetricService.js.map +1 -0
- package/node/wrappers/services/security-metric-service/SecurityMetricService.ts +298 -0
- package/node/wrappers/services/security_metric_fake_server.d.ts +35 -0
- package/node/wrappers/services/security_metric_fake_server.js +203 -0
- package/node/wrappers/services/security_metric_fake_server.js.map +1 -0
- package/node/wrappers/services/security_metric_fake_server.ts +194 -0
- package/node/wrappers/services/security_metric_readme.test.d.ts +1 -0
- package/node/wrappers/services/security_metric_readme.test.js +132 -0
- package/node/wrappers/services/security_metric_readme.test.js.map +1 -0
- package/node/wrappers/services/security_metric_readme.test.ts +115 -0
- package/node/wrappers/services/security_metric_service.test.d.ts +1 -0
- package/node/wrappers/services/security_metric_service.test.js +307 -0
- package/node/wrappers/services/security_metric_service.test.js.map +1 -0
- package/node/wrappers/services/security_metric_service.test.ts +321 -0
- package/node/wrappers/util/object-types.test.js +34 -1
- package/node/wrappers/util/object-types.test.js.map +1 -1
- package/node/wrappers/util/object-types.test.ts +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.FakeSecurityMetricServer = exports.SPY_UUID = void 0;
|
|
36
|
+
/**
|
|
37
|
+
* Test helper, not part of the library API (LM-485): an in-memory
|
|
38
|
+
* SecurityMetric gRPC server on 127.0.0.1 for the SecurityMetricService
|
|
39
|
+
* tests. It counts calls per RPC and keeps every request.
|
|
40
|
+
*
|
|
41
|
+
* - GetLatest: walks the requested securities in reverse order; omits a
|
|
42
|
+
* security with no data for any metric; else returns its latest point on
|
|
43
|
+
* or before `date` (a zero-point series when there is none).
|
|
44
|
+
* - Search: streams the range in messages of 2 points; one zero-point
|
|
45
|
+
* message when there are none.
|
|
46
|
+
* - CreateOrUpdate: stores the points and returns the series header with a
|
|
47
|
+
* distinct as_of per call (2026-11-23T21:00:00Z plus the call count in seconds).
|
|
48
|
+
*/
|
|
49
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
50
|
+
const timestamp_pb_1 = require("google-protobuf/google/protobuf/timestamp_pb");
|
|
51
|
+
const security_metric_service_grpc_pb_1 = require("../../fintekkers/services/security-metric-service/security_metric_service_grpc_pb");
|
|
52
|
+
const security_metric_pb_1 = require("../../fintekkers/models/security/security_metric_pb");
|
|
53
|
+
const security_metric_type_pb_1 = require("../../fintekkers/models/security/security_metric_type_pb");
|
|
54
|
+
const local_date_pb_1 = require("../../fintekkers/models/util/local_date_pb");
|
|
55
|
+
const local_timestamp_pb_1 = require("../../fintekkers/models/util/local_timestamp_pb");
|
|
56
|
+
const create_security_metric_request_pb_1 = require("../../fintekkers/requests/security_metric/create_security_metric_request_pb");
|
|
57
|
+
const get_latest_security_metric_request_pb_1 = require("../../fintekkers/requests/security_metric/get_latest_security_metric_request_pb");
|
|
58
|
+
const search_security_metric_request_pb_1 = require("../../fintekkers/requests/security_metric/search_security_metric_request_pb");
|
|
59
|
+
const object_types_1 = require("../util/object-types");
|
|
60
|
+
const decimal_1 = require("../models/utils/decimal");
|
|
61
|
+
const uuid_1 = require("../models/utils/uuid");
|
|
62
|
+
/** The seeded SPY security: SHARES_OUTSTANDING 2026-11-19 → 15204137000, 2026-11-20 → 15210000000. */
|
|
63
|
+
exports.SPY_UUID = '5f0c2a1e-7b3d-4c8e-9a10-2b3c4d5e6f70';
|
|
64
|
+
const AS_OF_BASE_SECONDS = Date.UTC(2026, 10, 23, 21, 0, 0) / 1000;
|
|
65
|
+
function iso(d) {
|
|
66
|
+
if (!d)
|
|
67
|
+
return '';
|
|
68
|
+
return `${String(d.getYear()).padStart(4, '0')}-${String(d.getMonth()).padStart(2, '0')}-${String(d.getDay()).padStart(2, '0')}`;
|
|
69
|
+
}
|
|
70
|
+
function dateProto(isoDate) {
|
|
71
|
+
const [y, m, d] = isoDate.split('-').map(s => parseInt(s, 10));
|
|
72
|
+
return new local_date_pb_1.LocalDateProto().setYear(y).setMonth(m).setDay(d);
|
|
73
|
+
}
|
|
74
|
+
function uuidKey(p) {
|
|
75
|
+
const u = uuid_1.UUID.fromUUIDProto(p);
|
|
76
|
+
return u ? u.toString() : '';
|
|
77
|
+
}
|
|
78
|
+
function timestamp(seconds) {
|
|
79
|
+
return new local_timestamp_pb_1.LocalTimestampProto().setTimestamp(new timestamp_pb_1.Timestamp().setSeconds(seconds).setNanos(0)).setTimeZone('UTC');
|
|
80
|
+
}
|
|
81
|
+
class FakeSecurityMetricServer {
|
|
82
|
+
constructor(server, port) {
|
|
83
|
+
this.calls = { getLatest: 0, search: 0, createOrUpdate: 0 };
|
|
84
|
+
this.getLatestRequests = [];
|
|
85
|
+
this.searchRequests = [];
|
|
86
|
+
this.createRequests = [];
|
|
87
|
+
/** `${uuid}|${metric}` → ISO date → canonical decimal string. */
|
|
88
|
+
this.store = new Map();
|
|
89
|
+
this.server = server;
|
|
90
|
+
this.port = port;
|
|
91
|
+
}
|
|
92
|
+
/** Starts a server on 127.0.0.1 with a free port, seeded with SPY. */
|
|
93
|
+
static start() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const server = new grpc.Server();
|
|
96
|
+
const port = yield new Promise((resolve, reject) => {
|
|
97
|
+
server.bindAsync('127.0.0.1:0', grpc.ServerCredentials.createInsecure(), (err, p) => (err ? reject(err) : resolve(p)));
|
|
98
|
+
});
|
|
99
|
+
const fake = new FakeSecurityMetricServer(server, port);
|
|
100
|
+
server.addService(security_metric_service_grpc_pb_1.SecurityMetricService, {
|
|
101
|
+
getLatest: fake.getLatest.bind(fake),
|
|
102
|
+
search: fake.search.bind(fake),
|
|
103
|
+
createOrUpdate: fake.createOrUpdate.bind(fake),
|
|
104
|
+
});
|
|
105
|
+
// grpc-js 1.8 (this package's lockfile) serves only after start().
|
|
106
|
+
server.start();
|
|
107
|
+
fake.seed(exports.SPY_UUID, security_metric_type_pb_1.SecurityMetricTypeProto.SHARES_OUTSTANDING, [
|
|
108
|
+
['2026-11-19', '15204137000'],
|
|
109
|
+
['2026-11-20', '15210000000'],
|
|
110
|
+
]);
|
|
111
|
+
return fake;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** `host:port` of the server. */
|
|
115
|
+
get address() {
|
|
116
|
+
return `127.0.0.1:${this.port}`;
|
|
117
|
+
}
|
|
118
|
+
/** Adds points for (uuid, metric). */
|
|
119
|
+
seed(uuid, metric, points) {
|
|
120
|
+
var _a;
|
|
121
|
+
const key = `${uuid}|${metric}`;
|
|
122
|
+
const series = (_a = this.store.get(key)) !== null && _a !== void 0 ? _a : new Map();
|
|
123
|
+
for (const [date, value] of points)
|
|
124
|
+
series.set(date, value);
|
|
125
|
+
this.store.set(key, series);
|
|
126
|
+
}
|
|
127
|
+
/** Stops the server and drops open calls. */
|
|
128
|
+
stop() {
|
|
129
|
+
return new Promise(resolve => {
|
|
130
|
+
this.server.tryShutdown(() => resolve());
|
|
131
|
+
this.server.forceShutdown();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
knows(uuid) {
|
|
135
|
+
for (const key of this.store.keys())
|
|
136
|
+
if (key.startsWith(`${uuid}|`))
|
|
137
|
+
return true;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
sorted(uuid, metric) {
|
|
141
|
+
const series = this.store.get(`${uuid}|${metric}`);
|
|
142
|
+
return series ? [...series.entries()].sort((a, b) => (a[0] < b[0] ? -1 : 1)) : [];
|
|
143
|
+
}
|
|
144
|
+
series(uuid, metric, points, asOf) {
|
|
145
|
+
return (0, object_types_1.stampOwn)(new security_metric_pb_1.SecurityMetricSeriesProto())
|
|
146
|
+
.setSecurityId(uuid)
|
|
147
|
+
.setMetric(metric)
|
|
148
|
+
.setAsOf(timestamp(asOf))
|
|
149
|
+
.setPointsList(points.map(([d, v]) => new security_metric_pb_1.SecurityMetricPointProto()
|
|
150
|
+
.setObservationDate(dateProto(d))
|
|
151
|
+
.setValue((0, decimal_1.encodeDecimal)((0, decimal_1.parseDecimalString)(v)))));
|
|
152
|
+
}
|
|
153
|
+
getLatest(call, callback) {
|
|
154
|
+
this.calls.getLatest++;
|
|
155
|
+
const request = call.request;
|
|
156
|
+
this.getLatestRequests.push(request);
|
|
157
|
+
const on = iso(request.getDate());
|
|
158
|
+
const response = (0, object_types_1.stampOwn)(new get_latest_security_metric_request_pb_1.GetLatestSecurityMetricResponseProto());
|
|
159
|
+
for (const id of [...request.getSecurityIdsList()].reverse()) {
|
|
160
|
+
const uuid = uuidKey(id);
|
|
161
|
+
if (!this.knows(uuid))
|
|
162
|
+
continue;
|
|
163
|
+
for (const metric of request.getMetricsList()) {
|
|
164
|
+
const onOrBefore = this.sorted(uuid, metric).filter(([d]) => d <= on);
|
|
165
|
+
response.addSeries(this.series(id, metric, onOrBefore.slice(-1), AS_OF_BASE_SECONDS));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
callback(null, response);
|
|
169
|
+
}
|
|
170
|
+
search(call) {
|
|
171
|
+
this.calls.search++;
|
|
172
|
+
const request = call.request;
|
|
173
|
+
this.searchRequests.push(request);
|
|
174
|
+
const from = iso(request.getStartDate());
|
|
175
|
+
const to = iso(request.getEndDate());
|
|
176
|
+
const uuid = uuidKey(request.getSecurityId());
|
|
177
|
+
const metric = request.getMetricsList()[0];
|
|
178
|
+
const points = this.sorted(uuid, metric).filter(([d]) => d >= from && d <= to);
|
|
179
|
+
const send = (chunk) => call.write((0, object_types_1.stampOwn)(new search_security_metric_request_pb_1.SearchSecurityMetricResponseProto())
|
|
180
|
+
.setSeries(this.series(request.getSecurityId(), metric, chunk, AS_OF_BASE_SECONDS)));
|
|
181
|
+
if (points.length === 0)
|
|
182
|
+
send([]);
|
|
183
|
+
for (let i = 0; i < points.length; i += 2)
|
|
184
|
+
send(points.slice(i, i + 2));
|
|
185
|
+
call.end();
|
|
186
|
+
}
|
|
187
|
+
createOrUpdate(call, callback) {
|
|
188
|
+
this.calls.createOrUpdate++;
|
|
189
|
+
const request = call.request;
|
|
190
|
+
this.createRequests.push(request);
|
|
191
|
+
const series = request.getSeries();
|
|
192
|
+
if (!series) {
|
|
193
|
+
callback({ code: grpc.status.INVALID_ARGUMENT, details: 'series is required' }, null);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.seed(uuidKey(series.getSecurityId()), series.getMetric(), series.getPointsList().map(p => [iso(p.getObservationDate()), (0, decimal_1.toCanonicalString)((0, decimal_1.decodeDecimal)(p.getValue()))]));
|
|
197
|
+
callback(null, (0, object_types_1.stampOwn)(new create_security_metric_request_pb_1.CreateSecurityMetricResponseProto())
|
|
198
|
+
.setOperationType(request.getOperationType())
|
|
199
|
+
.setSeries(this.series(series.getSecurityId(), series.getMetric(), [], AS_OF_BASE_SECONDS + this.calls.createOrUpdate)));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.FakeSecurityMetricServer = FakeSecurityMetricServer;
|
|
203
|
+
//# sourceMappingURL=security_metric_fake_server.js.map
|
|
@@ -0,0 +1 @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4
|
+
* tests. It counts calls per RPC and keeps every request.
|
|
5
|
+
*
|
|
6
|
+
* - GetLatest: walks the requested securities in reverse order; omits a
|
|
7
|
+
* security with no data for any metric; else returns its latest point on
|
|
8
|
+
* or before `date` (a zero-point series when there is none).
|
|
9
|
+
* - Search: streams the range in messages of 2 points; one zero-point
|
|
10
|
+
* message when there are none.
|
|
11
|
+
* - CreateOrUpdate: stores the points and returns the series header with a
|
|
12
|
+
* distinct as_of per call (2026-11-23T21:00:00Z plus the call count in seconds).
|
|
13
|
+
*/
|
|
14
|
+
import * as grpc from '@grpc/grpc-js';
|
|
15
|
+
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
|
|
16
|
+
|
|
17
|
+
import { SecurityMetricService as SecurityMetricServiceDefinition } from '../../fintekkers/services/security-metric-service/security_metric_service_grpc_pb';
|
|
18
|
+
import { SecurityMetricPointProto, SecurityMetricSeriesProto } from '../../fintekkers/models/security/security_metric_pb';
|
|
19
|
+
import { SecurityMetricTypeProto } from '../../fintekkers/models/security/security_metric_type_pb';
|
|
20
|
+
import { LocalDateProto } from '../../fintekkers/models/util/local_date_pb';
|
|
21
|
+
import { LocalTimestampProto } from '../../fintekkers/models/util/local_timestamp_pb';
|
|
22
|
+
import type { UUIDProto } from '../../fintekkers/models/util/uuid_pb';
|
|
23
|
+
import {
|
|
24
|
+
type CreateSecurityMetricRequestProto,
|
|
25
|
+
CreateSecurityMetricResponseProto,
|
|
26
|
+
} from '../../fintekkers/requests/security_metric/create_security_metric_request_pb';
|
|
27
|
+
import {
|
|
28
|
+
type GetLatestSecurityMetricRequestProto,
|
|
29
|
+
GetLatestSecurityMetricResponseProto,
|
|
30
|
+
} from '../../fintekkers/requests/security_metric/get_latest_security_metric_request_pb';
|
|
31
|
+
import {
|
|
32
|
+
type SearchSecurityMetricRequestProto,
|
|
33
|
+
SearchSecurityMetricResponseProto,
|
|
34
|
+
} from '../../fintekkers/requests/security_metric/search_security_metric_request_pb';
|
|
35
|
+
import { stampOwn } from '../util/object-types';
|
|
36
|
+
import { decodeDecimal, encodeDecimal, parseDecimalString, toCanonicalString } from '../models/utils/decimal';
|
|
37
|
+
import { UUID } from '../models/utils/uuid';
|
|
38
|
+
|
|
39
|
+
/** The seeded SPY security: SHARES_OUTSTANDING 2026-11-19 → 15204137000, 2026-11-20 → 15210000000. */
|
|
40
|
+
export const SPY_UUID = '5f0c2a1e-7b3d-4c8e-9a10-2b3c4d5e6f70';
|
|
41
|
+
|
|
42
|
+
const AS_OF_BASE_SECONDS = Date.UTC(2026, 10, 23, 21, 0, 0) / 1000;
|
|
43
|
+
|
|
44
|
+
function iso(d: LocalDateProto | undefined): string {
|
|
45
|
+
if (!d) return '';
|
|
46
|
+
return `${String(d.getYear()).padStart(4, '0')}-${String(d.getMonth()).padStart(2, '0')}-${String(d.getDay()).padStart(2, '0')}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function dateProto(isoDate: string): LocalDateProto {
|
|
50
|
+
const [y, m, d] = isoDate.split('-').map(s => parseInt(s, 10));
|
|
51
|
+
return new LocalDateProto().setYear(y).setMonth(m).setDay(d);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function uuidKey(p: UUIDProto | undefined): string {
|
|
55
|
+
const u = UUID.fromUUIDProto(p);
|
|
56
|
+
return u ? u.toString() : '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function timestamp(seconds: number): LocalTimestampProto {
|
|
60
|
+
return new LocalTimestampProto().setTimestamp(new Timestamp().setSeconds(seconds).setNanos(0)).setTimeZone('UTC');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class FakeSecurityMetricServer {
|
|
64
|
+
readonly port: number;
|
|
65
|
+
readonly calls = { getLatest: 0, search: 0, createOrUpdate: 0 };
|
|
66
|
+
readonly getLatestRequests: GetLatestSecurityMetricRequestProto[] = [];
|
|
67
|
+
readonly searchRequests: SearchSecurityMetricRequestProto[] = [];
|
|
68
|
+
readonly createRequests: CreateSecurityMetricRequestProto[] = [];
|
|
69
|
+
/** `${uuid}|${metric}` → ISO date → canonical decimal string. */
|
|
70
|
+
private readonly store = new Map<string, Map<string, string>>();
|
|
71
|
+
private readonly server: grpc.Server;
|
|
72
|
+
|
|
73
|
+
private constructor(server: grpc.Server, port: number) {
|
|
74
|
+
this.server = server;
|
|
75
|
+
this.port = port;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Starts a server on 127.0.0.1 with a free port, seeded with SPY. */
|
|
79
|
+
static async start(): Promise<FakeSecurityMetricServer> {
|
|
80
|
+
const server = new grpc.Server();
|
|
81
|
+
const port = await new Promise<number>((resolve, reject) => {
|
|
82
|
+
server.bindAsync('127.0.0.1:0', grpc.ServerCredentials.createInsecure(), (err, p) => (err ? reject(err) : resolve(p)));
|
|
83
|
+
});
|
|
84
|
+
const fake = new FakeSecurityMetricServer(server, port);
|
|
85
|
+
server.addService(SecurityMetricServiceDefinition, {
|
|
86
|
+
getLatest: fake.getLatest.bind(fake),
|
|
87
|
+
search: fake.search.bind(fake),
|
|
88
|
+
createOrUpdate: fake.createOrUpdate.bind(fake),
|
|
89
|
+
});
|
|
90
|
+
// grpc-js 1.8 (this package's lockfile) serves only after start().
|
|
91
|
+
server.start();
|
|
92
|
+
fake.seed(SPY_UUID, SecurityMetricTypeProto.SHARES_OUTSTANDING, [
|
|
93
|
+
['2026-11-19', '15204137000'],
|
|
94
|
+
['2026-11-20', '15210000000'],
|
|
95
|
+
]);
|
|
96
|
+
return fake;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** `host:port` of the server. */
|
|
100
|
+
get address(): string {
|
|
101
|
+
return `127.0.0.1:${this.port}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Adds points for (uuid, metric). */
|
|
105
|
+
seed(uuid: string, metric: SecurityMetricTypeProto, points: Array<[string, string]>): void {
|
|
106
|
+
const key = `${uuid}|${metric}`;
|
|
107
|
+
const series = this.store.get(key) ?? new Map<string, string>();
|
|
108
|
+
for (const [date, value] of points) series.set(date, value);
|
|
109
|
+
this.store.set(key, series);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Stops the server and drops open calls. */
|
|
113
|
+
stop(): Promise<void> {
|
|
114
|
+
return new Promise(resolve => {
|
|
115
|
+
this.server.tryShutdown(() => resolve());
|
|
116
|
+
this.server.forceShutdown();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private knows(uuid: string): boolean {
|
|
121
|
+
for (const key of this.store.keys()) if (key.startsWith(`${uuid}|`)) return true;
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private sorted(uuid: string, metric: SecurityMetricTypeProto): Array<[string, string]> {
|
|
126
|
+
const series = this.store.get(`${uuid}|${metric}`);
|
|
127
|
+
return series ? [...series.entries()].sort((a, b) => (a[0] < b[0] ? -1 : 1)) : [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private series(uuid: UUIDProto | undefined, metric: SecurityMetricTypeProto, points: Array<[string, string]>, asOf: number): SecurityMetricSeriesProto {
|
|
131
|
+
return stampOwn(new SecurityMetricSeriesProto())
|
|
132
|
+
.setSecurityId(uuid)
|
|
133
|
+
.setMetric(metric)
|
|
134
|
+
.setAsOf(timestamp(asOf))
|
|
135
|
+
.setPointsList(points.map(([d, v]) => new SecurityMetricPointProto()
|
|
136
|
+
.setObservationDate(dateProto(d))
|
|
137
|
+
.setValue(encodeDecimal(parseDecimalString(v)))));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private getLatest(
|
|
141
|
+
call: grpc.ServerUnaryCall<GetLatestSecurityMetricRequestProto, GetLatestSecurityMetricResponseProto>,
|
|
142
|
+
callback: grpc.sendUnaryData<GetLatestSecurityMetricResponseProto>,
|
|
143
|
+
): void {
|
|
144
|
+
this.calls.getLatest++;
|
|
145
|
+
const request = call.request;
|
|
146
|
+
this.getLatestRequests.push(request);
|
|
147
|
+
const on = iso(request.getDate());
|
|
148
|
+
const response = stampOwn(new GetLatestSecurityMetricResponseProto());
|
|
149
|
+
for (const id of [...request.getSecurityIdsList()].reverse()) {
|
|
150
|
+
const uuid = uuidKey(id);
|
|
151
|
+
if (!this.knows(uuid)) continue;
|
|
152
|
+
for (const metric of request.getMetricsList()) {
|
|
153
|
+
const onOrBefore = this.sorted(uuid, metric).filter(([d]) => d <= on);
|
|
154
|
+
response.addSeries(this.series(id, metric, onOrBefore.slice(-1), AS_OF_BASE_SECONDS));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
callback(null, response);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private search(call: grpc.ServerWritableStream<SearchSecurityMetricRequestProto, SearchSecurityMetricResponseProto>): void {
|
|
161
|
+
this.calls.search++;
|
|
162
|
+
const request = call.request;
|
|
163
|
+
this.searchRequests.push(request);
|
|
164
|
+
const from = iso(request.getStartDate());
|
|
165
|
+
const to = iso(request.getEndDate());
|
|
166
|
+
const uuid = uuidKey(request.getSecurityId());
|
|
167
|
+
const metric = request.getMetricsList()[0];
|
|
168
|
+
const points = this.sorted(uuid, metric).filter(([d]) => d >= from && d <= to);
|
|
169
|
+
const send = (chunk: Array<[string, string]>) => call.write(stampOwn(new SearchSecurityMetricResponseProto())
|
|
170
|
+
.setSeries(this.series(request.getSecurityId(), metric, chunk, AS_OF_BASE_SECONDS)));
|
|
171
|
+
if (points.length === 0) send([]);
|
|
172
|
+
for (let i = 0; i < points.length; i += 2) send(points.slice(i, i + 2));
|
|
173
|
+
call.end();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private createOrUpdate(
|
|
177
|
+
call: grpc.ServerUnaryCall<CreateSecurityMetricRequestProto, CreateSecurityMetricResponseProto>,
|
|
178
|
+
callback: grpc.sendUnaryData<CreateSecurityMetricResponseProto>,
|
|
179
|
+
): void {
|
|
180
|
+
this.calls.createOrUpdate++;
|
|
181
|
+
const request = call.request;
|
|
182
|
+
this.createRequests.push(request);
|
|
183
|
+
const series = request.getSeries();
|
|
184
|
+
if (!series) {
|
|
185
|
+
callback({ code: grpc.status.INVALID_ARGUMENT, details: 'series is required' }, null);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.seed(uuidKey(series.getSecurityId()), series.getMetric(), series.getPointsList().map(p =>
|
|
189
|
+
[iso(p.getObservationDate()), toCanonicalString(decodeDecimal(p.getValue()!))] as [string, string]));
|
|
190
|
+
callback(null, stampOwn(new CreateSecurityMetricResponseProto())
|
|
191
|
+
.setOperationType(request.getOperationType())
|
|
192
|
+
.setSeries(this.series(series.getSecurityId(), series.getMetric(), [], AS_OF_BASE_SECONDS + this.calls.createOrUpdate)));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
/**
|
|
39
|
+
* LM-485: the "Security metrics" example in ledger-models-javascript/README.md
|
|
40
|
+
* runs here, against the in-memory SecurityMetric server. The code between
|
|
41
|
+
* the README:start and README:end markers must equal the README's example
|
|
42
|
+
* block (after removing common indentation and trailing whitespace).
|
|
43
|
+
*/
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const security_metric_type_pb_1 = require("../../fintekkers/models/security/security_metric_type_pb");
|
|
47
|
+
const security_1 = __importDefault(require("../models/security/security"));
|
|
48
|
+
const security_metric_1 = require("../models/security/security_metric");
|
|
49
|
+
const uuid_1 = require("../models/utils/uuid");
|
|
50
|
+
const SecurityMetricService_1 = require("./security-metric-service/SecurityMetricService");
|
|
51
|
+
const security_metric_fake_server_1 = require("./security_metric_fake_server");
|
|
52
|
+
const README = path.resolve(__dirname, '../../../README.md');
|
|
53
|
+
const EXAMPLE_MARKER = '<!-- tested by node/wrappers/services/security_metric_readme.test.ts -->';
|
|
54
|
+
function normalise(code) {
|
|
55
|
+
const lines = code.split('\n').map(l => l.replace(/\s+$/, ''));
|
|
56
|
+
while (lines.length && lines[0] === '')
|
|
57
|
+
lines.shift();
|
|
58
|
+
while (lines.length && lines[lines.length - 1] === '')
|
|
59
|
+
lines.pop();
|
|
60
|
+
const indents = lines.filter(l => l !== '').map(l => l.length - l.trimStart().length);
|
|
61
|
+
const common = indents.length ? Math.min(...indents) : 0;
|
|
62
|
+
return lines.map(l => l.slice(common)).join('\n');
|
|
63
|
+
}
|
|
64
|
+
function readmeExample() {
|
|
65
|
+
const text = fs.readFileSync(README, 'utf8');
|
|
66
|
+
const at = text.indexOf(EXAMPLE_MARKER);
|
|
67
|
+
expect(at).toBeGreaterThanOrEqual(0);
|
|
68
|
+
const block = /```(?:ts|typescript)\n([\s\S]*?)```/.exec(text.slice(at));
|
|
69
|
+
expect(block).not.toBeNull();
|
|
70
|
+
return normalise(block[1]);
|
|
71
|
+
}
|
|
72
|
+
function testedExample() {
|
|
73
|
+
const source = fs.readFileSync(path.resolve(__dirname, 'security_metric_readme.test.ts'), 'utf8');
|
|
74
|
+
// The markers are comment lines of their own.
|
|
75
|
+
const marked = /^[ \t]*\/\/ README:start\n([\s\S]*?)^[ \t]*\/\/ README:end$/m.exec(source);
|
|
76
|
+
expect(marked).not.toBeNull();
|
|
77
|
+
return normalise(marked[1]);
|
|
78
|
+
}
|
|
79
|
+
let fake;
|
|
80
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
fake = yield security_metric_fake_server_1.FakeSecurityMetricServer.start();
|
|
82
|
+
fake.seed(security_metric_fake_server_1.SPY_UUID, security_metric_type_pb_1.SecurityMetricTypeProto.NAV_PER_SHARE, [['2026-11-20', '512.34']]);
|
|
83
|
+
}));
|
|
84
|
+
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
yield fake.stop();
|
|
86
|
+
}));
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
(0, SecurityMetricService_1.setSecurityMetricService)(SecurityMetricService_1.SecurityMetricService.fromEnv({
|
|
89
|
+
PRICE_SERVICE_HOST: '127.0.0.1',
|
|
90
|
+
PRICE_SERVICE_PORT: String(fake.port),
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
afterEach(() => {
|
|
94
|
+
(0, SecurityMetricService_1.resetSecurityMetricServiceForTests)();
|
|
95
|
+
});
|
|
96
|
+
test('the README example is the code tested here', () => {
|
|
97
|
+
expect(readmeExample()).toBe(testedExample());
|
|
98
|
+
});
|
|
99
|
+
test('the README example runs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const spyUuid = security_metric_fake_server_1.SPY_UUID;
|
|
101
|
+
const qqqUuid = '00000000-0000-4000-8000-000000000999';
|
|
102
|
+
// README:start
|
|
103
|
+
const spy = new security_1.default(security_1.default.linkOfLatest(new uuid_1.UUID(uuid_1.UUID.fromString(spyUuid))));
|
|
104
|
+
// The latest value on or before a date: undefined when there is none, never 0.
|
|
105
|
+
const shares = yield spy.getMetric(security_metric_type_pb_1.SecurityMetricTypeProto.SHARES_OUTSTANDING, '2026-11-23');
|
|
106
|
+
// shares.value: Decimal 15210000000, isoDate(shares.date): '2026-11-20', shares.ageDays: 3
|
|
107
|
+
// Shortcuts; `on` defaults to today.
|
|
108
|
+
const nav = yield spy.navPerShare('2026-11-23');
|
|
109
|
+
// Many securities in one call: every UUID is a key, undefined when it has no value.
|
|
110
|
+
const service = (0, SecurityMetricService_1.getSecurityMetricService)();
|
|
111
|
+
const latest = yield service.get('SHARES_OUTSTANDING', [spyUuid, qqqUuid], '2026-11-23');
|
|
112
|
+
// History in date order, gaps kept; `to` defaults to today.
|
|
113
|
+
const history = yield spy.sharesOutstandingHistory('2026-11-01', '2026-11-23');
|
|
114
|
+
const byDate = history.asDict(); // Map { '2026-11-19' => 15204137000, '2026-11-20' => 15210000000 }
|
|
115
|
+
// Record: points are checked first, then sent; returns the as_of the service stamped.
|
|
116
|
+
const asOf = yield service.record('NAV_PER_SHARE', spyUuid, { '2026-11-23': '513.02' });
|
|
117
|
+
// README:end
|
|
118
|
+
expect(shares.value.toFixed()).toBe('15210000000');
|
|
119
|
+
expect((0, security_metric_1.isoDate)(shares.date)).toBe('2026-11-20');
|
|
120
|
+
expect(shares.ageDays).toBe(3);
|
|
121
|
+
expect(nav.value.toFixed()).toBe('512.34');
|
|
122
|
+
expect([...latest.keys()]).toEqual([spyUuid, qqqUuid]);
|
|
123
|
+
expect(latest.get(spyUuid).value.toFixed()).toBe('15210000000');
|
|
124
|
+
expect(latest.get(qqqUuid)).toBeUndefined();
|
|
125
|
+
expect([...byDate.entries()].map(([d, v]) => [d, v.toFixed()])).toEqual([
|
|
126
|
+
['2026-11-19', '15204137000'],
|
|
127
|
+
['2026-11-20', '15210000000'],
|
|
128
|
+
]);
|
|
129
|
+
expect(asOf.getTimezone()).toBe('UTC');
|
|
130
|
+
expect((yield spy.navPerShare('2026-11-23')).value.toFixed()).toBe('513.02');
|
|
131
|
+
}));
|
|
132
|
+
//# sourceMappingURL=security_metric_readme.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security_metric_readme.test.js","sourceRoot":"","sources":["security_metric_readme.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,uCAAyB;AACzB,2CAA6B;AAC7B,sGAAmG;AACnG,2EAAmD;AACnD,wEAA6D;AAC7D,+CAA4C;AAC5C,2FAKyD;AACzD,+EAAmF;AAEnF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAC7D,MAAM,cAAc,GAAG,0EAA0E,CAAC;AAElG,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CA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