@genesislcap/mock-server 15.7.3-alpha-277c463.0 → 15.7.3-alpha-e7d4aa5.0
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 +237 -52
- package/dist/db/criteria.d.ts +5 -0
- package/dist/db/criteria.js +304 -0
- package/dist/db/metadata.d.ts +3 -0
- package/dist/db/metadata.js +35 -0
- package/dist/db/store.d.ts +27 -0
- package/dist/db/store.js +226 -0
- package/dist/handlers/auth.d.ts +9 -0
- package/dist/handlers/auth.js +99 -0
- package/dist/handlers/commitEvent.d.ts +8 -0
- package/dist/handlers/commitEvent.js +40 -0
- package/dist/handlers/dataLogon.d.ts +5 -0
- package/dist/handlers/dataLogon.js +46 -0
- package/dist/handlers/heartbeat.d.ts +3 -0
- package/dist/handlers/heartbeat.js +16 -0
- package/dist/handlers/http.d.ts +4 -0
- package/dist/handlers/http.js +165 -0
- package/dist/handlers/jsonSchema.d.ts +5 -0
- package/dist/handlers/jsonSchema.js +77 -0
- package/dist/handlers/meta.d.ts +4 -0
- package/dist/handlers/meta.js +42 -0
- package/dist/handlers/requestReply.d.ts +4 -0
- package/dist/handlers/requestReply.js +68 -0
- package/dist/handlers/resourceAuth.d.ts +5 -0
- package/dist/handlers/resourceAuth.js +27 -0
- package/dist/handlers/resources.d.ts +3 -0
- package/dist/handlers/resources.js +34 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/launch.d.ts +19 -0
- package/dist/launch.js +59 -0
- package/dist/protocol/connection.d.ts +24 -0
- package/dist/protocol/connection.js +35 -0
- package/dist/protocol/errors.d.ts +17 -0
- package/dist/protocol/errors.js +16 -0
- package/dist/protocol/messageTypes.d.ts +28 -0
- package/dist/protocol/messageTypes.js +42 -0
- package/dist/protocol/router.d.ts +6 -0
- package/dist/protocol/router.js +101 -0
- package/dist/protocol/rowUpdate.d.ts +4 -0
- package/dist/protocol/rowUpdate.js +17 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +274 -0
- package/dist/types.d.ts +142 -0
- package/dist/types.js +4 -0
- package/package.json +16 -6
- package/src/db/criteria.ts +53 -21
- package/src/db/store.ts +100 -27
- package/src/handlers/commitEvent.ts +13 -5
- package/src/handlers/dataLogon.ts +11 -4
- package/src/handlers/heartbeat.ts +16 -3
- package/src/handlers/http.ts +27 -0
- package/src/handlers/jsonSchema.ts +3 -3
- package/src/handlers/meta.ts +11 -3
- package/src/handlers/requestReply.ts +22 -8
- package/src/handlers/resourceAuth.ts +37 -0
- package/src/handlers/resources.ts +8 -1
- package/src/index.ts +9 -0
- package/src/launch.ts +95 -0
- package/src/protocol/connection.ts +3 -1
- package/src/protocol/messageTypes.ts +9 -0
- package/src/protocol/router.ts +19 -12
- package/src/protocol/rowUpdate.ts +5 -4
- package/src/server.ts +73 -8
- package/src/types.ts +132 -8
- package/test/criteria.test.ts +0 -174
- package/test/jsonSchema.test.ts +0 -38
- package/test/metadata.test.ts +0 -49
- package/test/server.test.ts +0 -289
- package/test/store.test.ts +0 -181
- package/tsconfig.json +0 -18
package/test/store.test.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { beforeEach, describe, it } from 'node:test';
|
|
3
|
-
import { Store } from '../src/db/store.ts';
|
|
4
|
-
|
|
5
|
-
function makeStore(): Store {
|
|
6
|
-
const store = new Store();
|
|
7
|
-
store.registerTable('TRADE', {
|
|
8
|
-
pkField: 'TRADE_ID',
|
|
9
|
-
sequencePrefix: 'TR',
|
|
10
|
-
rows: [
|
|
11
|
-
{ TRADE_ID: 'TR001', INSTRUMENT_ID: 'VOD', COUNTERPARTY_ID: 'CP001', PRICE: 105.5 },
|
|
12
|
-
{ TRADE_ID: 'TR007', INSTRUMENT_ID: 'MSFT', COUNTERPARTY_ID: 'CP002', PRICE: 98 },
|
|
13
|
-
],
|
|
14
|
-
});
|
|
15
|
-
store.registerTable('COUNTERPARTY', {
|
|
16
|
-
pkField: 'COUNTERPARTY_ID',
|
|
17
|
-
rows: [
|
|
18
|
-
{ COUNTERPARTY_ID: 'CP001', NAME: 'Acme' },
|
|
19
|
-
{ COUNTERPARTY_ID: 'CP002', NAME: 'Globex' },
|
|
20
|
-
],
|
|
21
|
-
});
|
|
22
|
-
store.registerView('TRADE_VIEW', {
|
|
23
|
-
base: 'TRADE',
|
|
24
|
-
pkField: 'TRADE_ID',
|
|
25
|
-
joins: [
|
|
26
|
-
{
|
|
27
|
-
table: 'COUNTERPARTY',
|
|
28
|
-
on: ['COUNTERPARTY_ID', 'COUNTERPARTY_ID'],
|
|
29
|
-
select: { COUNTERPARTY_NAME: 'NAME' },
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
derived: { LABEL: (row) => `${row.TRADE_ID}:${row.INSTRUMENT_ID}` },
|
|
33
|
-
});
|
|
34
|
-
return store;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('Store sequences', () => {
|
|
38
|
-
let store: Store;
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
store = makeStore();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('seeds the counter past the highest existing pk for the prefix', () => {
|
|
44
|
-
const row = store.insertRow('TRADE', { INSTRUMENT_ID: 'AMZ' });
|
|
45
|
-
assert.equal(row.TRADE_ID, 'TR008');
|
|
46
|
-
assert.equal(store.insertRow('TRADE', {}).TRADE_ID, 'TR009');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('pads generated pks to the configured width', () => {
|
|
50
|
-
const store2 = new Store();
|
|
51
|
-
store2.registerTable('FILL', { pkField: 'FILL_ID', sequencePrefix: 'FL', sequenceWidth: 5 });
|
|
52
|
-
assert.equal(store2.insertRow('FILL', {}).FILL_ID, 'FL00001');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('throws when inserting without a pk into a table with no sequence', () => {
|
|
56
|
-
assert.throws(() => store.insertRow('COUNTERPARTY', { NAME: 'No PK' }), /Primary key/);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('throws for an unknown table', () => {
|
|
60
|
-
assert.throws(() => store.insertRow('NOPE', {}), /Unknown table/);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('Store.findRow fallback matching', () => {
|
|
65
|
-
let store: Store;
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
store = makeStore();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('matches by the pk field first', () => {
|
|
71
|
-
assert.equal(store.findRow('TRADE', { TRADE_ID: 'TR007' })?.INSTRUMENT_ID, 'MSFT');
|
|
72
|
-
assert.equal(store.findRow('TRADE', { TRADE_ID: 'missing' }), undefined);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('matches by any single field that uniquely identifies one row', () => {
|
|
76
|
-
assert.equal(store.findRow('TRADE', { INSTRUMENT_ID: 'VOD' })?.TRADE_ID, 'TR001');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('matches by the full combination when no single field is unique', () => {
|
|
80
|
-
store.insertRow('TRADE', { INSTRUMENT_ID: 'VOD', COUNTERPARTY_ID: 'CP002' });
|
|
81
|
-
const row = store.findRow('TRADE', { INSTRUMENT_ID: 'VOD', COUNTERPARTY_ID: 'CP002' });
|
|
82
|
-
assert.equal(row?.TRADE_ID, 'TR008');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('returns undefined when the combination matches nothing', () => {
|
|
86
|
-
assert.equal(
|
|
87
|
-
store.findRow('TRADE', { INSTRUMENT_ID: 'VOD', COUNTERPARTY_ID: 'CP999' }),
|
|
88
|
-
undefined,
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('Store row mutation', () => {
|
|
94
|
-
let store: Store;
|
|
95
|
-
beforeEach(() => {
|
|
96
|
-
store = makeStore();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('updateRow merges the patch and returns the updated row', () => {
|
|
100
|
-
const updated = store.updateRow('TRADE', 'TR001', { PRICE: 999 });
|
|
101
|
-
assert.equal(updated?.PRICE, 999);
|
|
102
|
-
assert.equal(updated?.INSTRUMENT_ID, 'VOD');
|
|
103
|
-
assert.equal(store.getRow('TRADE', 'TR001')?.PRICE, 999);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('updateRow returns undefined for a missing pk', () => {
|
|
107
|
-
assert.equal(store.updateRow('TRADE', 'TR999', { PRICE: 1 }), undefined);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('deleteRow removes the row and reports whether it existed', () => {
|
|
111
|
-
assert.equal(store.deleteRow('TRADE', 'TR001'), true);
|
|
112
|
-
assert.equal(store.deleteRow('TRADE', 'TR001'), false);
|
|
113
|
-
assert.equal(store.getRow('TRADE', 'TR001'), undefined);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('Store views', () => {
|
|
118
|
-
let store: Store;
|
|
119
|
-
beforeEach(() => {
|
|
120
|
-
store = makeStore();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('joins aliased fields and computes derived fields', () => {
|
|
124
|
-
const rows = store.getViewRows('TRADE_VIEW');
|
|
125
|
-
assert.equal(rows.length, 2);
|
|
126
|
-
assert.equal(rows[0].COUNTERPARTY_NAME, 'Acme');
|
|
127
|
-
assert.equal(rows[0].LABEL, 'TR001:VOD');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('leaves joined fields undefined when the join has no match', () => {
|
|
131
|
-
store.insertRow('TRADE', { INSTRUMENT_ID: 'AMZ', COUNTERPARTY_ID: 'CP999' });
|
|
132
|
-
const row = store.getViewRows('TRADE_VIEW').find((r) => r.TRADE_ID === 'TR008');
|
|
133
|
-
assert.equal(row?.COUNTERPARTY_NAME, undefined);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('resolves pk fields for views and tables', () => {
|
|
137
|
-
assert.equal(store.getPkField('TRADE_VIEW'), 'TRADE_ID');
|
|
138
|
-
assert.equal(store.getPkField('COUNTERPARTY'), 'COUNTERPARTY_ID');
|
|
139
|
-
assert.equal(store.getPkField('NOPE'), undefined);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('throws for an unknown view', () => {
|
|
143
|
-
assert.throws(() => store.getViewRows('NOPE'), /Unknown view/);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('Store.getMetadataRows seed fallback', () => {
|
|
148
|
-
let store: Store;
|
|
149
|
-
beforeEach(() => {
|
|
150
|
-
store = makeStore();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('returns live rows while any exist', () => {
|
|
154
|
-
store.updateRow('TRADE', 'TR001', { PRICE: 1 });
|
|
155
|
-
const rows = store.getMetadataRows('TRADE');
|
|
156
|
-
assert.equal(rows.find((r) => r.TRADE_ID === 'TR001')?.PRICE, 1);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('falls back to seed rows after every live row is deleted', () => {
|
|
160
|
-
store.deleteRow('TRADE', 'TR001');
|
|
161
|
-
store.deleteRow('TRADE', 'TR007');
|
|
162
|
-
assert.equal(store.getResourceRows('TRADE').length, 0);
|
|
163
|
-
const rows = store.getMetadataRows('TRADE');
|
|
164
|
-
assert.equal(rows.length, 2);
|
|
165
|
-
assert.deepEqual(Object.keys(rows[0]), [
|
|
166
|
-
'TRADE_ID',
|
|
167
|
-
'INSTRUMENT_ID',
|
|
168
|
-
'COUNTERPARTY_ID',
|
|
169
|
-
'PRICE',
|
|
170
|
-
]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('re-joins views through seed data when the base table is emptied', () => {
|
|
174
|
-
store.deleteRow('TRADE', 'TR001');
|
|
175
|
-
store.deleteRow('TRADE', 'TR007');
|
|
176
|
-
const rows = store.getMetadataRows('TRADE_VIEW');
|
|
177
|
-
assert.equal(rows.length, 2);
|
|
178
|
-
assert.equal(rows[0].COUNTERPARTY_NAME, 'Acme');
|
|
179
|
-
assert.equal(rows[0].LABEL, 'TR001:VOD');
|
|
180
|
-
});
|
|
181
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ESNext"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noUncheckedIndexedAccess": false,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
"allowJs": false,
|
|
14
|
-
"allowImportingTsExtensions": true,
|
|
15
|
-
"verbatimModuleSyntax": false
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*.ts", "test/**/*.ts"]
|
|
18
|
-
}
|