@genesislcap/mock-server 15.68.1 → 15.69.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.
@@ -1,4 +1,5 @@
1
1
  import type { MockServerConfig, ResourceItem, Row } from '../types.ts';
2
+ import { type PlatformProduct } from './products.ts';
2
3
  export interface PlatformUser {
3
4
  username: string;
4
5
  password?: string;
@@ -18,6 +19,7 @@ export interface PlatformPresetOptions {
18
19
  seed?: PlatformSeed;
19
20
  resources?: ResourceItem[];
20
21
  sessionUser?: string;
22
+ products?: readonly PlatformProduct[];
21
23
  }
22
24
  /**
23
25
  * The Genesis platform's data and handlers, to merge with an app's own config:
@@ -1,16 +1,19 @@
1
1
  // The Genesis platform a GSF 8.15.x app runs beside its own processes: auth
2
- // (users, profiles, rights, the key-value store), notify's alerts, and the
3
- // RESOURCES every platform PBC registers. Data comes from ./platform/*.json,
4
- // which scripts/platform-preset/generate.ts builds from real recordings and the
5
- // PBCs' own seed files; behaviour and texts cite the PBC scripts at the
6
- // versions the showcase server pins (server/gradle.properties: GSF 8.15.29,
7
- // auth 8.15.5, genesis-notify 8.15.16).
2
+ // (users, profiles, rights, the key-value store), notify's alerts, the
3
+ // RESOURCES every platform product registers, and the tables, queries and
4
+ // request servers its products' screens read (./products.ts). Data comes from
5
+ // ./platform/*.json, which scripts/platform-preset/generate.ts builds from
6
+ // real recordings and the products' own dictionaries, scripts and seed files;
7
+ // behaviour and texts cite the product scripts at the versions the showcase
8
+ // server pins (server/gradle.properties: GSF 8.15.29, auth 8.15.5,
9
+ // genesis-notify 8.15.16, reporting 8.15.3, file-server 8.15.9,
10
+ // reconciliation 8.15.4).
8
11
  import { NackError } from "../protocol/errors.js";
9
12
  import defaultUser from './platform/default-user.json' with { type: 'json' };
10
13
  import platformProfileRights from './platform/profile-rights.json' with { type: 'json' };
11
14
  import platformProfiles from './platform/profiles.json' with { type: 'json' };
12
- import platformResources from './platform/resources.json' with { type: 'json' };
13
15
  import platformRights from './platform/rights.json' with { type: 'json' };
16
+ import { includedProducts, ofIncluded, productBacking, productResources, } from "./products.js";
14
17
  const DEFAULT_PASSWORD = 'admin';
15
18
  // --- tables --------------------------------------------------------------------
16
19
  const field = (name, type = 'STRING', more = {}) => ({
@@ -286,6 +289,11 @@ const LOGIN_USER_FIELDS = new Set(['FIRST_NAME', 'LAST_NAME', 'EMAIL_ADDRESS', '
286
289
  * README's "Platform preset".
287
290
  */
288
291
  export function platformPreset(options = {}) {
292
+ const included = includedProducts(options.products);
293
+ const notify = included.has('genesis-notify');
294
+ if (!notify && options.seed?.NOTIFY_ALERT?.length) {
295
+ throw new Error("seed.NOTIFY_ALERT needs the 'genesis-notify' product");
296
+ }
289
297
  const users = options.users ?? [DEFAULT_USER];
290
298
  const fallback = options.sessionUser ?? users[0]?.username;
291
299
  const seed = {
@@ -302,9 +310,16 @@ export function platformPreset(options = {}) {
302
310
  permission: permission ?? rightsOf(profile, seed.PROFILE_RIGHT),
303
311
  user: user && pick(user, LOGIN_USER_FIELDS),
304
312
  }));
313
+ // NOTIFY_ALERT is genesis-notify's; the rest are GSF's and auth's.
314
+ const { NOTIFY_ALERT, ...always } = platformTables(seed, users);
315
+ const tables = notify ? { ...always, NOTIFY_ALERT } : always;
316
+ // What the included products' screens read, generated from their scripts;
317
+ // the pieces written out here replace any of the same name.
318
+ const generated = productBacking(included, tables);
305
319
  return {
306
- tables: platformTables(seed, users),
320
+ tables: { ...generated.tables, ...tables },
307
321
  views: {
322
+ ...generated.views,
308
323
  // genesis-view-dictionary.kts:2 (GSF v8.15.29): USER and its
309
324
  // USER_ATTRIBUTES, without the password, RECORD_ID and TIMESTAMP columns.
310
325
  USER_VIEW: {
@@ -351,60 +366,79 @@ export function platformPreset(options = {}) {
351
366
  fields: ['RIGHT_CODE', 'RIGHT_DESCRIPTION'],
352
367
  },
353
368
  },
354
- // auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
355
- // (genesis-notify v8.15.16).
369
+ // The preset's own, over the generated ones, for the included products.
356
370
  queries: {
357
- ALL_USERS: { source: 'USER_VIEW' },
358
- ALL_PROFILES: { source: 'PROFILE_PREFIXED' },
359
- ALL_RIGHTS: { source: 'RIGHT_PREFIXED' },
360
- ALL_PROFILE_RIGHTS: { source: 'PROFILE_RIGHT_VIEW' },
361
- ALL_PROFILE_USERS: { source: 'PROFILE_USER_VIEW' },
362
- // `permissioning { auth { filterWithUserName { userName == data.userName } } }`
363
- ALL_NOTIFY_ALERT_RECORDS: {
364
- source: 'NOTIFY_ALERT',
365
- auth: { rowFilter: (row, user) => row.USER_NAME === (user.userName ?? fallback) },
366
- },
371
+ ...generated.queries,
372
+ ...ofIncluded(ownQueries(fallback), 'DATASERVER', included),
367
373
  },
368
- // auth-reqrep.kts (auth v8.15.5).
369
374
  requestReplies: {
370
- // :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
371
- // RECORD_ID.
372
- RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
373
- // :7 request { NAME withPrefix PROFILE } reply { ..., STATUS, DESCRIPTION }
374
- PROFILE: {
375
- source: 'PROFILE_PREFIXED',
376
- requestFields: ['PROFILE_NAME'],
377
- fields: ['PROFILE_NAME', 'STATUS', 'DESCRIPTION'],
378
- },
379
- // :212 request { USER_NAME } reply { KV_KEY withAlias "KEY" }
380
- KEY_VALUE_LIST: {
381
- requestFields: ['USER_NAME'],
382
- resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({ KEY: row.KV_KEY })),
383
- metadataRows: [{ KEY: 'example' }],
384
- },
385
- // :232 request { USER_NAME, KV_KEY withAlias "KEY" }
386
- // reply { KV_KEY withAlias "KEY", KV_VALUE withAlias "VALUE" }
387
- KEY_VALUE_READ: {
388
- requestFields: ['USER_NAME', 'KEY'],
389
- resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({
390
- KEY: row.KV_KEY,
391
- VALUE: rawValue(row.KV_VALUE),
392
- })),
393
- metadataRows: [{ KEY: 'example', VALUE: '' }],
394
- },
375
+ ...generated.requestReplies,
376
+ ...ofIncluded(ownRequestReplies(), 'REQUEST_SERVER', included),
395
377
  },
396
- eventHandlers: { ...keyValueHandlers(fallback), ...alertHandlers(fallback) },
378
+ eventHandlers: ofIncluded({ ...keyValueHandlers(fallback), ...alertHandlers(fallback) }, 'EVENT_HANDLER', included),
397
379
  // The DETAILS classes of the alert events, which their names alone would
398
380
  // make NOTIFY_ALERT table events.
399
- eventSchemas: {
381
+ eventSchemas: ofIncluded({
400
382
  EVENT_DISMISS_NOTIFY_ALERT: {
401
383
  table: 'NOTIFY_ALERT',
402
384
  pkOnly: true,
403
385
  className: 'global.genesis.gen.dao.NotifyAlert.ByAlertId',
404
386
  },
405
387
  EVENT_DISMISS_ALL_NOTIFY_ALERT: { fields: [], className: 'kotlin.Unit' },
406
- },
388
+ }, 'EVENT_HANDLER', included),
407
389
  auth: { users: authUsers },
408
- additionalResources: [...platformResources, ...(options.resources ?? [])],
390
+ additionalResources: [...productResources(included), ...(options.resources ?? [])],
391
+ };
392
+ }
393
+ // auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
394
+ // (genesis-notify v8.15.16): the ones the generated backing can't say, as
395
+ // they rename columns or filter the alerts by user.
396
+ function ownQueries(fallback) {
397
+ const ownAlert = (row, user) => row.USER_NAME === (user.userName ?? fallback);
398
+ return {
399
+ ALL_USERS: { source: 'USER_VIEW' },
400
+ ALL_PROFILES: { source: 'PROFILE_PREFIXED' },
401
+ ALL_RIGHTS: { source: 'RIGHT_PREFIXED' },
402
+ ALL_PROFILE_RIGHTS: { source: 'PROFILE_RIGHT_VIEW' },
403
+ ALL_PROFILE_USERS: { source: 'PROFILE_USER_VIEW' },
404
+ // `permissioning { auth { filterWithUserName { userName == data.userName } } }`
405
+ ALL_NOTIFY_ALERT_RECORDS: { source: 'NOTIFY_ALERT', auth: { rowFilter: ownAlert } },
406
+ // :11, the same with `filter { data.alertStatus == AlertStatus.NEW &&
407
+ // data.showToast }`.
408
+ ALL_TOAST_NOTIFICATIONS: {
409
+ source: 'NOTIFY_ALERT',
410
+ filter: (row) => row.ALERT_STATUS === 'NEW' && row.SHOW_TOAST === true,
411
+ auth: { rowFilter: ownAlert },
412
+ },
413
+ };
414
+ }
415
+ // auth-reqrep.kts (auth v8.15.5): the ones that rename columns.
416
+ function ownRequestReplies() {
417
+ return {
418
+ // :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
419
+ // RECORD_ID.
420
+ RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
421
+ // :7 request { NAME withPrefix PROFILE } reply { ..., STATUS, DESCRIPTION }
422
+ PROFILE: {
423
+ source: 'PROFILE_PREFIXED',
424
+ requestFields: ['PROFILE_NAME'],
425
+ fields: ['PROFILE_NAME', 'STATUS', 'DESCRIPTION'],
426
+ },
427
+ // :212 request { USER_NAME } reply { KV_KEY withAlias "KEY" }
428
+ KEY_VALUE_LIST: {
429
+ requestFields: ['USER_NAME'],
430
+ resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({ KEY: row.KV_KEY })),
431
+ metadataRows: [{ KEY: 'example' }],
432
+ },
433
+ // :232 request { USER_NAME, KV_KEY withAlias "KEY" }
434
+ // reply { KV_KEY withAlias "KEY", KV_VALUE withAlias "VALUE" }
435
+ KEY_VALUE_READ: {
436
+ requestFields: ['USER_NAME', 'KEY'],
437
+ resolver: ({ request, store }) => keyValues(store.getAllRows('KEY_VALUE'), request).map((row) => ({
438
+ KEY: row.KV_KEY,
439
+ VALUE: rawValue(row.KV_VALUE),
440
+ })),
441
+ metadataRows: [{ KEY: 'example', VALUE: '' }],
442
+ },
409
443
  };
