@genesislcap/ai-assistant 15.46.5 → 15.47.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.
- package/dist/custom-elements.json +426 -214
- package/dist/dts/genesis/config.d.ts +30 -6
- package/dist/dts/genesis/config.d.ts.map +1 -1
- package/dist/dts/genesis/consumes.d.ts.map +1 -1
- package/dist/dts/genesis/event-fields.d.ts.map +1 -1
- package/dist/dts/genesis/filter-fields.d.ts +31 -0
- package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
- package/dist/dts/genesis/index.d.ts +3 -1
- package/dist/dts/genesis/index.d.ts.map +1 -1
- package/dist/dts/genesis/reference-check.d.ts +83 -0
- package/dist/dts/genesis/reference-check.d.ts.map +1 -0
- package/dist/dts/genesis/reference-existence.d.ts +110 -0
- package/dist/dts/genesis/reference-existence.d.ts.map +1 -0
- package/dist/dts/genesis/resource-tools.d.ts +4 -4
- package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
- package/dist/dts/genesis/review-model.d.ts +2 -2
- package/dist/dts/genesis/review-model.d.ts.map +1 -1
- package/dist/dts/genesis/row-source.d.ts +32 -0
- package/dist/dts/genesis/row-source.d.ts.map +1 -1
- package/dist/dts/genesis/server-text.d.ts +29 -0
- package/dist/dts/genesis/server-text.d.ts.map +1 -1
- package/dist/dts/genesis/types.d.ts +32 -5
- package/dist/dts/genesis/types.d.ts.map +1 -1
- package/dist/dts/genesis/write-payload.d.ts +14 -1
- package/dist/dts/genesis/write-payload.d.ts.map +1 -1
- package/dist/dts/genesis/write-plan.d.ts +8 -2
- package/dist/dts/genesis/write-plan.d.ts.map +1 -1
- package/dist/dts/genesis/write-tools.d.ts +5 -3
- package/dist/dts/genesis/write-tools.d.ts.map +1 -1
- package/dist/dts/genesis/write-turn.d.ts +4 -1
- package/dist/dts/genesis/write-turn.d.ts.map +1 -1
- package/dist/esm/genesis/config.js +152 -20
- package/dist/esm/genesis/consumes.js +2 -1
- package/dist/esm/genesis/event-fields.js +5 -8
- package/dist/esm/genesis/filter-fields.js +159 -78
- package/dist/esm/genesis/index.js +1 -0
- package/dist/esm/genesis/reference-check.js +132 -0
- package/dist/esm/genesis/reference-existence.js +283 -0
- package/dist/esm/genesis/resource-tools.js +135 -18
- package/dist/esm/genesis/review-model.js +3 -1
- package/dist/esm/genesis/row-source.js +107 -16
- package/dist/esm/genesis/server-text.js +52 -0
- package/dist/esm/genesis/write-payload.js +32 -4
- package/dist/esm/genesis/write-plan.js +3 -2
- package/dist/esm/genesis/write-tools.js +248 -44
- package/dist/genesis-consumes.cjs +3 -2
- package/dist/genesis-consumes.cjs.map +2 -2
- package/dist/genesis-consumes.mjs +3 -2
- package/dist/genesis-consumes.mjs.map +2 -2
- package/docs/genesis.md +131 -21
- package/package.json +17 -17
- package/scripts/smoke-genesis-consumes-node.mjs +2 -2
|
@@ -3,9 +3,28 @@ import { withTimeout } from '../utils/with-timeout';
|
|
|
3
3
|
import { composeCriteria } from './criteria';
|
|
4
4
|
import { loadFilterFields } from './filter-fields';
|
|
5
5
|
import { serialisable } from './serialisable';
|
|
6
|
-
import { plainFailure, plainServerText } from './server-text';
|
|
6
|
+
import { nackErrorsOf, plainFailure, plainServerText, refusalOf } from './server-text';
|
|
7
|
+
import { sameValue } from './value-compare';
|
|
7
8
|
/** Two rows are enough to know a key is not one, and one row more than a key should match. */
|
|
8
9
|
const KEY_MAX_ROWS = 2;
|
|
10
|
+
/**
|
|
11
|
+
* Memoises `load`'s promise while it succeeds. A failed answer, or a rejection, is asked again on
|
|
12
|
+
* the next call: kept, it would answer every later call the same way, for the session.
|
|
13
|
+
*/
|
|
14
|
+
function whileOk(load) {
|
|
15
|
+
let pending;
|
|
16
|
+
return () => {
|
|
17
|
+
pending !== null && pending !== void 0 ? pending : (pending = load().then((loaded) => {
|
|
18
|
+
if (loaded.status !== 'ok')
|
|
19
|
+
pending = undefined;
|
|
20
|
+
return loaded;
|
|
21
|
+
}, (error) => {
|
|
22
|
+
pending = undefined;
|
|
23
|
+
throw error;
|
|
24
|
+
}));
|
|
25
|
+
return pending;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
9
28
|
/** A read that never settles would hang the turn; see the read tools' own timeout. */
|
|
10
29
|
const READ_TIMEOUT_MS = 30000;
|
|
11
30
|
/**
|
|
@@ -20,19 +39,13 @@ const READ_TIMEOUT_MS = 30000;
|
|
|
20
39
|
* @internal
|
|
21
40
|
*/
|
|
22
41
|
export function createRequestRowSource({ connect, resource, timeouts, }) {
|
|
23
|
-
|
|
24
|
-
const loadFields = () => {
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
const loadMetadata = whileOk(() => loadFilterFields(connect, resource, timeouts === null || timeouts === void 0 ? void 0 : timeouts.metadataMs));
|
|
43
|
+
const loadFields = () => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const loaded = yield loadMetadata();
|
|
45
|
+
return loaded.status === 'ok'
|
|
27
46
|
? { fields: loaded.fields, described: loaded.described }
|
|
28
|
-
: `${resource} could not be read (${loaded.reason})
|
|
29
|
-
|
|
30
|
-
if (typeof loaded === 'string')
|
|
31
|
-
metadata = undefined;
|
|
32
|
-
return loaded;
|
|
33
|
-
}));
|
|
34
|
-
return metadata;
|
|
35
|
-
};
|
|
47
|
+
: `${resource} could not be read (${loaded.reason})`;
|
|
48
|
+
});
|
|
36
49
|
return {
|
|
37
50
|
resource,
|
|
38
51
|
describes() {
|
|
@@ -47,6 +60,75 @@ export function createRequestRowSource({ connect, resource, timeouts, }) {
|
|
|
47
60
|
return typeof metadata === 'string' ? undefined : metadata.fields;
|
|
48
61
|
});
|
|
49
62
|
},
|
|
63
|
+
metadata: loadMetadata,
|
|
64
|
+
exists(values) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
67
|
+
const entries = Object.entries(values);
|
|
68
|
+
if (!(connect === null || connect === void 0 ? void 0 : connect.isConnected)) {
|
|
69
|
+
return { status: 'failed', reason: 'the app is not connected to its server' };
|
|
70
|
+
}
|
|
71
|
+
const metadata = yield loadFields();
|
|
72
|
+
if (typeof metadata === 'string') {
|
|
73
|
+
return {
|
|
74
|
+
status: 'failed',
|
|
75
|
+
reason: plainServerText(metadata, `${resource} could not be described`, `${resource} could not be read`),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const composed = composeCriteria(entries.map(([field, value]) => ({ field, op: 'equals', value: String(value) })), metadata.fields);
|
|
79
|
+
// The composer's reason quotes the value, and on a modify a composite partner's value is
|
|
80
|
+
// another user's row text. So the reason is ours, and the caller names the field.
|
|
81
|
+
if (composed.status === 'rejected') {
|
|
82
|
+
return {
|
|
83
|
+
status: 'failed',
|
|
84
|
+
reason: `${resource} cannot be searched for that value`,
|
|
85
|
+
cause: 'unsearchable',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!composed.criteria) {
|
|
89
|
+
return { status: 'failed', reason: 'there is no value to look for' };
|
|
90
|
+
}
|
|
91
|
+
let reply;
|
|
92
|
+
try {
|
|
93
|
+
reply = yield withTimeout(connect.request(resource, {
|
|
94
|
+
REQUEST: {},
|
|
95
|
+
DETAILS: { MAX_ROWS: KEY_MAX_ROWS, CRITERIA_MATCH: composed.criteria },
|
|
96
|
+
}), (_a = timeouts === null || timeouts === void 0 ? void 0 : timeouts.readMs) !== null && _a !== void 0 ? _a : READ_TIMEOUT_MS);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const nack = nackErrorsOf(error);
|
|
100
|
+
return {
|
|
101
|
+
status: 'failed',
|
|
102
|
+
reason: nack
|
|
103
|
+
? plainServerText(refusalOf(nack).text, `${resource} refused a check`, `${resource} refused the read`)
|
|
104
|
+
: plainFailure(error, `${resource} check failed`, {
|
|
105
|
+
timeout: `${resource} took too long to answer`,
|
|
106
|
+
failed: `reading ${resource} failed`,
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const errors = reply === null || reply === void 0 ? void 0 : reply.ERROR;
|
|
111
|
+
if (Array.isArray(errors) && errors.length) {
|
|
112
|
+
return {
|
|
113
|
+
status: 'failed',
|
|
114
|
+
reason: plainServerText(refusalOf(errors).text, `${resource} refused a check`, `${resource} refused the read`),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const rows = Array.isArray(reply === null || reply === void 0 ? void 0 : reply.REPLY) ? reply.REPLY : [];
|
|
118
|
+
if (!rows.length)
|
|
119
|
+
return { status: 'missing' };
|
|
120
|
+
const matches = rows.some((row) => entries.every(([field, value]) => {
|
|
121
|
+
var _a;
|
|
122
|
+
return sameValue(row === null || row === void 0 ? void 0 : row[field], value, (_a = metadata.fields.get(field)) === null || _a === void 0 ? void 0 : _a.type);
|
|
123
|
+
}));
|
|
124
|
+
return matches
|
|
125
|
+
? { status: 'exists' }
|
|
126
|
+
: {
|
|
127
|
+
status: 'failed',
|
|
128
|
+
reason: `${resource} returned rows that do not match the value, so the check could not be trusted`,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
},
|
|
50
132
|
read(key) {
|
|
51
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
134
|
var _a;
|
|
@@ -87,9 +169,18 @@ export function createRequestRowSource({ connect, resource, timeouts, }) {
|
|
|
87
169
|
}), (_a = timeouts === null || timeouts === void 0 ? void 0 : timeouts.readMs) !== null && _a !== void 0 ? _a : READ_TIMEOUT_MS);
|
|
88
170
|
}
|
|
89
171
|
catch (error) {
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
172
|
+
// A router NACK rejects with the message it received, which is the app refusing the read
|
|
173
|
+
// in its own words; "reading it failed" would hide them.
|
|
174
|
+
const nack = nackErrorsOf(error);
|
|
175
|
+
if (nack) {
|
|
176
|
+
return {
|
|
177
|
+
status: 'failed',
|
|
178
|
+
reason: plainServerText(refusalOf(nack).text, `${resource} refused a row read`, `${resource} refused the read`),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// Any other rejection goes through the allow-list: a request server that throws mid-read
|
|
182
|
+
// can carry a SQL code, a class name or an internal host in its message, and this reason
|
|
183
|
+
// lands in a red row of the review table as well as in the tool result.
|
|
93
184
|
return {
|
|
94
185
|
status: 'failed',
|
|
95
186
|
reason: plainFailure(error, `${resource} row read failed`, {
|
|
@@ -184,3 +184,55 @@ export function plainFailure(error, context, wording) {
|
|
|
184
184
|
return wording.timeout;
|
|
185
185
|
return detail && readsLikeProse(detail) ? `${wording.failed}: ${detail}` : `${wording.failed}.`;
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* The app's refusal off an `ERROR` list: every `TEXT` joined, and the codes for the console.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
export const refusalOf = (errors) => ({
|
|
193
|
+
text: errors
|
|
194
|
+
.map((e) => e === null || e === void 0 ? void 0 : e.TEXT)
|
|
195
|
+
.filter((t) => typeof t === 'string' && !!t)
|
|
196
|
+
.join('; '),
|
|
197
|
+
codes: errors
|
|
198
|
+
.map((e) => e === null || e === void 0 ? void 0 : e.CODE)
|
|
199
|
+
.filter(Boolean)
|
|
200
|
+
.join(', '),
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* The `ERROR` list of the NACK a request was rejected with, or `undefined` when the rejection is
|
|
204
|
+
* not a NACK. On the socket path comms rejects a router MSG_NACK or LOGON_NACK with
|
|
205
|
+
* `{ receivedMessage, sentMessage }`, and that message is the app's answer.
|
|
206
|
+
*
|
|
207
|
+
* @internal
|
|
208
|
+
*/
|
|
209
|
+
export const nackErrorsOf = (error) => {
|
|
210
|
+
var _a;
|
|
211
|
+
const errors = (_a = error === null || error === void 0 ? void 0 : error.receivedMessage) === null || _a === void 0 ? void 0 : _a.ERROR;
|
|
212
|
+
return Array.isArray(errors) ? errors : undefined;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Why a metadata request failed, in words that are safe to show.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* The app's refusal is read off the router's MSG_NACK only when comms keeps it: the socket rejects
|
|
219
|
+
* with `{ receivedMessage, sentMessage }`, but `DefaultConnect.getMetadata` rewraps that as
|
|
220
|
+
* `Error('[object Object]')` today, which reads as the transport failing and gets the generic text.
|
|
221
|
+
* Nothing leaks either way: both go through the allow-list, with the raw text logged.
|
|
222
|
+
*
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
export function metadataFailureOf(error, resourceName) {
|
|
226
|
+
const errors = nackErrorsOf(error);
|
|
227
|
+
// The reason is quoted only when it is safe to show; otherwise the sentence stands on its own.
|
|
228
|
+
const saying = (lead, detail) => {
|
|
229
|
+
const shown = plainServerText(detail, `${resourceName}: ${lead}`, '');
|
|
230
|
+
return shown ? `${lead} (${shown})` : lead;
|
|
231
|
+
};
|
|
232
|
+
if (errors)
|
|
233
|
+
return saying('the app refused its metadata', refusalOf(errors).text);
|
|
234
|
+
const detail = describeFailure(error);
|
|
235
|
+
if (detail && TIMED_OUT.test(detail))
|
|
236
|
+
return 'the metadata request timed out';
|
|
237
|
+
return saying('the metadata request failed', detail);
|
|
238
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { utcMillisOf } from './calendar';
|
|
2
|
+
import { cannotBeChanged, notAcceptedHere } from './reference-check';
|
|
2
3
|
import { genesisTypeName } from './type-name';
|
|
3
4
|
import { sameValue } from './value-compare';
|
|
4
5
|
/**
|
|
@@ -148,7 +149,12 @@ const EXPONENT = /^[-+]?\d+(?:\.\d+)?[eE][-+]?\d+$/;
|
|
|
148
149
|
*/
|
|
149
150
|
const MAX_QUOTED = 64;
|
|
150
151
|
const MAX_LISTED_VALUES = 20;
|
|
151
|
-
|
|
152
|
+
/**
|
|
153
|
+
* A value echoed into one of our sentences: bounded, and without the quote that delimits it.
|
|
154
|
+
*
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
export const quoted = (raw) => {
|
|
152
158
|
// The single quote goes, because our own sentences delimit with one: untrusted text carrying
|
|
153
159
|
// an apostrophe closes the quote early and the rest reads as ours. Bounding the length without
|
|
154
160
|
// neutralising the delimiter leaves the smaller half of the same problem.
|
|
@@ -504,7 +510,29 @@ function sourceOf(field, given, changes, rowValue, merge, op) {
|
|
|
504
510
|
}
|
|
505
511
|
return { raw, fromRow: merge && !modelSent };
|
|
506
512
|
}
|
|
507
|
-
|
|
513
|
+
const typeOfField = (fields, name) => { var _a; return (_a = fields.find((field) => field.name === name)) === null || _a === void 0 ? void 0 : _a.type; };
|
|
514
|
+
/**
|
|
515
|
+
* Takes out of a sent row each value that must match another table's row and cannot be checked
|
|
516
|
+
* (contracts C-17.8): an insert leaves the column empty, a modify keeps the row's. An echo of the
|
|
517
|
+
* row's value, or a blank, asks for nothing new, so it passes without a word.
|
|
518
|
+
*/
|
|
519
|
+
function withoutUncheckedValues(fields, sent, { op, preImage, unchecked }) {
|
|
520
|
+
const refused = [];
|
|
521
|
+
if (!unchecked.size)
|
|
522
|
+
return { changes: sent, refused };
|
|
523
|
+
const changes = Object.fromEntries(Object.entries(sent).filter(([name, value]) => {
|
|
524
|
+
const reason = unchecked.get(name);
|
|
525
|
+
if (!reason || isBlankEntry(value))
|
|
526
|
+
return !reason;
|
|
527
|
+
if (op === 'modify' && sameValue(value, preImage === null || preImage === void 0 ? void 0 : preImage[name], typeOfField(fields, name))) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
refused.push(op === 'modify' ? cannotBeChanged(name, reason) : notAcceptedHere(name, reason));
|
|
531
|
+
return false;
|
|
532
|
+
}));
|
|
533
|
+
return { changes, refused };
|
|
534
|
+
}
|
|
535
|
+
export function buildEventPayload(fields, row, { op, preImage, unchecked }) {
|
|
508
536
|
var _a;
|
|
509
537
|
if (!row || typeof row !== 'object' || Array.isArray(row)) {
|
|
510
538
|
return {
|
|
@@ -514,7 +542,7 @@ export function buildEventPayload(fields, row, { op, preImage } = {}) {
|
|
|
514
542
|
}
|
|
515
543
|
// Merged BEFORE anything is validated or frozen, so what is checked, shown and committed is
|
|
516
544
|
// one object: re-deriving a payload after the review is the gap the review exists to close.
|
|
517
|
-
const changes = row;
|
|
545
|
+
const { changes, refused: refusedReferences } = withoutUncheckedValues(fields, row, { op, preImage, unchecked });
|
|
518
546
|
// A modify or delete without the row it is changing cannot be built at all: under replace
|
|
519
547
|
// semantics the unnamed fields would be written as null. Saying so beats the required-field
|
|
520
548
|
// loop's "SYMBOL needs a value", which blames the model for a value it cannot supply — the
|
|
@@ -575,7 +603,7 @@ export function buildEventPayload(fields, row, { op, preImage } = {}) {
|
|
|
575
603
|
};
|
|
576
604
|
}
|
|
577
605
|
const byName = new Map(fields.map((field) => [field.name, field]));
|
|
578
|
-
const problems = [];
|
|
606
|
+
const problems = [...refusedReferences];
|
|
579
607
|
const details = {};
|
|
580
608
|
for (const name of Object.keys(given)) {
|
|
581
609
|
const field = byName.get(name);
|
|
@@ -25,7 +25,7 @@ const keyOf = (entry) => asRecord(entry.key);
|
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
27
|
export function planWrite(rows_1, _a) {
|
|
28
|
-
return __awaiter(this, arguments, void 0, function* (rows, { op, fields, source }) {
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* (rows, { op, fields, source, unchecked }) {
|
|
29
29
|
if (!Array.isArray(rows) || !rows.length) {
|
|
30
30
|
return { status: 'rejected', reason: 'rows must be a non-empty list of rows to write.' };
|
|
31
31
|
}
|
|
@@ -86,7 +86,7 @@ export function planWrite(rows_1, _a) {
|
|
|
86
86
|
if (entry.problems)
|
|
87
87
|
return { index: entry.index, key: entry.key, problems: entry.problems };
|
|
88
88
|
if (!needsRow) {
|
|
89
|
-
const built = buildEventPayload(fields, entry.given, { op });
|
|
89
|
+
const built = buildEventPayload(fields, entry.given, { op, unchecked });
|
|
90
90
|
return built.status === 'ok'
|
|
91
91
|
? { index: entry.index, details: built.details }
|
|
92
92
|
: { index: entry.index, problems: built.problems };
|
|
@@ -156,6 +156,7 @@ export function planWrite(rows_1, _a) {
|
|
|
156
156
|
const built = buildEventPayload(fields, Object.assign(Object.assign({}, changes), entry.key), {
|
|
157
157
|
op,
|
|
158
158
|
preImage: read.row,
|
|
159
|
+
unchecked,
|
|
159
160
|
});
|
|
160
161
|
// A modify has to CHANGE something, and saying what is not the same as changing it. A
|
|
161
162
|
// non-empty `changes` can still leave every value as it is — `{NOTE: ''}` (an empty string
|