@genesislcap/mock-server 15.74.0 → 15.75.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
@@ -9,11 +9,20 @@
9
9
  // genesis-notify 8.15.16, reporting 8.15.3, file-server 8.15.9,
10
10
  // reconciliation 8.15.4).
11
11
  import { NackError } from "../protocol/errors.js";
12
+ import { authBacking, changePasswordRoute, hasRight } from "./auth.js";
13
+ import { fileServerBacking } from "./fileServer.js";
14
+ import { statusQueries, SYSTEM_STATUS_BYTES, systemInfoRequestReplies } from "./gsf.js";
15
+ import { notifyBacking } from "./notify.js";
16
+ import { DEFAULT_NOTIFY_GATEWAYS, dispatchBacking } from "./notifyDispatch.js";
17
+ import { ruleBacking } from "./notifyRules.js";
12
18
  import defaultUser from './platform/default-user.json' with { type: 'json' };
13
19
  import platformProfileRights from './platform/profile-rights.json' with { type: 'json' };
14
20
  import platformProfiles from './platform/profiles.json' with { type: 'json' };
15
21
  import platformRights from './platform/rights.json' with { type: 'json' };
16
- import { includedProducts, ofIncluded, productBacking, productResources, } from "./products.js";
22
+ import { includedProducts, ofIncluded, platformTable, productBacking, productResources, typedRequestReply, } from "./products.js";
23
+ import { reconciliationBacking } from "./reconciliation.js";
24
+ import { reportingBacking } from "./reporting.js";
25
+ const RECONCILIATION_RUN_MS = 1000;
17
26
  const DEFAULT_PASSWORD = 'admin';
18
27
  // --- tables --------------------------------------------------------------------
