@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.
Files changed (100) hide show
  1. package/README.md +296 -58
  2. package/dist/db/schema.d.ts +9 -1
  3. package/dist/db/schema.js +40 -11
  4. package/dist/db/store.d.ts +1 -0
  5. package/dist/db/store.js +4 -0
  6. package/dist/handlers/auth.d.ts +15 -6
  7. package/dist/handlers/auth.js +152 -33
  8. package/dist/handlers/commitEvent.js +43 -20
  9. package/dist/handlers/crudEvents.d.ts +3 -1
  10. package/dist/handlers/crudEvents.js +3 -2
  11. package/dist/handlers/eventValidation.js +6 -3
  12. package/dist/handlers/http.d.ts +2 -2
  13. package/dist/handlers/http.js +66 -43
  14. package/dist/handlers/jsonSchema.d.ts +1 -0
  15. package/dist/handlers/jsonSchema.js +72 -21
  16. package/dist/handlers/meta.d.ts +1 -1
  17. package/dist/handlers/meta.js +59 -10
  18. package/dist/handlers/requestReply.js +36 -9
  19. package/dist/index.d.ts +1 -1
  20. package/dist/presets/auth.d.ts +25 -0
  21. package/dist/presets/auth.js +855 -0
  22. package/dist/presets/cronExpression.d.ts +1 -0
  23. package/dist/presets/cronExpression.js +429 -0
  24. package/dist/presets/fileServer.d.ts +13 -0
  25. package/dist/presets/fileServer.js +399 -0
  26. package/dist/presets/gsf.d.ts +24 -0
  27. package/dist/presets/gsf.js +450 -0
  28. package/dist/presets/index.d.ts +1 -0
  29. package/dist/presets/index.js +1 -0
  30. package/dist/presets/javaTime.d.ts +7 -0
  31. package/dist/presets/javaTime.js +322 -0
  32. package/dist/presets/multipart.d.ts +14 -0
  33. package/dist/presets/multipart.js +91 -0
  34. package/dist/presets/notify.d.ts +27 -0
  35. package/dist/presets/notify.js +250 -0
  36. package/dist/presets/notifyDispatch.d.ts +28 -0
  37. package/dist/presets/notifyDispatch.js +570 -0
  38. package/dist/presets/notifyRules.d.ts +9 -0
  39. package/dist/presets/notifyRules.js +754 -0
  40. package/dist/presets/platform/backing.json +8058 -217
  41. package/dist/presets/platform/criteria-model.json +362 -0
  42. package/dist/presets/platform/time-zones.json +608 -0
  43. package/dist/presets/platform.d.ts +7 -0
  44. package/dist/presets/platform.js +145 -103
  45. package/dist/presets/products.d.ts +9 -7
  46. package/dist/presets/products.js +89 -21
  47. package/dist/presets/reconciliation.d.ts +18 -0
  48. package/dist/presets/reconciliation.js +721 -0
  49. package/dist/presets/reporting.d.ts +14 -0
  50. package/dist/presets/reporting.js +862 -0
  51. package/dist/protocol/connection.d.ts +2 -0
  52. package/dist/protocol/connection.js +4 -0
  53. package/dist/protocol/dtoTypes.d.ts +30 -0
  54. package/dist/protocol/dtoTypes.js +250 -0
  55. package/dist/protocol/errors.d.ts +3 -1
  56. package/dist/protocol/errors.js +2 -0
  57. package/dist/protocol/fieldTypes.js +5 -0
  58. package/dist/protocol/router.d.ts +1 -0
  59. package/dist/protocol/router.js +3 -3
  60. package/dist/protocol/schemaValidation.d.ts +1 -1
  61. package/dist/protocol/schemaValidation.js +53 -8
  62. package/dist/server.js +34 -2
  63. package/dist/types.d.ts +50 -2
  64. package/package.json +1 -1
  65. package/src/db/schema.ts +56 -13
  66. package/src/db/store.ts +5 -0
  67. package/src/handlers/auth.ts +211 -37
  68. package/src/handlers/commitEvent.ts +44 -19
  69. package/src/handlers/crudEvents.ts +9 -2
  70. package/src/handlers/eventValidation.ts +6 -3
  71. package/src/handlers/http.ts +83 -42
  72. package/src/handlers/jsonSchema.ts +86 -23
  73. package/src/handlers/meta.ts +77 -9
  74. package/src/handlers/requestReply.ts +42 -6
  75. package/src/index.ts +7 -0
  76. package/src/presets/auth.ts +961 -0
  77. package/src/presets/cronExpression.ts +445 -0
  78. package/src/presets/fileServer.ts +475 -0
  79. package/src/presets/gsf.ts +475 -0
  80. package/src/presets/index.ts +5 -0
  81. package/src/presets/javaTime.ts +354 -0
  82. package/src/presets/multipart.ts +110 -0
  83. package/src/presets/notify.ts +312 -0
  84. package/src/presets/notifyDispatch.ts +685 -0
  85. package/src/presets/notifyRules.ts +866 -0
  86. package/src/presets/platform/backing.json +8058 -217
  87. package/src/presets/platform/criteria-model.json +362 -0
  88. package/src/presets/platform/time-zones.json +608 -0
  89. package/src/presets/platform.ts +204 -115
  90. package/src/presets/products.ts +125 -19
  91. package/src/presets/reconciliation.ts +824 -0
  92. package/src/presets/reporting.ts +953 -0
  93. package/src/protocol/connection.ts +4 -0
  94. package/src/protocol/dtoTypes.ts +310 -0
  95. package/src/protocol/errors.ts +13 -1
  96. package/src/protocol/fieldTypes.ts +5 -0
  97. package/src/protocol/router.ts +3 -3
  98. package/src/protocol/schemaValidation.ts +61 -8
  99. package/src/server.ts +38 -2
  100. package/src/types.ts +147 -3
