@genesislcap/mock-server 15.3.2-canary.16
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 +262 -0
- package/license.txt +46 -0
- package/package.json +37 -0
- package/src/db/criteria.ts +182 -0
- package/src/db/metadata.ts +32 -0
- package/src/db/store.ts +173 -0
- package/src/handlers/auth.ts +91 -0
- package/src/handlers/commitEvent.ts +54 -0
- package/src/handlers/dataLogon.ts +52 -0
- package/src/handlers/heartbeat.ts +10 -0
- package/src/handlers/http.ts +153 -0
- package/src/handlers/jsonSchema.ts +92 -0
- package/src/handlers/meta.ts +49 -0
- package/src/handlers/requestReply.ts +47 -0
- package/src/handlers/resources.ts +35 -0
- package/src/index.ts +25 -0
- package/src/protocol/connection.ts +50 -0
- package/src/protocol/errors.ts +32 -0
- package/src/protocol/messageTypes.ts +38 -0
- package/src/protocol/router.ts +45 -0
- package/src/protocol/rowUpdate.ts +25 -0
- package/src/server.ts +251 -0
- package/src/types.ts +116 -0
- package/tsconfig.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# @genesislcap/mock-server
|
|
2
|
+
|
|
3
|
+
A reusable, in-memory Genesis Framework WebSocket protocol server for client
|
|
4
|
+
automation and local dev — no JVM, no database, starts in milliseconds.
|
|
5
|
+
|
|
6
|
+
Written in TypeScript, runs directly from source under **either** runtime, no
|
|
7
|
+
build step:
|
|
8
|
+
|
|
9
|
+
- **Node (>=22.6)**: `node --experimental-strip-types src/index.ts`. Node's
|
|
10
|
+
type-stripping flag erases type annotations at load time; it does not
|
|
11
|
+
type-check. This is the default/safe choice — nothing extra to install
|
|
12
|
+
beyond the Node version the rest of this monorepo already requires.
|
|
13
|
+
- **[Bun](https://bun.sh) (>=1.1.0)**: `bun run src/index.ts`. Bun's own TS
|
|
14
|
+
support is used instead — faster startup, but requires installing Bun
|
|
15
|
+
separately (`brew install bun` or https://bun.sh/install).
|
|
16
|
+
|
|
17
|
+
Both runtimes execute the exact same `.ts` sources unmodified — this package
|
|
18
|
+
deliberately avoids any Bun-only API (e.g. `Bun.serve`'s native WebSocket
|
|
19
|
+
support) in favor of `node:http` + the `ws` package, which both runtimes
|
|
20
|
+
support identically. All relative imports use explicit `.ts` extensions
|
|
21
|
+
(`import { X } from './foo.ts'`) rather than the more common `.js`-referring-
|
|
22
|
+
to-`.ts` convention, because Node's type-stripping resolver requires the
|
|
23
|
+
literal extension match — Bun is lenient about this but Node isn't, so `.ts`
|
|
24
|
+
is the one form that works everywhere. `tsconfig.json` sets
|
|
25
|
+
`allowImportingTsExtensions: true` so `tsc` accepts this without complaint.
|
|
26
|
+
|
|
27
|
+
Type-check with `npm run --workspace=@genesislcap/mock-server typecheck`
|
|
28
|
+
(`tsc --noEmit`) — this is for editor/CI type-checking only; neither runtime
|
|
29
|
+
compiles or reads the emitted output (there isn't any, `noEmit: true`).
|
|
30
|
+
|
|
31
|
+
This package is the **protocol engine only**: message routing, `SOURCE_REF`
|
|
32
|
+
correlation, `CRITERIA_MATCH` evaluation, subscription/broadcast plumbing, and
|
|
33
|
+
auto-derived field metadata. It knows nothing about any specific project's
|
|
34
|
+
tables or business rules — that lives in per-project config, seeded via
|
|
35
|
+
`createMockServer(config)`. See
|
|
36
|
+
[`packages/showcase/client-app/mock-server`](../../showcase/client-app/mock-server)
|
|
37
|
+
for a complete example wired up against the showcase app.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createMockServer, NackError, type MockServerConfig } from '@genesislcap/mock-server';
|
|
43
|
+
|
|
44
|
+
const config: MockServerConfig = {
|
|
45
|
+
tables: {
|
|
46
|
+
TRADE: { pkField: 'TRADE_ID', sequencePrefix: 'TR', rows: [...] },
|
|
47
|
+
},
|
|
48
|
+
views: {
|
|
49
|
+
TRADE_VIEW: {
|
|
50
|
+
base: 'TRADE',
|
|
51
|
+
pkField: 'TRADE_ID',
|
|
52
|
+
joins: [{ table: 'COUNTERPARTY', on: ['COUNTERPARTY_ID', 'COUNTERPARTY_ID'], select: { COUNTERPARTY_NAME: 'NAME' } }],
|
|
53
|
+
derived: { TOTAL: (row) => row.PRICE + row.QUANTITY },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
queries: {
|
|
57
|
+
ALL_TRADES: { source: 'TRADE_VIEW' },
|
|
58
|
+
},
|
|
59
|
+
requestReplies: {
|
|
60
|
+
TRADE: { source: 'TRADE' },
|
|
61
|
+
},
|
|
62
|
+
eventHandlers: {
|
|
63
|
+
EVENT_TRADE_INSERT: (details, { store, broadcastTableChange }) => {
|
|
64
|
+
if (!store.getRow('COUNTERPARTY', details.COUNTERPARTY_ID)) {
|
|
65
|
+
throw new NackError({ TEXT: `Counterparty '${details.COUNTERPARTY_ID}' does not exist`, FIELD: 'COUNTERPARTY_ID' });
|
|
66
|
+
}
|
|
67
|
+
const row = store.insertRow('TRADE', details);
|
|
68
|
+
broadcastTableChange('TRADE', 'INSERT', row.TRADE_ID);
|
|
69
|
+
return { generated: [{ TRADE_ID: row.TRADE_ID }] };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
auth: {
|
|
73
|
+
users: [{ username: 'admin', password: 'admin', profile: ['USER_ADMIN'], permission: [] }],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const server = createMockServer(config);
|
|
78
|
+
server.start(9064);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Two auth transports
|
|
82
|
+
|
|
83
|
+
Genesis client apps built on `@genesislcap/foundation-auth`'s login UI don't
|
|
84
|
+
use the WebSocket `EVENT_LOGIN_AUTH` flow at all — they POST credentials over
|
|
85
|
+
plain HTTP to `gwf/event-login-auth`, and GET `gwf/event-login-details` on
|
|
86
|
+
every app load for cookie-based silent login
|
|
87
|
+
(`foundation-comms/src/connect/sessionRefresh.ts`'s `isAuthenticated()`).
|
|
88
|
+
`createMockServer` runs one `http.Server` (via `node:http` + the `ws`
|
|
89
|
+
package) that both the WebSocket upgrade and the HTTP login handler
|
|
90
|
+
(`handlers/http.ts`, built on Node's `IncomingMessage`/`ServerResponse`)
|
|
91
|
+
share, so both transports work against the same port under either runtime.
|
|
92
|
+
|
|
93
|
+
Set `config.auth.httpAutoLogin: '<username>'` to make `event-login-details`
|
|
94
|
+
always ack as that user — the client's silent-login check succeeds on first
|
|
95
|
+
load and the login screen never appears, which is usually what you want for
|
|
96
|
+
CI/local dev. Leave it unset to require an explicit `EVENT_LOGIN_AUTH` POST
|
|
97
|
+
(validated against `config.auth.users`, same as the WS flow) before
|
|
98
|
+
`event-login-details` will succeed on a later reload.
|
|
99
|
+
|
|
100
|
+
## Protocol coverage
|
|
101
|
+
|
|
102
|
+
| MESSAGE_TYPE | Handled |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `EVENT_LOGIN_AUTH` / `_ACK` / `_NACK` (WS) | ✅ |
|
|
105
|
+
| `gwf/event-login-auth`, `gwf/event-login-details` (HTTP) | ✅ |
|
|
106
|
+
| `EVENT_LOGOUT` / `LOGOUT_ACK` | ✅ |
|
|
107
|
+
| `HEARTBEAT_PING` / `_PONG` | ✅ |
|
|
108
|
+
| `DATA_LOGON` / `DATA_LOGOFF` / `QUERY_UPDATE` | ✅ snapshot + live push |
|
|
109
|
+
| `META_REQUEST` | ✅ auto-derived from seed data |
|
|
110
|
+
| `JSON_SCHEMA_REQUEST` | ✅ auto-derived per event — see below |
|
|
111
|
+
| `RESOURCES_REQUEST` | ✅ |
|
|
112
|
+
| `REQ_<NAME>` / `REP_<NAME>` | ✅ |
|
|
113
|
+
| `EVENT_<ENTITY>_<VERB>` commit events | ✅ via `config.eventHandlers` |
|
|
114
|
+
|
|
115
|
+
## Entity-management (`@genesislcap/foundation-entity-management`) support
|
|
116
|
+
|
|
117
|
+
`<entity-management>`'s create/update forms and delete confirmation don't use
|
|
118
|
+
`META_REQUEST` at all — they call `JSON_SCHEMA_REQUEST` for the *event name*
|
|
119
|
+
(e.g. `EVENT_COUNTERPARTY_INSERT`), and read the reply's
|
|
120
|
+
`INBOUND.properties.DETAILS.properties` to know which fields to render (for
|
|
121
|
+
insert/update) or which fields to copy from the selected row into the commit
|
|
122
|
+
payload (for delete). It's a completely different reply shape from
|
|
123
|
+
`META_REQUEST` (`{INBOUND, OUTBOUND}` draft-07 JSON Schema, not
|
|
124
|
+
`{DETAILS: {FIELD}}`) — route it through the same handler as `META_REQUEST`
|
|
125
|
+
and every entity-management form silently renders with zero fields, and
|
|
126
|
+
delete can never build a payload. No error, no console warning — just a dead
|
|
127
|
+
button.
|
|
128
|
+
|
|
129
|
+
`handleJsonSchemaRequest()` (`src/handlers/jsonSchema.ts`) resolves this with
|
|
130
|
+
zero config for the common case: `EVENT_<TABLE>_<VERB...>` is matched against
|
|
131
|
+
`config.tables` (longest match wins), and any event name matching
|
|
132
|
+
`.../_DELETE(/...)?/` gets a PK-only schema (matching what
|
|
133
|
+
`EntityManagement.confirmDelete` actually needs) while everything else gets
|
|
134
|
+
every field on that table. This covers naming variants like
|
|
135
|
+
`EVENT_COUNTERPARTY_INSERT_WITH_APPROVAL`, `EVENT_TRADE_MODIFY_PRICE`, or
|
|
136
|
+
`EVENT_TRADE_INSERT_FAIL` without per-event config. Override via
|
|
137
|
+
`config.eventSchemas['<eventName>'] = { table, pkOnly, fieldTypes }` for
|
|
138
|
+
names that don't follow the convention.
|
|
139
|
+
|
|
140
|
+
Everything else `<entity-management>` needs — resource discovery
|
|
141
|
+
(`RESOURCES_REQUEST`), grid metadata (`META_REQUEST`), row data (`DATA_LOGON`
|
|
142
|
+
or `REQ_<name>` depending on `datasourceType`), and the actual
|
|
143
|
+
insert/update/delete commit — reuses the exact same handlers as any other
|
|
144
|
+
project on this engine; there is no entity-management-specific commit
|
|
145
|
+
envelope.
|
|
146
|
+
|
|
147
|
+
## Overriding or extending a dataserver or event handler
|
|
148
|
+
|
|
149
|
+
`createMockServer()` returns a handle with `set*`/`get*`/`extend*` methods
|
|
150
|
+
for every config section — use these instead of forking a shared config
|
|
151
|
+
object when you only need to change one thing:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { createMockServer, NackError } from '@genesislcap/mock-server';
|
|
155
|
+
import { config as baseConfig } from './showcase-config.ts';
|
|
156
|
+
|
|
157
|
+
const server = createMockServer(baseConfig);
|
|
158
|
+
|
|
159
|
+
// Override a dataserver (query) entirely — e.g. point it at a different
|
|
160
|
+
// source, or add fieldTypes overrides.
|
|
161
|
+
server.setQuery('ALL_TRADES', { source: 'TRADE_VIEW', fieldTypes: { PRICE: 'DOUBLE' } });
|
|
162
|
+
|
|
163
|
+
// Override an event handler entirely — e.g. force a scenario for one test.
|
|
164
|
+
server.setEventHandler('EVENT_TRADE_INSERT', () => {
|
|
165
|
+
throw new NackError({ TEXT: 'Simulated outage', FIELD: 'COUNTERPARTY_ID' });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Extend (wrap) the existing handler instead of replacing it — augment(current)
|
|
169
|
+
// gets the handler currently registered (undefined if none), and returns the
|
|
170
|
+
// new one. Useful for adding a side effect, a delay, or partial validation
|
|
171
|
+
// without re-implementing the whole handler.
|
|
172
|
+
server.extendEventHandler('EVENT_TRADE_INSERT', (original) => (details, ctx) => {
|
|
173
|
+
console.log('inserting trade', details);
|
|
174
|
+
return original(details, ctx);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Same pattern for requestReplies, tables, and views (setTable/setView also
|
|
178
|
+
// register the change into the live Store, not just config).
|
|
179
|
+
server.extendQuery('ALL_TRADES', (current) => ({ ...current, fieldTypes: { ...current.fieldTypes, SIDE: 'STRING' } }));
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
These mutate the server's own config object in place, and every handler
|
|
183
|
+
resolves `config.eventHandlers[name]`/`config.queries[name]` fresh on each
|
|
184
|
+
message — so changes take effect immediately on an already-`start()`ed
|
|
185
|
+
server, no restart needed. This is deliberate: it lets a test inject a
|
|
186
|
+
one-off failure or edge case for a single scenario (e.g. "force this insert
|
|
187
|
+
to NACK") and then move on, without spinning up a second server or
|
|
188
|
+
duplicating the whole config for one different handler.
|
|
189
|
+
|
|
190
|
+
For compile-time composition (a new project starting from the showcase's
|
|
191
|
+
config but changing a handful of things up front), plain object spreading
|
|
192
|
+
works just as well and needs no special API:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { config as baseConfig } from '@genesislcap/showcase-mock-server/config.ts';
|
|
196
|
+
|
|
197
|
+
export const config = {
|
|
198
|
+
...baseConfig,
|
|
199
|
+
eventHandlers: { ...baseConfig.eventHandlers, EVENT_TRADE_INSERT: myOverride },
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Protocol-correctness pitfalls this engine handles for you
|
|
204
|
+
|
|
205
|
+
These are real bugs that make a real Genesis client hang silently (no error,
|
|
206
|
+
no timeout) if you get them wrong — see the full write-up this package was
|
|
207
|
+
extracted from for how each was actually found:
|
|
208
|
+
|
|
209
|
+
1. **Every response echoes the request's `SOURCE_REF`.** `Connection.reply()`
|
|
210
|
+
(`src/protocol/connection.ts`) does this automatically — never build a raw
|
|
211
|
+
response object yourself without going through it. A response missing
|
|
212
|
+
`SOURCE_REF` leaves the client's pending promise unresolved forever.
|
|
213
|
+
2. **`EVENT_NACK`/`REP_*` errors are always `ERROR: [{CODE, TEXT}]`** — an
|
|
214
|
+
array, uppercase keys. Throw `NackError` from an event handler or
|
|
215
|
+
request-reply resolver rather than hand-rolling this shape; a lowercase
|
|
216
|
+
`{error, details}` object crashes the real client's `.forEach`.
|
|
217
|
+
3. **`DATA_LOGON` snapshot and later live pushes use the identical envelope**
|
|
218
|
+
(`MESSAGE_TYPE: 'QUERY_UPDATE'`, same `SOURCE_REF`) — the client
|
|
219
|
+
distinguishes insert/amend/delete purely via each row's
|
|
220
|
+
`DETAILS.OPERATION` (`'INSERT' | 'MODIFY' | 'DELETE'`, no other vocabulary
|
|
221
|
+
is recognized) plus `DETAILS.ROW_REF` for row identity. `stampRow()`
|
|
222
|
+
(`src/protocol/rowUpdate.ts`) does this for you — always route pushes
|
|
223
|
+
through `broadcast()`/`broadcastTableChange()`, never `connection.send()`
|
|
224
|
+
directly.
|
|
225
|
+
4. **Datasource `init()` needs `TYPE: 'DATASERVER'` plus a non-empty `FIELD`
|
|
226
|
+
array** or the client silently reports "no fields returned" and gives up.
|
|
227
|
+
`deriveFields()` (`src/db/metadata.ts`) infers this from the seed rows'
|
|
228
|
+
own JS types the first time a resource is queried — only hand-author
|
|
229
|
+
metadata for cases inference gets wrong.
|
|
230
|
+
5. **`CRITERIA_MATCH` needs more than `==`.** `compileCriteria()`
|
|
231
|
+
(`src/db/criteria.ts`) supports `== != > >= < <= AND OR NOT` and
|
|
232
|
+
parentheses via a small typed grammar (not `eval`/`new Function` — a
|
|
233
|
+
malformed criteria string can only fail to parse, never execute
|
|
234
|
+
arbitrary JS).
|
|
235
|
+
6. **Composite-key AMEND/DELETE matching needs a fallback beyond the PK.**
|
|
236
|
+
`Store.findRow()` (`src/db/store.ts`) tries the configured PK field, then
|
|
237
|
+
any single field that uniquely identifies one row, then the full
|
|
238
|
+
combination of provided fields — needed for tables where no single field
|
|
239
|
+
is unique on its own.
|
|
240
|
+
|
|
241
|
+
## Known, accepted limitation
|
|
242
|
+
|
|
243
|
+
If a live update makes a row fall out of a subscription's `CRITERIA_MATCH`,
|
|
244
|
+
the correct behavior is to push it as a `DELETE` so the client drops the now
|
|
245
|
+
out-of-scope row. This engine does not do that automatically — `broadcast()`
|
|
246
|
+
only checks the *new* row against the predicate, so a row that stops
|
|
247
|
+
matching just stops being pushed rather than being explicitly removed from
|
|
248
|
+
the client's local state. Fix this in your own `eventHandlers` if a project
|
|
249
|
+
leans harder on live filtering than the showcase example does (e.g. re-check
|
|
250
|
+
membership yourself and call `broadcastTableChange(table, 'DELETE', pk)`
|
|
251
|
+
when a row exits the criteria).
|
|
252
|
+
|
|
253
|
+
## What's per-project vs. generic
|
|
254
|
+
|
|
255
|
+
Per-project (goes in your own config, e.g. `packages/showcase/client-app/mock-server`):
|
|
256
|
+
table/view schemas, seed data, event-handler names and validation rules, auth
|
|
257
|
+
users.
|
|
258
|
+
|
|
259
|
+
Generic (lives here): message routing, `SOURCE_REF` handling, criteria
|
|
260
|
+
evaluation, metadata derivation, subscription/broadcast plumbing. If you're
|
|
261
|
+
building a mock server for a different Genesis client app, depend on this
|
|
262
|
+
package and write your own config — don't fork the engine.
|
package/license.txt
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Developer License Agreement
|
|
2
|
+
|
|
3
|
+
This Developer License Agreement (the “Agreement”) is entered into by and between Genesis, Global FinTech Inc.(“Genesis”) and you and/or the entity on whose behalf you are downloading the Software (as defined below) (“you”). This Agreement forms a legally binding contract between you and Genesis in relation to your use of the software libraries, reference implementations, and other related demonstration code (collectively, the “Genesis Software”). [a]
|
|
4
|
+
|
|
5
|
+
To use the Software, you must first agree to this Agreement. You may not use the Software if you do not agree to be bound by the terms of this Agreement. Accordingly, you and Genesis acknowledge and agree as follows:
|
|
6
|
+
|
|
7
|
+
1. LIMITED LICENSE.
|
|
8
|
+
Subject to your complete and ongoing compliance with all the terms and conditions set forth in this Agreement, including without limitation all license limitations and restrictions set forth herein, Genesis grants you the following limited, non-exclusive, non-transferable, non-sublicensable, revocable licenses to use, and (where applicable) authorize your employees to use, the Software internally solely in connection with building, developing and testing your own applications that interoperate with or incorporate the Software (“Applications”) for the purposes of evaluation.
|
|
9
|
+
|
|
10
|
+
2. RESTRICTIONS.
|
|
11
|
+
A. By accessing or using the Software, you represent, warrant, and covenant that (a) you are a person or business entity engaged in the development of software applications, and (b) in the case of a business entity, you have the full power and authority to bind such entity to the terms of this Agreement.
|
|
12
|
+
B. You acknowledge that the foregoing license does not include any right to:
|
|
13
|
+
(i) redistribute, sell, lease, license, modify or otherwise create any derivative works of any portion of the Software, or;
|
|
14
|
+
(ii) distribute, deploy, or otherwise utilize Applications on a public, production, commercial, or other similar purpose other than internal use for evaluation and the development of non-public, experimental Applications (any other public, production, commercial, or similar use requires a separate agreement with Genesis), or
|
|
15
|
+
(iii) use or implement any undocumented feature or API or use any documented feature or API other than in accordance with applicable documentation. You agree to not to do any of the foregoing.
|
|
16
|
+
C. Except as expressly provided herein, you may not:
|
|
17
|
+
(a) reproduce, distribute, publicly display, or publicly perform any part of the Software;
|
|
18
|
+
(b) decompile, reverse engineer, or otherwise access or attempt to access the source code for the Software not made available to you in source code form;
|
|
19
|
+
(c) make or attempt to make any modification to, or otherwise create derivative works of the Software; or
|
|
20
|
+
(d) remove, obscure, interfere with or circumvent any feature of the Software, including without limitation any copyright or other intellectual property notices, security, or access control mechanism;
|
|
21
|
+
(f) use the Software to do anything illegal, including facilitating, promoting, or otherwise encouraging any illegal activities.
|
|
22
|
+
|
|
23
|
+
3. RESERVATION OF RIGHTS.
|
|
24
|
+
A. The Software is owned by Genesis and licensed, not sold, to you. The Software, content, visual interfaces, interactive features, information, graphics, design, compilation, computer code, products, services, and all other elements of the Software and related documentation (the “Materials“), are protected by copyright, trade dress, patent, and trademark laws of the United States and other jurisdictions, international conventions, and all other relevant intellectual property and proprietary rights, and applicable laws (collectively, the “Intellectual Property Rights“).
|
|
25
|
+
B. You agree that Genesis or its subsidiaries or affiliated companies and/or its third-party licensors own all legal right, title and interest in and to the Software and Materials, including any and all Intellectual Property Rights. Genesis reserves all rights not expressly granted in this Agreement. You do not acquire any right, interest or title to the Materials, whether by implication, estoppel, or otherwise, except for the limited rights set forth in this Agreement.
|
|
26
|
+
C. You agree that the form and nature of the Software that Genesis provides may change without prior notice to you and that future versions of the Software may be incompatible with applications developed on previous of the Software. You agree that Genesis may stop (permanently or temporarily) providing the Software (or any features within the Software) to you or to users generally at Genesis’s sole discretion, without prior notice to you. Nothing in this Agreement gives you a right to use any of Genesis’s trade names, trademarks, service marks, logos, domain names, or other distinctive brand features.
|
|
27
|
+
|
|
28
|
+
4. TERMINATION.
|
|
29
|
+
At Genesis’s sole discretion, Genesis may terminate your Developer License and cease provision of the Genesis Software with or without notice, effective immediately, for any reason or no reason at all. Upon the expiration or termination of this Agreement all rights and licenses granted under this Agreement will immediately terminate.
|
|
30
|
+
|
|
31
|
+
5. THIRD PARTY SOFTWARE.
|
|
32
|
+
The Software consists of a package of components and may include references to certain third-party software (“Third Party Software”) that are provided by their authors under separate license terms (the “Third Party Terms”). Your use of any such Third-Party Software in conjunction with the Software in a manner consistent with this Agreement is permitted, however, you may have broader rights and/or restrictions under the applicable Third-Party Terms. Genesis cannot accept any responsibility for the Third-Party Software or your use thereof.
|
|
33
|
+
|
|
34
|
+
6. DISCLAIMER OF WARRANTIES.
|
|
35
|
+
YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SOFTWARE IS AT YOUR SOLE RISK AND THAT THE SOFTWARE IS PROVIDED “AS IS” AND “AS AVAILABLE” WITHOUT WARRANTY OF ANY KIND FROM GENESIS. YOUR USE OF THE SOFTWARE AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SOFTWARE IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. GENESIS FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. GENESIS EXPRESSLY DISCLAIMS ANY WARRANTIES OF ANY KIND WITH RESPECT TO THE ACCURACY OR FUNCTIONALITY OF THE SOFTWARE, AND WITH RESPECT TO THE ACCURACY, VALIDITY, OR COMPLETENESS OF ANY INFORMATION OR FEATURES AVAILABLE THROUGH THE SOFTWARE, OR THE QUALITY OR CONSISTENCY OF THE SOFTWARE OR RESULTS OBTAINED THROUGH ITS USE.
|
|
36
|
+
|
|
37
|
+
7. INDEMNIFICATION. To the maximum extent permitted by law, you agree to defend, indemnify, and hold harmless Genesis, its affiliates, and their respective directors, officers, employees, and agents, from and against any and all third-party claims, actions, suits, or proceedings, as well as any and all losses, liabilities, damages, costs, and expenses (including reasonable attorneys’ fees) arising out of or accruing from (a) your breach of this Developer License; (b) your use or misuse of the Genesis Software; (c) your negligence or willful misconduct; and/or (d) your use of the Genesis Software that actually or allegedly infringes any Intellectual Property Rights or privacy rights of any third party in any jurisdiction.
|
|
38
|
+
|
|
39
|
+
8. MISCELLANEOUS.
|
|
40
|
+
(a) If you are agreeing to be bound by this Agreement on behalf of your employer or other entity, you represent and warrant that you have full legal authority to bind your employer or such entity to this Agreement. If you do not have the requisite authority, you may not accept this Agreement on behalf of your employer or other entity.
|
|
41
|
+
(b) This Developer License shall be governed by, and construed in accordance with, the laws of the State of New York without regard to conflict of law principles. For all purposes of this Developer License, the parties’ consent to exclusive jurisdiction and venue in the state and federal courts located in New York County, New York.
|
|
42
|
+
(c) Nothing in this Agreement, or in the nature of your access and use of the Genesis Software, shall create or is intended to create a joint-venture, partnership, or agency relationship between you and Genesis.
|
|
43
|
+
(d) You may not assign or transfer this Agreement or any of your rights or obligations hereunder, absent the prior written consent of Genesis.
|
|
44
|
+
(e) You agree that if Genesis does not exercise or enforce any legal right or remedy contained in this Agreement, this will not be taken to be a formal waiver of Genesis’s rights and that those rights or remedies will still be available to Genesis.
|
|
45
|
+
(f) This Agreement constitutes the complete understanding between you and Genesis with respect to the subject matter contained herein, and supersedes all prior written or oral communications, understandings, and agreements.
|
|
46
|
+
(g) If any provision of this Agreement is deemed to be illegal, invalid, or unenforceable, then that provision shall be removed, and the remaining terms will continue to be valid and enforceable.
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@genesislcap/mock-server",
|
|
3
|
+
"version": "15.3.2-canary.16",
|
|
4
|
+
"description": "Reusable in-memory Genesis WebSocket protocol mock server for client automation/CI, without a JVM or database.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "echo \"@genesislcap/mock-server: no build step — runs src/*.ts directly under Node or Bun\"",
|
|
13
|
+
"lint": "echo \"@genesislcap/mock-server: no lint step\"",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "node --experimental-strip-types --test"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ws": "^8.18.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.10.2",
|
|
22
|
+
"@types/ws": "^8.5.13",
|
|
23
|
+
"typescript": "5.9.2"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.6.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/genesislcap/foundation-ui.git",
|
|
31
|
+
"directory": "packages/tooling/mock-server"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "c42f51609cc3891f49defc8a8e443e42976c5688"
|
|
37
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Evaluator for Genesis CRITERIA_MATCH expressions, e.g.:
|
|
2
|
+
// TRADE_STATUS == 'CONFIRMED' AND QUANTITY > 100
|
|
3
|
+
// NOT (SIDE == 'SELL') OR PRICE >= 100.5
|
|
4
|
+
//
|
|
5
|
+
// Supports: == = != <> > >= < <=, AND OR NOT, parentheses, string/number/boolean
|
|
6
|
+
// literals, and bare field identifiers. Deliberately NOT eval()/new Function() —
|
|
7
|
+
// this parses a small typed grammar so a malformed or hostile criteria string can
|
|
8
|
+
// only fail to parse, never execute arbitrary JS.
|
|
9
|
+
|
|
10
|
+
import type { Row } from '../types.ts';
|
|
11
|
+
|
|
12
|
+
export type Predicate = (record: Row) => boolean;
|
|
13
|
+
|
|
14
|
+
const TOKEN_RE =
|
|
15
|
+
/\s*(=>|<=|>=|!=|<>|==|=|<|>|\(|\)|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|-?\d+(?:\.\d+)?|[A-Za-z_][A-Za-z0-9_.]*)/g;
|
|
16
|
+
|
|
17
|
+
function tokenize(input: string): string[] {
|
|
18
|
+
const tokens: string[] = [];
|
|
19
|
+
let match: RegExpExecArray | null;
|
|
20
|
+
let lastIndex = 0;
|
|
21
|
+
TOKEN_RE.lastIndex = 0;
|
|
22
|
+
while ((match = TOKEN_RE.exec(input))) {
|
|
23
|
+
if (match.index !== lastIndex) {
|
|
24
|
+
throw new Error(`Unable to tokenize criteria near: ${input.slice(lastIndex)}`);
|
|
25
|
+
}
|
|
26
|
+
tokens.push(match[1]);
|
|
27
|
+
lastIndex = TOKEN_RE.lastIndex;
|
|
28
|
+
}
|
|
29
|
+
if (lastIndex !== input.length) {
|
|
30
|
+
throw new Error(`Unable to tokenize criteria near: ${input.slice(lastIndex)}`);
|
|
31
|
+
}
|
|
32
|
+
return tokens;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseLiteral(token: string): unknown {
|
|
36
|
+
if (/^['"]/.test(token)) return token.slice(1, -1).replace(/\\(.)/g, '$1');
|
|
37
|
+
if (/^-?\d+(?:\.\d+)?$/.test(token)) return Number(token);
|
|
38
|
+
if (token === 'true') return true;
|
|
39
|
+
if (token === 'false') return false;
|
|
40
|
+
if (token === 'null') return null;
|
|
41
|
+
return undefined; // not a literal -> treat as a field reference
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const COMPARATORS = new Set(['==', '=', '!=', '<>', '<', '<=', '>', '>=']);
|
|
45
|
+
|
|
46
|
+
class Parser {
|
|
47
|
+
private tokens: string[];
|
|
48
|
+
private pos = 0;
|
|
49
|
+
|
|
50
|
+
constructor(tokens: string[]) {
|
|
51
|
+
this.tokens = tokens;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get position(): number {
|
|
55
|
+
return this.pos;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
peek(): string | undefined {
|
|
59
|
+
return this.tokens[this.pos];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
next(): string | undefined {
|
|
63
|
+
const token = this.tokens[this.pos];
|
|
64
|
+
this.pos += 1;
|
|
65
|
+
return token;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
parseExpression(): Predicate {
|
|
69
|
+
return this.parseOr();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
parseOr(): Predicate {
|
|
73
|
+
let left = this.parseAnd();
|
|
74
|
+
while (this.peek()?.toUpperCase() === 'OR') {
|
|
75
|
+
this.next();
|
|
76
|
+
const right = this.parseAnd();
|
|
77
|
+
const prev = left;
|
|
78
|
+
left = (record) => prev(record) || right(record);
|
|
79
|
+
}
|
|
80
|
+
return left;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
parseAnd(): Predicate {
|
|
84
|
+
let left = this.parseNot();
|
|
85
|
+
while (this.peek()?.toUpperCase() === 'AND') {
|
|
86
|
+
this.next();
|
|
87
|
+
const right = this.parseNot();
|
|
88
|
+
const prev = left;
|
|
89
|
+
left = (record) => prev(record) && right(record);
|
|
90
|
+
}
|
|
91
|
+
return left;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
parseNot(): Predicate {
|
|
95
|
+
if (this.peek()?.toUpperCase() === 'NOT') {
|
|
96
|
+
this.next();
|
|
97
|
+
const operand = this.parseNot();
|
|
98
|
+
return (record) => !operand(record);
|
|
99
|
+
}
|
|
100
|
+
return this.parseComparison();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
parseComparison(): Predicate {
|
|
104
|
+
if (this.peek() === '(') {
|
|
105
|
+
this.next();
|
|
106
|
+
const inner = this.parseExpression();
|
|
107
|
+
if (this.next() !== ')') throw new Error('Missing closing parenthesis in criteria');
|
|
108
|
+
return inner;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const leftToken = this.next();
|
|
112
|
+
if (leftToken === undefined) {
|
|
113
|
+
throw new Error('Expected operand on the left side of comparison');
|
|
114
|
+
}
|
|
115
|
+
const op = this.peek();
|
|
116
|
+
if (!op || !COMPARATORS.has(op)) {
|
|
117
|
+
throw new Error(`Expected comparator, got: ${op}`);
|
|
118
|
+
}
|
|
119
|
+
this.next();
|
|
120
|
+
const rightToken = this.next();
|
|
121
|
+
if (rightToken === undefined) {
|
|
122
|
+
throw new Error('Expected operand on the right side of comparison');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const resolveLeft = (record: Row) => this.resolveValue(leftToken, record);
|
|
126
|
+
const resolveRight = (record: Row) => this.resolveValue(rightToken, record);
|
|
127
|
+
|
|
128
|
+
return (record: Row) => {
|
|
129
|
+
const a = resolveLeft(record);
|
|
130
|
+
const b = resolveRight(record);
|
|
131
|
+
switch (op) {
|
|
132
|
+
case '==':
|
|
133
|
+
case '=':
|
|
134
|
+
return a === b;
|
|
135
|
+
case '!=':
|
|
136
|
+
case '<>':
|
|
137
|
+
return a !== b;
|
|
138
|
+
case '>':
|
|
139
|
+
return (a as any) > (b as any);
|
|
140
|
+
case '>=':
|
|
141
|
+
return (a as any) >= (b as any);
|
|
142
|
+
case '<':
|
|
143
|
+
return (a as any) < (b as any);
|
|
144
|
+
case '<=':
|
|
145
|
+
return (a as any) <= (b as any);
|
|
146
|
+
default:
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
resolveValue(token: string, record: Row): unknown {
|
|
153
|
+
const literal = parseLiteral(token);
|
|
154
|
+
if (literal !== undefined) return literal;
|
|
155
|
+
return record[token];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Compiles a CRITERIA_MATCH string into a predicate function(record) => boolean. */
|
|
160
|
+
export function compileCriteria(criteria?: string | null): Predicate {
|
|
161
|
+
if (!criteria || typeof criteria !== 'string' || criteria.trim() === '') {
|
|
162
|
+
return () => true;
|
|
163
|
+
}
|
|
164
|
+
const tokens = tokenize(criteria.trim());
|
|
165
|
+
const parser = new Parser(tokens);
|
|
166
|
+
const predicate = parser.parseExpression();
|
|
167
|
+
if (parser.position !== tokens.length) {
|
|
168
|
+
throw new Error(`Unexpected trailing tokens in criteria: ${criteria}`);
|
|
169
|
+
}
|
|
170
|
+
return predicate;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function filterByCriteria(rows: Row[], criteria?: string | null): Row[] {
|
|
174
|
+
const predicate = compileCriteria(criteria);
|
|
175
|
+
return rows.filter((row) => {
|
|
176
|
+
try {
|
|
177
|
+
return predicate(row);
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Derives META_REQUEST/JSON_SCHEMA_REQUEST field metadata from seed data itself,
|
|
2
|
+
// so every table/view/query gets working metadata without hand-authoring it —
|
|
3
|
+
// datasource init won't complete without a non-empty FIELD array (see README).
|
|
4
|
+
|
|
5
|
+
import type { FieldMetadata, Row } from '../types.ts';
|
|
6
|
+
|
|
7
|
+
function inferFieldType(value: unknown): string {
|
|
8
|
+
if (typeof value === 'number') return Number.isInteger(value) ? 'LONG' : 'DOUBLE';
|
|
9
|
+
if (typeof value === 'boolean') return 'BOOLEAN';
|
|
10
|
+
if (typeof value === 'string') return 'STRING';
|
|
11
|
+
return 'STRING';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** rows: array of plain row objects. Returns a FIELD array covering every key seen. */
|
|
15
|
+
export function deriveFields(rows: Row[], overrides: Record<string, string> = {}): FieldMetadata[] {
|
|
16
|
+
const fieldNames: string[] = [];
|
|
17
|
+
const seen = new Set<string>();
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
for (const key of Object.keys(row)) {
|
|
20
|
+
if (!seen.has(key)) {
|
|
21
|
+
seen.add(key);
|
|
22
|
+
fieldNames.push(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return fieldNames.map((name) => {
|
|
28
|
+
const sampleRow = rows.find((row) => row[name] !== undefined && row[name] !== null);
|
|
29
|
+
const type = overrides[name] ?? (sampleRow ? inferFieldType(sampleRow[name]) : 'STRING');
|
|
30
|
+
return { NAME: name, TYPE: type };
|
|
31
|
+
});
|
|
32
|
+
}
|