410
444
  }
@@ -0,0 +1,23 @@
1
+ import type { MockServerConfig, ResourceItem, TableDef } from '../types.ts';
2
+ /**
3
+ * A platform product an app may include beside GSF and auth, by its GSF
4
+ * product name: Create's Notifications, Reporting, Document Management and
5
+ * Reconciliation.
6
+ */
7
+ export type PlatformProduct = 'genesis-notify' | 'reporting' | 'file-server' | 'reconciliation';
8
+ export declare const PLATFORM_PRODUCTS: readonly PlatformProduct[];
9
+ export declare function includedProducts(products?: readonly string[]): Set<string>;
10
+ export declare function productOf(type: ResourceItem['RESOURCE_TYPE'], name: string): string | undefined;
11
+ export declare function productResources(included: Set<string>): ResourceItem[];
12
+ export declare function ofIncluded<T>(record: Record<string, T>, type: ResourceItem['RESOURCE_TYPE'], included: Set<string>): Record<string, T>;
13
+ /**
14
+ * The generated backing for the included products, a fresh copy each call:
15
+ * their queries and request servers over a table or view, those tables
16
+ * (empty, or holding the product's own seed rows) and views. GSF's and auth's are served only over
17
+ * the tables `presetTables` fills (users, profiles, rights): the rest of
18
+ * theirs (audits, approvals, cron rules, RIGHT_SUMMARY) are filled at runtime
19
+ * by platform processes the mock doesn't run, so an empty table would be a
20
+ * wrong answer rather than a fresh one. A table in `presetTables` is the
21
+ * caller's, and isn't repeated here.
22
+ */
23
+ export declare function productBacking(included: Set<string>, presetTables: Record<string, TableDef>): Pick<MockServerConfig, 'tables' | 'views' | 'queries' | 'requestReplies'>;
@@ -0,0 +1,95 @@
1
+ import platformBacking from './platform/backing.json' with { type: 'json' };
2
+ import platformResources from './platform/resources.json' with { type: 'json' };
3
+ export const PLATFORM_PRODUCTS = [
4
+ 'genesis-notify',
5
+ 'reporting',
6
+ 'file-server',
7
+ 'reconciliation',
8
+ ];
9
+ // In every app.
10
+ const ALWAYS = ['genesis', 'auth'];
11
+ const backing = platformBacking;
12
+ const attributed = platformResources;
13
+ const productByKey = new Map(attributed.map((resource) => [
14
+ `${resource.RESOURCE_TYPE}:${resource.RESOURCE_NAME}`,
15
+ resource.PRODUCT,
16
+ ]));
17
+ // The products a preset serves: GSF, auth and the chosen ones (all of them
18
+ // when none are given).
19
+ export function includedProducts(products) {
20
+ for (const product of products ?? []) {
21
+ if (!PLATFORM_PRODUCTS.includes(product)) {
22
+ throw new Error(`Unknown platform product '${product}' (one of ${PLATFORM_PRODUCTS.join(', ')}; GSF and auth are always in)`);
23
+ }
24
+ }
25
+ return new Set([...ALWAYS, ...(products ?? PLATFORM_PRODUCTS)]);
26
+ }
27
+ // The product that registers a platform resource, if it is one.
28
+ export function productOf(type, name) {
29
+ return productByKey.get(`${type}:${name}`);
30
+ }
31
+ // The platform resources the included products register, as the real server
32
+ // lists them.
33
+ export function productResources(included) {
34
+ return attributed
35
+ .filter((resource) => included.has(resource.PRODUCT))
36
+ .map(({ RESOURCE_NAME, RESOURCE_TYPE }) => ({ RESOURCE_NAME, RESOURCE_TYPE }));
37
+ }
38
+ // Keeps the entries of a preset's own record whose resource an included
39
+ // product registers (or that isn't a platform resource at all).
40
+ export function ofIncluded(record, type, included) {
41
+ return Object.fromEntries(Object.entries(record).filter(([name]) => {
42
+ const product = productOf(type, name);
43
+ return product === undefined || included.has(product);
44
+ }));
45
+ }
46
+ // A derived field's value is the product's Kotlin, which isn't modelled: the
47
+ // column is declared, and null. Its tables start empty, so no row shows it.
48
+ const unmodelledValue = () => null;
49
+ /**
50
+ * The generated backing for the included products, a fresh copy each call:
51
+ * their queries and request servers over a table or view, those tables
52
+ * (empty, or holding the product's own seed rows) and views. GSF's and auth's are served only over
53
+ * the tables `presetTables` fills (users, profiles, rights): the rest of
54
+ * theirs (audits, approvals, cron rules, RIGHT_SUMMARY) are filled at runtime
55
+ * by platform processes the mock doesn't run, so an empty table would be a
56
+ * wrong answer rather than a fresh one. A table in `presetTables` is the
57
+ * caller's, and isn't repeated here.
58
+ */
59
+ export function productBacking(included, presetTables) {
60
+ const tables = new Set();
61
+ const views = new Set();
62
+ const pick = (entries) => Object.fromEntries(Object.entries(entries).flatMap(([name, entry]) => {
63
+ const { product, script: _script, reads, unmodelled: _unmodelled, ...definition } = structuredClone(entry);
64
+ if (!included.has(product))
65
+ return [];
66
+ if (ALWAYS.includes(product) && !reads.every((table) => table in presetTables))
67
+ return [];
68
+ for (const table of reads)
69
+ tables.add(table);
70
+ const { source } = definition;
71
+ if (source && source in backing.views)
72
+ views.add(source);
73
+ return [[name, definition]];
74
+ }));
75
+ const queries = pick(backing.queries);
76
+ const requestReplies = pick(backing.requestReplies);
77
+ return {
78
+ tables: Object.fromEntries([...tables]
79
+ .filter((name) => !(name in presetTables))
80
+ .map((name) => {
81
+ const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
82
+ return [name, table];
83
+ })),
84
+ views: Object.fromEntries([...views].map((name) => {
85
+ const { dictionary: _dictionary, derivedTypes, ...view } = structuredClone(backing.views[name]);
86
+ const derived = derivedTypes && {
87
+ derivedTypes: derivedTypes,
88
+ derived: Object.fromEntries(Object.keys(derivedTypes).map((field) => [field, unmodelledValue])),
89
+ };
90
+ return [name, { ...view, ...derived }];
91
+ })),
92
+ queries,
93
+ requestReplies,
94
+ };
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genesislcap/mock-server",
3
- "version": "15.68.1",
3
+ "version": "15.69.0",
4
4
  "description": "Reusable in-memory Genesis WebSocket protocol mock server for client automation/CI, without a JVM or database.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "test": "node --experimental-strip-types --test \"test/**/*.test.ts\"",
31
31
  "test:conformance": "node --experimental-strip-types --test \"test/conformance/**/*.test.ts\"",
32
32
  "conformance:record": "node --experimental-strip-types test/conformance/record.ts",
33
- "preset:generate": "node --experimental-strip-types scripts/platform-preset/generate.ts"
33
+ "preset:generate": "node --experimental-strip-types scripts/platform-preset/generate.ts && oxfmt --write src/presets/platform"
34
34
  },
35
35
  "dependencies": {
36
36
  "ws": "^8.18.0"
@@ -6,3 +6,4 @@ export {
6
6
  type PlatformSeed,
7
7
  type PlatformUser,
8
8
  } from './platform.ts';
9
+ export { PLATFORM_PRODUCTS, type PlatformProduct } from './products.ts';