19
28
  const field = (name, type = 'STRING', more = {}) => ({
@@ -21,91 +30,53 @@ const field = (name, type = 'STRING', more = {}) => ({
21
30
  type,
22
31
  ...more,
23
32
  });
24
- // USER, genesis-tables-dictionary.kts:360 (GSF v8.15.29), types from
25
- // genesis-fields-dictionary.kts. PASSWORD and PASSWORD_EXPIRY_DATETIME are left
26
- // out: credentials are PlatformUser.password, and no query exposes them.
27
- const USER_FIELDS = [
28
- field('USER_NAME', 'STRING', { maxSize: 255 }),
29
- field('FIRST_NAME'),
30
- field('LAST_NAME'),
31
- field('EMAIL_ADDRESS'),
32
- field('LAST_LOGIN', 'DATE'),
33
- field('STATUS'),
34
- field('ONLINE', 'BOOLEAN', { default: false }),
35
- field('COMPANY_NAME'),
36
- field('COMPANY_ID'),
37
- field('DOMAIN'),
38
- ];
39
- // USER_ATTRIBUTES, genesis-tables-dictionary.kts:378 (GSF v8.15.29).
40
- const USER_ATTRIBUTE_FIELDS = [
41
- field('USER_NAME', 'STRING', { maxSize: 255 }),
42
- field('USER_TYPE', 'ENUM', {
43
- values: ['USER', 'ADVISOR', 'CLIENT', 'SYSTEM', 'API'],
44
- default: 'USER',
45
- }),
46
- field('ACCESS_TYPE', 'ENUM', { values: ['ALL', 'ENTITY', 'MULTI_ENTITY'], default: 'ALL' }),
47
- ...['ADDRESS_LINE1', 'ADDRESS_LINE2', 'ADDRESS_LINE3', 'ADDRESS_LINE4'].map((name) => field(name, 'STRING', { maxSize: 400 })),
48
- ...[
49
- 'CITY',
50
- 'REGION',
51
- 'POSTAL_CODE',
52
- 'COUNTRY',
53
- 'TITLE',
54
- 'WEBSITE',
55
- 'MOBILE_NUMBER',
56
- 'TELEPHONE_NUMBER_DIRECT',
57
- 'TELEPHONE_NUMBER_OFFICE',
58
- ].map((name) => field(name)),
59
- ];
60
- const fieldNames = (fields) => fields.map(({ name }) => name);
61
- const USER_COLUMNS = new Set(fieldNames(USER_FIELDS));
62
- const ATTRIBUTE_COLUMNS = new Set(fieldNames(USER_ATTRIBUTE_FIELDS));
63
- // auth-tables-dictionary.kts (auth v8.15.5): KEY_VALUE :2, PROFILE :12,
64
- // PROFILE_USER :22, RIGHT :46, PROFILE_RIGHT :54; types from
65
- // auth-fields-dictionary.kts. NOTIFY_ALERT: genesis-notify-tables-dictionary.kts:112
66
- // (genesis-notify v8.15.16), types from genesis-notify-fields-dictionary.kts.
33
+ // USER as GSF declares it (genesis-tables-dictionary.kts:360, v8.15.29) but
34
+ // for PASSWORD, which auth.ts keeps beside the store.
35
+ const userTable = () => {
36
+ const table = platformTable('USER');
37
+ return { ...table, fields: table.fields?.filter(({ name }) => name !== 'PASSWORD') };
38
+ };
39
+ // What a PlatformUser's `user` may set.
40
+ const columnsOf = (table) => new Set((table.fields ?? []).map(({ name }) => name));
41
+ const USER_COLUMNS = columnsOf(userTable());
42
+ const ATTRIBUTE_COLUMNS = columnsOf(platformTable('USER_ATTRIBUTES'));
43
+ // The users, profiles and rights, in GSF's and auth's own tables (their
44
+ // audits included): USER, USER_ATTRIBUTES and RIGHT_SUMMARY (GSF v8.15.29),
45
+ // PROFILE, PROFILE_USER, RIGHT and PROFILE_RIGHT (auth v8.15.5). A user's
46
+ // RIGHT_SUMMARY rows are their rights, as auth's consolidation keeps them.
47
+ // KEY_VALUE: auth-tables-dictionary.kts:2. NOTIFY_ALERT:
48
+ // genesis-notify-tables-dictionary.kts:112 (genesis-notify v8.15.16), types
49
+ // from genesis-notify-fields-dictionary.kts.
67
50
  function platformTables(seed, users) {
68
51
  return {
69
52
  USER: {
70
- pkField: 'USER_NAME',
71
- fields: USER_FIELDS,
53
+ ...userTable(),
72
54
  rows: users.map(({ username, user = {} }) => ({
73
55
  ...pick(user, USER_COLUMNS),
74
56
  USER_NAME: username,
57
+ STATUS: user.STATUS ?? 'ENABLED',
75
58
  })),
76
59
  },
77
60
  USER_ATTRIBUTES: {
78
- pkField: 'USER_NAME',
79
- fields: USER_ATTRIBUTE_FIELDS,
61
+ ...platformTable('USER_ATTRIBUTES'),
80
62
  rows: users.map(({ username, user = {} }) => ({
81
63
  ...pick(user, ATTRIBUTE_COLUMNS),
82
64
  USER_NAME: username,
83
65
  })),
84
66
  },
85
- PROFILE: {
86
- pkField: 'NAME',
87
- fields: [
88
- field('NAME', 'STRING', { maxSize: 255 }),
89
- field('DESCRIPTION'),
90
- field('STATUS'),
91
- field('IS_PRIMARY', 'BOOLEAN', { nullable: false, default: true }),
92
- ],
93
- rows: seed.PROFILE,
94
- },
67
+ PROFILE: { ...platformTable('PROFILE'), rows: seed.PROFILE },
95
68
  PROFILE_USER: {
96
- pkField: ['PROFILE_NAME', 'USER_NAME'],
97
- fields: [field('PROFILE_NAME'), field('USER_NAME', 'STRING', { maxSize: 255 })],
69
+ ...platformTable('PROFILE_USER'),
98
70
  rows: users.flatMap(({ username, profile = [] }) => profile.map((PROFILE_NAME) => ({ PROFILE_NAME, USER_NAME: username }))),
99
71
  },
100
- RIGHT: {
101
- pkField: 'CODE',
102
- fields: [field('CODE'), field('DESCRIPTION')],
103
- rows: seed.RIGHT,
104
- },
105
- PROFILE_RIGHT: {
106
- pkField: ['RIGHT_CODE', 'PROFILE_NAME'],
107
- fields: [field('RIGHT_CODE'), field('PROFILE_NAME')],
108
- rows: seed.PROFILE_RIGHT,
72
+ RIGHT: { ...platformTable('RIGHT'), rows: seed.RIGHT },
73
+ PROFILE_RIGHT: { ...platformTable('PROFILE_RIGHT'), rows: seed.PROFILE_RIGHT },
74
+ RIGHT_SUMMARY: {
75
+ ...platformTable('RIGHT_SUMMARY'),
76
+ rows: users.flatMap((user) => permissionOf(user, seed.PROFILE_RIGHT).map((RIGHT_CODE) => ({
77
+ USER_NAME: user.username,
78
+ RIGHT_CODE,
79
+ }))),
109
80
  },
110
81
  // USER_NAME, KV_KEY, KV_VALUE (RAW). Left undeclared: a declared table
111
82
  // would have the engine check EVENT_KEY_VALUE_PUT's DETAILS against it,
@@ -113,9 +84,10 @@ function platformTables(seed, users) {
113
84
  KEY_VALUE: { pkField: ['USER_NAME', 'KV_KEY'], rows: seed.KEY_VALUE },
114
85
  NOTIFY_ALERT: {
115
86
  pkField: 'ALERT_ID',
116
- // sequence(ALERT_ID, "AL")
87
+ // sequence(ALERT_ID, "AL"), audit = details(..., sequence = "NA")
117
88
  sequencePrefix: 'AL',
118
89
  sequenceFormat: 'genesis',
90
+ audit: { sequencePrefix: 'NA' },
119
91
  fields: [
120
92
  field('ALERT_ID'),
121
93
  field('MESSAGE'),
@@ -265,11 +237,13 @@ function alertHandlers(fallback) {
265
237
  };
266
238
  }
267
239
  // --- the preset ------------------------------------------------------------------
268
- // A user's rights: their profiles' PROFILE_RIGHT codes, sorted as the real
269
- // login ack lists them.
270
- function rightsOf(profiles, profileRights) {
240
+ // A user's rights: `permission`, else their profiles' PROFILE_RIGHT codes,
241
+ // sorted as the real login ack lists them.
242
+ function permissionOf({ profile = [], permission }, profileRights) {
243
+ if (permission)
244
+ return permission;
271
245
  const codes = profileRights
272
- .filter((row) => profiles.includes(row.PROFILE_NAME))
246
+ .filter((row) => profile.includes(row.PROFILE_NAME))
273
247
  .map((row) => row.RIGHT_CODE);
274
248
  return [...new Set(codes)].sort();
275
249
  }
@@ -303,12 +277,16 @@ export function platformPreset(options = {}) {
303
277
  NOTIFY_ALERT: options.seed?.NOTIFY_ALERT ?? [],
304
278
  KEY_VALUE: options.seed?.KEY_VALUE ?? [],
305
279
  };
306
- const authUsers = users.map(({ username, password, profile = [], permission, user }) => ({
307
- username,
308
- password,
309
- profile: [...profile].sort(),
310
- permission: permission ?? rightsOf(profile, seed.PROFILE_RIGHT),
311
- user: user && pick(user, LOGIN_USER_FIELDS),
280
+ // What the users log in as at first. Logins read the store
281
+ // (authDirectory), so they follow what auth's events change; these name the
282
+ // user httpAutoLogin: true logs in as.
283
+ const authUsers = users.map((platformUser) => ({
284
+ username: platformUser.username,
285
+ password: platformUser.password,
286
+ profile: [...(platformUser.profile ?? [])].sort(),
287
+ permission: permissionOf(platformUser, seed.PROFILE_RIGHT),
288
+ user: platformUser.user && pick(platformUser.user, LOGIN_USER_FIELDS),
289
+ status: platformUser.user?.STATUS ?? 'ENABLED',
312
290
  }));
313
291
  // NOTIFY_ALERT is genesis-notify's; the rest are GSF's and auth's.
314
292
  const { NOTIFY_ALERT, ...always } = platformTables(seed, users);
@@ -316,25 +294,43 @@ export function platformPreset(options = {}) {
316
294
  // What the included products' screens read, generated from their scripts;
317
295
  // the pieces written out here replace any of the same name.
318
296
  const generated = productBacking(included, tables);
297
+ const notifyEvents = notifyBacking();
298
+ const notifyUsers = {
299
+ userOf: (ctx) => sessionUserOf(ctx.connection.userName, fallback),
300
+ fallback,
301
+ hasRight: (store, name, code) => name !== undefined && hasRight(store, name, code),
302
+ };
303
+ const auth = authBacking({
304
+ userOf: notifyUsers.userOf,
305
+ fixedRights: new Map(users.flatMap(({ username, permission }) => permission ? [[username, permission]] : [])),
306
+ passwords: new Map(users.flatMap(({ username, password }) => password === undefined ? [] : [[username, password]])),
307
+ });
308
+ const notifyRules = ruleBacking(notifyUsers);
309
+ const notifyDispatch = dispatchBacking({
310
+ users: notifyUsers,
311
+ gateways: options.notifyGateways ?? DEFAULT_NOTIFY_GATEWAYS,
312
+ entities: options.notifyEntities,
313
+ });
314
+ const fileServer = fileServerBacking();
315
+ const files = included.has('file-server');
316
+ const reconciliation = reconciliationBacking({
317
+ userOf: notifyUsers.userOf,
318
+ runMs: options.reconciliationRunMs ?? RECONCILIATION_RUN_MS,
319
+ pipelines: options.reconciliationPipelines,
320
+ fileContent: files ? fileServer.fileContent : undefined,
321
+ });
322
+ const reporting = reportingBacking({
323
+ userOf: notifyUsers.userOf,
324
+ timeZone: options.reportingTimeZone,
325
+ datasources: options.reportingDatasources,
326
+ notify: notify ? notifyDispatch.raise : undefined,
327
+ });
319
328
  return {
320
329
  tables: { ...generated.tables, ...tables },
321
330
  views: {
322
331
  ...generated.views,
323
- // genesis-view-dictionary.kts:2 (GSF v8.15.29): USER and its
324
- // USER_ATTRIBUTES, without the password, RECORD_ID and TIMESTAMP columns.
325
- USER_VIEW: {
326
- base: 'USER',
327
- joins: [
328
- {
329
- table: 'USER_ATTRIBUTES',
330
- on: ['USER_NAME', 'USER_NAME'],
331
- backwardsJoin: true,
332
- select: Object.fromEntries([...ATTRIBUTE_COLUMNS]
333
- .filter((name) => name !== 'USER_NAME')
334
- .map((name) => [name, name])),
335
- },
336
- ],
337
- },
332
+ ...auth.views,
333
+ SYSTEM_STATUS_BYTES,
338
334
  // auth-view-dictionary.kts (auth v8.15.5) :50 and :65.
339
335
  PROFILE_RIGHT_VIEW: {
340
336
  base: 'PROFILE_RIGHT',
@@ -369,13 +365,32 @@ export function platformPreset(options = {}) {
369
365
  // The preset's own, over the generated ones, for the included products.
370
366
  queries: {
371
367
  ...generated.queries,
372
- ...ofIncluded(ownQueries(fallback), 'DATASERVER', included),
368
+ ...ofIncluded({ ...ownQueries(fallback), ...statusQueries(), ...notifyRules.queries }, 'DATASERVER', included),
373
369
  },
374
- requestReplies: {
370
+ requestReplies: typedWhereTheyAre({
375
371
  ...generated.requestReplies,
376
- ...ofIncluded(ownRequestReplies(), 'REQUEST_SERVER', included),
377
- },
378
- eventHandlers: ofIncluded({ ...keyValueHandlers(fallback), ...alertHandlers(fallback) }, 'EVENT_HANDLER', included),
372
+ ...ofIncluded({
373
+ ...ownRequestReplies(fallback),
374
+ ...systemInfoRequestReplies(),
375
+ ...auth.requestReplies,
376
+ ...notifyRules.requestReplies,
377
+ ...notifyDispatch.requestReplies,
378
+ ...reporting.requestReplies,
379
+ ...reconciliation.requestReplies,
380
+ ...fileServer.requestReplies,
381
+ }, 'REQUEST_SERVER', included),
382
+ }),
383
+ eventHandlers: ofIncluded({
384
+ ...keyValueHandlers(fallback),
385
+ ...auth.eventHandlers,
386
+ ...alertHandlers(fallback),
387
+ ...notifyEvents.eventHandlers,
388
+ ...notifyRules.eventHandlers,
389
+ ...notifyDispatch.eventHandlers,
390
+ ...reporting.eventHandlers,
391
+ ...reconciliation.eventHandlers,
392
+ ...fileServer.eventHandlers,
393
+ }, 'EVENT_HANDLER', included),
379
394
  // The DETAILS classes of the alert events, which their names alone would
380
395
  // make NOTIFY_ALERT table events.
381
396
  eventSchemas: ofIncluded({
@@ -385,11 +400,29 @@ export function platformPreset(options = {}) {
385
400
  className: 'global.genesis.gen.dao.NotifyAlert.ByAlertId',
386
401
  },
387
402
  EVENT_DISMISS_ALL_NOTIFY_ALERT: { fields: [], className: 'kotlin.Unit' },
403
+ ...auth.eventSchemas,
404
+ ...notifyEvents.eventSchemas,
405
+ ...notifyRules.eventSchemas,
406
+ ...notifyDispatch.eventSchemas,
407
+ ...reporting.eventSchemas,
408
+ ...reconciliation.eventSchemas,
409
+ ...fileServer.eventSchemas,
388
410
  }, 'EVENT_HANDLER', included),
389
- auth: { users: authUsers },
411
+ auth: { users: authUsers, directory: auth.directory },
412
+ // auth's change of password, which an expired-password login needs, and
413
+ // file-server's endpoints.
414
+ httpRoutes: [changePasswordRoute, ...(files ? fileServer.httpRoutes : [])],
390
415
  additionalResources: [...productResources(included), ...(options.resources ?? [])],
391
416
  };
392
417
  }
418
+ // The products' typed request servers (requestReply<In, Out>) say so: their
419
+ // META as GSF builds it, PARAMETRIC_TYPE and MAX_ROWS (RequestReplyDef.typed).
420
+ function typedWhereTheyAre(requestReplies) {
421
+ return Object.fromEntries(Object.entries(requestReplies).map(([name, definition]) => {
422
+ const typed = typedRequestReply(name);
423
+ return [name, typed ? { ...definition, typed } : definition];
424
+ }));
425
+ }
393
426
  // auth-dataserver.kts (auth v8.15.5) and genesis-notify-rules-dataserver.kts
394
427
  // (genesis-notify v8.15.16): the ones the generated backing can't say, as
395
428
  // they rename columns or filter the alerts by user.
@@ -412,9 +445,18 @@ function ownQueries(fallback) {
412
445
  },
413
446
  };
414
447
  }
415
- // auth-reqrep.kts (auth v8.15.5): the ones that rename columns.
416
- function ownRequestReplies() {
448
+ // auth-reqrep.kts (auth v8.15.5): the ones that rename columns; and
449
+ // genesis-notify-rules-reqrep.kts (genesis-notify v8.15.16) :162, which filters
450
+ // the alerts' audit by user.
451
+ function ownRequestReplies(fallback) {
417
452
  return {
453
+ // requestReply("NOTIFY_ALERT", NOTIFY_ALERT_AUDIT) { permissioning { auth {
454
+ // filterWithUserName { userName == data.userName } } } }
455
+ NOTIFY_ALERT: {
456
+ source: 'NOTIFY_ALERT_AUDIT',
457
+ requestFields: ['NOTIFY_ALERT_AUDIT_ID'],
458
+ auth: { rowFilter: (row, user) => row.USER_NAME === (user.userName ?? fallback) },
459
+ },
418
460
  // :57 request { CODE } reply { CODE DESCRIPTION }, so its rows carry no
419
461
  // RECORD_ID.
420
462
  RIGHT: { source: 'RIGHT', fields: ['CODE', 'DESCRIPTION'] },
@@ -1,4 +1,4 @@
1
- import type { MockServerConfig, ResourceItem, TableDef } from '../types.ts';
1
+ import type { MockServerConfig, ResourceItem, TableDef, TypedRequestReply } from '../types.ts';
2
2
  /**
3
3
  * A platform product an app may include beside GSF and auth, by its GSF
4
4
  * product name: Create's Notifications, Reporting, Document Management and
@@ -10,14 +10,16 @@ export declare function includedProducts(products?: readonly string[]): Set<stri
10
10
  export declare function productOf(type: ResourceItem['RESOURCE_TYPE'], name: string): string | undefined;
11
11
  export declare function productResources(included: Set<string>): ResourceItem[];
12
12
  export declare function ofIncluded<T>(record: Record<string, T>, type: ResourceItem['RESOURCE_TYPE'], included: Set<string>): Record<string, T>;
13
+ export declare function platformTable(name: string): TableDef;
14
+ export declare const isPlatformTable: (name: string) => boolean;
15
+ export declare const aliasedEnumKeys: (table: string, field: string) => string[] | undefined;
16
+ export declare const fieldFormat: (field: string) => string | undefined;
17
+ export declare const typedRequestReply: (name: string) => TypedRequestReply | undefined;
13
18
  /**
14
19
  * The generated backing for the included products, a fresh copy each call:
15
20
  * 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.
21
+ * (empty, or holding the product's own seed rows) and their views, read or
22
+ * not, as the real dictionary holds them all. A table in `presetTables` is
23
+ * the caller's, and isn't repeated here.
22
24
  */
23
25
  export declare function productBacking(included: Set<string>, presetTables: Record<string, TableDef>): Pick<MockServerConfig, 'tables' | 'views' | 'queries' | 'requestReplies'>;
@@ -43,33 +43,101 @@ export function ofIncluded(record, type, included) {
43
43
  return product === undefined || included.has(product);
44
44
  }));
45
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.
46
+ // 'genesis-notify@8.15.16' -> 'genesis-notify'.
47
+ const productOfOrigin = (origin) => origin.slice(0, origin.lastIndexOf('@'));
48
+ const input = (sources, table, field) => sources.tables[table]?.[field] ?? null;
49
+ const DERIVED = {
50
+ // genesis-notify-view-dictionary.kts:117: timestamp!!.shr(22)
51
+ DYNAMIC_RULE_VIEW: { DATETIME: (_row, s) => input(s, 'DYNAMIC_RULE', 'TIMESTAMP') },
52
+ // reporting-view-dictionary.kts:42-64
53
+ GENERATED_REPORT_VIEW: {
54
+ LAST_UPDATED_AT: (_row, s) => input(s, 'GENERATED_REPORT', 'TIMESTAMP'),
55
+ FILE_NAME: (_row, s) => {
56
+ const name = input(s, 'GENERATED_REPORT', 'FILE_NAME');
57
+ // Status.GENERATED, whose label the column holds.
58
+ if (input(s, 'GENERATED_REPORT', 'STATUS') !== 'Generated')
59
+ return name;
60
+ const configName = input(s, 'REPORT_CONFIG', 'FILE_NAME');
61
+ const format = input(s, 'REPORT_CONFIG', 'OUTPUT_FORMAT');
62
+ return (name ??
63
+ (configName !== null && format !== null
64
+ ? `${configName}.${String(format).toLowerCase()}`
65
+ : null));
66
+ },
67
+ },
68
+ // reconciliation-view-dictionary.kts:30-38: the start, else the timestamp.
69
+ RECONCILIATION_VIEW: {
70
+ DATETIME: (_row, s) => {
71
+ const start = input(s, 'RECONCILIATION', 'START_TIMESTAMP');
72
+ return start === null || start === 0 ? input(s, 'RECONCILIATION', 'TIMESTAMP') : start;
73
+ },
74
+ },
75
+ // :59-63: the comment's timestamp.
76
+ RECONCILIATION_RECORD_RESULT_VIEW: {
77
+ DATETIME: (_row, s) => input(s, 'RECONCILIATION_RECORD_RESULT_COMMENT', 'TIMESTAMP'),
78
+ },
79
+ };
80
+ // A derived field the list above doesn't know is declared, and null.
48
81
  const unmodelledValue = () => null;
82
+ // A platform table as its product's dictionary declares it (fields, key,
83
+ // indexes, sequence, audit), a fresh copy, for the preset to fill.
84
+ export function platformTable(name) {
85
+ const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
86
+ return table;
87
+ }
88
+ export const isPlatformTable = (name) => Object.hasOwn(backing.tables, name);
89
+ // An ALIASED_ENUM column's keys, in its labels' order; undefined for any
90
+ // other column.
91
+ export const aliasedEnumKeys = (table, field) => backing.aliasedEnums[`${table}.${field}`];
92
+ // A platform RAW field's format (BASE_64, UTF_8), if it has one.
93
+ export const fieldFormat = (field) => backing.fieldFormats[field];
94
+ // A product's typed request server (requestReply<In, Out>), a fresh copy, if
95
+ // `name` is one.
96
+ export const typedRequestReply = (name) => Object.hasOwn(backing.typedRequestReplies, name)
97
+ ? structuredClone(backing.typedRequestReplies[name])
98
+ : undefined;
99
+ const AUDIT_SUFFIX = '_AUDIT';
49
100
  /**
50
101
  * The generated backing for the included products, a fresh copy each call:
51
102
  * 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.
103
+ * (empty, or holding the product's own seed rows) and their views, read or
104
+ * not, as the real dictionary holds them all. A table in `presetTables` is
105
+ * the caller's, and isn't repeated here.
58
106
  */
59
107
  export function productBacking(included, presetTables) {
60
- const tables = new Set();
61
- const views = new Set();
108
+ // Every table of an included product, which its event handlers write; a
109
+ // query or request server reads some. An audit table is the engine's to
110
+ // derive from its table's `audit`.
111
+ const tables = new Set(Object.entries(backing.tables)
112
+ .filter(([, table]) => included.has(productOfOrigin(table.dictionary)))
113
+ .map(([name]) => name));
114
+ // A table the app has: a preset or product one, or the audit table the
115
+ // engine derives from an audited one.
116
+ const definitionOf = (name) => presetTables[name] ?? (tables.has(name) ? backing.tables[name] : undefined);
117
+ const hasTable = (name) => definitionOf(name) !== undefined ||
118
+ (name.endsWith(AUDIT_SUFFIX) &&
119
+ Boolean(definitionOf(name.slice(0, -AUDIT_SUFFIX.length))?.audit));
120
+ const views = new Set(Object.entries(backing.views)
121
+ .filter(([, view]) => included.has(productOfOrigin(view.dictionary)) &&
122
+ [view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable))
123
+ .map(([name]) => name));
62
124
  const pick = (entries) => Object.fromEntries(Object.entries(entries).flatMap(([name, entry]) => {
63
- const { product, script: _script, reads, unmodelled: _unmodelled, ...definition } = structuredClone(entry);
125
+ const { product, script: _script, reads: _reads, unmodelled: _unmodelled, ...definition } = structuredClone(entry);
64
126
  if (!included.has(product))
65
127
  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
128
  const { source } = definition;
71
- if (source && source in backing.views)
129
+ // A source the app can't build is never served, should a product
130
+ // read another's view or table.
131
+ if (source && source in backing.views) {
132
+ const view = backing.views[source];
133
+ if (![view.base, ...(view.joins ?? []).map(({ table }) => table)].every(hasTable)) {
134
+ return [];
135
+ }
72
136
  views.add(source);
137
+ }
138
+ else if (source && !hasTable(source)) {
139
+ return [];
140
+ }
73
141
  return [[name, definition]];
74
142
  }));
75
143
  const queries = pick(backing.queries);
@@ -77,15 +145,15 @@ export function productBacking(included, presetTables) {
77
145
  return {
78
146
  tables: Object.fromEntries([...tables]
79
147
  .filter((name) => !(name in presetTables))
80
- .map((name) => {
81
- const { dictionary: _dictionary, ...table } = structuredClone(backing.tables[name]);
82
- return [name, table];
83
- })),
148
+ .map((name) => [name, platformTable(name)])),
84
149
  views: Object.fromEntries([...views].map((name) => {
85
150
  const { dictionary: _dictionary, derivedTypes, ...view } = structuredClone(backing.views[name]);
86
151
  const derived = derivedTypes && {
87
152
  derivedTypes: derivedTypes,
88
- derived: Object.fromEntries(Object.keys(derivedTypes).map((field) => [field, unmodelledValue])),
153
+ derived: Object.fromEntries(Object.keys(derivedTypes).map((field) => [
154
+ field,
155
+ DERIVED[name]?.[field] ?? unmodelledValue,
156
+ ])),
89
157
  };
90
158
  return [name, { ...view, ...derived }];
91
159
  })),
@@ -0,0 +1,18 @@
1
+ import type { EventHandler, EventHandlerCtx, EventSchemaOverride, RequestReplyDef } from '../types.ts';
2
+ export type FileContent = (store: EventHandlerCtx['store'], fileStorageId: string) => {
3
+ fileName: string;
4
+ } | {
5
+ error: string;
6
+ };
7
+ export interface ReconciliationOptions {
8
+ userOf(ctx: EventHandlerCtx): string;
9
+ runMs: number;
10
+ pipelines?: string[];
11
+ fileContent?: FileContent;
12
+ }
13
+ export interface ReconciliationBacking {
14
+ eventHandlers: Record<string, EventHandler>;
15
+ eventSchemas: Record<string, EventSchemaOverride>;
16
+ requestReplies: Record<string, RequestReplyDef>;
17
+ }
18
+ export declare function reconciliationBacking(options: ReconciliationOptions): ReconciliationBacking;