@genesislcap/mock-server 15.71.1-alpha-71cb16e4d3.0 → 15.73.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 (42) hide show
  1. package/README.md +58 -5
  2. package/dist/db/audit.d.ts +12 -0
  3. package/dist/db/audit.js +98 -0
  4. package/dist/db/criteriaDialect.js +15 -8
  5. package/dist/db/criteriaJuxtaposition.d.ts +6 -0
  6. package/dist/db/criteriaJuxtaposition.js +123 -0
  7. package/dist/db/groovySyntax.js +4 -1
  8. package/dist/db/groovyValidator.js +166 -7
  9. package/dist/db/schema.d.ts +2 -0
  10. package/dist/db/schema.js +2 -0
  11. package/dist/db/store.d.ts +14 -2
  12. package/dist/db/store.js +64 -4
  13. package/dist/handlers/commitEvent.js +16 -3
  14. package/dist/handlers/dataLogon.js +8 -4
  15. package/dist/handlers/jsonSchema.js +1 -1
  16. package/dist/handlers/meta.js +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/protocol/fieldTypes.d.ts +5 -1
  19. package/dist/protocol/fieldTypes.js +9 -2
  20. package/dist/protocol/msgNack.d.ts +2 -0
  21. package/dist/protocol/msgNack.js +14 -0
  22. package/dist/protocol/router.js +12 -1
  23. package/dist/server.js +21 -2
  24. package/dist/types.d.ts +6 -0
  25. package/package.json +1 -1
  26. package/src/db/audit.ts +127 -0
  27. package/src/db/criteriaDialect.ts +15 -8
  28. package/src/db/criteriaJuxtaposition.ts +132 -0
  29. package/src/db/groovySyntax.ts +6 -1
  30. package/src/db/groovyValidator.ts +176 -11
  31. package/src/db/schema.ts +4 -0
  32. package/src/db/store.ts +70 -4
  33. package/src/handlers/commitEvent.ts +18 -3
  34. package/src/handlers/dataLogon.ts +8 -4
  35. package/src/handlers/jsonSchema.ts +1 -1
  36. package/src/handlers/meta.ts +1 -1
  37. package/src/index.ts +1 -0
  38. package/src/protocol/fieldTypes.ts +13 -2
  39. package/src/protocol/msgNack.ts +16 -0
  40. package/src/protocol/router.ts +14 -1
  41. package/src/server.ts +26 -2
  42. package/src/types.ts +17 -0
@@ -17,7 +17,7 @@ import type { GenesisMessage, MockServerConfig } from '../types.ts';
17
17
  import type { Connection } from './connection.ts';
18
18
  import { isLegacyFidelity } from './fidelity.ts';
19
19
  import { MESSAGE_TYPE, ERROR_CODE, isCommitEvent, isRequestReply } from './messageTypes.ts';
20
- import { websocketForbiddenNack } from './msgNack.ts';
20
+ import { missingMessageTypeNack, missingSourceRefNack, websocketForbiddenNack } from './msgNack.ts';
21
21
 
22
22
  // Message types a connection may send before authenticating when the OPT-IN
23
23
  // auth gate (config.auth.requireAuth = true) is enabled. Everything else
@@ -90,6 +90,10 @@ function replyNotLoggedOn(message: GenesisMessage, connection: Connection): void
90
90
  connection.reply(message, { MESSAGE_TYPE: type, ERROR });
91
91
  }
92
92
 
