@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
package/src/presets/platform.ts
CHANGED
|
@@ -22,6 +22,12 @@ import type {
|
|
|
22
22
|
Row,
|
|
23
23
|
TableDef,
|
|
24
24
|
} from '../types.ts';
|
|
25
|
+
import { authBacking, changePasswordRoute, hasRight } from './auth.ts';
|
|
26
|
+
import { fileServerBacking } from './fileServer.ts';
|
|
27
|
+
import { statusQueries, SYSTEM_STATUS_BYTES, systemInfoRequestReplies } from './gsf.ts';
|
|
28
|
+
import { notifyBacking, type NotifyUsers } from './notify.ts';
|
|
29
|
+
import { DEFAULT_NOTIFY_GATEWAYS, dispatchBacking, type NotifyGateway } from './notifyDispatch.ts';
|
|
30
|
+
import { ruleBacking } from './notifyRules.ts';
|
|
25
31
|
import defaultUser from './platform/default-user.json' with { type: 'json' };
|
|
26
32
|
import platformProfileRights from './platform/profile-rights.json' with { type: 'json' };
|
|
27
33
|
import platformProfiles from './platform/profiles.json' with { type: 'json' };
|
|
@@ -30,24 +36,34 @@ import {
|
|
|
30
36
|
includedProducts,
|
|
31
37
|
ofIncluded,
|
|
32
38
|
type PlatformProduct,
|
|
39
|
+
platformTable,
|
|
33
40
|
productBacking,
|
|
34
41
|
productResources,
|
|
42
|
+
typedRequestReply,
|
|
35
43
|
} from './products.ts';
|
|
44
|
+
import { reconciliationBacking } from './reconciliation.ts';
|
|
45
|
+
import { reportingBacking } from './reporting.ts';
|
|
36
46
|
|
|
37
47
|
export interface PlatformUser {
|
|
38
48
|
username: string;
|
|
39
|
-
// What a credentials login must send
|
|
40
|
-
//
|
|
49
|
+
// What a credentials login must send, kept hashed as auth keeps
|
|
50
|
+
// USER.PASSWORD, outside the USER rows the mock serves. Unset: no password
|
|
51
|
+
// logs this user in until one is set, which a change of password with a
|
|
52
|
+
// blank old one does, as auth's PasswordService allows (httpAutoLogin and
|
|
53
|
+
// issued tokens still work).
|
|
41
54
|
password?: string;
|
|
42
55
|
// The profiles the user belongs to (PROFILE_USER). Unless `permission` is
|
|
43
56
|
// set, the user's rights are these profiles' rights (PROFILE_RIGHT), as
|
|
44
57
|
// auth's consolidator works them out.
|
|
45
58
|
profile?: string[];
|
|
46
|
-
// The user's rights, replacing the ones the profiles give
|
|
59
|
+
// The user's rights, replacing the ones the profiles give, for as long as
|
|
60
|
+
// the user exists: auth's events that work rights out from profiles leave
|
|
61
|
+
// them as they are.
|
|
47
62
|
permission?: string[];
|
|
48
63
|
// The user's USER and USER_ATTRIBUTES columns (FIRST_NAME, LAST_NAME,
|
|
49
64
|
// EMAIL_ADDRESS, COMPANY_NAME, STATUS, LAST_LOGIN, ACCESS_TYPE, ...): its
|
|
50
|
-
// ALL_USERS row.
|
|
65
|
+
// ALL_USERS row. STATUS defaults to ENABLED: a login checks it as auth's
|
|
66
|
+
// does.
|
|
51
67
|
user?: Row;
|
|
52
68
|
}
|
|
53
69
|
|
|
@@ -78,8 +94,34 @@ export interface PlatformPresetOptions {
|
|
|
78
94
|
// always in: their resources are listed and backed, the others' aren't.
|
|
79
95
|
// Default: all of them.
|
|
80
96
|
products?: readonly PlatformProduct[];
|
|
97
|
+
// The gateways the app's genesis-notify.kts declares: what the notify
|
|
98
|
+
// dispatcher sends through (only a `screen` one writes NOTIFY_ALERT rows)
|
|
99
|
+
// and CONFIGURED_NOTIFY_ROUTES lists. Default: the product's own, screen
|
|
100
|
+
// "Screen" and email "Email"; Create's seed and the showcase add teams
|
|
101
|
+
// "Teams".
|
|
102
|
+
notifyGateways?: NotifyGateway[];
|
|
103
|
+
// The sysdef's NOTIFY_ENTITY_LIST: the tables and views NOTIFY_SYSTEM_ENTITY
|
|
104
|
+
// offers the rule dialogs. Default: all of them, as an empty list is.
|
|
105
|
+
notifyEntities?: string[];
|
|
106
|
+
// The sysdef's REPORTING_DEFAULT_TIMEZONE: the zone a report's
|
|
107
|
+
// `$(timestamp:...)` file name is written in. Default: the host's, as the
|
|
108
|
+
// JVM's is when it's unset.
|
|
109
|
+
reportingTimeZone?: string;
|
|
110
|
+
// The sysdef's REPORTING_DATASOURCE_LIST: the request servers a report can
|
|
111
|
+
// read. Default: all of them.
|
|
112
|
+
reportingDatasources?: string[];
|
|
113
|
+
// How long a reconciliation run stays IN_PROGRESS before it completes (with
|
|
114
|
+
// no results: the mock matches nothing). Default 1000 ms; Infinity, or
|
|
115
|
+
// anything past 2^31 - 1 ms, never completes it.
|
|
116
|
+
reconciliationRunMs?: number;
|
|
117
|
+
// The batch pipelines the app's reconciliation process defines, which a
|
|
118
|
+
// PIPELINE datasource can name. Default: none, as the product's own
|
|
119
|
+
// reconciliation-pipelines.kts defines.
|
|
120
|
+
reconciliationPipelines?: string[];
|
|
81
121
|
}
|
|
82
122
|
|
|
123
|
+
const RECONCILIATION_RUN_MS = 1000;
|
|
124
|
+
|
|
83
125
|
const DEFAULT_PASSWORD = 'admin';
|
|
84
126
|
|
|
85
127
|
// --- tables --------------------------------------------------------------------
|
|
@@ -90,101 +132,61 @@ const field = (name: string, type: FieldDef['type'] = 'STRING', more: Partial<Fi
|
|
|
90
132
|
...more,
|
|
91
133
|
});
|
|
92
134
|
|
|
93
|
-
// USER
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
field('ONLINE', 'BOOLEAN', { default: false }),
|
|
104
|
-
field('COMPANY_NAME'),
|
|
105
|
-
field('COMPANY_ID'),
|
|
106
|
-
field('DOMAIN'),
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
// USER_ATTRIBUTES, genesis-tables-dictionary.kts:378 (GSF v8.15.29).
|
|
110
|
-
const USER_ATTRIBUTE_FIELDS: FieldDef[] = [
|
|
111
|
-
field('USER_NAME', 'STRING', { maxSize: 255 }),
|
|
112
|
-
field('USER_TYPE', 'ENUM', {
|
|
113
|
-
values: ['USER', 'ADVISOR', 'CLIENT', 'SYSTEM', 'API'],
|
|
114
|
-
default: 'USER',
|
|
115
|
-
}),
|
|
116
|
-
field('ACCESS_TYPE', 'ENUM', { values: ['ALL', 'ENTITY', 'MULTI_ENTITY'], default: 'ALL' }),
|
|
117
|
-
...['ADDRESS_LINE1', 'ADDRESS_LINE2', 'ADDRESS_LINE3', 'ADDRESS_LINE4'].map((name) =>
|
|
118
|
-
field(name, 'STRING', { maxSize: 400 }),
|
|
119
|
-
),
|
|
120
|
-
...[
|
|
121
|
-
'CITY',
|
|
122
|
-
'REGION',
|
|
123
|
-
'POSTAL_CODE',
|
|
124
|
-
'COUNTRY',
|
|
125
|
-
'TITLE',
|
|
126
|
-
'WEBSITE',
|
|
127
|
-
'MOBILE_NUMBER',
|
|
128
|
-
'TELEPHONE_NUMBER_DIRECT',
|
|
129
|
-
'TELEPHONE_NUMBER_OFFICE',
|
|
130
|
-
].map((name) => field(name)),
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
const fieldNames = (fields: FieldDef[]) => fields.map(({ name }) => name);
|
|
134
|
-
const USER_COLUMNS = new Set(fieldNames(USER_FIELDS));
|
|
135
|
-
const ATTRIBUTE_COLUMNS = new Set(fieldNames(USER_ATTRIBUTE_FIELDS));
|
|
135
|
+
// USER as GSF declares it (genesis-tables-dictionary.kts:360, v8.15.29) but
|
|
136
|
+
// for PASSWORD, which auth.ts keeps beside the store.
|
|
137
|
+
const userTable = (): TableDef => {
|
|
138
|
+
const table = platformTable('USER');
|
|
139
|
+
return { ...table, fields: table.fields?.filter(({ name }) => name !== 'PASSWORD') };
|
|
140
|
+
};
|
|
141
|
+
// What a PlatformUser's `user` may set.
|
|
142
|
+
const columnsOf = (table: TableDef) => new Set((table.fields ?? []).map(({ name }) => name));
|
|
143
|
+
const USER_COLUMNS = columnsOf(userTable());
|
|
144
|
+
const ATTRIBUTE_COLUMNS = columnsOf(platformTable('USER_ATTRIBUTES'));
|
|
136
145
|
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
// auth
|
|
140
|
-
//
|
|
146
|
+
// The users, profiles and rights, in GSF's and auth's own tables (their
|
|
147
|
+
// audits included): USER, USER_ATTRIBUTES and RIGHT_SUMMARY (GSF v8.15.29),
|
|
148
|
+
// PROFILE, PROFILE_USER, RIGHT and PROFILE_RIGHT (auth v8.15.5). A user's
|
|
149
|
+
// RIGHT_SUMMARY rows are their rights, as auth's consolidation keeps them.
|
|
150
|
+
// KEY_VALUE: auth-tables-dictionary.kts:2. NOTIFY_ALERT:
|
|
151
|
+
// genesis-notify-tables-dictionary.kts:112 (genesis-notify v8.15.16), types
|
|
152
|
+
// from genesis-notify-fields-dictionary.kts.
|
|
141
153
|
function platformTables(
|
|
142
154
|
seed: Required<PlatformSeed>,
|
|
143
155
|
users: PlatformUser[],
|
|
144
156
|
): Record<string, TableDef> {
|
|
145
157
|
return {
|
|
146
158
|
USER: {
|
|
147
|
-
|
|
148
|
-
fields: USER_FIELDS,
|
|
159
|
+
...userTable(),
|
|
149
160
|
rows: users.map(({ username, user = {} }) => ({
|
|
150
161
|
...pick(user, USER_COLUMNS),
|
|
151
162
|
USER_NAME: username,
|
|
163
|
+
STATUS: user.STATUS ?? 'ENABLED',
|
|
152
164
|
})),
|
|
153
165
|
},
|
|
154
166
|
USER_ATTRIBUTES: {
|
|
155
|
-
|
|
156
|
-
fields: USER_ATTRIBUTE_FIELDS,
|
|
167
|
+
...platformTable('USER_ATTRIBUTES'),
|
|
157
168
|
rows: users.map(({ username, user = {} }) => ({
|
|
158
169
|
...pick(user, ATTRIBUTE_COLUMNS),
|
|
159
170
|
USER_NAME: username,
|
|
160
171
|
})),
|
|
161
172
|
},
|
|
162
|
-
PROFILE: {
|
|
163
|
-
pkField: 'NAME',
|
|
164
|
-
fields: [
|
|
165
|
-
field('NAME', 'STRING', { maxSize: 255 }),
|
|
166
|
-
field('DESCRIPTION'),
|
|
167
|
-
field('STATUS'),
|
|
168
|
-
field('IS_PRIMARY', 'BOOLEAN', { nullable: false, default: true }),
|
|
169
|
-
],
|
|
170
|
-
rows: seed.PROFILE,
|
|
171
|
-
},
|
|
173
|
+
PROFILE: { ...platformTable('PROFILE'), rows: seed.PROFILE },
|
|
172
174
|
PROFILE_USER: {
|
|
173
|
-
|
|
174
|
-
fields: [field('PROFILE_NAME'), field('USER_NAME', 'STRING', { maxSize: 255 })],
|
|
175
|
+
...platformTable('PROFILE_USER'),
|
|
175
176
|
rows: users.flatMap(({ username, profile = [] }) =>
|
|
176
177
|
profile.map((PROFILE_NAME) => ({ PROFILE_NAME, USER_NAME: username })),
|
|
177
178
|
),
|
|
178
179
|
},
|
|
179
|
-
RIGHT: {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
180
|
+
RIGHT: { ...platformTable('RIGHT'), rows: seed.RIGHT },
|
|
181
|
+
PROFILE_RIGHT: { ...platformTable('PROFILE_RIGHT'), rows: seed.PROFILE_RIGHT },
|
|
182
|
+
RIGHT_SUMMARY: {
|
|
183
|
+
...platformTable('RIGHT_SUMMARY'),
|
|
184
|
+
rows: users.flatMap((user) =>
|
|
185
|
+
permissionOf(user, seed.PROFILE_RIGHT).map((RIGHT_CODE) => ({
|
|
186
|
+
USER_NAME: user.username,
|
|
187
|
+
RIGHT_CODE,
|
|
188
|
+
})),
|
|
189
|
+
),
|
|
188
190
|
},
|
|
189
191
|
// USER_NAME, KV_KEY, KV_VALUE (RAW). Left undeclared: a declared table
|
|
190
192
|
// would have the engine check EVENT_KEY_VALUE_PUT's DETAILS against it,
|
|
@@ -192,9 +194,10 @@ function platformTables(
|
|
|
192
194
|
KEY_VALUE: { pkField: ['USER_NAME', 'KV_KEY'], rows: seed.KEY_VALUE },
|
|
193
195
|
NOTIFY_ALERT: {
|
|
194
196
|
pkField: 'ALERT_ID',
|
|
195
|
-
// sequence(ALERT_ID, "AL")
|
|
197
|
+
// sequence(ALERT_ID, "AL"), audit = details(..., sequence = "NA")
|
|
196
198
|
sequencePrefix: 'AL',
|
|
197
199
|
sequenceFormat: 'genesis',
|
|
200
|
+
audit: { sequencePrefix: 'NA' },
|
|
198
201
|
fields: [
|
|
199
202
|
field('ALERT_ID'),
|
|
200
203
|
field('MESSAGE'),
|
|
@@ -358,11 +361,12 @@ function alertHandlers(fallback: string | undefined): Record<string, EventHandle
|
|
|
358
361
|
|
|
359
362
|
// --- the preset ------------------------------------------------------------------
|
|
360
363
|
|
|
361
|
-
// A user's rights: their profiles' PROFILE_RIGHT codes,
|
|
362
|
-
// login ack lists them.
|
|
363
|
-
function
|
|
364
|
+
// A user's rights: `permission`, else their profiles' PROFILE_RIGHT codes,
|
|
365
|
+
// sorted as the real login ack lists them.
|
|
366
|
+
function permissionOf({ profile = [], permission }: PlatformUser, profileRights: Row[]): string[] {
|
|
367
|
+
if (permission) return permission;
|
|
364
368
|
const codes = profileRights
|
|
365
|
-
.filter((row) =>
|
|
369
|
+
.filter((row) => profile.includes(row.PROFILE_NAME))
|
|
366
370
|
.map((row) => row.RIGHT_CODE as string);
|
|
367
371
|
return [...new Set(codes)].sort();
|
|
368
372
|
}
|
|
@@ -403,42 +407,68 @@ export function platformPreset(options: PlatformPresetOptions = {}): MockServerC
|
|
|
403
407
|
NOTIFY_ALERT: options.seed?.NOTIFY_ALERT ?? [],
|
|
404
408
|
KEY_VALUE: options.seed?.KEY_VALUE ?? [],
|
|
405
409
|
};
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
// What the users log in as at first. Logins read the store
|
|
411
|
+
// (authDirectory), so they follow what auth's events change; these name the
|
|
412
|
+
// user httpAutoLogin: true logs in as.
|
|
413
|
+
const authUsers: AuthUser[] = users.map((platformUser) => ({
|
|
414
|
+
username: platformUser.username,
|
|
415
|
+
password: platformUser.password,
|
|
416
|
+
profile: [...(platformUser.profile ?? [])].sort(),
|
|
417
|
+
permission: permissionOf(platformUser, seed.PROFILE_RIGHT),
|
|
418
|
+
user: platformUser.user && pick(platformUser.user, LOGIN_USER_FIELDS),
|
|
419
|
+
status: platformUser.user?.STATUS ?? 'ENABLED',
|
|
420
|
+
}));
|
|
415
421
|
// NOTIFY_ALERT is genesis-notify's; the rest are GSF's and auth's.
|
|
416
422
|
const { NOTIFY_ALERT, ...always } = platformTables(seed, users);
|
|
417
423
|
const tables = notify ? { ...always, NOTIFY_ALERT } : always;
|
|
418
424
|
// What the included products' screens read, generated from their scripts;
|
|
419
425
|
// the pieces written out here replace any of the same name.
|
|
420
426
|
const generated = productBacking(included, tables);
|
|
427
|
+
const notifyEvents = notifyBacking();
|
|
428
|
+
const notifyUsers: NotifyUsers = {
|
|
429
|
+
userOf: (ctx) => sessionUserOf(ctx.connection.userName, fallback),
|
|
430
|
+
fallback,
|
|
431
|
+
hasRight: (store, name, code) => name !== undefined && hasRight(store, name, code),
|
|
432
|
+
};
|
|
433
|
+
const auth = authBacking({
|
|
434
|
+
userOf: notifyUsers.userOf,
|
|
435
|
+
fixedRights: new Map(
|
|
436
|
+
users.flatMap(({ username, permission }) =>
|
|
437
|
+
permission ? [[username, permission] as const] : [],
|
|
438
|
+
),
|
|
439
|
+
),
|
|
440
|
+
passwords: new Map(
|
|
441
|
+
users.flatMap(({ username, password }) =>
|
|
442
|
+
password === undefined ? [] : [[username, password] as const],
|
|
443
|
+
),
|
|
444
|
+
),
|
|
445
|
+
});
|
|
446
|
+
const notifyRules = ruleBacking(notifyUsers);
|
|
447
|
+
const notifyDispatch = dispatchBacking({
|
|
448
|
+
users: notifyUsers,
|
|
449
|
+
gateways: options.notifyGateways ?? DEFAULT_NOTIFY_GATEWAYS,
|
|
450
|
+
entities: options.notifyEntities,
|
|
451
|
+
});
|
|
452
|
+
const fileServer = fileServerBacking();
|
|
453
|
+
const files = included.has('file-server');
|
|
454
|
+
const reconciliation = reconciliationBacking({
|
|
455
|
+
userOf: notifyUsers.userOf,
|
|
456
|
+
runMs: options.reconciliationRunMs ?? RECONCILIATION_RUN_MS,
|
|
457
|
+
pipelines: options.reconciliationPipelines,
|
|
458
|
+
fileContent: files ? fileServer.fileContent : undefined,
|
|
459
|
+
});
|
|
460
|
+
const reporting = reportingBacking({
|
|
461
|
+
userOf: notifyUsers.userOf,
|
|
462
|
+
timeZone: options.reportingTimeZone,
|
|
463
|
+
datasources: options.reportingDatasources,
|
|
464
|
+
notify: notify ? notifyDispatch.raise : undefined,
|
|
465
|
+
});
|
|
421
466
|
return {
|
|
422
467
|
tables: { ...generated.tables, ...tables },
|
|
423
468
|
views: {
|
|
424
469
|
...generated.views,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
USER_VIEW: {
|
|
428
|
-
base: 'USER',
|
|
429
|
-
joins: [
|
|
430
|
-
{
|
|
431
|
-
table: 'USER_ATTRIBUTES',
|
|
432
|
-
on: ['USER_NAME', 'USER_NAME'],
|
|
433
|
-
backwardsJoin: true,
|
|
434
|
-
select: Object.fromEntries(
|
|
435
|
-
[...ATTRIBUTE_COLUMNS]
|
|
436
|
-
.filter((name) => name !== 'USER_NAME')
|
|
437
|
-
.map((name) => [name, name]),
|
|
438
|
-
),
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
},
|
|
470
|
+
...auth.views,
|
|
471
|
+
SYSTEM_STATUS_BYTES,
|
|
442
472
|
// auth-view-dictionary.kts (auth v8.15.5) :50 and :65.
|
|
443
473
|
PROFILE_RIGHT_VIEW: {
|
|
444
474
|
base: 'PROFILE_RIGHT',
|
|
@@ -473,14 +503,41 @@ export function platformPreset(options: PlatformPresetOptions = {}): MockServerC
|
|
|
473
503
|
// The preset's own, over the generated ones, for the included products.
|
|
474
504
|
queries: {
|
|
475
505
|
...generated.queries,
|
|
476
|
-
...ofIncluded(
|
|
506
|
+
...ofIncluded(
|
|
507
|
+
{ ...ownQueries(fallback), ...statusQueries(), ...notifyRules.queries },
|
|
508
|
+
'DATASERVER',
|
|
509
|
+
included,
|
|
510
|
+
),
|
|
477
511
|
},
|
|
478
|
-
requestReplies: {
|
|
512
|
+
requestReplies: typedWhereTheyAre({
|
|
479
513
|
...generated.requestReplies,
|
|
480
|
-
...ofIncluded(
|
|
481
|
-
|
|
514
|
+
...ofIncluded(
|
|
515
|
+
{
|
|
516
|
+
...ownRequestReplies(fallback),
|
|
517
|
+
...systemInfoRequestReplies(),
|
|
518
|
+
...auth.requestReplies,
|
|
519
|
+
...notifyRules.requestReplies,
|
|
520
|
+
...notifyDispatch.requestReplies,
|
|
521
|
+
...reporting.requestReplies,
|
|
522
|
+
...reconciliation.requestReplies,
|
|
523
|
+
...fileServer.requestReplies,
|
|
524
|
+
},
|
|
525
|
+
'REQUEST_SERVER',
|
|
526
|
+
included,
|
|
527
|
+
),
|
|
528
|
+
}),
|
|
482
529
|
eventHandlers: ofIncluded(
|
|
483
|
-
{
|
|
530
|
+
{
|
|
531
|
+
...keyValueHandlers(fallback),
|
|
532
|
+
...auth.eventHandlers,
|
|
533
|
+
...alertHandlers(fallback),
|
|
534
|
+
...notifyEvents.eventHandlers,
|
|
535
|
+
...notifyRules.eventHandlers,
|
|
536
|
+
...notifyDispatch.eventHandlers,
|
|
537
|
+
...reporting.eventHandlers,
|
|
538
|
+
...reconciliation.eventHandlers,
|
|
539
|
+
...fileServer.eventHandlers,
|
|
540
|
+
},
|
|
484
541
|
'EVENT_HANDLER',
|
|
485
542
|
included,
|
|
486
543
|
),
|
|
@@ -494,15 +551,38 @@ export function platformPreset(options: PlatformPresetOptions = {}): MockServerC
|
|
|
494
551
|
className: 'global.genesis.gen.dao.NotifyAlert.ByAlertId',
|
|
495
552
|
},
|
|
496
553
|
EVENT_DISMISS_ALL_NOTIFY_ALERT: { fields: [], className: 'kotlin.Unit' },
|
|
554
|
+
...auth.eventSchemas,
|
|
555
|
+
...notifyEvents.eventSchemas,
|
|
556
|
+
...notifyRules.eventSchemas,
|
|
557
|
+
...notifyDispatch.eventSchemas,
|
|
558
|
+
...reporting.eventSchemas,
|
|
559
|
+
...reconciliation.eventSchemas,
|
|
560
|
+
...fileServer.eventSchemas,
|
|
497
561
|
},
|
|
498
562
|
'EVENT_HANDLER',
|
|
499
563
|
included,
|
|
500
564
|
),
|
|
501
|
-
auth: { users: authUsers },
|
|
565
|
+
auth: { users: authUsers, directory: auth.directory },
|
|
566
|
+
// auth's change of password, which an expired-password login needs, and
|
|
567
|
+
// file-server's endpoints.
|
|
568
|
+
httpRoutes: [changePasswordRoute, ...(files ? fileServer.httpRoutes : [])],
|
|
502
569
|
additionalResources: [...productResources(included), ...(options.resources ?? [])],
|
|
503
570
|
};
|
|
504
571
|
}
|
|
505
572
|
|
|
573
|
+
// The products' typed request servers (requestReply<In, Out>) say so: their
|
|
574
|
+
// META as GSF builds it, PARAMETRIC_TYPE and MAX_ROWS (RequestReplyDef.typed).
|
|
575
|
+
function typedWhereTheyAre(
|
|
576
|
+
requestReplies: Record<string, RequestReplyDef>,
|
|
577
|
+
): Record<string, RequestReplyDef> {
|
|
578
|
+
return Object.fromEntries(
|
|
579
|
+
Object.entries(requestReplies).map(([name, definition]) => {
|
|
580
|
+
const typed = typedRequestReply(name);
|
|
581
|
+
return [name, typed ? { ...definition, typed } : definition];
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
506
586
|
// auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
|
|
507
587
|
// (genesis-notify v8.15.16): the ones the generated backing can't say, as
|
|
508
588
|
// they rename columns or filter the alerts by user.
|
|
@@ -527,9 +607,18 @@ function ownQueries(fallback: string | undefined): Record<string, QueryDef> {
|
|
|
527
607
|
};
|
|
528
608
|
}
|
|
529
609
|
|
|
530
|
-
// auth-reqrep.kts (auth v8.15.5): the ones that rename columns
|
|
531
|
-
|
|
610
|
+
// auth-reqrep.kts (auth v8.15.5): the ones that rename columns; and
|
|
611
|
+
// genesis-notify-rules-reqrep.kts (genesis-notify v8.15.16) :162, which filters
|
|
612
|
+
// the alerts' audit by user.
|
|
613
|
+
function ownRequestReplies(fallback: string | undefined): Record<string, RequestReplyDef> {
|
|
532
614
|
return {
|
|
615
|
+
// requestReply("NOTIFY_ALERT", NOTIFY_ALERT_AUDIT) { permissioning { auth {
|
|
616
|
+
// filterWithUserName { userName == data.userName } } } }
|
|
617
|
+
NOTIFY_ALERT: {
|
|
618
|
+
source: 'NOTIFY_ALERT_AUDIT',
|
|
619
|
+
requestFields: ['NOTIFY_ALERT_AUDIT_ID'],
|
|
620
|
+
auth: { rowFilter: (row, user) => row.USER_NAME === (user.userName ?? fallback) },
|
|
621
|
+
},
|
|
533
622
|
// :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
|
|
534
623
|
// RECORD_ID.
|
|
535
624
|
RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
|
package/src/presets/products.ts
CHANGED
|
@@ -9,8 +9,11 @@ import type {
|
|
|
9
9
|
QueryDef,
|
|
10
10
|
RequestReplyDef,
|
|
11
11
|
ResourceItem,
|
|
12
|
+
Row,
|
|
12
13
|
TableDef,
|
|
14
|
+
TypedRequestReply,
|
|
13
15
|
ViewDef,
|
|
16
|
+
ViewRowSources,
|
|
14
17
|
} from '../types.ts';
|
|
15
18
|
import platformBacking from './platform/backing.json' with { type: 'json' };
|
|
16
19
|
import platformResources from './platform/resources.json' with { type: 'json' };
|
|
@@ -55,6 +58,14 @@ interface Backing {
|
|
|
55
58
|
>;
|
|
56
59
|
queries: Record<string, QueryDef & Provenance>;
|
|
57
60
|
requestReplies: Record<string, RequestReplyDef & Provenance>;
|
|
61
|
+
// An ALIASED_ENUM's keys by TABLE.FIELD (its values are the labels), and a
|
|
62
|
+
// RAW field's format by field: what GSF's dictionary reports beside the
|
|
63
|
+
// FieldDefs.
|
|
64
|
+
aliasedEnums: Record<string, string[]>;
|
|
65
|
+
fieldFormats: Record<string, string>;
|
|
66
|
+
// The products' typed request servers, by name: their META as GSF builds
|
|
67
|
+
// it from the pinned jars, and their classes' fields.
|
|
68
|
+
typedRequestReplies: Record<string, TypedRequestReply>;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
const backing = platformBacking as unknown as Backing;
|
|
@@ -109,41 +120,136 @@ export function ofIncluded<T>(
|
|
|
109
120
|
);
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
//
|
|
113
|
-
|
|
123
|
+
// 'genesis-notify@8.15.16' -> 'genesis-notify'.
|
|
124
|
+
const productOfOrigin = (origin: string) => origin.slice(0, origin.lastIndexOf('@'));
|
|
125
|
+
|
|
126
|
+
// The products' derived view fields, from each view dictionary's
|
|
127
|
+
// derivedField { withInput(...) { ... } } in the product's config jar. GSF's
|
|
128
|
+
// TIMESTAMP `shr 22` is epoch millis, which the mock's TIMESTAMP already is.
|
|
129
|
+
type Derive = (row: Row, sources: ViewRowSources) => unknown;
|
|
130
|
+
const input = (sources: ViewRowSources, table: string, field: string) =>
|
|
131
|
+
sources.tables[table]?.[field] ?? null;
|
|
132
|
+
const DERIVED: Record<string, Record<string, Derive>> = {
|
|
133
|
+
// genesis-notify-view-dictionary.kts:117: timestamp!!.shr(22)
|
|
134
|
+
DYNAMIC_RULE_VIEW: { DATETIME: (_row, s) => input(s, 'DYNAMIC_RULE', 'TIMESTAMP') },
|
|
135
|
+
// reporting-view-dictionary.kts:42-64
|
|
136
|
+
GENERATED_REPORT_VIEW: {
|
|
137
|
+
LAST_UPDATED_AT: (_row, s) => input(s, 'GENERATED_REPORT', 'TIMESTAMP'),
|
|
138
|
+
FILE_NAME: (_row, s) => {
|
|
139
|
+
const name = input(s, 'GENERATED_REPORT', 'FILE_NAME');
|
|
140
|
+
// Status.GENERATED, whose label the column holds.
|
|
141
|
+
if (input(s, 'GENERATED_REPORT', 'STATUS') !== 'Generated') return name;
|
|
142
|
+
const configName = input(s, 'REPORT_CONFIG', 'FILE_NAME');
|
|
143
|
+
const format = input(s, 'REPORT_CONFIG', 'OUTPUT_FORMAT');
|
|
144
|
+
return (
|
|
145
|
+
name ??
|
|
146
|
+
(configName !== null && format !== null
|
|
147
|
+
? `${configName}.${String(format).toLowerCase()}`
|
|
148
|
+
: null)
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
// reconciliation-view-dictionary.kts:30-38: the start, else the timestamp.
|
|
153
|
+
RECONCILIATION_VIEW: {
|
|
154
|
+
DATETIME: (_row, s) => {
|
|
155
|
+
const start = input(s, 'RECONCILIATION', 'START_TIMESTAMP');
|
|
156
|
+
return start === null || start === 0 ? input(s, 'RECONCILIATION', 'TIMESTAMP') : start;
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
// :59-63: the comment's timestamp.
|
|
160
|
+
RECONCILIATION_RECORD_RESULT_VIEW: {
|
|
161
|
+
DATETIME: (_row, s) => input(s, 'RECONCILIATION_RECORD_RESULT_COMMENT', 'TIMESTAMP'),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// A derived field the list above doesn't know is declared, and null.
|
|
114
166
|
const unmodelledValue = () => null;
|
|
115
167
|
|
|
168
|
+
// A platform table as its product's dictionary declares it (fields, key,
|
|
169
|
+
// indexes, sequence, audit), a fresh copy, for the preset to fill.
|
|
170
|
+
export function platformTable(name: string): TableDef {
|
|
171
|
+
const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
|
|
172
|
+
return table;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const isPlatformTable = (name: string) => Object.hasOwn(backing.tables, name);
|
|
176
|
+
|
|
177
|
+
// An ALIASED_ENUM column's keys, in its labels' order; undefined for any
|
|
178
|
+
// other column.
|
|
179
|
+
export const aliasedEnumKeys = (table: string, field: string): string[] | undefined =>
|
|
180
|
+
backing.aliasedEnums[`${table}.${field}`];
|
|
181
|
+
|
|
182
|
+
// A platform RAW field's format (BASE_64, UTF_8), if it has one.
|
|
183
|
+
export const fieldFormat = (field: string): string | undefined => backing.fieldFormats[field];
|
|
184
|
+
|
|
185
|
+
// A product's typed request server (requestReply<In, Out>), a fresh copy, if
|
|
186
|
+
// `name` is one.
|
|
187
|
+
export const typedRequestReply = (name: string): TypedRequestReply | undefined =>
|
|
188
|
+
Object.hasOwn(backing.typedRequestReplies, name)
|
|
189
|
+
? structuredClone(backing.typedRequestReplies[name])
|
|
190
|
+
: undefined;
|
|
191
|
+
|
|
192
|
+
const AUDIT_SUFFIX = '_AUDIT';
|
|
193
|
+
|
|
116
194
|
/**
|
|
117
195
|
* The generated backing for the included products, a fresh copy each call:
|
|
118
196
|
* their queries and request servers over a table or view, those tables
|
|
119
|
-
* (empty, or holding the product's own seed rows) and views
|
|
120
|
-
* the
|
|
121
|
-
*
|
|
122
|
-
* by platform processes the mock doesn't run, so an empty table would be a
|
|
123
|
-
* wrong answer rather than a fresh one. A table in `presetTables` is the
|
|
124
|
-
* caller's, and isn't repeated here.
|
|
197
|
+
* (empty, or holding the product's own seed rows) and their views, read or
|
|
198
|
+
* not, as the real dictionary holds them all. A table in `presetTables` is
|
|
199
|
+
* the caller's, and isn't repeated here.
|
|
125
200
|
*/
|
|
126
201
|
export function productBacking(
|
|
127
202
|
included: Set<string>,
|
|
128
203
|
presetTables: Record<string, TableDef>,
|
|
129
204
|
): Pick<MockServerConfig, 'tables' | 'views' | 'queries' | 'requestReplies'> {
|
|
130
|
-
|
|
131
|
-
|
|
205
|
+
// Every table of an included product, which its event handlers write; a
|
|
206
|
+
// query or request server reads some. An audit table is the engine's to
|
|
207
|
+
// derive from its table's `audit`.
|
|
208
|
+
const tables = new Set(
|
|
209
|
+
Object.entries(backing.tables)
|
|
210
|
+
.filter(([, table]) => included.has(productOfOrigin(table.dictionary)))
|
|
211
|
+
.map(([name]) => name),
|
|
212
|
+
);
|
|
213
|
+
// A table the app has: a preset or product one, or the audit table the
|
|
214
|
+
// engine derives from an audited one.
|
|
215
|
+
const definitionOf = (name: string) =>
|
|
216
|
+
presetTables[name] ?? (tables.has(name) ? backing.tables[name] : undefined);
|
|
217
|
+
const hasTable = (name: string) =>
|
|
218
|
+
definitionOf(name) !== undefined ||
|
|
219
|
+
(name.endsWith(AUDIT_SUFFIX) &&
|
|
220
|
+
Boolean(definitionOf(name.slice(0, -AUDIT_SUFFIX.length))?.audit));
|
|
221
|
+
const views = new Set(
|
|
222
|
+
Object.entries(backing.views)
|
|
223
|
+
.filter(
|
|
224
|
+
([, view]) =>
|
|
225
|
+
included.has(productOfOrigin(view.dictionary)) &&
|
|
226
|
+
[view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable),
|
|
227
|
+
)
|
|
228
|
+
.map(([name]) => name),
|
|
229
|
+
);
|
|
132
230
|
const pick = <T extends Provenance>(entries: Record<string, T>) =>
|
|
133
231
|
Object.fromEntries(
|
|
134
232
|
Object.entries(entries).flatMap(([name, entry]) => {
|
|
135
233
|
const {
|
|
136
234
|
product,
|
|
137
235
|
script: _script,
|
|
138
|
-
reads,
|
|
236
|
+
reads: _reads,
|
|
139
237
|
unmodelled: _unmodelled,
|
|
140
238
|
...definition
|
|
141
239
|
} = structuredClone(entry);
|
|
142
240
|
if (!included.has(product)) return [];
|
|
143
|
-
if (ALWAYS.includes(product) && !reads.every((table) => table in presetTables)) return [];
|
|
144
|
-
for (const table of reads) tables.add(table);
|
|
145
241
|
const { source } = definition as { source?: string };
|
|
146
|
-
|
|
242
|
+
// A source the app can't build is never served, should a product
|
|
243
|
+
// read another's view or table.
|
|
244
|
+
if (source && source in backing.views) {
|
|
245
|
+
const view = backing.views[source];
|
|
246
|
+
if (![view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable)) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
views.add(source);
|
|
250
|
+
} else if (source && !hasTable(source)) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
147
253
|
return [[name, definition]];
|
|
148
254
|
}),
|
|
149
255
|
);
|
|
@@ -153,10 +259,7 @@ export function productBacking(
|
|
|
153
259
|
tables: Object.fromEntries(
|
|
154
260
|
[...tables]
|
|
155
261
|
.filter((name) => !(name in presetTables))
|
|
156
|
-
.map((name) =>
|
|
157
|
-
const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
|
|
158
|
-
return [name, table];
|
|
159
|
-
}),
|
|
262
|
+
.map((name) => [name, platformTable(name)]),
|
|
160
263
|
),
|
|
161
264
|
views: Object.fromEntries(
|
|
162
265
|
[...views].map((name) => {
|
|
@@ -168,7 +271,10 @@ export function productBacking(
|
|
|
168
271
|
const derived = derivedTypes && {
|
|
169
272
|
derivedTypes: derivedTypes as ViewDef['derivedTypes'],
|
|
170
273
|
derived: Object.fromEntries(
|
|
171
|
-
Object.keys(derivedTypes).map((field) => [
|
|
274
|
+
Object.keys(derivedTypes).map((field) => [
|
|
275
|
+
field,
|
|
276
|
+
DERIVED[name]?.[field] ?? unmodelledValue,
|
|
277
|
+
]),
|
|
172
278
|
),
|
|
173
279
|
};
|
|
174
280
|
return [name, { ...view, ...derived }];
|