@genesislcap/ai-assistant 15.70.0 → 15.71.0-FUI-2650.1
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/dist/ai-assistant.api.json +97 -0
- package/dist/ai-assistant.d.ts +65 -0
- package/dist/chat-driver.cjs +18031 -0
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +18024 -0
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +9287 -6447
- package/dist/dts/chat-driver-node.d.ts +2 -0
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/code-review/code-review.types.d.ts +76 -0
- package/dist/dts/code-review/code-review.types.d.ts.map +1 -0
- package/dist/dts/code-review/code-reviewer.agent.d.ts +77 -0
- package/dist/dts/code-review/code-reviewer.agent.d.ts.map +1 -0
- package/dist/dts/code-review/code-reviewer.prompt.d.ts +23 -0
- package/dist/dts/code-review/code-reviewer.prompt.d.ts.map +1 -0
- package/dist/dts/code-review/gate.d.ts +44 -0
- package/dist/dts/code-review/gate.d.ts.map +1 -0
- package/dist/dts/code-review/index.d.ts +27 -0
- package/dist/dts/code-review/index.d.ts.map +1 -0
- package/dist/dts/code-review/review-changes.d.ts +70 -0
- package/dist/dts/code-review/review-changes.d.ts.map +1 -0
- package/dist/dts/code-review/rules/context-trigger-map.d.ts +6 -0
- package/dist/dts/code-review/rules/context-trigger-map.d.ts.map +1 -0
- package/dist/dts/code-review/rules/context.registry.d.ts +123 -0
- package/dist/dts/code-review/rules/context.registry.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-ai-extensions.d.ts +13 -0
- package/dist/dts/code-review/rules/fui-ai-extensions.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-blotter.d.ts +16 -0
- package/dist/dts/code-review/rules/fui-blotter.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-chart.d.ts +20 -0
- package/dist/dts/code-review/rules/fui-chart.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-column-defs.d.ts +21 -0
- package/dist/dts/code-review/rules/fui-column-defs.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-components.d.ts +9 -0
- package/dist/dts/code-review/rules/fui-components.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-criteria.d.ts +32 -0
- package/dist/dts/code-review/rules/fui-criteria.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-custom-renderer.d.ts +15 -0
- package/dist/dts/code-review/rules/fui-custom-renderer.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-dashboard.d.ts +19 -0
- package/dist/dts/code-review/rules/fui-dashboard.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-dialogs.d.ts +19 -0
- package/dist/dts/code-review/rules/fui-dialogs.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-entity-management.d.ts +19 -0
- package/dist/dts/code-review/rules/fui-entity-management.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-error-boundary.d.ts +9 -0
- package/dist/dts/code-review/rules/fui-error-boundary.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-eventing.d.ts +8 -0
- package/dist/dts/code-review/rules/fui-eventing.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-flexlayout.d.ts +17 -0
- package/dist/dts/code-review/rules/fui-flexlayout.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-flyout-panel.d.ts +10 -0
- package/dist/dts/code-review/rules/fui-flyout-panel.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-form-component.d.ts +9 -0
- package/dist/dts/code-review/rules/fui-form-component.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-formatters.d.ts +12 -0
- package/dist/dts/code-review/rules/fui-formatters.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-foundation-comms.d.ts +10 -0
- package/dist/dts/code-review/rules/fui-foundation-comms.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-global-filters.d.ts +33 -0
- package/dist/dts/code-review/rules/fui-global-filters.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-import-surface.d.ts +37 -0
- package/dist/dts/code-review/rules/fui-import-surface.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-inline-editing.d.ts +10 -0
- package/dist/dts/code-review/rules/fui-inline-editing.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-layout.d.ts +7 -0
- package/dist/dts/code-review/rules/fui-layout.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-notifications.d.ts +12 -0
- package/dist/dts/code-review/rules/fui-notifications.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-primitives.d.ts +26 -0
- package/dist/dts/code-review/rules/fui-primitives.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-rapid-grid-pro.d.ts +18 -0
- package/dist/dts/code-review/rules/fui-rapid-grid-pro.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-redux-store.d.ts +8 -0
- package/dist/dts/code-review/rules/fui-redux-store.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-reporting.d.ts +19 -0
- package/dist/dts/code-review/rules/fui-reporting.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-styling.d.ts +15 -0
- package/dist/dts/code-review/rules/fui-styling.d.ts.map +1 -0
- package/dist/dts/code-review/rules/fui-trade-form.d.ts +13 -0
- package/dist/dts/code-review/rules/fui-trade-form.d.ts.map +1 -0
- package/dist/dts/code-review/submit-code-review.tool.d.ts +12 -0
- package/dist/dts/code-review/submit-code-review.tool.d.ts.map +1 -0
- package/dist/dts/code-review/unified-diff.d.ts +7 -0
- package/dist/dts/code-review/unified-diff.d.ts.map +1 -0
- package/dist/dts/code-review/verdict.d.ts +23 -0
- package/dist/dts/code-review/verdict.d.ts.map +1 -0
- package/dist/dts/components/code-review-result/code-review-result.d.ts +26 -0
- package/dist/dts/components/code-review-result/code-review-result.d.ts.map +1 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/react.d.ts +10 -0
- package/dist/esm/chat-driver-node.js +6 -0
- package/dist/esm/code-review/code-review.types.js +6 -0
- package/dist/esm/code-review/code-reviewer.agent.js +167 -0
- package/dist/esm/code-review/code-reviewer.prompt.js +103 -0
- package/dist/esm/code-review/gate.js +93 -0
- package/dist/esm/code-review/index.js +28 -0
- package/dist/esm/code-review/review-changes.js +123 -0
- package/dist/esm/code-review/rules/context-trigger-map.js +20 -0
- package/dist/esm/code-review/rules/context.registry.js +772 -0
- package/dist/esm/code-review/rules/fui-ai-extensions.js +306 -0
- package/dist/esm/code-review/rules/fui-blotter.js +596 -0
- package/dist/esm/code-review/rules/fui-chart.js +669 -0
- package/dist/esm/code-review/rules/fui-column-defs.js +862 -0
- package/dist/esm/code-review/rules/fui-components.js +245 -0
- package/dist/esm/code-review/rules/fui-criteria.js +538 -0
- package/dist/esm/code-review/rules/fui-custom-renderer.js +612 -0
- package/dist/esm/code-review/rules/fui-dashboard.js +604 -0
- package/dist/esm/code-review/rules/fui-dialogs.js +588 -0
- package/dist/esm/code-review/rules/fui-entity-management.js +1014 -0
- package/dist/esm/code-review/rules/fui-error-boundary.js +244 -0
- package/dist/esm/code-review/rules/fui-eventing.js +628 -0
- package/dist/esm/code-review/rules/fui-flexlayout.js +860 -0
- package/dist/esm/code-review/rules/fui-flyout-panel.js +432 -0
- package/dist/esm/code-review/rules/fui-form-component.js +898 -0
- package/dist/esm/code-review/rules/fui-formatters.js +415 -0
- package/dist/esm/code-review/rules/fui-foundation-comms.js +518 -0
- package/dist/esm/code-review/rules/fui-global-filters.js +778 -0
- package/dist/esm/code-review/rules/fui-import-surface.js +452 -0
- package/dist/esm/code-review/rules/fui-inline-editing.js +445 -0
- package/dist/esm/code-review/rules/fui-layout.js +431 -0
- package/dist/esm/code-review/rules/fui-notifications.js +439 -0
- package/dist/esm/code-review/rules/fui-primitives.js +1216 -0
- package/dist/esm/code-review/rules/fui-rapid-grid-pro.js +650 -0
- package/dist/esm/code-review/rules/fui-redux-store.js +522 -0
- package/dist/esm/code-review/rules/fui-reporting.js +506 -0
- package/dist/esm/code-review/rules/fui-styling.js +1229 -0
- package/dist/esm/code-review/rules/fui-trade-form.js +618 -0
- package/dist/esm/code-review/submit-code-review.tool.js +43 -0
- package/dist/esm/code-review/unified-diff.js +96 -0
- package/dist/esm/code-review/verdict.js +24 -0
- package/dist/esm/components/code-review-result/code-review-result.js +89 -0
- package/dist/esm/index.js +3 -0
- package/dist/react.cjs +7 -0
- package/dist/react.mjs +6 -0
- package/docs/code-review.md +137 -0
- package/package.json +24 -17
- package/scripts/smoke-chat-driver-node.mjs +15 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context injected into the UI Builder system prompt.
|
|
3
|
+
* Covers the correct usage of the Connect service from @genesislcap/foundation-comms
|
|
4
|
+
* for direct server communication in custom React components.
|
|
5
|
+
*
|
|
6
|
+
* Tags for selective context injection — inject when conversation mentions these keywords.
|
|
7
|
+
*/
|
|
8
|
+
export const FUI_FOUNDATION_COMMS_TAGS = [
|
|
9
|
+
'connect',
|
|
10
|
+
'snapshot',
|
|
11
|
+
'commitEvent',
|
|
12
|
+
'REQ_',
|
|
13
|
+
'request-reply',
|
|
14
|
+
'server call',
|
|
15
|
+
'foundation-comms',
|
|
16
|
+
'stream',
|
|
17
|
+
'datasource subscription',
|
|
18
|
+
'data server',
|
|
19
|
+
'event handler',
|
|
20
|
+
'request server',
|
|
21
|
+
'getConnect',
|
|
22
|
+
'messageOrThrow',
|
|
23
|
+
'live data',
|
|
24
|
+
'real-time data',
|
|
25
|
+
'fetch from server',
|
|
26
|
+
'send event',
|
|
27
|
+
'server mutation',
|
|
28
|
+
'server request',
|
|
29
|
+
'EVENT_',
|
|
30
|
+
'DATA_LOGON',
|
|
31
|
+
];
|
|
32
|
+
export const FUI_FOUNDATION_COMMS_CONTEXT = `
|
|
33
|
+
## FOUNDATION-COMMS — DIRECT SERVER COMMUNICATION
|
|
34
|
+
|
|
35
|
+
Use the \`Connect\` service when you need to fetch data directly from the server in a custom component (not via EntityManagement / RapidGridPro datasource props). This is only needed for custom code that calls the server manually.
|
|
36
|
+
|
|
37
|
+
### Import paths (verified against src/connect/connect.ts)
|
|
38
|
+
|
|
39
|
+
\`\`\`ts
|
|
40
|
+
// Preferred — singleton helper, safe at module scope or inside hooks/functions
|
|
41
|
+
import { getConnect } from '@genesislcap/foundation-comms';
|
|
42
|
+
|
|
43
|
+
// Types used in function signatures
|
|
44
|
+
import type { Message, DataserverParams, RequestParams, CommitParams } from '@genesislcap/foundation-comms';
|
|
45
|
+
|
|
46
|
+
// Utility — throws if the message contains an ERROR array (use when you want throw-on-error)
|
|
47
|
+
import { messageOrThrow } from '@genesislcap/foundation-comms';
|
|
48
|
+
|
|
49
|
+
// Alternative DI pattern — use when you need the DI container for other reasons
|
|
50
|
+
import { Connect } from '@genesislcap/foundation-comms';
|
|
51
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### Getting the Connect instance — two valid patterns
|
|
57
|
+
|
|
58
|
+
\`\`\`ts
|
|
59
|
+
// Pattern A — getConnect() helper (preferred in React components/hooks/utility functions):
|
|
60
|
+
import { getConnect } from '@genesislcap/foundation-comms';
|
|
61
|
+
|
|
62
|
+
async function fetchTrades() {
|
|
63
|
+
const connect = getConnect(); // Safe to call inside async functions, hooks, callbacks
|
|
64
|
+
const response = await connect.snapshot('ALL_TRADES');
|
|
65
|
+
return response.ROW ?? [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Pattern B — explicit DI container (use when you already hold a DI container reference):
|
|
69
|
+
import { Connect } from '@genesislcap/foundation-comms';
|
|
70
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
71
|
+
|
|
72
|
+
const connect = DI.getOrCreateDOMContainer().get(Connect);
|
|
73
|
+
\`\`\`
|
|
74
|
+
|
|
75
|
+
Connect is a **singleton** — both patterns return the same instance. Do NOT instantiate \`Connect\` directly with \`new\`.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### Two server resource types — use the correct method
|
|
80
|
+
|
|
81
|
+
| Resource type | What it is | Naming convention | Method |
|
|
82
|
+
|---|---|---|---|
|
|
83
|
+
| **Data Server** (query) | Real-time view, e.g. \`ALL_TRADES\` | Plain name | \`connect.snapshot()\` or \`connect.stream()\` |
|
|
84
|
+
| **Request Server** (reqRep) | One-shot/polled request, e.g. \`REQ_TRADE_DETAILS\` | \`REQ_\` prefix | \`connect.request()\` |
|
|
85
|
+
| **Event Handler** | Mutation, e.g. \`EVENT_TRADE_INSERT\` | \`EVENT_\` prefix | \`connect.commitEvent()\` |
|
|
86
|
+
|
|
87
|
+
**Never guess.** \`query_project_schema('queries')\` now returns both: \`queries\` are the Data Server (realtime) ones, \`snapshotResources\` the Request Server ones — every entity and view, plus \`<ENTITY>_AUDIT\` for audited entities — bound by their bare name (the platform registers each as \`REQ_<NAME>\`). Event handler names come from \`query_project_schema('events')\`; at runtime they are \`EVENT_<name>\`.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### snapshot() — Data Server one-off read
|
|
92
|
+
|
|
93
|
+
Returns all rows from a Data Server resource at a point in time (no live subscription).
|
|
94
|
+
|
|
95
|
+
\`\`\`ts
|
|
96
|
+
const response = await connect.snapshot('ALL_TRADES');
|
|
97
|
+
const rows = response.ROW ?? []; // ROW is the data array — never response.value or response.data
|
|
98
|
+
|
|
99
|
+
// With filter params (DataserverParams):
|
|
100
|
+
const filtered = await connect.snapshot('ALL_TRADES', {
|
|
101
|
+
CRITERIA_MATCH: "SIDE == 'BUY'",
|
|
102
|
+
MAX_ROWS: 100,
|
|
103
|
+
ORDER_BY: 'TRADE_DATE',
|
|
104
|
+
});
|
|
105
|
+
const rows = filtered.ROW ?? [];
|
|
106
|
+
\`\`\`
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### stream() — real-time Data Server subscription
|
|
111
|
+
|
|
112
|
+
Use \`stream()\` only when you need live push updates. Prefer \`snapshot()\` for one-off reads.
|
|
113
|
+
\`stream()\` returns an RxJS \`SocketObservable<Message>\` (extends Observable). You MUST subscribe
|
|
114
|
+
to it and unsubscribe in the cleanup to prevent memory leaks.
|
|
115
|
+
|
|
116
|
+
\`\`\`tsx
|
|
117
|
+
import React, { useEffect, useState } from 'react';
|
|
118
|
+
import { getConnect, type Message } from '@genesislcap/foundation-comms';
|
|
119
|
+
|
|
120
|
+
interface Trade { TRADE_ID: string; SIDE: string; QUANTITY: number; }
|
|
121
|
+
|
|
122
|
+
function useLiveTrades(): Trade[] {
|
|
123
|
+
const [trades, setTrades] = useState<Trade[]>([]);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
const connect = getConnect();
|
|
127
|
+
const observable = connect.stream(
|
|
128
|
+
'ALL_TRADES',
|
|
129
|
+
(msg: Message) => { /* onMessage — called by the Connect internals */ },
|
|
130
|
+
(error: unknown) => console.error('stream error', error),
|
|
131
|
+
);
|
|
132
|
+
// Subscribe to the Observable to start receiving; unsubscribe on cleanup
|
|
133
|
+
const sub = observable.subscribe({
|
|
134
|
+
next: (msg: Message) => setTrades((msg.ROW ?? []) as Trade[]),
|
|
135
|
+
error: (err) => console.error(err),
|
|
136
|
+
});
|
|
137
|
+
return () => sub.unsubscribe();
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
return trades;
|
|
141
|
+
}
|
|
142
|
+
\`\`\`
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### streamState() — real-time subscription with accumulated state
|
|
147
|
+
|
|
148
|
+
Use \`streamState()\` when you need the full current state (add/modify/remove applied), not just
|
|
149
|
+
raw delta messages. Returns an RxJS \`Observable<any[]>\`; subscribe and unsubscribe the same way.
|
|
150
|
+
|
|
151
|
+
\`\`\`ts
|
|
152
|
+
import { getConnect } from '@genesislcap/foundation-comms';
|
|
153
|
+
|
|
154
|
+
function subscribeRfqFlow(
|
|
155
|
+
rfqId: string,
|
|
156
|
+
onRow: (row: unknown) => void,
|
|
157
|
+
onError: (error: unknown) => void,
|
|
158
|
+
): () => void {
|
|
159
|
+
const connect = getConnect();
|
|
160
|
+
const observable = connect.streamState(
|
|
161
|
+
'RFQ_FLOW_BY_RFQ_ID',
|
|
162
|
+
() => {}, // onMessage passed to inner stream (can be no-op when using subscribe)
|
|
163
|
+
() => {}, // onError passed to inner stream
|
|
164
|
+
{ CRITERIA_MATCH: \`RFQ_ID == '\${rfqId}'\`, MAX_ROWS: 1 },
|
|
165
|
+
);
|
|
166
|
+
const subscription = observable.subscribe({
|
|
167
|
+
next: (rows: unknown[]) => onRow(rows[0]),
|
|
168
|
+
error: onError,
|
|
169
|
+
});
|
|
170
|
+
return () => subscription.unsubscribe();
|
|
171
|
+
}
|
|
172
|
+
\`\`\`
|
|
173
|
+
|
|
174
|
+
\`stream()\` gives raw delta messages (adds/modifies/removes per tick). \`streamState()\` applies the
|
|
175
|
+
deltas and gives the full current list after each update. **\`streamState()\` is the pattern generated
|
|
176
|
+
aggregation/chart tiles use** to compute KPIs or chart inputs from a live query — subscribe in
|
|
177
|
+
\`useEffect\`, \`setState(rows)\` in \`next\`, aggregate with \`useMemo\`, unsubscribe in cleanup.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### request() — Request Server (REQ_*)
|
|
182
|
+
|
|
183
|
+
For \`REQ_*\` resources. The SDK auto-prefixes \`REQ_\` if the resource name doesn't include it
|
|
184
|
+
(verified: \`resourceName.startsWith('REQ_') ? resourceName : \\\`REQ_\\\${resourceName}\\\`\`).
|
|
185
|
+
Pass request fields inside a \`REQUEST\` wrapper object.
|
|
186
|
+
|
|
187
|
+
\`\`\`ts
|
|
188
|
+
import { getConnect, messageOrThrow, type Message } from '@genesislcap/foundation-comms';
|
|
189
|
+
|
|
190
|
+
// Simple request
|
|
191
|
+
const response = await getConnect().request('QTE_BY_TEMPLATE_NAME', {
|
|
192
|
+
REQUEST: { TEMPLATE_NAME: 'DEFAULT_IRG' },
|
|
193
|
+
});
|
|
194
|
+
const row = response.REPLY?.[0]; // REPLY is the data array for request responses
|
|
195
|
+
|
|
196
|
+
// Using messageOrThrow to propagate server errors as JS exceptions
|
|
197
|
+
const response2 = await getConnect().request('COUNTERPARTY', {
|
|
198
|
+
REQUEST: { USER_NAME: 'user1', DOMAIN: 'CPTY', KEY: 'FAV' },
|
|
199
|
+
});
|
|
200
|
+
const rows = messageOrThrow(response2).REPLY ?? [];
|
|
201
|
+
\`\`\`
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### commitEvent() — Event Handler (EVENT_*)
|
|
206
|
+
|
|
207
|
+
For \`EVENT_*\` resources. Pass event fields inside a \`DETAILS\` wrapper object.
|
|
208
|
+
**commitEvent() does NOT throw on server NACK** — always inspect \`MESSAGE_TYPE\` (both forms below return the same \`Message\`).
|
|
209
|
+
|
|
210
|
+
**Typed form — PREFER this** when \`generated/genesis-event-types.ts\` is listed in \`vfs_list\` **and** it exports a class for this event: import the generated event class (relative path matching the file depth, like store imports) and commit it with \`commitGenesisEvent(connect, event)\`. \`DETAILS\` is then checked against the generated \`*Details\` type. Fall back to the plain form below when that file is absent or the event is not in the map. Never create or edit the generated file.
|
|
211
|
+
|
|
212
|
+
\`\`\`ts
|
|
213
|
+
import { getConnect, commitGenesisEvent } from '@genesislcap/foundation-comms';
|
|
214
|
+
import { EventTradeInsert } from '../generated/genesis-event-types'; // one class per EVENT_*, DETAILS typed
|
|
215
|
+
// (relative depth like store imports: ../../ from a route page, ../../../ from a nested subcomponent, ../ from a flat shared component)
|
|
216
|
+
|
|
217
|
+
// wrong/missing DETAILS fields now fail tsc instead of failing silently at runtime
|
|
218
|
+
const response = await commitGenesisEvent(
|
|
219
|
+
getConnect(),
|
|
220
|
+
new EventTradeInsert({ TRADE_DATE: '2025-01-01', SIDE: 'BUY', QUANTITY: 100 }),
|
|
221
|
+
);
|
|
222
|
+
if (response.MESSAGE_TYPE !== 'EVENT_ACK') {
|
|
223
|
+
const errorText = (response.ERROR ?? []).map((e) => e.TEXT).join(', ');
|
|
224
|
+
console.error('Commit failed:', errorText); // MESSAGE_TYPE === 'EVENT_NACK'
|
|
225
|
+
}
|
|
226
|
+
\`\`\`
|
|
227
|
+
|
|
228
|
+
**Plain form** — the fallback when the generated map is absent or the event is not in it:
|
|
229
|
+
|
|
230
|
+
\`\`\`ts
|
|
231
|
+
import { getConnect } from '@genesislcap/foundation-comms';
|
|
232
|
+
|
|
233
|
+
const response = await getConnect().commitEvent('EVENT_TRADE_INSERT', {
|
|
234
|
+
DETAILS: {
|
|
235
|
+
TRADE_DATE: '2025-01-01',
|
|
236
|
+
SIDE: 'BUY',
|
|
237
|
+
QUANTITY: 100,
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
if (response.MESSAGE_TYPE === 'EVENT_ACK') {
|
|
241
|
+
// success
|
|
242
|
+
} else {
|
|
243
|
+
// response.MESSAGE_TYPE === 'EVENT_NACK'
|
|
244
|
+
const errorText = (response.ERROR ?? []).map((e) => e.TEXT).join(', ');
|
|
245
|
+
console.error('Commit failed:', errorText);
|
|
246
|
+
}
|
|
247
|
+
\`\`\`
|
|
248
|
+
|
|
249
|
+
Alternatively, use \`messageOrThrow\` when you want the error to propagate as a JS exception:
|
|
250
|
+
\`\`\`ts
|
|
251
|
+
import { getConnect, messageOrThrow } from '@genesislcap/foundation-comms';
|
|
252
|
+
|
|
253
|
+
// Throws a JS Error if MESSAGE_TYPE is not ACK / response contains ERROR[]
|
|
254
|
+
messageOrThrow(
|
|
255
|
+
await getConnect().commitEvent('EVENT_USER_PREFERENCE_UPSERT', {
|
|
256
|
+
DETAILS: { DOMAIN: 'CPTY', KEY: 'FAV', VALUE: id },
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
\`\`\`
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### Message shape — ROW vs REPLY
|
|
264
|
+
|
|
265
|
+
| Call | Data field | Notes |
|
|
266
|
+
|---|---|---|
|
|
267
|
+
| \`snapshot()\` | \`response.ROW\` | Array of row objects; empty array when no data |
|
|
268
|
+
| \`stream()\` | message callback arg has \`.ROW\` | Delta rows per tick |
|
|
269
|
+
| \`streamState()\` subscribe | \`rows\` array in \`next()\` | Full current state (accumulated) |
|
|
270
|
+
| \`request()\` | \`response.REPLY\` | Array of reply objects |
|
|
271
|
+
| \`commitEvent()\` | Check \`response.MESSAGE_TYPE\` | \`'EVENT_ACK'\` = success; \`'EVENT_NACK'\` = server error |
|
|
272
|
+
|
|
273
|
+
**Never use \`response.value\`, \`response.data\`, \`response.TRADES\`, or any field named after the
|
|
274
|
+
resource.** The field is always \`ROW\` (Data Server) or \`REPLY\` (Request Server), regardless of
|
|
275
|
+
resource name.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
### Full example — custom hook using snapshot
|
|
280
|
+
|
|
281
|
+
\`\`\`tsx
|
|
282
|
+
import React, { useEffect, useState } from 'react';
|
|
283
|
+
import { getConnect } from '@genesislcap/foundation-comms';
|
|
284
|
+
|
|
285
|
+
interface Trade {
|
|
286
|
+
TRADE_ID: string;
|
|
287
|
+
SIDE: string;
|
|
288
|
+
QUANTITY: number;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function useTradeData(side?: string): Trade[] {
|
|
292
|
+
const [trades, setTrades] = useState<Trade[]>([]);
|
|
293
|
+
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
const params = side ? { CRITERIA_MATCH: \`SIDE == '\${side}'\` } : undefined;
|
|
296
|
+
getConnect()
|
|
297
|
+
.snapshot('ALL_TRADES', params)
|
|
298
|
+
.then((response) => setTrades((response.ROW ?? []) as Trade[]));
|
|
299
|
+
}, [side]);
|
|
300
|
+
|
|
301
|
+
return trades;
|
|
302
|
+
}
|
|
303
|
+
\`\`\`
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
### getMetadata() — field metadata
|
|
308
|
+
|
|
309
|
+
\`\`\`ts
|
|
310
|
+
const metadata = await getConnect().getMetadata('ALL_TRADES');
|
|
311
|
+
// Returns field definitions: name, type, nullable, enum values, etc.
|
|
312
|
+
// Cached by default — pass false as second arg to force refresh:
|
|
313
|
+
const fresh = await getConnect().getMetadata('ALL_TRADES', false);
|
|
314
|
+
\`\`\`
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
### DataserverParams — available filter/pagination options
|
|
319
|
+
|
|
320
|
+
\`\`\`ts
|
|
321
|
+
// All fields are optional (source-verified from message.ts DataserverParams type)
|
|
322
|
+
type DataserverParams = {
|
|
323
|
+
DATASOURCE_NAME?: string; // Override the datasource name
|
|
324
|
+
CRITERIA_MATCH?: string; // Server-side filter expression, e.g. "SIDE == 'BUY'"
|
|
325
|
+
MAX_ROWS?: number; // Limit rows returned
|
|
326
|
+
VIEW_NUMBER?: number; // Page/view number for pagination
|
|
327
|
+
FIELDS?: string; // Comma-separated field names to include
|
|
328
|
+
MAX_VIEW?: number; // Max rows tracked in client view
|
|
329
|
+
MOVING_VIEW?: boolean; // Whether new rows push into the view
|
|
330
|
+
ORDER_BY?: string; // Field name for server-side sort
|
|
331
|
+
REVERSE?: boolean; // Reverse the sort order
|
|
332
|
+
};
|
|
333
|
+
\`\`\`
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
### CommitParams — event payload structure
|
|
338
|
+
|
|
339
|
+
\`\`\`ts
|
|
340
|
+
// Source-verified from message.ts CommitParams type
|
|
341
|
+
type CommitParams = {
|
|
342
|
+
DETAILS: any; // Required — event-specific payload fields
|
|
343
|
+
HOSTNAME?: string;
|
|
344
|
+
IGNORE_WARNINGS?: boolean;
|
|
345
|
+
VALIDATE?: boolean; // Set true to validate without committing
|
|
346
|
+
};
|
|
347
|
+
\`\`\`
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
### Resource name conventions
|
|
352
|
+
|
|
353
|
+
| Resource type | Name pattern | Method |
|
|
354
|
+
|---|---|---|
|
|
355
|
+
| Data Server (live views) | Plain names: \`ALL_TRADES\`, \`POSITION_VIEW\` | \`snapshot()\` or \`stream()\` |
|
|
356
|
+
| Request Server | \`REQ_\` prefix: \`REQ_TRADE_DETAILS\` (auto-added if omitted) | \`request()\` |
|
|
357
|
+
| Event Handler | \`EVENT_\` prefix: \`EVENT_TRADE_INSERT\` | \`commitEvent()\` |
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
### Connect interface — public methods (source-verified)
|
|
362
|
+
|
|
363
|
+
| Method | Returns | Use for |
|
|
364
|
+
|---|---|---|
|
|
365
|
+
| \`connect(host?)\` | \`Promise<boolean>\` | Establish WS connection (done by app bootstrap) |
|
|
366
|
+
| \`disconnect()\` | \`void\` | Tear down WS (done by app bootstrap) |
|
|
367
|
+
| \`snapshot(resource, params?)\` | \`Promise<Message>\` | One-off Data Server read |
|
|
368
|
+
| \`stream(resource, onMsg, onErr, params?)\` | \`SocketObservable<Message>\` | Live Data Server subscription |
|
|
369
|
+
| \`streamState(resource, onMsg, onErr, params?, initialState?)\` | \`Observable<any[]>\` | Live subscription with accumulated state |
|
|
370
|
+
| \`request(resource, params?, useCache?)\` | \`Promise<Message>\` | Request Server (REQ_*) |
|
|
371
|
+
| \`commitEvent(event, params?)\` | \`Promise<Message>\` | Event Handler (EVENT_*) |
|
|
372
|
+
| \`getMetadata(resource, useCache?)\` | \`Promise<Metadata>\` | Field metadata for a resource |
|
|
373
|
+
| \`getJSONSchema(resource)\` | \`Promise<SchemaResponse>\` | JSON schema for a resource |
|
|
374
|
+
| \`getMoreRows(sourceRef, viewNum?)\` | \`Promise<Message>\` | Fetch next page of a stream |
|
|
375
|
+
| \`getAvailableResources(params?, useCache?)\` | \`Promise<ResourcesMessage>\` | List all server resources |
|
|
376
|
+
|
|
377
|
+
(\`streamWithoutAutoTeardown\` is deprecated — use \`stream\`; \`send()\` is @internal — never call it.)
|
|
378
|
+
Methods that do NOT exist: \`get()\`, \`getData()\`, \`query()\`, \`fetch()\`, \`commitEventPromise()\`.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
### KEY RULES
|
|
383
|
+
|
|
384
|
+
- **Use \`getConnect()\`** — never instantiate \`Connect\` directly or call \`new DefaultConnect()\`.
|
|
385
|
+
- **Data Server → \`snapshot()\` or \`stream()\`; Request Server → \`request()\`** — do not swap them.
|
|
386
|
+
Using \`request()\` on a Data Server resource will fail at runtime.
|
|
387
|
+
- **Response data is always in \`ROW\` (snapshot/stream) or \`REPLY\` (request)** — never in a
|
|
388
|
+
resource-named field, never in \`value\`, never in \`data\`.
|
|
389
|
+
- **\`stream()\` and \`streamState()\` return Observables** — you must \`.subscribe()\` and call
|
|
390
|
+
\`subscription.unsubscribe()\` in \`useEffect\` cleanup. The returned Observable is not a Subscription.
|
|
391
|
+
- **For EntityManagement / RapidGridPro / GridProGenesisDatasource**: do NOT use Connect — pass
|
|
392
|
+
\`resourceName\` and \`datasourceConfig\` as props and let the component manage the data subscription.
|
|
393
|
+
- **For a DATA-ENTRY FORM: do NOT hand-wire \`commitEvent\`** — give a foundation-forms \`<Form>\` the
|
|
394
|
+
event as its \`resourceName\` and it commits for you, with validation and server field errors
|
|
395
|
+
(\`read_context('fui-form-component')\`). Commit directly only for FIELDLESS actions (cancel,
|
|
396
|
+
approve, reject, delete) — there, prefer the typed generated event class.
|
|
397
|
+
- **For dropdown options: do NOT \`snapshot\`/\`request\` rows and map them to \`<ListboxOption>\`** —
|
|
398
|
+
nest an \`<OptionsDatasource>\` (\`read_context('fui-primitives')\`), or inside a \`<Form>\` use the
|
|
399
|
+
uischema \`allOptionsResourceName\` option.
|
|
400
|
+
- \`commitEvent()\` does NOT throw on server NACK — always check \`response.MESSAGE_TYPE\`.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## DANGEROUS PATTERNS
|
|
405
|
+
|
|
406
|
+
### WRONG: \`stream()\` without subscribing and without cleanup
|
|
407
|
+
|
|
408
|
+
\`\`\`tsx
|
|
409
|
+
// WRONG — calling stream() returns an Observable; you never subscribed, data never flows.
|
|
410
|
+
// Also: no cleanup means a memory leak if you did subscribe.
|
|
411
|
+
useEffect(() => {
|
|
412
|
+
const connect = getConnect();
|
|
413
|
+
connect.stream('ALL_TRADES', (msg) => setTrades((msg.ROW ?? []) as Trade[]), console.error);
|
|
414
|
+
// Missing: subscribe + unsubscribe
|
|
415
|
+
}, []);
|
|
416
|
+
\`\`\`
|
|
417
|
+
|
|
418
|
+
\`\`\`tsx
|
|
419
|
+
// CORRECT — subscribe to the Observable; return the unsubscribe function for cleanup
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
const connect = getConnect();
|
|
422
|
+
const sub = connect.stream(
|
|
423
|
+
'ALL_TRADES',
|
|
424
|
+
() => {}, // onMessage arg (called internally by Connect)
|
|
425
|
+
console.error, // onError arg
|
|
426
|
+
).subscribe({
|
|
427
|
+
next: (msg) => setTrades((msg.ROW ?? []) as Trade[]),
|
|
428
|
+
error: console.error,
|
|
429
|
+
});
|
|
430
|
+
return () => sub.unsubscribe();
|
|
431
|
+
}, []);
|
|
432
|
+
\`\`\`
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
### WRONG: Assuming \`commitEvent()\` throws on server NACK
|
|
437
|
+
|
|
438
|
+
\`\`\`tsx
|
|
439
|
+
// WRONG — only catches JS exceptions; server NACK resolves normally, showError() never fires
|
|
440
|
+
try {
|
|
441
|
+
await getConnect().commitEvent('EVENT_INSERT_TRADE', { DETAILS: data });
|
|
442
|
+
showSuccess();
|
|
443
|
+
} catch (e) {
|
|
444
|
+
showError(); // Never reached on server-side NACK
|
|
445
|
+
}
|
|
446
|
+
\`\`\`
|
|
447
|
+
|
|
448
|
+
\`\`\`tsx
|
|
449
|
+
// CORRECT — always check MESSAGE_TYPE explicitly
|
|
450
|
+
const response = await getConnect().commitEvent('EVENT_INSERT_TRADE', { DETAILS: data });
|
|
451
|
+
if (response.MESSAGE_TYPE === 'EVENT_ACK') {
|
|
452
|
+
showSuccess();
|
|
453
|
+
} else {
|
|
454
|
+
const text = (response.ERROR ?? []).map((e) => e.TEXT).join(', ') || 'Unknown error';
|
|
455
|
+
showError(text);
|
|
456
|
+
}
|
|
457
|
+
\`\`\`
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
### WRONG: Using \`request()\` on a Data Server resource (or vice versa)
|
|
462
|
+
|
|
463
|
+
\`\`\`tsx
|
|
464
|
+
// WRONG — ALL_TRADES is a Data Server resource; request() is for REQ_* resources
|
|
465
|
+
const response = await getConnect().request('ALL_TRADES');
|
|
466
|
+
const rows = response.REPLY ?? []; // REPLY is empty; data is in ROW for Data Server
|
|
467
|
+
|
|
468
|
+
// WRONG — REQ_TRADE_DETAILS is a Request Server; snapshot() is for Data Server
|
|
469
|
+
const response2 = await getConnect().snapshot('REQ_TRADE_DETAILS', { MAX_ROWS: 1 });
|
|
470
|
+
\`\`\`
|
|
471
|
+
|
|
472
|
+
\`\`\`tsx
|
|
473
|
+
// CORRECT — match method to resource type
|
|
474
|
+
const dsResponse = await getConnect().snapshot('ALL_TRADES'); // Data Server → snapshot
|
|
475
|
+
const rows = dsResponse.ROW ?? [];
|
|
476
|
+
|
|
477
|
+
const rrResponse = await getConnect().request('REQ_TRADE_DETAILS', { REQUEST: { TRADE_ID: id } });
|
|
478
|
+
const detail = rrResponse.REPLY?.[0]; // Request Server → request → REPLY
|
|
479
|
+
\`\`\`
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
### WRONG: Reading response data from a resource-named field
|
|
484
|
+
|
|
485
|
+
\`\`\`tsx
|
|
486
|
+
// WRONG — the data is NEVER in a field named after the resource
|
|
487
|
+
const response = await getConnect().snapshot('ALL_TRADES');
|
|
488
|
+
const rows = (response as any).ALL_TRADES; // undefined always
|
|
489
|
+
const rows2 = (response as any).data; // undefined always
|
|
490
|
+
const rows3 = (response as any).value; // undefined always
|
|
491
|
+
\`\`\`
|
|
492
|
+
|
|
493
|
+
\`\`\`tsx
|
|
494
|
+
// CORRECT — always use ROW (snapshot/stream) or REPLY (request)
|
|
495
|
+
const response = await getConnect().snapshot('ALL_TRADES');
|
|
496
|
+
const rows = response.ROW ?? [];
|
|
497
|
+
\`\`\`
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
### WRONG: Calling non-existent Connect methods
|
|
502
|
+
|
|
503
|
+
\`\`\`tsx
|
|
504
|
+
// WRONG — these methods do not exist on Connect
|
|
505
|
+
connect.get('ALL_TRADES');
|
|
506
|
+
connect.getData('ALL_TRADES');
|
|
507
|
+
connect.query('ALL_TRADES');
|
|
508
|
+
connect.fetch('ALL_TRADES');
|
|
509
|
+
connect.commitEventPromise('EVENT_INSERT', data); // does not exist
|
|
510
|
+
\`\`\`
|
|
511
|
+
|
|
512
|
+
\`\`\`tsx
|
|
513
|
+
// CORRECT — use the documented methods only
|
|
514
|
+
connect.snapshot('ALL_TRADES');
|
|
515
|
+
connect.request('REQ_TRADE_DETAILS', { REQUEST: { ... } });
|
|
516
|
+
connect.commitEvent('EVENT_INSERT', { DETAILS: { ... } });
|
|
517
|
+
\`\`\`
|
|
518
|
+
`.trim();
|