93
+ // Kotlin's isNullOrBlank on GenesisSet.getString, which reads any value as text.
94
+ const isBlank = (value: unknown) =>
95
+ value === undefined || value === null || String(value).trim() === '';
96
+
93
97
  export function routeMessage(
94
98
  inbound: GenesisMessage,
95
99
  connection: Connection,
@@ -112,6 +116,15 @@ export function routeMessage(
112
116
  message = { ...message, SESSION_AUTH_TOKEN: cookieToken };
113
117
  }
114
118
 
119
+ // GSF refuses a message with no SOURCE_REF or MESSAGE_TYPE, a heartbeat
120
+ // included, before its client handler sees it (so LAST_SENT and
121
+ // LAST_RECEIVED stay as they were); the 15.47 mock routed it anyway.
122
+ if (!isLegacyFidelity(config)) {
123
+ if (isBlank(message.SOURCE_REF)) return connection.send(missingSourceRefNack(), false);
124
+ if (isBlank(message.MESSAGE_TYPE))
125
+ return connection.reply(message, missingMessageTypeNack(), false);
126
+ }
127
+
115
128
  // Adopt token auth on every message (not just gated ones) so e.g. a
116
129
  // HEARTBEAT_PONG's IS_AUTHENTICATED reflects an HTTP-issued token straight
117
130
  // away; the gate itself only applies to data traffic.
package/src/server.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import http from 'node:http';
2
2
  import { WebSocketServer, type WebSocket } from 'ws';
3
+ import {
4
+ auditTableDef,
5
+ auditTableName,
6
+ checkNotDeclared,
7
+ isAudited,
8
+ withAuditTables,
9
+ } from './db/audit.ts';
3
10
  import { recordKey } from './db/identity.ts';
4
11
  import { compareRecordIds } from './db/ordering.ts';
5
12
  import { Store } from './db/store.ts';
@@ -131,7 +138,12 @@ const HTTP_UNAUTHORIZED = 401;
131
138
  export function createMockServer(config: MockServerConfig): MockServer {
132
139
  // Declared columns are held by type (db/values.ts), except under
133
140
  // fidelity: 'legacy', which keeps rows as given.
134
- const store = new Store({ normalizeValues: () => !isLegacyFidelity(config) });
141
+ const store = new Store({
142
+ normalizeValues: () => !isLegacyFidelity(config),
143
+ holdSharedSequences: () => !isLegacyFidelity(config),
144
+ });
145
+ // An audited table's audit table is a table like any other from here on.
146
+ if (config.tables) config.tables = withAuditTables(config.tables);
135
147
  for (const [tableName, tableDef] of Object.entries(config.tables ?? {})) {
136
148
  store.registerTable(tableName, tableDef);
137
149
  }
@@ -590,8 +602,20 @@ export function createMockServer(config: MockServerConfig): MockServer {
590
602
  // want to inject a one-off failure/edge case (`extendEventHandler`) without
591
603
  // spinning up a second server.
592
604
  function setTable(tableName: string, tableDef: TableDef): void {
593
- config.tables = { ...config.tables, [tableName]: tableDef };
605
+ checkNotDeclared(config.tables ?? {}, tableName, tableDef);
606
+ const tables = { ...config.tables, [tableName]: tableDef };
607
+ // Nor may it take over a table declared under its audit table's name.
608
+ if (isAudited(tableDef)) {
609
+ const auditName = auditTableName(tableName);
610
+ checkNotDeclared(tables, auditName, config.tables?.[auditName]);
611
+ }
612
+ config.tables = tables;
594
613
  store.registerTable(tableName, tableDef);
614
+ // A new definition makes a new audit table too, empty as the table's
615
+ // own rows are its new ones.
616
+ if (isAudited(tableDef)) {
617
+ setTable(auditTableName(tableName), auditTableDef(tableName, tableDef));
618
+ }
595
619
  }
596
620
 
597
621
  function setView(viewName: string, viewDef: ViewDef): void {
package/src/types.ts CHANGED
@@ -56,6 +56,11 @@ export interface FieldDef {
56
56
  scale?: number;
57
57
  // `metadata { minLength = 0 }`: MIN_LENGTH / minLength.
58
58
  minLength?: number;
59
+ // An INT, SHORT, LONG or DOUBLE column's `metadata { min = 0; max = 100 }`:
60
+ // MIN / MAX in event META and minimum / maximum in the event's JSON schema,
61
+ // which an inbound event is validated against. Unset: the type's own range.
62
+ min?: number;
63
+ max?: number;
59
64
  // Replaces the DESCRIPTION / description the real server fills with the
60
65
  // field's JVM class (kotlin.String, org.joda.time.DateTime, ...). Leave it
61
66
  // unset for DATE/DATETIME: foundation-forms recognises dates partly by that
@@ -131,6 +136,18 @@ export interface TableDef {
131
136
  // eventHandlers entry of the same name wins. See the README's "Generic CRUD
132
137
  // events".
133
138
  events?: CrudEventVerb[];
139
+ // `audit = details(…, sequence = "XA")` in the dictionary: the table gets a
140
+ // <TABLE>_AUDIT table (its fields, <TABLE>_AUDIT_ID from the audit sequence,
141
+ // AUDIT_EVENT_TYPE / _DATETIME / _TEXT / _USER), and every write an event
142
+ // handler makes to it adds a row there. Serve it with a requestReplies entry
143
+ // like any table (`requestFields` the table's key, for GSF's
144
+ // BY_UNDERLYING_ID). See the README's "Audit tables".
145
+ audit?: boolean | AuditDef;
146
+ }
147
+
148
+ export interface AuditDef {
149
+ // The audit sequence (`sequence = "XA"`), for <TABLE>_AUDIT_ID. Default 'AU'.
150
+ sequencePrefix?: string;
134
151
  }
135
152
 
136
153
  // 'prefix' (the default): sequencePrefix + a counter padded to sequenceWidth