@@ -0,0 +1,475 @@
1
+ // GSF's own resources in the platform preset (genesis 8.15.29): the system
2
+ // information request servers system-info-reqrep.kts declares, over the
3
+ // server's dictionary, and the status dataservers GSF registers in code
4
+ // (StatusDataserver.java), over the tables its Resource Daemon fills.
5
+ // Behaviour read from GSF's source and checked against its jars (the
6
+ // handoff's research-gsf-system.md).
7
+ import { createContext, Script } from 'node:vm';
8
+ import { auditTableName } from '../db/audit.ts';
9
+ import { pkFieldsOf } from '../db/schema.ts';
10
+ import { NackError } from '../protocol/errors.ts';
11
+ import type {
12
+ FieldDef,
13
+ MockServerConfig,
14
+ QueryDef,
15
+ RequestReplyDef,
16
+ Row,
17
+ TableDef,
18
+ TypedRequestReply,
19
+ ViewDef,
20
+ } from '../types.ts';
21
+ import { dto } from './notify.ts';
22
+ import { aliasedEnumKeys, fieldFormat, isPlatformTable, platformTable } from './products.ts';
23
+
24
+ const SYSINFO = 'global.genesis.console.sysinfo';
25
+
26
+ // The views the preset declares only to serve a resource GSF serves with a
27
+ // renamed column (platform.ts, auth.ts); GSF's dictionary has none of them.
28
+ export const SERVING_VIEWS = new Set([
29
+ 'PROFILE_PREFIXED',
30
+ 'RIGHT_PREFIXED',
31
+ 'USER_PROFILE_NAMES',
32
+ 'SYSTEM_STATUS_BYTES',
33
+ ]);
34
+
35
+ // The table an audit table is, when `name` is one (<TABLE>_AUDIT of an
36
+ // audited table).
37
+ function auditedTableOf(config: MockServerConfig, name: string): string | undefined {
38
+ const tables = config.tables ?? {};
39
+ const base = Object.keys(tables).find(
40
+ (table) => auditTableName(table) === name && Boolean(tables[table].audit),
41
+ );
42
+ return base;
43
+ }
44
+
45
+ /**
46
+ * GSF's getAllEntityNames (DbReflectionUtils.kt:116-123): the dictionary's
47
+ * tables, each audit table right after its table, then the views. GSF lists
48
+ * the tables by product, in its dictionary files' HashMap order (which the
49
+ * app's own file names decide), then declaration order: here, in the
50
+ * config's order.
51
+ */
52
+ export function entityNames(config: MockServerConfig): string[] {
53
+ const tables = Object.keys(config.tables ?? {});
54
+ const audits = new Set(tables.filter((name) => auditedTableOf(config, name)));
55
+ const ordered = tables
56
+ .filter((name) => !audits.has(name))
57
+ .flatMap((name) => (audits.has(auditTableName(name)) ? [name, auditTableName(name)] : [name]));
58
+ const views = Object.keys(config.views ?? {}).filter((name) => !SERVING_VIEWS.has(name));
59
+ return [...ordered, ...views];
60
+ }
61
+
62
+ // --- Java patterns -------------------------------------------------------------------
63
+
64
+ // PatternSyntaxException.getMessage (Java 17): the description, the index
65
+ // when there is one, the pattern, and a caret under the index when it's
66
+ // inside the pattern.
67
+ function patternError(description: string, index: number, pattern: string): Error {
68
+ const near = index >= 0 ? ` near index ${index}` : '';
69
+ const caret = index >= 0 && index < pattern.length ? `\n${' '.repeat(index)}^` : '';
70
+ return new Error(`${description}${near}\n${pattern}${caret}`);
71
+ }
72
+
73
+ // The characters a JavaScript (u-mode) pattern needs escaped to mean
74
+ // themselves.
75
+ const JS_SYNTAX = new Set('^$\\.*+?()[]{}|/');
76
+ const ALNUM = /[0-9A-Za-z]/;
77
+ const literal = (char: string) => (JS_SYNTAX.has(char) ? `\\${char}` : char);
78
+ // Java's anchors, as a whole-string match reads them.
79
+ const ANCHORS: Record<string, string> = { A: '^', z: '$', Z: '(?=\\n?$)' };
80
+ const CASE_INSENSITIVE = '(?i)';
81
+
82
+ // The escape at `index` (a backslash), as JavaScript spells it, and the
83
+ // index of its last character.
84
+ function escaped(pattern: string, index: number, inClass: boolean): { text: string; end: number } {
85
+ const next = pattern[index + 1] ?? '';
86
+ const end = index + 1;
87
+ if (inClass) return { text: ALNUM.test(next) || next === '-' ? `\\${next}` : literal(next), end };
88
+ if (next === 'Q') {
89
+ const close = pattern.indexOf('\\E', end + 1);
90
+ const quoted = pattern.slice(end + 1, close === -1 ? pattern.length : close);
91
+ return {
92
+ text: [...quoted].map(literal).join(''),
93
+ end: close === -1 ? pattern.length : close + 1,
94
+ };
95
+ }
96
+ if (next in ANCHORS) return { text: ANCHORS[next], end };
97
+ // Any other letter or digit as JavaScript reads it (\d, \p{Lu}, ...).
98
+ return { text: ALNUM.test(next) ? `\\${next}` : literal(next), end };
99
+ }
100
+
101
+ // Kotlin's toRegex() and String.matches: a whole-string java.util.regex
102
+ // match. A pattern Java refuses fails with its PatternSyntaxException
103
+ // message for the mistakes a name pattern makes (a quantifier with nothing
104
+ // to repeat, an unmatched or unclosed group, an unclosed class); the Java
105
+ // spellings JavaScript lacks are translated (\Q...\E, \A, \z, \Z, a leading
106
+ // (?i), a backslash before a character that needs none), and what
107
+ // JavaScript can't express at all (an inline flag after the start, Java's
108
+ // own escapes) fails with JavaScript's message.
109
+ export function javaPattern(pattern: string): RegExp {
110
+ let source = '';
111
+ let flags = 'u';
112
+ let depth = 0;
113
+ let inClass = false;
114
+ // What came last: nothing to repeat, something that can be, a quantifier,
115
+ // or a lazy/possessive mark on one.
116
+ let last: 'none' | 'atom' | 'quantifier' | 'marked' = 'none';
117
+ let index = 0;
118
+ if (pattern.startsWith(CASE_INSENSITIVE)) {
119
+ flags += 'i';
120
+ index = CASE_INSENSITIVE.length;
121
+ }
122
+ for (; index < pattern.length; index += 1) {
123
+ const char = pattern[index];
124
+ if (char === '\\') {
125
+ const escape = escaped(pattern, index, inClass);
126
+ source += escape.text;
127
+ index = escape.end;
128
+ if (!inClass) last = 'atom';
129
+ } else if (inClass) {
130
+ source += char;
131
+ if (char === ']') {
132
+ inClass = false;
133
+ last = 'atom';
134
+ }
135
+ } else if (char === '[') {
136
+ source += char;
137
+ inClass = true;
138
+ } else if (char === '(') {
139
+ source += char;
140
+ depth += 1;
141
+ // (?:, (?=, (?<name>, ...: a group construct, not a quantifier.
142
+ if (pattern[index + 1] === '?') {
143
+ source += '?';
144
+ index += 1;
145
+ }
146
+ last = 'none';
147
+ } else if (char === ')') {
148
+ depth -= 1;
149
+ if (depth < 0) throw patternError("Unmatched closing ')'", index - 1, pattern);
150
+ source += char;
151
+ last = 'atom';
152
+ } else if (char === '|') {
153
+ source += char;
154
+ last = 'none';
155
+ } else if (char === '*' || char === '+' || char === '?') {
156
+ // After a quantifier, `?` makes it lazy and `+` possessive; anything
157
+ // else has nothing to repeat.
158
+ const marks: boolean = last === 'quantifier' && char !== '*';
159
+ if (last === 'none' || last === 'marked' || (last === 'quantifier' && !marks)) {
160
+ throw patternError(`Dangling meta character '${char}'`, index, pattern);
161
+ }
162
+ // JavaScript has no possessive quantifier; on a whole-string match of
163
+ // a name, a greedy one finds the same names.
164
+ if (!(marks && char === '+')) source += char;
165
+ last = marks ? 'marked' : 'quantifier';
166
+ } else {
167
+ source += char === ']' || char === '}' ? `\\${char}` : char;
168
+ last = char === '{' ? 'quantifier' : 'atom';
169
+ if (char === '{') {
170
+ // A counted closure, copied whole.
171
+ const close = pattern.indexOf('}', index + 1);
172
+ if (close !== -1) {
173
+ source += pattern.slice(index + 1, close + 1);
174
+ index = close;
175
+ last = 'atom';
176
+ }
177
+ }
178
+ }
179
+ }
180
+ if (inClass) throw patternError('Unclosed character class', pattern.length - 1, pattern);
181
+ if (depth > 0) throw patternError('Unclosed group', pattern.length, pattern);
182
+ return new RegExp(`^(?:${source})$`, flags);
183
+ }
184
+
185
+ // How long matching names may take. A pattern that backtracks badly ties
186
+ // up one of the real server's request threads; here it would stall every
187
+ // socket, so it fails instead (GENERIC_ERROR, with this text).
188
+ const MATCH_BUDGET_MS = 1000;
189
+ const matchScript = new Script('names.filter((name) => pattern.test(name))');
190
+
191
+ // The names `pattern` matches whole, in their order.
192
+ export function matchingNames(pattern: RegExp, names: string[]): string[] {
193
+ try {
194
+ return matchScript.runInContext(createContext({ pattern, names }), {
195
+ timeout: MATCH_BUDGET_MS,
196
+ }) as string[];
197
+ } catch (error) {
198
+ if ((error as { code?: string }).code !== 'ERR_SCRIPT_EXECUTION_TIMEOUT') throw error;
199
+ throw new Error(
200
+ `The mock stopped matching ${pattern.source} after ${MATCH_BUDGET_MS} ms: it backtracks too much`,
201
+ );
202
+ }
203
+ }
204
+
205
+ // --- SYSTEM_ENTITY and SYSTEM_ENTITY_FIELDS ----------------------------------------------
206
+
207
+ // system-info-reqrep.kts: SystemEntityRequest(entityName: String), and the
208
+ // two reply classes (console API.kt). SystemFieldResponse's TYPE is the
209
+ // dictionary's Field.Type.
210
+ const FIELD_TYPES = [
211
+ 'STRING',
212
+ 'ENUM',
213
+ 'INT',
214
+ 'SHORT',
215
+ 'DOUBLE',
216
+ 'LONG',
217
+ 'BOOLEAN',
218
+ 'RAW',
219
+ 'BIGDECIMAL',
220
+ 'NANO_TIMESTAMP',
221
+ 'DATETIME',
222
+ 'DATE',
223
+ ];
224
+ const entityRequest = {
225
+ className: `${SYSINFO}.SystemEntityRequest`,
226
+ fields: [dto('ENTITY_NAME', 'STRING')],
227
+ };
228
+ const optionalString = (name: string) => dto(name, 'STRING', { nullable: true, optional: true });
229
+ export const SYSTEM_ENTITY_TYPES: TypedRequestReply = {
230
+ request: entityRequest,
231
+ reply: { className: `${SYSINFO}.SystemEntityResponse`, fields: [dto('ENTITY_NAME', 'STRING')] },
232
+ };
233
+ const SYSTEM_FIELD_TYPES: TypedRequestReply = {
234
+ request: entityRequest,
235
+ reply: {
236
+ className: `${SYSINFO}.SystemFieldResponse`,
237
+ fields: [
238
+ dto('DEFAULT_VALUE', 'ANY', { nullable: true, optional: true }),
239
+ optionalString('FILE_NAME'),
240
+ optionalString('FORMAT'),
241
+ dto('MAX_SIZE', 'INT', { nullable: true, optional: true }),
242
+ dto('NAME', 'STRING'),
243
+ dto('NULLABLE', 'BOOLEAN', { optional: true }),
244
+ optionalString('SENSITIVE_MASK'),
245
+ dto('TYPE', 'ENUM', {
246
+ values: FIELD_TYPES,
247
+ enumClass: 'global.genesis.dictionary.Field.Type',
248
+ }),
249
+ optionalString('VALUES'),
250
+ ],
251
+ },
252
+ };
253
+
254
+ // A request without ENTITY_NAME fails to decode into SystemEntityRequest
255
+ // (GenesisJacksonExceptionTranslator); not recorded end to end.
256
+ function entityNameOf(request: Row): string {
257
+ const name = request.ENTITY_NAME;
258
+ if (name === undefined || name === null) {
259
+ throw NackError.field(
260
+ 'ENTITY_NAME',
261
+ 'Missing mandatory field ENTITY_NAME',
262
+ '$.REQUEST.ENTITY_NAME',
263
+ 'MISSING_FIELD',
264
+ );
265
+ }
266
+ return String(name);
267
+ }
268
+
269
+ // One SystemFieldResponse, as GSF's generated config classes give a field:
270
+ // never a MAX_SIZE or a FILE_NAME (the generator drops both), nulls sent.
271
+ const fieldReply = (field: Partial<Row> & { NAME: string; TYPE: string }): Row => ({
272
+ NAME: field.NAME,
273
+ TYPE: field.TYPE,
274
+ VALUES: field.VALUES ?? null,
275
+ DEFAULT_VALUE: field.DEFAULT_VALUE ?? null,
276
+ MAX_SIZE: null,
277
+ FILE_NAME: null,
278
+ FORMAT: field.FORMAT ?? null,
279
+ SENSITIVE_MASK: null,
280
+ NULLABLE: field.NULLABLE ?? true,
281
+ });
282
+ // GSF adds every table's RECORD_ID and TIMESTAMP after its own fields.
283
+ const IDENTITY = [
284
+ fieldReply({ NAME: 'RECORD_ID', TYPE: 'LONG', NULLABLE: false }),
285
+ fieldReply({ NAME: 'TIMESTAMP', TYPE: 'NANO_TIMESTAMP', NULLABLE: false }),
286
+ ];
287
+
288
+ // A table as GSF's dictionary has it: a platform one as its product declares
289
+ // it (the preset leaves USER's PASSWORD and KEY_VALUE's columns out of its
290
+ // own), else the config's.
291
+ const tableDefOf = (config: MockServerConfig, name: string): TableDef | undefined =>
292
+ isPlatformTable(name) ? platformTable(name) : config.tables?.[name];
293
+
294
+ // A table field's TYPE, VALUES and DEFAULT_VALUE: an ALIASED_ENUM by its keys,
295
+ // an ENUM with no default defaulting to its first value (ParsedTable.kt:113).
296
+ function enumOf(table: string, field: FieldDef): Pick<Row, 'VALUES' | 'DEFAULT_VALUE'> {
297
+ if (field.type !== 'ENUM') return { VALUES: null, DEFAULT_VALUE: field.default ?? null };
298
+ const values = field.values ?? [];
299
+ const keys = aliasedEnumKeys(table, field.name);
300
+ const keyOf = (value: unknown) => (keys ? keys[values.indexOf(String(value))] : value);
301
+ const fallback = field.default ?? values[0];
302
+ return {
303
+ VALUES: (keys ?? values).join(' ') || null,
304
+ DEFAULT_VALUE: fallback === undefined ? null : keyOf(fallback),
305
+ };
306
+ }
307
+
308
+ // A table's own fields (Helper.kt:73-88): not nullable when the dictionary
309
+ // says so, when the field is in any index (the key's included), generated,
310
+ // or has a default.
311
+ function tableFieldReplies(table: string, def: TableDef): Row[] {
312
+ const required = new Set([
313
+ ...pkFieldsOf(def),
314
+ ...(def.indexes ?? []).flatMap((index) => index.fields),
315
+ ...(def.generated ?? []).map(({ field }) => field),
316
+ ]);
317
+ return (def.fields ?? []).map((field) => {
318
+ const typed = enumOf(table, field);
319
+ return fieldReply({
320
+ NAME: field.name,
321
+ TYPE: field.type,
322
+ ...typed,
323
+ FORMAT: field.type === 'RAW' ? (fieldFormat(field.name) ?? null) : null,
324
+ NULLABLE:
325
+ field.nullable !== false && !required.has(field.name) && typed.DEFAULT_VALUE === null,
326
+ });
327
+ });
328
+ }
329
+
330
+ // An audit table's: its table's, then its own id and the four audit fields
331
+ // (Audit.kt:76-80).
332
+ function auditFieldReplies(table: string, def: TableDef): Row[] {
333
+ const audit = auditTableName(table);
334
+ return [
335
+ ...tableFieldReplies(table, def),
336
+ ...IDENTITY,
337
+ fieldReply({ NAME: `${audit}_ID`, TYPE: 'STRING', NULLABLE: false }),
338
+ fieldReply({ NAME: 'AUDIT_EVENT_TYPE', TYPE: 'STRING' }),
339
+ fieldReply({ NAME: 'AUDIT_EVENT_DATETIME', TYPE: 'DATETIME' }),
340
+ fieldReply({ NAME: 'AUDIT_EVENT_TEXT', TYPE: 'STRING' }),
341
+ fieldReply({ NAME: 'AUDIT_EVENT_USER', TYPE: 'STRING' }),
342
+ ];
343
+ }
344
+
345
+ // A view's fields (ViewConfigClassGenerator.kt:176-251), by their names in
346
+ // the view: a base table column as nullable as in its table, a joined one
347
+ // always nullable, a derived one too and with only its type; none with a
348
+ // default or format. Then RECORD_ID and TIMESTAMP.
349
+ function viewFieldReplies(config: MockServerConfig, view: ViewDef): Row[] {
350
+ const columnOf = (table: string, column: string) => {
351
+ const def = tableDefOf(config, table);
352
+ const field = def?.fields?.find(({ name }) => name === column);
353
+ if (!def || !field) return undefined;
354
+ return tableFieldReplies(table, { ...def, fields: [field] })[0];
355
+ };
356
+ const baseDef = tableDefOf(config, view.base);
357
+ const names = view.fields ?? [
358
+ ...(baseDef?.fields ?? []).map(({ name }) => name),
359
+ ...Object.keys(view.select ?? {}),
360
+ ...(view.joins ?? []).flatMap((join) => Object.keys(join.select ?? {})),
361
+ ...Object.keys(view.derivedTypes ?? {}),
362
+ ];
363
+ const replies = names
364
+ .filter((name) => name !== 'RECORD_ID' && name !== 'TIMESTAMP')
365
+ .map((name) => {
366
+ const derived = view.derivedTypes?.[name];
367
+ if (derived) {
368
+ const type = typeof derived === 'string' ? derived : derived.type;
369
+ const values = typeof derived === 'string' ? undefined : derived.values;
370
+ return fieldReply({ NAME: name, TYPE: type, VALUES: values?.join(' ') ?? null });
371
+ }
372
+ const join = (view.joins ?? []).find((candidate) => candidate.select?.[name]);
373
+ const source = join
374
+ ? columnOf(join.table, join.select![name])
375
+ : columnOf(view.base, view.select?.[name] ?? name);
376
+ return fieldReply({
377
+ NAME: name,
378
+ TYPE: source?.TYPE ?? 'STRING',
379
+ VALUES: source?.VALUES ?? null,
380
+ NULLABLE: join ? true : (source?.NULLABLE ?? true),
381
+ });
382
+ });
383
+ return [...replies, ...IDENTITY];
384
+ }
385
+
386
+ function entityFieldReplies(config: MockServerConfig, entity: string): Row[] {
387
+ const view = config.views?.[entity];
388
+ if (view) return viewFieldReplies(config, view);
389
+ const audited = auditedTableOf(config, entity);
390
+ if (audited) return auditFieldReplies(audited, tableDefOf(config, audited)!);
391
+ return [...tableFieldReplies(entity, tableDefOf(config, entity) ?? { pkField: [] }), ...IDENTITY];
392
+ }
393
+
394
+ /** system-info-reqrep.kts's two request servers. */
395
+ export function systemInfoRequestReplies(): Record<string, RequestReplyDef> {
396
+ return {
397
+ // :11 the entities whose name the pattern matches whole, `*` any run.
398
+ SYSTEM_ENTITY: {
399
+ typed: SYSTEM_ENTITY_TYPES,
400
+ requestFields: ['ENTITY_NAME'],
401
+ resolver: ({ request, config }) => {
402
+ const pattern = javaPattern(entityNameOf(request).replaceAll('*', '.*'));
403
+ return matchingNames(pattern, entityNames(config)).map((ENTITY_NAME) => ({
404
+ ENTITY_NAME,
405
+ }));
406
+ },
407
+ },
408
+ // :25 the first entity the pattern (as given: `*` alone is no pattern)
409
+ // matches, and its fields.
410
+ SYSTEM_ENTITY_FIELDS: {
411
+ typed: SYSTEM_FIELD_TYPES,
412
+ requestFields: ['ENTITY_NAME'],
413
+ resolver: ({ request, config }) => {
414
+ const pattern = javaPattern(entityNameOf(request));
415
+ const [entity] = matchingNames(pattern, entityNames(config));
416
+ if (!entity) throw new Error('Collection contains no element matching the predicate.');
417
+ return entityFieldReplies(config, entity);
418
+ },
419
+ },
420
+ };
421
+ }
422
+
423
+ // --- the status dataservers ----------------------------------------------------------
424
+
425
+ // StatusDataserver.java:113-145: SYSTEM_STATUS with its memory columns
426
+ // renamed.
427
+ export const SYSTEM_STATUS_BYTES: ViewDef = {
428
+ base: 'SYSTEM_STATUS',
429
+ select: {
430
+ TOTAL_PHYSICAL_MEMORY_SIZE_BYTES: 'TOTAL_PHYSICAL_MEMORY_SIZE',
431
+ FREE_PHYSICAL_MEMORY_SIZE_BYTES: 'FREE_PHYSICAL_MEMORY_SIZE',
432
+ },
433
+ fields: [
434
+ 'SYSTEM_CPU_LOAD',
435
+ 'TOTAL_PHYSICAL_MEMORY_SIZE_BYTES',
436
+ 'HOST_NAME',
437
+ 'FREE_PHYSICAL_MEMORY_SIZE_BYTES',
438
+ ],
439
+ };
440
+
441
+ /**
442
+ * StatusDataserver.java's two dataservers, on GSF's older engine (no INDEXES
443
+ * in their META), their fields in the order its HashSet of fields gives
444
+ * them. Only GSF's Resource Daemon fills GENESIS_PROCESS and SYSTEM_STATUS,
445
+ * and Genesis Start and Create's preview don't run it, so both stream no
446
+ * rows, as there.
447
+ */
448
+ export function statusQueries(): Record<string, QueryDef> {
449
+ return {
450
+ ALL_PROCESSES_STATUS: {
451
+ source: 'GENESIS_PROCESS',
452
+ legacyEngine: true,
453
+ fields: [
454
+ 'PROCESS_PORT',
455
+ 'START_TIME',
456
+ 'PROCESS_STATUS',
457
+ 'PROCESS_ENABLED',
458
+ 'PROCESS_SECURE',
459
+ 'PROCESS_STATE_TEXT',
460
+ 'DATADUMP',
461
+ 'PROCESS_RESOURCES',
462
+ 'PROCESS_MEM_USAGE',
463
+ 'PROCESS_CPU_USAGE',
464
+ 'PROCESS_NAME',
465
+ 'PROCESS_STATUS_MESSAGE',
466
+ 'LOG_LEVEL',
467
+ 'PROCESS_HOSTNAME',
468
+ 'RESOURCE_TYPES',
469
+ ],
470
+ // A STRING in its metadata, an ENUM in its table.
471
+ fieldTypes: { PROCESS_STATE_TEXT: 'STRING' },
472
+ },
473
+ ALL_SYSTEM_STATUS: { source: 'SYSTEM_STATUS_BYTES', legacyEngine: true },
474
+ };
475
+ }
@@ -1,5 +1,10 @@
1
1
  export { parseSeedCsv } from './csv.ts';
2
2
  export { mergeConfigs } from './merge.ts';
3
+ export {
4
+ DEFAULT_NOTIFY_GATEWAYS,
5
+ type NotifyGateway,
6
+ type NotifyGatewayKind,
7
+ } from './notifyDispatch.ts';
3
8
  export {
4
9
  platformPreset,
5
10
  type PlatformPresetOptions,