@genesislcap/mock-server 15.74.0 → 15.76.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 +296 -58
- package/dist/db/schema.d.ts +9 -1
- package/dist/db/schema.js +40 -11
- package/dist/db/store.d.ts +1 -0
- package/dist/db/store.js +4 -0
- package/dist/handlers/auth.d.ts +15 -6
- package/dist/handlers/auth.js +152 -33
- package/dist/handlers/commitEvent.js +43 -20
- package/dist/handlers/crudEvents.d.ts +3 -1
- package/dist/handlers/crudEvents.js +3 -2
- package/dist/handlers/eventValidation.js +6 -3
- package/dist/handlers/http.d.ts +2 -2
- package/dist/handlers/http.js +66 -43
- package/dist/handlers/jsonSchema.d.ts +1 -0
- package/dist/handlers/jsonSchema.js +72 -21
- package/dist/handlers/meta.d.ts +1 -1
- package/dist/handlers/meta.js +59 -10
- package/dist/handlers/requestReply.js +36 -9
- package/dist/index.d.ts +1 -1
- package/dist/presets/auth.d.ts +25 -0
- package/dist/presets/auth.js +855 -0
- package/dist/presets/cronExpression.d.ts +1 -0
- package/dist/presets/cronExpression.js +429 -0
- package/dist/presets/fileServer.d.ts +13 -0
- package/dist/presets/fileServer.js +399 -0
- package/dist/presets/gsf.d.ts +24 -0
- package/dist/presets/gsf.js +450 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/javaTime.d.ts +7 -0
- package/dist/presets/javaTime.js +322 -0
- package/dist/presets/multipart.d.ts +14 -0
- package/dist/presets/multipart.js +91 -0
- package/dist/presets/notify.d.ts +27 -0
- package/dist/presets/notify.js +250 -0
- package/dist/presets/notifyDispatch.d.ts +28 -0
- package/dist/presets/notifyDispatch.js +570 -0
- package/dist/presets/notifyRules.d.ts +9 -0
- package/dist/presets/notifyRules.js +754 -0
- package/dist/presets/platform/backing.json +8058 -217
- package/dist/presets/platform/criteria-model.json +362 -0
- package/dist/presets/platform/time-zones.json +608 -0
- package/dist/presets/platform.d.ts +7 -0
- package/dist/presets/platform.js +145 -103
- package/dist/presets/products.d.ts +9 -7
- package/dist/presets/products.js +89 -21
- package/dist/presets/reconciliation.d.ts +18 -0
- package/dist/presets/reconciliation.js +721 -0
- package/dist/presets/reporting.d.ts +14 -0
- package/dist/presets/reporting.js +862 -0
- package/dist/protocol/connection.d.ts +2 -0
- package/dist/protocol/connection.js +4 -0
- package/dist/protocol/dtoTypes.d.ts +30 -0
- package/dist/protocol/dtoTypes.js +250 -0
- package/dist/protocol/errors.d.ts +3 -1
- package/dist/protocol/errors.js +2 -0
- package/dist/protocol/fieldTypes.js +5 -0
- package/dist/protocol/router.d.ts +1 -0
- package/dist/protocol/router.js +3 -3
- package/dist/protocol/schemaValidation.d.ts +1 -1
- package/dist/protocol/schemaValidation.js +53 -8
- package/dist/server.js +34 -2
- package/dist/types.d.ts +50 -2
- package/package.json +1 -1
- package/src/db/schema.ts +56 -13
- package/src/db/store.ts +5 -0
- package/src/handlers/auth.ts +211 -37
- package/src/handlers/commitEvent.ts +44 -19
- package/src/handlers/crudEvents.ts +9 -2
- package/src/handlers/eventValidation.ts +6 -3
- package/src/handlers/http.ts +83 -42
- package/src/handlers/jsonSchema.ts +86 -23
- package/src/handlers/meta.ts +77 -9
- package/src/handlers/requestReply.ts +42 -6
- package/src/index.ts +7 -0
- package/src/presets/auth.ts +961 -0
- package/src/presets/cronExpression.ts +445 -0
- package/src/presets/fileServer.ts +475 -0
- package/src/presets/gsf.ts +475 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/javaTime.ts +354 -0
- package/src/presets/multipart.ts +110 -0
- package/src/presets/notify.ts +312 -0
- package/src/presets/notifyDispatch.ts +685 -0
- package/src/presets/notifyRules.ts +866 -0
- package/src/presets/platform/backing.json +8058 -217
- package/src/presets/platform/criteria-model.json +362 -0
- package/src/presets/platform/time-zones.json +608 -0
- package/src/presets/platform.ts +204 -115
- package/src/presets/products.ts +125 -19
- package/src/presets/reconciliation.ts +824 -0
- package/src/presets/reporting.ts +953 -0
- package/src/protocol/connection.ts +4 -0
- package/src/protocol/dtoTypes.ts +310 -0
- package/src/protocol/errors.ts +13 -1
- package/src/protocol/fieldTypes.ts +5 -0
- package/src/protocol/router.ts +3 -3
- package/src/protocol/schemaValidation.ts +61 -8
- package/src/server.ts +38 -2
- package/src/types.ts +147 -3
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
import { primaryKeyIndexName } from "../db/schema.js";
|
|
2
|
+
import { checkUnique } from "../handlers/crudEvents.js";
|
|
3
|
+
import { NackError } from "../protocol/errors.js";
|
|
4
|
+
import { kotlinString } from "./javaTime.js";
|
|
5
|
+
import { dto, nullable } from "./notify.js";
|
|
6
|
+
// --- schemas ---------------------------------------------------------------------
|
|
7
|
+
const MESSAGES = 'global.genesis.recon.messages';
|
|
8
|
+
const enumOf = (table, name, className, values, more = {}) => dto(name, 'ENUM', {
|
|
9
|
+
values,
|
|
10
|
+
enumClass: `global.genesis.gen.dao.enums.reconciliation.${table}.${className}`,
|
|
11
|
+
...more,
|
|
12
|
+
});
|
|
13
|
+
const FIELD_TYPES = [
|
|
14
|
+
'STRING',
|
|
15
|
+
'SHORT',
|
|
16
|
+
'INT',
|
|
17
|
+
'LONG',
|
|
18
|
+
'DOUBLE',
|
|
19
|
+
'RAW',
|
|
20
|
+
'BOOLEAN',
|
|
21
|
+
'BIGDECIMAL',
|
|
22
|
+
'DATETIME',
|
|
23
|
+
'DATE',
|
|
24
|
+
'NANO_TIMESTAMP',
|
|
25
|
+
];
|
|
26
|
+
const TOLERANCE_TYPES = ['EQUALITY', 'PERCENTAGE', 'ABSOLUTE', 'DAYS', 'MINUTES'];
|
|
27
|
+
const STRATEGIES = ['ONE_TO_ONE', 'ONE_TO_MANY', 'MANY_TO_MANY'];
|
|
28
|
+
const fieldType = (more = {}) => enumOf('data_dictionary_field', 'FIELD_TYPE', 'FieldType', FIELD_TYPES, more);
|
|
29
|
+
const strategy = (more = {}) => enumOf('reconciliation_config', 'RECONCILIATION_STRATEGY', 'ReconciliationStrategy', STRATEGIES, more);
|
|
30
|
+
const listOf = (name, className, fields) => dto(name, 'ARRAY', { items: { type: 'OBJECT', className, nullable: false, fields } });
|
|
31
|
+
// ReconciliationRuleData: no defaults, so a nullable TOLERANCE_VALUE is sent too.
|
|
32
|
+
const RULES = listOf('RULES', `${MESSAGES}.ReconciliationRuleData`, [
|
|
33
|
+
dto('FIELD_NAME', 'STRING'),
|
|
34
|
+
fieldType(),
|
|
35
|
+
dto('IS_MATCH_KEY', 'BOOLEAN'),
|
|
36
|
+
enumOf('reconciliation_rule', 'TOLERANCE_TYPE', 'ToleranceType', TOLERANCE_TYPES),
|
|
37
|
+
dto('TOLERANCE_VALUE', 'STRING', { nullable: true }),
|
|
38
|
+
]);
|
|
39
|
+
const DATASOURCES = listOf('DATASOURCES', `${MESSAGES}.DatasourceConfigData`, [
|
|
40
|
+
dto('NAME', 'STRING'),
|
|
41
|
+
enumOf('datasource_config', 'TYPE', 'Type', ['FILE', 'DATABASE', 'PIPELINE']),
|
|
42
|
+
dto('INDEX', 'INT'),
|
|
43
|
+
dto('CONFIG_DATA', 'STRING', nullable),
|
|
44
|
+
]);
|
|
45
|
+
const SCHEMAS = {
|
|
46
|
+
EVENT_DATA_DICTIONARY_INSERT: {
|
|
47
|
+
className: `${MESSAGES}.ReconDictionaryInsert`,
|
|
48
|
+
fields: [
|
|
49
|
+
dto('DICTIONARY_NAME', 'STRING'),
|
|
50
|
+
listOf('FIELDS', `${MESSAGES}.Field`, [dto('FIELD_NAME', 'STRING'), fieldType()]),
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
// DataDictionary unwrapped, its fields as table entities.
|
|
54
|
+
EVENT_DATA_DICTIONARY_UPDATE: {
|
|
55
|
+
className: `${MESSAGES}.ReconDictionaryUpdate`,
|
|
56
|
+
fields: [
|
|
57
|
+
dto('DICTIONARY_ID', 'STRING'),
|
|
58
|
+
dto('DICTIONARY_NAME', 'STRING'),
|
|
59
|
+
listOf('FIELDS', 'global.genesis.gen.dao.DataDictionaryField', [
|
|
60
|
+
dto('DICTIONARY_ID', 'STRING'),
|
|
61
|
+
dto('FIELD_NAME', 'STRING'),
|
|
62
|
+
fieldType({ optional: true }),
|
|
63
|
+
]),
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
EVENT_DATA_DICTIONARY_DELETE: {
|
|
67
|
+
table: 'DATA_DICTIONARY',
|
|
68
|
+
pkOnly: true,
|
|
69
|
+
className: 'global.genesis.gen.dao.DataDictionary.ByDictionaryId',
|
|
70
|
+
},
|
|
71
|
+
EVENT_RECONCILIATION_CONFIG_INSERT: {
|
|
72
|
+
className: `${MESSAGES}.ReconciliationConfigInsert`,
|
|
73
|
+
fields: [
|
|
74
|
+
dto('NAME', 'STRING'),
|
|
75
|
+
dto('DICTIONARY_ID', 'STRING'),
|
|
76
|
+
strategy(),
|
|
77
|
+
RULES,
|
|
78
|
+
DATASOURCES,
|
|
79
|
+
dto('MATCH_NULL', 'BOOLEAN', { optional: true }),
|
|
80
|
+
dto('PRIMARY_DATASOURCE_NAME', 'STRING', nullable),
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
// ReconciliationConfig unwrapped: its key and defaulted columns optional,
|
|
84
|
+
// as the generated entity has them.
|
|
85
|
+
EVENT_RECONCILIATION_CONFIG_UPDATE: {
|
|
86
|
+
className: `${MESSAGES}.ReconciliationConfigUpdate`,
|
|
87
|
+
fields: [
|
|
88
|
+
RULES,
|
|
89
|
+
DATASOURCES,
|
|
90
|
+
dto('RECONCILIATION_CONFIG_ID', 'STRING', { optional: true }),
|
|
91
|
+
dto('NAME', 'STRING'),
|
|
92
|
+
dto('DICTIONARY_ID', 'STRING'),
|
|
93
|
+
strategy({ optional: true }),
|
|
94
|
+
dto('PRIMARY_DATASOURCE', 'STRING', nullable),
|
|
95
|
+
dto('MATCH_NULL', 'BOOLEAN', { optional: true }),
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
EVENT_RECONCILIATION_CONFIG_DELETE: {
|
|
99
|
+
table: 'RECONCILIATION_CONFIG',
|
|
100
|
+
pkOnly: true,
|
|
101
|
+
className: 'global.genesis.gen.dao.ReconciliationConfig.ById',
|
|
102
|
+
},
|
|
103
|
+
EVENT_RUN_RECONCILIATION: {
|
|
104
|
+
className: `${MESSAGES}.ReconciliationRun`,
|
|
105
|
+
fields: [
|
|
106
|
+
dto('RECONCILIATION_CONFIG_NAME', 'STRING', nullable),
|
|
107
|
+
dto('RECONCILIATION_CONFIG_ID', 'STRING', nullable),
|
|
108
|
+
dto('RECONCILIATION_NAME', 'STRING'),
|
|
109
|
+
dto('INPUT_PARAMETERS', 'MAP', { items: { type: 'MAP' } }),
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
EVENT_CANCEL_RECONCILIATION: {
|
|
113
|
+
table: 'RECONCILIATION',
|
|
114
|
+
pkOnly: true,
|
|
115
|
+
className: 'global.genesis.gen.dao.Reconciliation.ById',
|
|
116
|
+
},
|
|
117
|
+
EVENT_UPDATE_RESULT_COMMENT: {
|
|
118
|
+
className: `${MESSAGES}.RecordComment`,
|
|
119
|
+
fields: [dto('TEXT', 'STRING'), dto('RECORD_RESULT_ID', 'STRING')],
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// --- validators ----------------------------------------------------------------------
|
|
123
|
+
// ReconStrategyUtils.validateStrategyElseThrow.
|
|
124
|
+
const MANY = 3;
|
|
125
|
+
function validateStrategy(count, reconStrategy, primary) {
|
|
126
|
+
if (reconStrategy === 'ONE_TO_ONE' && count !== 2) {
|
|
127
|
+
throw new NackError('Reconciliation strategy of ONE_TO_ONE must have two data sources');
|
|
128
|
+
}
|
|
129
|
+
if (reconStrategy === 'ONE_TO_MANY') {
|
|
130
|
+
if (count < MANY) {
|
|
131
|
+
throw new NackError('Reconciliation strategy of ONE_TO_MANY must have three or more data sources');
|
|
132
|
+
}
|
|
133
|
+
if (primary === null || primary === undefined || String(primary).trim() === '') {
|
|
134
|
+
throw new NackError('Reconciliation strategy of ONE_TO_MANY must have a primary datasource');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (reconStrategy === 'MANY_TO_MANY' && count < MANY) {
|
|
138
|
+
throw new NackError('Reconciliation strategy of MANY_TO_MANY must have at least three data sources');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ReconStrategyUtils.createDataSourcePairs: which datasources are compared.
|
|
142
|
+
function dataSourcePairs(reconStrategy, names, primary) {
|
|
143
|
+
validateStrategy(names.length, reconStrategy, primary);
|
|
144
|
+
const pair = (FIRST_DATA_SOURCE_NAME, SECOND_DATA_SOURCE_NAME) => ({
|
|
145
|
+
FIRST_DATA_SOURCE_NAME,
|
|
146
|
+
SECOND_DATA_SOURCE_NAME,
|
|
147
|
+
});
|
|
148
|
+
if (reconStrategy === 'ONE_TO_ONE')
|
|
149
|
+
return [pair(names[0], names.at(-1))];
|
|
150
|
+
if (reconStrategy === 'ONE_TO_MANY') {
|
|
151
|
+
const at = names.indexOf(String(primary));
|
|
152
|
+
return names.flatMap((name, i) => {
|
|
153
|
+
if (name === primary)
|
|
154
|
+
return [];
|
|
155
|
+
return [i < at ? pair(name, String(primary)) : pair(String(primary), name)];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return names.flatMap((name, i) => names
|
|
159
|
+
.slice(i)
|
|
160
|
+
.filter((other) => other !== name)
|
|
161
|
+
.map((other) => pair(name, other)));
|
|
162
|
+
}
|
|
163
|
+
// Kotlin's String.toLongOrNull, toDoubleOrNull and toBigDecimalOrNull.
|
|
164
|
+
const LONG_MAX = 9223372036854775807n;
|
|
165
|
+
const isLong = (s) => /^[+-]?\d+$/.test(s) && BigInt(s) <= LONG_MAX && BigInt(s) >= -LONG_MAX - 1n;
|
|
166
|
+
// Java's Double grammar, the characters up to a space trimmed off each end.
|
|
167
|
+
const SPACE = 0x20;
|
|
168
|
+
const trimToSpace = (s) => {
|
|
169
|
+
let start = 0;
|
|
170
|
+
let end = s.length;
|
|
171
|
+
while (start < end && s.charCodeAt(start) <= SPACE)
|
|
172
|
+
start += 1;
|
|
173
|
+
while (end > start && s.charCodeAt(end - 1) <= SPACE)
|
|
174
|
+
end -= 1;
|
|
175
|
+
return s.slice(start, end);
|
|
176
|
+
};
|
|
177
|
+
const isDouble = (s) => /^[+-]?(NaN|Infinity|((\d+\.?\d*|\.\d+)([eE][+-]?\d+)?[fFdD]?))$/.test(trimToSpace(s));
|
|
178
|
+
const isBigDecimal = (s) => /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(s);
|
|
179
|
+
const anyValue = () => true;
|
|
180
|
+
// A whole number: one with only zeros after its point is too.
|
|
181
|
+
const whole = (value) => {
|
|
182
|
+
if (value === null)
|
|
183
|
+
return false;
|
|
184
|
+
if (!value.includes('.'))
|
|
185
|
+
return isLong(value);
|
|
186
|
+
return isDouble(value) && /^0*$/.test(value.slice(value.lastIndexOf('.') + 1));
|
|
187
|
+
};
|
|
188
|
+
const number = (value) => value !== null && isBigDecimal(value);
|
|
189
|
+
const EQUALITY_ONLY = { EQUALITY: anyValue };
|
|
190
|
+
const NUMERIC = { EQUALITY: anyValue, ABSOLUTE: whole, PERCENTAGE: whole };
|
|
191
|
+
// FieldToleranceUtils' table: each field type's tolerance types, in order,
|
|
192
|
+
// and the check on a tolerance value.
|
|
193
|
+
const TOLERANCES = {
|
|
194
|
+
STRING: EQUALITY_ONLY,
|
|
195
|
+
SHORT: NUMERIC,
|
|
196
|
+
INT: NUMERIC,
|
|
197
|
+
LONG: NUMERIC,
|
|
198
|
+
DOUBLE: NUMERIC,
|
|
199
|
+
RAW: EQUALITY_ONLY,
|
|
200
|
+
BOOLEAN: EQUALITY_ONLY,
|
|
201
|
+
BIGDECIMAL: { EQUALITY: anyValue, ABSOLUTE: number, PERCENTAGE: whole },
|
|
202
|
+
DATETIME: { EQUALITY: anyValue, MINUTES: whole },
|
|
203
|
+
DATE: { EQUALITY: anyValue, DAYS: whole },
|
|
204
|
+
NANO_TIMESTAMP: EQUALITY_ONLY,
|
|
205
|
+
};
|
|
206
|
+
// FieldToleranceUtils.isValidFieldTolerancesElseThrow.
|
|
207
|
+
function validateTolerances(rules) {
|
|
208
|
+
for (const rule of rules) {
|
|
209
|
+
const tolerances = TOLERANCES[rule.FIELD_TYPE];
|
|
210
|
+
if (!tolerances)
|
|
211
|
+
throw new NackError(`Unsupported Field Type '${rule.FIELD_TYPE}'`);
|
|
212
|
+
const check = tolerances[rule.TOLERANCE_TYPE];
|
|
213
|
+
if (!check) {
|
|
214
|
+
throw new NackError(`Field Type '${rule.FIELD_TYPE}' does not support Tolerance Type '${rule.TOLERANCE_TYPE}'`);
|
|
215
|
+
}
|
|
216
|
+
const value = rule.TOLERANCE_VALUE ?? null;
|
|
217
|
+
if (!check(value)) {
|
|
218
|
+
throw new NackError(`Tolerance value '${value}' is not supported for ${rule.FIELD_TYPE} -> ${rule.TOLERANCE_TYPE} pair`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Jackson's default pretty printer: objects a field a line, `"key" : value`,
|
|
223
|
+
// arrays inline.
|
|
224
|
+
function prettyJson(value, indent = '') {
|
|
225
|
+
if (Array.isArray(value)) {
|
|
226
|
+
return value.length ? `[ ${value.map((item) => prettyJson(item, indent)).join(', ')} ]` : '[ ]';
|
|
227
|
+
}
|
|
228
|
+
if (value !== null && typeof value === 'object') {
|
|
229
|
+
const entries = Object.entries(value);
|
|
230
|
+
if (!entries.length)
|
|
231
|
+
return '{ }';
|
|
232
|
+
const inner = `${indent} `;
|
|
233
|
+
return `{\n${entries
|
|
234
|
+
.map(([key, item]) => `${inner}${JSON.stringify(key)} : ${prettyJson(item, inner)}`)
|
|
235
|
+
.join(',\n')}\n${indent}}`;
|
|
236
|
+
}
|
|
237
|
+
return JSON.stringify(value ?? null);
|
|
238
|
+
}
|
|
239
|
+
// --- writes ------------------------------------------------------------------------
|
|
240
|
+
function insert(ctx, table, row) {
|
|
241
|
+
checkUnique(table, ctx.config.tables[table], row, ctx.store);
|
|
242
|
+
const written = ctx.store.insertRow(table, row);
|
|
243
|
+
ctx.broadcastTableChange(table, 'INSERT', ctx.store.rowKey(table, written));
|
|
244
|
+
return written;
|
|
245
|
+
}
|
|
246
|
+
function modify(ctx, table, key, patch) {
|
|
247
|
+
const def = ctx.config.tables[table];
|
|
248
|
+
const existing = ctx.store.getRow(table, key);
|
|
249
|
+
if (!existing)
|
|
250
|
+
throw NackError.recordNotFound(table, primaryKeyIndexName(table, def));
|
|
251
|
+
checkUnique(table, def, { ...existing, ...patch }, ctx.store, key);
|
|
252
|
+
const written = ctx.store.updateRow(table, key, patch);
|
|
253
|
+
ctx.broadcastTableChange(table, 'MODIFY', key);
|
|
254
|
+
return written;
|
|
255
|
+
}
|
|
256
|
+
function remove(ctx, table, key) {
|
|
257
|
+
if (!ctx.store.deleteRow(table, key))
|
|
258
|
+
throw NackError.recordNotFound(table);
|
|
259
|
+
ctx.broadcastTableChange(table, 'DELETE', key);
|
|
260
|
+
}
|
|
261
|
+
const rowsWhere = (store, table, column, value) => store.getAllRows(table).filter((row) => row[column] === value);
|
|
262
|
+
const removeWhere = (ctx, table, column, value) => {
|
|
263
|
+
for (const row of rowsWhere(ctx.store, table, column, value))
|
|
264
|
+
remove(ctx, table, ctx.store.rowKey(table, row));
|
|
265
|
+
};
|
|
266
|
+
// A configuration's datasources, by INDEX (a nullable INT, 0 when unset).
|
|
267
|
+
const datasourcesOf = (store, configId) => rowsWhere(store, 'DATASOURCE_CONFIG', 'RECONCILIATION_CONFIG_ID', configId).sort((a, b) => Number(a.INDEX ?? 0) - Number(b.INDEX ?? 0));
|
|
268
|
+
// ReconciliationManager's live runs: the IN_PROGRESS ones, here.
|
|
269
|
+
const activeConfigIds = (store) => rowsWhere(store, 'RECONCILIATION', 'STATUS', 'IN_PROGRESS').map((row) => row.RECONCILIATION_CONFIG_ID);
|
|
270
|
+
const LIVE_RUN = 'Reconciliation Config ID is currently being used by a live reconciliation run';
|
|
271
|
+
const isBlank = (value) => value === undefined || value === null || String(value).trim() === '';
|
|
272
|
+
// The longest a Node timer waits (2^31 - 1 ms); a longer one fires at once.
|
|
273
|
+
const MAX_TIMER_MS = 2_147_483_647;
|
|
274
|
+
// Writes outside the event, audited as `audit` when given: what a
|
|
275
|
+
// non-transactional handler keeps though its event NACKs, and what the run
|
|
276
|
+
// writes once it's over.
|
|
277
|
+
function writeAfter(ctx, audit, write, retry = false) {
|
|
278
|
+
const { store } = ctx;
|
|
279
|
+
// Inside the event (its transaction still open): once it's over, before
|
|
280
|
+
// the next message; then, should a transaction stay open, on a timer that
|
|
281
|
+
// neither spins nor keeps the process up.
|
|
282
|
+
if (store.inTransaction) {
|
|
283
|
+
const again = () => writeAfter(ctx, audit, write, true);
|
|
284
|
+
if (retry)
|
|
285
|
+
setTimeout(again, 1).unref();
|
|
286
|
+
else
|
|
287
|
+
setImmediate(again);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!audit) {
|
|
291
|
+
try {
|
|
292
|
+
write();
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
console.warn('[mock-server] reconciliation: a write after the event failed:', error);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
store.begin(audit);
|
|
300
|
+
try {
|
|
301
|
+
write();
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
store.rollback();
|
|
305
|
+
console.warn('[mock-server] reconciliation: a write after the event failed:', error);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const audits = store.takeAuditWrites();
|
|
309
|
+
store.commit();
|
|
310
|
+
for (const { tableName, key } of audits)
|
|
311
|
+
ctx.broadcastTableChange(tableName, 'INSERT', key);
|
|
312
|
+
}
|
|
313
|
+
export function reconciliationBacking(options) {
|
|
314
|
+
const { userOf } = options;
|
|
315
|
+
// DataSourceFactory.getDataSourceDetails: what each datasource needs before
|
|
316
|
+
// the run can start. A pipeline is only read once the run has started.
|
|
317
|
+
function checkDatasources(store, sources, inputs) {
|
|
318
|
+
for (const source of sources) {
|
|
319
|
+
if (source.TYPE === 'DATABASE')
|
|
320
|
+
throw new NackError('DataSource Type DATABASE has not been implemented yet!');
|
|
321
|
+
if (source.TYPE === 'PIPELINE')
|
|
322
|
+
continue;
|
|
323
|
+
const input = inputs[source.NAME];
|
|
324
|
+
if (input === undefined || input === null) {
|
|
325
|
+
throw new NackError(`Details for datasource: ${source.NAME} can't be found in the input parameters!`);
|
|
326
|
+
}
|
|
327
|
+
if (isBlank(input.FILE_STORAGE_ID)) {
|
|
328
|
+
throw new NackError(`File Storage Id has not been provided for input parameter ${kotlinString(input)}`);
|
|
329
|
+
}
|
|
330
|
+
const content = options.fileContent?.(store, String(input.FILE_STORAGE_ID));
|
|
331
|
+
if (!content)
|
|
332
|
+
continue;
|
|
333
|
+
if ('error' in content)
|
|
334
|
+
throw new NackError(content.error);
|
|
335
|
+
const extension = content.fileName.slice(content.fileName.lastIndexOf('.') + 1);
|
|
336
|
+
// Named for the datasource, not the extension.
|
|
337
|
+
if (extension !== 'csv')
|
|
338
|
+
throw new NackError(`File type for ${source.NAME} has not been implemented yet!`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// The run over: COMPLETED, unless it was cancelled meanwhile, or FAILED
|
|
342
|
+
// when it reads a pipeline that has no name (onReconciliationFailed: the
|
|
343
|
+
// message as thrown).
|
|
344
|
+
function complete(ctx, id, sources) {
|
|
345
|
+
const unnamed = sources.some((source) => source.TYPE === 'PIPELINE' && isBlank(source.CONFIG_DATA));
|
|
346
|
+
// A run that never ends: Infinity, or past what a timer can wait.
|
|
347
|
+
if (!(options.runMs <= MAX_TIMER_MS))
|
|
348
|
+
return;
|
|
349
|
+
setTimeout(() => {
|
|
350
|
+
writeAfter(ctx, undefined, () => {
|
|
351
|
+
const run = ctx.store.getRow('RECONCILIATION', id);
|
|
352
|
+
if (run?.STATUS !== 'IN_PROGRESS')
|
|
353
|
+
return;
|
|
354
|
+
ctx.store.updateRow('RECONCILIATION', id, {
|
|
355
|
+
STATUS: unnamed ? 'FAILED' : 'COMPLETED',
|
|
356
|
+
...(unnamed
|
|
357
|
+
? { MESSAGE: 'Unable to invoke pipeline as no pipeline name was specified' }
|
|
358
|
+
: {}),
|
|
359
|
+
END_TIMESTAMP: Date.now(),
|
|
360
|
+
});
|
|
361
|
+
ctx.broadcastTableChange('RECONCILIATION', 'MODIFY', id);
|
|
362
|
+
});
|
|
363
|
+
}, options.runMs).unref();
|
|
364
|
+
}
|
|
365
|
+
const eventHandlers = {
|
|
366
|
+
// EH :35-62
|
|
367
|
+
EVENT_DATA_DICTIONARY_INSERT: (details, ctx) => {
|
|
368
|
+
if (String(details.DICTIONARY_NAME).trim() === '')
|
|
369
|
+
throw new NackError('Dictionary name must not be empty');
|
|
370
|
+
if (!details.FIELDS.length) {
|
|
371
|
+
throw new NackError('One or more fields are required to create a dictionary');
|
|
372
|
+
}
|
|
373
|
+
if (ctx.validate)
|
|
374
|
+
return {};
|
|
375
|
+
const dictionary = insert(ctx, 'DATA_DICTIONARY', {
|
|
376
|
+
DICTIONARY_NAME: details.DICTIONARY_NAME,
|
|
377
|
+
});
|
|
378
|
+
for (const field of details.FIELDS) {
|
|
379
|
+
insert(ctx, 'DATA_DICTIONARY_FIELD', {
|
|
380
|
+
DICTIONARY_ID: dictionary.DICTIONARY_ID,
|
|
381
|
+
FIELD_NAME: field.FIELD_NAME,
|
|
382
|
+
FIELD_TYPE: field.FIELD_TYPE,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return { generated: [{ DICTIONARY_ID: dictionary.DICTIONARY_ID }] };
|
|
386
|
+
},
|
|
387
|
+
// EH :64-87: the fields replaced by those sent, each with its own
|
|
388
|
+
// DICTIONARY_ID.
|
|
389
|
+
EVENT_DATA_DICTIONARY_UPDATE: (details, ctx) => {
|
|
390
|
+
if (isBlank(details.DICTIONARY_ID))
|
|
391
|
+
throw new NackError('Dictionary ID must not be empty');
|
|
392
|
+
if (isBlank(details.DICTIONARY_NAME))
|
|
393
|
+
throw new NackError('Dictionary name must not be empty');
|
|
394
|
+
if (!details.FIELDS.length)
|
|
395
|
+
throw new NackError('Dictionary fields must not be empty');
|
|
396
|
+
if (ctx.validate)
|
|
397
|
+
return {};
|
|
398
|
+
const id = details.DICTIONARY_ID;
|
|
399
|
+
modify(ctx, 'DATA_DICTIONARY', id, { DICTIONARY_NAME: details.DICTIONARY_NAME });
|
|
400
|
+
removeWhere(ctx, 'DATA_DICTIONARY_FIELD', 'DICTIONARY_ID', id);
|
|
401
|
+
for (const field of details.FIELDS) {
|
|
402
|
+
insert(ctx, 'DATA_DICTIONARY_FIELD', {
|
|
403
|
+
DICTIONARY_ID: field.DICTIONARY_ID,
|
|
404
|
+
FIELD_NAME: field.FIELD_NAME,
|
|
405
|
+
FIELD_TYPE: field.FIELD_TYPE ?? 'STRING',
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
return {};
|
|
409
|
+
},
|
|
410
|
+
// EH :89-105: a configuration using it is left pointing at nothing.
|
|
411
|
+
EVENT_DATA_DICTIONARY_DELETE: (details, ctx) => {
|
|
412
|
+
if (isBlank(details.DICTIONARY_ID))
|
|
413
|
+
throw new NackError('Dictionary ID must not be empty');
|
|
414
|
+
if (ctx.validate)
|
|
415
|
+
return {};
|
|
416
|
+
remove(ctx, 'DATA_DICTIONARY', details.DICTIONARY_ID);
|
|
417
|
+
removeWhere(ctx, 'DATA_DICTIONARY_FIELD', 'DICTIONARY_ID', details.DICTIONARY_ID);
|
|
418
|
+
return {};
|
|
419
|
+
},
|
|
420
|
+
// EH :107-157
|
|
421
|
+
EVENT_RECONCILIATION_CONFIG_INSERT: (details, ctx) => {
|
|
422
|
+
validateStrategy(details.DATASOURCES.length, details.RECONCILIATION_STRATEGY, details.PRIMARY_DATASOURCE_NAME);
|
|
423
|
+
validateTolerances(details.RULES);
|
|
424
|
+
if (!ctx.store.getRow('DATA_DICTIONARY', details.DICTIONARY_ID)) {
|
|
425
|
+
throw new NackError(`Data Dictionary of ID ${details.DICTIONARY_ID} doesn't exist!`);
|
|
426
|
+
}
|
|
427
|
+
if (ctx.validate)
|
|
428
|
+
return {};
|
|
429
|
+
const config = insert(ctx, 'RECONCILIATION_CONFIG', {
|
|
430
|
+
NAME: details.NAME,
|
|
431
|
+
DICTIONARY_ID: details.DICTIONARY_ID,
|
|
432
|
+
RECONCILIATION_STRATEGY: details.RECONCILIATION_STRATEGY,
|
|
433
|
+
MATCH_NULL: details.MATCH_NULL ?? false,
|
|
434
|
+
PRIMARY_DATASOURCE: details.PRIMARY_DATASOURCE_NAME ?? null,
|
|
435
|
+
});
|
|
436
|
+
writeRules(ctx, config.RECONCILIATION_CONFIG_ID, details);
|
|
437
|
+
return { generated: [{ RECONCILIATION_CONFIG_ID: config.RECONCILIATION_CONFIG_ID }] };
|
|
438
|
+
},
|
|
439
|
+
// EH :160-212: the whole row replaced, rules and datasources too.
|
|
440
|
+
EVENT_RECONCILIATION_CONFIG_UPDATE: (details, ctx) => {
|
|
441
|
+
validateStrategy(details.DATASOURCES.length, details.RECONCILIATION_STRATEGY ?? 'ONE_TO_ONE', details.PRIMARY_DATASOURCE);
|
|
442
|
+
validateTolerances(details.RULES);
|
|
443
|
+
if (!ctx.store.getRow('DATA_DICTIONARY', details.DICTIONARY_ID)) {
|
|
444
|
+
throw new NackError(`Data Dictionary of ID ${details.DICTIONARY_ID} doesn't exist!`);
|
|
445
|
+
}
|
|
446
|
+
if (activeConfigIds(ctx.store).includes(details.RECONCILIATION_CONFIG_ID))
|
|
447
|
+
throw new NackError(LIVE_RUN);
|
|
448
|
+
if (ctx.validate)
|
|
449
|
+
return {};
|
|
450
|
+
const id = details.RECONCILIATION_CONFIG_ID;
|
|
451
|
+
modify(ctx, 'RECONCILIATION_CONFIG', id, {
|
|
452
|
+
NAME: details.NAME,
|
|
453
|
+
DICTIONARY_ID: details.DICTIONARY_ID,
|
|
454
|
+
RECONCILIATION_STRATEGY: details.RECONCILIATION_STRATEGY ?? 'ONE_TO_ONE',
|
|
455
|
+
PRIMARY_DATASOURCE: details.PRIMARY_DATASOURCE ?? null,
|
|
456
|
+
MATCH_NULL: details.MATCH_NULL ?? false,
|
|
457
|
+
});
|
|
458
|
+
removeWhere(ctx, 'RECONCILIATION_RULE', 'RECONCILIATION_CONFIG_ID', id);
|
|
459
|
+
removeWhere(ctx, 'DATASOURCE_CONFIG', 'RECONCILIATION_CONFIG_ID', id);
|
|
460
|
+
writeRules(ctx, id, details);
|
|
461
|
+
return {};
|
|
462
|
+
},
|
|
463
|
+
// EH :215-235: its past runs are kept.
|
|
464
|
+
EVENT_RECONCILIATION_CONFIG_DELETE: (details, ctx) => {
|
|
465
|
+
const id = details.RECONCILIATION_CONFIG_ID;
|
|
466
|
+
if (!ctx.store.getRow('RECONCILIATION_CONFIG', id)) {
|
|
467
|
+
throw new NackError(`Reconciliation Configuration of ID ${id} doesn't exist!`);
|
|
468
|
+
}
|
|
469
|
+
if (activeConfigIds(ctx.store).includes(id))
|
|
470
|
+
throw new NackError(LIVE_RUN);
|
|
471
|
+
if (ctx.validate)
|
|
472
|
+
return {};
|
|
473
|
+
remove(ctx, 'RECONCILIATION_CONFIG', id);
|
|
474
|
+
removeWhere(ctx, 'RECONCILIATION_RULE', 'RECONCILIATION_CONFIG_ID', id);
|
|
475
|
+
removeWhere(ctx, 'DATASOURCE_CONFIG', 'RECONCILIATION_CONFIG_ID', id);
|
|
476
|
+
return {};
|
|
477
|
+
},
|
|
478
|
+
// EH :238-282, ReconciliationManager.runReconciliation. Not transactional:
|
|
479
|
+
// a run that fails to start NACKs, and its row stays FAILED.
|
|
480
|
+
EVENT_RUN_RECONCILIATION: (details, ctx) => {
|
|
481
|
+
const id = details.RECONCILIATION_CONFIG_ID ?? null;
|
|
482
|
+
const name = details.RECONCILIATION_CONFIG_NAME ?? null;
|
|
483
|
+
if (id === null && name === null) {
|
|
484
|
+
throw new NackError('Either configuration ID or configuration name must be provided');
|
|
485
|
+
}
|
|
486
|
+
let config;
|
|
487
|
+
if (id !== null)
|
|
488
|
+
config = ctx.store.getRow('RECONCILIATION_CONFIG', id);
|
|
489
|
+
else {
|
|
490
|
+
// getRange(ByName).toList().first(): NoSuchElementException.
|
|
491
|
+
[config] = rowsWhere(ctx.store, 'RECONCILIATION_CONFIG', 'NAME', name);
|
|
492
|
+
if (!config)
|
|
493
|
+
throw NackError.nack('List is empty.');
|
|
494
|
+
}
|
|
495
|
+
if (!config)
|
|
496
|
+
throw new NackError(`Reconciliation Config for ID ${id} can't be found!`);
|
|
497
|
+
const sources = datasourcesOf(ctx.store, config.RECONCILIATION_CONFIG_ID);
|
|
498
|
+
if (!sources.length) {
|
|
499
|
+
throw new NackError(`No datasource config has been set up for Reconciliation Config ID: ${id}`);
|
|
500
|
+
}
|
|
501
|
+
validateStrategy(sources.length, config.RECONCILIATION_STRATEGY, config.PRIMARY_DATASOURCE);
|
|
502
|
+
if (!rowsWhere(ctx.store, 'DATA_DICTIONARY_FIELD', 'DICTIONARY_ID', config.DICTIONARY_ID).length) {
|
|
503
|
+
throw new NackError(`No fields have been set up for Data Dictionary ID: ${config.DICTIONARY_ID}`);
|
|
504
|
+
}
|
|
505
|
+
if (ctx.validate)
|
|
506
|
+
return {};
|
|
507
|
+
const run = insert(ctx, 'RECONCILIATION', {
|
|
508
|
+
RECONCILIATION_CONFIG_ID: config.RECONCILIATION_CONFIG_ID,
|
|
509
|
+
RECONCILIATION_NAME: isBlank(details.RECONCILIATION_NAME)
|
|
510
|
+
? config.NAME
|
|
511
|
+
: details.RECONCILIATION_NAME,
|
|
512
|
+
STATUS: 'IN_PROGRESS',
|
|
513
|
+
INPUT_PARAMETERS: prettyJson(details.INPUT_PARAMETERS),
|
|
514
|
+
START_TIMESTAMP: Date.now(),
|
|
515
|
+
MESSAGE: null,
|
|
516
|
+
CANCELED_BY: null,
|
|
517
|
+
END_TIMESTAMP: null,
|
|
518
|
+
});
|
|
519
|
+
try {
|
|
520
|
+
checkDatasources(ctx.store, sources, details.INPUT_PARAMETERS);
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
const message = error instanceof NackError ? error.errors[0]?.TEXT : String(error);
|
|
524
|
+
const { RECONCILIATION_ID, RECORD_ID, TIMESTAMP, ...columns } = run;
|
|
525
|
+
const audit = { eventType: ctx.message.MESSAGE_TYPE, user: userOf(ctx), text: null };
|
|
526
|
+
// Under fidelity: 'legacy' no transaction undoes the IN_PROGRESS row:
|
|
527
|
+
// that one fails; else it is written again once the event rolls back.
|
|
528
|
+
const kept = !ctx.store.inTransaction;
|
|
529
|
+
writeAfter(ctx, audit, () => {
|
|
530
|
+
const id = kept
|
|
531
|
+
? RECONCILIATION_ID
|
|
532
|
+
: ctx.store.insertRow('RECONCILIATION', columns).RECONCILIATION_ID;
|
|
533
|
+
if (!kept)
|
|
534
|
+
ctx.broadcastTableChange('RECONCILIATION', 'INSERT', id);
|
|
535
|
+
ctx.store.updateRow('RECONCILIATION', id, {
|
|
536
|
+
STATUS: 'FAILED',
|
|
537
|
+
MESSAGE: `Error caught while attempting to start reconciliation task, ${message}`,
|
|
538
|
+
});
|
|
539
|
+
ctx.broadcastTableChange('RECONCILIATION', 'MODIFY', id);
|
|
540
|
+
});
|
|
541
|
+
throw error;
|
|
542
|
+
}
|
|
543
|
+
complete(ctx, run.RECONCILIATION_ID, sources);
|
|
544
|
+
return { generated: [{ RECONCILIATION_ID: run.RECONCILIATION_ID }] };
|
|
545
|
+
},
|
|
546
|
+
// EH :285-303: cancelled once the event is over, as the workflow does.
|
|
547
|
+
EVENT_CANCEL_RECONCILIATION: (details, ctx) => {
|
|
548
|
+
const user = userOf(ctx);
|
|
549
|
+
const id = details.RECONCILIATION_ID;
|
|
550
|
+
if (isBlank(user))
|
|
551
|
+
throw new NackError('No User name has been provided');
|
|
552
|
+
const run = ctx.store.getRow('RECONCILIATION', id);
|
|
553
|
+
if (!run)
|
|
554
|
+
throw new NackError(`Reconciliation record does not exist for ID: ${id}`);
|
|
555
|
+
if (run.STATUS !== 'IN_PROGRESS') {
|
|
556
|
+
throw new NackError(`Reconciliation of ID: ${id} cannot be cancelled as it is not running. The current status is: ${run.STATUS}`);
|
|
557
|
+
}
|
|
558
|
+
if (ctx.validate)
|
|
559
|
+
return {};
|
|
560
|
+
setImmediate(() => writeAfter(ctx, undefined, () => {
|
|
561
|
+
// Unless it has ended since.
|
|
562
|
+
if (ctx.store.getRow('RECONCILIATION', id)?.STATUS !== 'IN_PROGRESS')
|
|
563
|
+
return;
|
|
564
|
+
ctx.store.updateRow('RECONCILIATION', id, {
|
|
565
|
+
STATUS: 'CANCELLED',
|
|
566
|
+
CANCELED_BY: user,
|
|
567
|
+
END_TIMESTAMP: Date.now(),
|
|
568
|
+
});
|
|
569
|
+
ctx.broadcastTableChange('RECONCILIATION', 'MODIFY', id);
|
|
570
|
+
}));
|
|
571
|
+
return {};
|
|
572
|
+
},
|
|
573
|
+
// EH :306-326: one comment a result, replaced.
|
|
574
|
+
EVENT_UPDATE_RESULT_COMMENT: (details, ctx) => {
|
|
575
|
+
const id = details.RECORD_RESULT_ID;
|
|
576
|
+
if (isBlank(id))
|
|
577
|
+
throw new NackError('Comment can not be added as record result id is missing');
|
|
578
|
+
if (!ctx.store.getRow('RECONCILIATION_RECORD_RESULT', id)) {
|
|
579
|
+
throw new NackError(`Comment could not be added as record result for ID '${id}' does not exist`);
|
|
580
|
+
}
|
|
581
|
+
if (ctx.validate)
|
|
582
|
+
return {};
|
|
583
|
+
const comment = {
|
|
584
|
+
RECONCILIATION_RECORD_RESULT_ID: id,
|
|
585
|
+
TEXT: details.TEXT,
|
|
586
|
+
USER_NAME: userOf(ctx),
|
|
587
|
+
};
|
|
588
|
+
if (ctx.store.getRow('RECONCILIATION_RECORD_RESULT_COMMENT', id)) {
|
|
589
|
+
modify(ctx, 'RECONCILIATION_RECORD_RESULT_COMMENT', id, comment);
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
insert(ctx, 'RECONCILIATION_RECORD_RESULT_COMMENT', comment);
|
|
593
|
+
}
|
|
594
|
+
return {};
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
// A configuration's rules and datasources, under its id.
|
|
598
|
+
function writeRules(ctx, configId, details) {
|
|
599
|
+
for (const rule of details.RULES) {
|
|
600
|
+
insert(ctx, 'RECONCILIATION_RULE', {
|
|
601
|
+
RECONCILIATION_CONFIG_ID: configId,
|
|
602
|
+
FIELD_NAME: rule.FIELD_NAME,
|
|
603
|
+
IS_MATCH_KEY: rule.IS_MATCH_KEY,
|
|
604
|
+
TOLERANCE_TYPE: rule.TOLERANCE_TYPE,
|
|
605
|
+
TOLERANCE_VALUE: rule.TOLERANCE_VALUE ?? null,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
for (const source of details.DATASOURCES) {
|
|
609
|
+
insert(ctx, 'DATASOURCE_CONFIG', {
|
|
610
|
+
RECONCILIATION_CONFIG_ID: configId,
|
|
611
|
+
NAME: source.NAME,
|
|
612
|
+
TYPE: source.TYPE,
|
|
613
|
+
INDEX: source.INDEX,
|
|
614
|
+
CONFIG_DATA: source.CONFIG_DATA ?? null,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
// --- request servers --------------------------------------------------------------
|
|
619
|
+
// RECONCILIATION_DATA_SOURCE_PAIRS (RR :69-89).
|
|
620
|
+
const pairs = ({ request, store }) => {
|
|
621
|
+
const id = request.RECONCILIATION_ID;
|
|
622
|
+
if (isBlank(id))
|
|
623
|
+
throw new Error('Reconciliation ID is missing');
|
|
624
|
+
const run = store.getRow('RECONCILIATION', id);
|
|
625
|
+
if (!run)
|
|
626
|
+
throw new Error(`Reconciliation with ID '${id}' does not exist`);
|
|
627
|
+
const config = store.getRow('RECONCILIATION_CONFIG', run.RECONCILIATION_CONFIG_ID);
|
|
628
|
+
if (!config) {
|
|
629
|
+
throw new Error(`Reconciliation Config with ID '${run.RECONCILIATION_CONFIG_ID}' does not exist`);
|
|
630
|
+
}
|
|
631
|
+
const names = datasourcesOf(store, config.RECONCILIATION_CONFIG_ID).map((row) => row.NAME);
|
|
632
|
+
// A strategy the datasources don't fit is an exception like any other:
|
|
633
|
+
// GENERIC_ERROR, with its text.
|
|
634
|
+
try {
|
|
635
|
+
return [
|
|
636
|
+
{
|
|
637
|
+
PAIRS: dataSourcePairs(config.RECONCILIATION_STRATEGY, names, config.PRIMARY_DATASOURCE),
|
|
638
|
+
},
|
|
639
|
+
];
|
|
640
|
+
}
|
|
641
|
+
catch (error) {
|
|
642
|
+
if (error instanceof NackError)
|
|
643
|
+
throw new Error(error.errors[0]?.TEXT);
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
// RECONCILIATION_RECORD_PAIR_RESULT (RR :92-135): each side's rule values.
|
|
648
|
+
const pairResult = ({ request, store }) => {
|
|
649
|
+
const id = request.RECONCILIATION_RECORD_RESULT_ID;
|
|
650
|
+
if (isBlank(id))
|
|
651
|
+
throw new Error('Reconciliation Record Result ID is missing');
|
|
652
|
+
const result = store.getRow('RECONCILIATION_RECORD_RESULT', id);
|
|
653
|
+
if (!result)
|
|
654
|
+
throw new Error(`Reconciliation Record Result of ID '${id}' does not exist`);
|
|
655
|
+
const rules = rowsWhere(store, 'RECONCILIATION_RULE_RESULT', 'RECONCILIATION_RECORD_RESULT_ID', id);
|
|
656
|
+
const side = (name, value) => ({
|
|
657
|
+
DATA_SOURCE_NAME: name ?? null,
|
|
658
|
+
RULES_INFO: rules.map((rule) => ({
|
|
659
|
+
FIELD_NAME: rule.FIELD_NAME,
|
|
660
|
+
FIELD_VALUE: rule[value] ?? null,
|
|
661
|
+
RESULT: rule.RESULT,
|
|
662
|
+
})),
|
|
663
|
+
});
|
|
664
|
+
return [
|
|
665
|
+
{
|
|
666
|
+
KEY_RESULT: result.KEY_RESULT,
|
|
667
|
+
COMPARISON_RESULT: result.COMPARISON_RESULT,
|
|
668
|
+
FIRST_DATA_SOURCE_DATA: side(result.FIRST_DATASOURCE_NAME, 'FIRST_VALUE'),
|
|
669
|
+
SECOND_DATA_SOURCE_DATA: side(result.SECOND_DATASOURCE_NAME, 'SECOND_VALUE'),
|
|
670
|
+
},
|
|
671
|
+
];
|
|
672
|
+
};
|
|
673
|
+
return {
|
|
674
|
+
eventHandlers,
|
|
675
|
+
eventSchemas: SCHEMAS,
|
|
676
|
+
requestReplies: {
|
|
677
|
+
// RR :148-156: every running run's configuration, repeats kept.
|
|
678
|
+
ACTIVE_RECONCILIATION_CONFIG_IDS: {
|
|
679
|
+
requestFields: [],
|
|
680
|
+
resolver: ({ store }) => activeConfigIds(store).map((RECONCILIATION_CONFIG_ID) => ({ RECONCILIATION_CONFIG_ID })),
|
|
681
|
+
metadataRows: [{ RECONCILIATION_CONFIG_ID: '' }],
|
|
682
|
+
},
|
|
683
|
+
// RR :138-146: a field type's tolerance types; REQUEST is the type.
|
|
684
|
+
FIELD_TYPE_TOLERANCES: {
|
|
685
|
+
requestFields: [],
|
|
686
|
+
resolver: ({ message }) => Object.keys(TOLERANCES[String(message.REQUEST)] ?? {}).map((TOLERANCE_TYPE) => ({
|
|
687
|
+
TOLERANCE_TYPE,
|
|
688
|
+
})),
|
|
689
|
+
metadataRows: [{ TOLERANCE_TYPE: 'EQUALITY' }],
|
|
690
|
+
},
|
|
691
|
+
// reconciliation-data-pipelines-reqrep.kts :8-18.
|
|
692
|
+
RECONCILIATION_DATA_PIPELINES: {
|
|
693
|
+
requestFields: [],
|
|
694
|
+
resolver: () => [
|
|
695
|
+
{
|
|
696
|
+
BATCH_DATA_SOURCE_NAMES: [...(options.pipelines ?? [])],
|
|
697
|
+
REAL_TIME_DATA_SOURCE_NAMES: [],
|
|
698
|
+
},
|
|
699
|
+
],
|
|
700
|
+
metadataRows: [{ BATCH_DATA_SOURCE_NAMES: [], REAL_TIME_DATA_SOURCE_NAMES: [] }],
|
|
701
|
+
},
|
|
702
|
+
RECONCILIATION_DATA_SOURCE_PAIRS: {
|
|
703
|
+
requestFields: ['RECONCILIATION_ID'],
|
|
704
|
+
resolver: pairs,
|
|
705
|
+
metadataRows: [{ PAIRS: [] }],
|
|
706
|
+
},
|
|
707
|
+
RECONCILIATION_RECORD_PAIR_RESULT: {
|
|
708
|
+
requestFields: ['RECONCILIATION_RECORD_RESULT_ID'],
|
|
709
|
+
resolver: pairResult,
|
|
710
|
+
metadataRows: [
|
|
711
|
+
{
|
|
712
|
+
KEY_RESULT: 'MATCHED',
|
|
713
|
+
COMPARISON_RESULT: 'MATCHED',
|
|
714
|
+
FIRST_DATA_SOURCE_DATA: {},
|
|
715
|
+
SECOND_DATA_SOURCE_DATA: {},
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
};
|
|
721
|
+
}
|