@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.
Files changed (52) hide show
  1. package/dist/custom-elements.json +426 -214
  2. package/dist/dts/genesis/config.d.ts +30 -6
  3. package/dist/dts/genesis/config.d.ts.map +1 -1
  4. package/dist/dts/genesis/consumes.d.ts.map +1 -1
  5. package/dist/dts/genesis/event-fields.d.ts.map +1 -1
  6. package/dist/dts/genesis/filter-fields.d.ts +31 -0
  7. package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
  8. package/dist/dts/genesis/index.d.ts +3 -1
  9. package/dist/dts/genesis/index.d.ts.map +1 -1
  10. package/dist/dts/genesis/reference-check.d.ts +83 -0
  11. package/dist/dts/genesis/reference-check.d.ts.map +1 -0
  12. package/dist/dts/genesis/reference-existence.d.ts +110 -0
  13. package/dist/dts/genesis/reference-existence.d.ts.map +1 -0
  14. package/dist/dts/genesis/resource-tools.d.ts +4 -4
  15. package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
  16. package/dist/dts/genesis/review-model.d.ts +2 -2
  17. package/dist/dts/genesis/review-model.d.ts.map +1 -1
  18. package/dist/dts/genesis/row-source.d.ts +32 -0
  19. package/dist/dts/genesis/row-source.d.ts.map +1 -1
  20. package/dist/dts/genesis/server-text.d.ts +29 -0
  21. package/dist/dts/genesis/server-text.d.ts.map +1 -1
  22. package/dist/dts/genesis/types.d.ts +32 -5
  23. package/dist/dts/genesis/types.d.ts.map +1 -1
  24. package/dist/dts/genesis/write-payload.d.ts +14 -1
  25. package/dist/dts/genesis/write-payload.d.ts.map +1 -1
  26. package/dist/dts/genesis/write-plan.d.ts +8 -2
  27. package/dist/dts/genesis/write-plan.d.ts.map +1 -1
  28. package/dist/dts/genesis/write-tools.d.ts +5 -3
  29. package/dist/dts/genesis/write-tools.d.ts.map +1 -1
  30. package/dist/dts/genesis/write-turn.d.ts +4 -1
  31. package/dist/dts/genesis/write-turn.d.ts.map +1 -1
  32. package/dist/esm/genesis/config.js +152 -20
  33. package/dist/esm/genesis/consumes.js +2 -1
  34. package/dist/esm/genesis/event-fields.js +5 -8
  35. package/dist/esm/genesis/filter-fields.js +159 -78
  36. package/dist/esm/genesis/index.js +1 -0
  37. package/dist/esm/genesis/reference-check.js +132 -0
  38. package/dist/esm/genesis/reference-existence.js +283 -0
  39. package/dist/esm/genesis/resource-tools.js +135 -18
  40. package/dist/esm/genesis/review-model.js +3 -1
  41. package/dist/esm/genesis/row-source.js +107 -16
  42. package/dist/esm/genesis/server-text.js +52 -0
  43. package/dist/esm/genesis/write-payload.js +32 -4
  44. package/dist/esm/genesis/write-plan.js +3 -2
  45. package/dist/esm/genesis/write-tools.js +248 -44
  46. package/dist/genesis-consumes.cjs +3 -2
  47. package/dist/genesis-consumes.cjs.map +2 -2
  48. package/dist/genesis-consumes.mjs +3 -2
  49. package/dist/genesis-consumes.mjs.map +2 -2
  50. package/docs/genesis.md +131 -21
  51. package/package.json +17 -17
  52. package/scripts/smoke-genesis-consumes-node.mjs +2 -2
@@ -2,6 +2,7 @@ import { __awaiter } from "tslib";
2
2
  import { logger } from '../utils/logger';
3
3
  import { withTimeout } from '../utils/with-timeout';
4
4
  import { fieldKindOf } from './criteria';
5
+ import { metadataFailureOf } from './server-text';
5
6
  import { genesisTypeName } from './type-name';
6
7
  /**
7
8
  * A metadata request that never settles would pin the tool list for the page: Connect drops
@@ -66,9 +67,16 @@ export function allowedValuesOf(detail) {
66
67
  * @internal
67
68
  */
68
69
  export const metadataNameOf = (resourceName) => resourceName.replace(/^REQ_/, '');
70
+ /**
71
+ * A metadata field list, or none when the reply holds something else there. A malformed list
72
+ * describes nothing rather than throwing out of the whole tool list.
73
+ *
74
+ * @internal
75
+ */
76
+ export const listOf = (value) => (Array.isArray(value) ? value : []);
69
77
  /** @internal */
70
78
  export function filterFieldsFrom(metadata) {
71
- var _a, _b, _c;
79
+ var _a, _b;
72
80
  // The REPLY's fields, and only those: `REPLY_FIELD`, or `REPLY.FIELD` where a class-typed
73
81
  // `requestReply<Input, Output>` puts them — the same two places foundation-comms reads for a
74
82
  // request server. A top-level `FIELD` is not an alias for them. On that class-typed shape it is
@@ -77,7 +85,7 @@ export function filterFieldsFrom(metadata) {
77
85
  // modify wrote it null with the review showing blank on both sides. Rows come from the reply,
78
86
  // and so do criteria, which are evaluated against each reply row.
79
87
  const details = new Map();
80
- for (const detail of (_c = (_a = metadata.REPLY_FIELD) !== null && _a !== void 0 ? _a : (_b = metadata.REPLY) === null || _b === void 0 ? void 0 : _b.FIELD) !== null && _c !== void 0 ? _c : []) {
88
+ for (const detail of listOf((_a = metadata.REPLY_FIELD) !== null && _a !== void 0 ? _a : (_b = metadata.REPLY) === null || _b === void 0 ? void 0 : _b.FIELD)) {
81
89
  if ((detail === null || detail === void 0 ? void 0 : detail.NAME) && !details.has(detail.NAME))
82
90
  details.set(detail.NAME, detail);
83
91
  }
@@ -95,49 +103,10 @@ export function filterFieldsFrom(metadata) {
95
103
  const criteriaFields = Array.isArray(metadata.CRITERIA_FIELDS)
96
104
  ? metadata.CRITERIA_FIELDS
97
105
  : [...details.keys()];
98
- const fields = new Map();
99
- const undescribed = [];
100
- const unfilterable = [];
101
- const unreadableValues = [];
102
- for (const name of criteriaFields) {
103
- const detail = details.get(name);
104
- // A criteria field the reply describes nowhere is LEFT OUT rather than guessed at. Calling
105
- // it STRING was the guess, and it is wrong in both directions, silently: `AMOUNT == '100'`
106
- // against a numeric column quotes a string at a number and matches nothing (this module's
107
- // own header says the same about a timestamp), while `greater_than` on it is refused with a
108
- // confident, wrong explanation — "AMOUNT is a string field" — that the model will act on by
109
- // rewording the query for ever.
110
- //
111
- // The cost is real: a criteria-only request server publishes CRITERIA_FIELDS for every
112
- // column of the table, so a field its reply does not carry is ordinary rather than exotic,
113
- // and dropping it means the model reads more rows and narrows them itself. That is a slower
114
- // right answer, and the alternative is a fast wrong one with nothing to notice it by.
115
- // A detail with no TYPE is as undescribed as no detail at all. The first fix here caught
116
- // only the second case and left `detail.TYPE ?? 'STRING'` one level down — the very guess
117
- // the fix was written to remove, surviving inside it.
118
- if (!(detail === null || detail === void 0 ? void 0 : detail.TYPE)) {
119
- undescribed.push(name);
120
- continue;
121
- }
122
- // Offered only if criteria.ts can compose a filter for it. A type it does not know is
123
- // refused there by name, so listing it here would be the tool schema promising a filter the
124
- // read then declines — a turn spent on the schema's word.
125
- if (!fieldKindOf(detail.TYPE)) {
126
- unfilterable.push(name);
127
- continue;
128
- }
129
- const allowed = allowedValuesOf(detail);
130
- if (allowed.status === 'unreadable') {
131
- unreadableValues.push(name);
132
- continue;
133
- }
134
- fields.set(name, { name, type: detail.TYPE, validValues: allowed.values });
135
- }
136
- return {
137
- fields,
138
- undescribed,
139
- unfilterable,
140
- unreadableValues,
106
+ const sorted = emptySort();
107
+ for (const name of criteriaFields)
108
+ sortField(name, details.get(name), sorted);
109
+ return Object.assign(Object.assign({}, sorted), {
141
110
  // EVERY column the reply names, typed or not: the write path's coverage check asks whether a
142
111
  // row read here CARRIES a column, and one described without a type is still carried. Keeping
143
112
  // typed names only (as d9ffe904d6 did, while adding the types for a delete's review) turned a
@@ -146,8 +115,74 @@ export function filterFieldsFrom(metadata) {
146
115
  described: new Map([...details.entries()].map(([name, detail]) => [
147
116
  name,
148
117
  detail.TYPE ? String(detail.TYPE) : '',
149
- ])),
150
- };
118
+ ])) });
119
+ }
120
+ const emptySort = () => ({
121
+ fields: new Map(),
122
+ undescribed: [],
123
+ unfilterable: [],
124
+ unreadableValues: [],
125
+ });
126
+ /**
127
+ * Offers one field as a filter, or says why not. The one rule for a request's criteria fields and a
128
+ * query's fields alike.
129
+ */
130
+ function sortField(name, detail, into) {
131
+ // A criteria field the reply describes nowhere is LEFT OUT rather than guessed at. Calling
132
+ // it STRING was the guess, and it is wrong in both directions, silently: `AMOUNT == '100'`
133
+ // against a numeric column quotes a string at a number and matches nothing (this module's
134
+ // own header says the same about a timestamp), while `greater_than` on it is refused with a
135
+ // confident, wrong explanation — "AMOUNT is a string field" — that the model will act on by
136
+ // rewording the query for ever.
137
+ //
138
+ // The cost is real: a criteria-only request server publishes CRITERIA_FIELDS for every
139
+ // column of the table, so a field its reply does not carry is ordinary rather than exotic,
140
+ // and dropping it means the model reads more rows and narrows them itself. That is a slower
141
+ // right answer, and the alternative is a fast wrong one with nothing to notice it by.
142
+ // A detail with no TYPE is as undescribed as no detail at all. The first fix here caught
143
+ // only the second case and left `detail.TYPE ?? 'STRING'` one level down — the very guess
144
+ // the fix was written to remove, surviving inside it.
145
+ if (!(detail === null || detail === void 0 ? void 0 : detail.TYPE)) {
146
+ into.undescribed.push(name);
147
+ return;
148
+ }
149
+ // Offered only if criteria.ts can compose a filter for it. A type it does not know is
150
+ // refused there by name, so listing it here would be the tool schema promising a filter the
151
+ // read then declines — a turn spent on the schema's word.
152
+ if (!fieldKindOf(detail.TYPE)) {
153
+ into.unfilterable.push(name);
154
+ return;
155
+ }
156
+ const allowed = allowedValuesOf(detail);
157
+ if (allowed.status === 'unreadable') {
158
+ into.unreadableValues.push(name);
159
+ return;
160
+ }
161
+ into.fields.set(name, { name, type: detail.TYPE, validValues: allowed.values });
162
+ }
163
+ /**
164
+ * A dataserver query's filterable fields, from its own metadata.
165
+ *
166
+ * @remarks
167
+ * A dataserver publishes `TYPE: DATASERVER` and one top-level `FIELD` list: what the query returns,
168
+ * and what a criteria on it may name. That is a different shape from a request's, where a top-level
169
+ * `FIELD` is the INPUT class (see {@link filterFieldsFrom}), so the two are never read by one parser.
170
+ * Every typed field of a filterable type with readable values is offered, enriched ones too: the
171
+ * metadata does not mark them, and the server refuses a filter on one in its own words.
172
+ *
173
+ * @internal
174
+ */
175
+ export function queryFieldsFrom(metadata) {
176
+ const sorted = emptySort();
177
+ const described = new Map();
178
+ for (const detail of listOf(metadata.FIELD)) {
179
+ const name = detail === null || detail === void 0 ? void 0 : detail.NAME;
180
+ if (!name || described.has(name))
181
+ continue;
182
+ described.set(name, detail.TYPE ? String(detail.TYPE) : '');
183
+ sortField(name, detail, sorted);
184
+ }
185
+ return Object.assign(Object.assign({}, sorted), { described });
151
186
  }
152
187
  /**
153
188
  * Fetches a resource's filterable fields. Never throws.
@@ -161,18 +196,64 @@ export function filterFieldsFrom(metadata) {
161
196
  */
162
197
  export function loadFilterFields(connect_1, resourceName_1) {
163
198
  return __awaiter(this, arguments, void 0, function* (connect, resourceName, timeoutMs = METADATA_TIMEOUT_MS) {
199
+ const fetched = yield fetchMetadata(connect, metadataNameOf(resourceName), timeoutMs);
200
+ if (fetched.status === 'failed')
201
+ return fetched;
202
+ const { metadata } = fetched;
203
+ // A dataserver's description is not a request's: its top-level FIELD would pass the write path's
204
+ // coverage check for columns a request never returns. Nothing is taken from it.
205
+ if (metadata.TYPE === 'DATASERVER') {
206
+ logger.warn(`Genesis assistant: ${resourceName} is described as a dataserver query, not a request, so ` +
207
+ 'its read tool takes no filters and no write reads its rows.');
208
+ return { status: 'ok', fields: new Map(), published: false, described: new Map() };
209
+ }
210
+ const from = filterFieldsFrom(metadata);
211
+ warnLeftOut(resourceName, from, 'request');
212
+ // Whether the reply DESCRIBED any fields at all, so the caller can tell "this resource has
213
+ // nothing to filter on" from "we asked in the wrong place, or the platform sent nothing".
214
+ // Presence of the keys, not their length: a resource that answers with empty lists HAS
215
+ // described itself — it has nothing to filter on — while a reply that mentions none of them
216
+ // has described nothing, which is a different thing to tell the host.
217
+ const published = ['CRITERIA_FIELDS', 'REPLY_FIELD', 'REPLY'].some((key) => key in metadata);
218
+ return { status: 'ok', fields: from.fields, published, described: from.described };
219
+ });
220
+ }
221
+ /**
222
+ * Fetches a dataserver query's filterable fields. Never throws.
223
+ *
224
+ * @remarks
225
+ * Asked for under the query's name exactly as configured: a query's metadata is published under its
226
+ * own name, and {@link metadataNameOf}'s `REQ_` rule is a request's, so a query that happens to be
227
+ * named `REQ_…` must not lose its prefix.
228
+ *
229
+ * @internal
230
+ */
231
+ export function loadQueryFields(connect_1, queryName_1) {
232
+ return __awaiter(this, arguments, void 0, function* (connect, queryName, timeoutMs = METADATA_TIMEOUT_MS) {
233
+ const fetched = yield fetchMetadata(connect, queryName, timeoutMs);
234
+ if (fetched.status === 'failed')
235
+ return fetched;
236
+ const from = queryFieldsFrom(fetched.metadata);
237
+ warnLeftOut(queryName, from, 'query');
238
+ return {
239
+ status: 'ok',
240
+ fields: from.fields,
241
+ published: 'FIELD' in fetched.metadata,
242
+ described: from.described,
243
+ };
244
+ });
245
+ }
246
+ /** A metadata reply, or why there is none. */
247
+ function fetchMetadata(connect, metadataName, timeoutMs) {
248
+ return __awaiter(this, void 0, void 0, function* () {
164
249
  let metadata;
165
250
  try {
166
- metadata = yield withTimeout(connect.getMetadata(metadataNameOf(resourceName)), timeoutMs);
251
+ metadata = yield withTimeout(connect.getMetadata(metadataName), timeoutMs);
167
252
  }
168
253
  catch (error) {
169
254
  // Classified by OUTCOME, not by the connection state before the await: a request that was
170
255
  // sent while connected and failed mid-flight is exactly the case worth retrying.
171
- return {
172
- status: 'failed',
173
- reason: `the metadata request failed (${String(error)})`,
174
- transient: true,
175
- };
256
+ return { status: 'failed', reason: metadataFailureOf(error, metadataName), transient: true };
176
257
  }
177
258
  if (!metadata || typeof metadata !== 'object' || metadata.ERROR) {
178
259
  // A reply came back and was unusable. Connect caches any non-empty metadata reply for the
@@ -186,30 +267,30 @@ export function loadFilterFields(connect_1, resourceName_1) {
186
267
  transient: !metadata,
187
268
  };
188
269
  }
189
- const { fields, undescribed, unfilterable, unreadableValues, described } = filterFieldsFrom(metadata);
190
- if (unfilterable.length) {
191
- logger.warn(`Genesis assistant: ${resourceName} describes ${unfilterable.join(', ')} with a type this ` +
192
- 'assistant cannot filter on, so they are not offered as filters.');
193
- }
194
- if (unreadableValues.length) {
195
- // Worded so one grep finds it: whether a Create-generated request server publishes an ENUM's
196
- // values has not been observed (the live capture is the showcase's hand-written one), and
197
- // if it does not, this is the line that says so.
198
- logger.warn(`Genesis assistant: ${resourceName} describes ${unreadableValues.join(', ')} with ` +
199
- 'allowed values this assistant cannot read (an ENUM with no readable values, or ' +
200
- 'VALID_VALUES in a shape it does not recognise), so they are not offered as filters.');
201
- }
202
- if (undescribed.length) {
203
- logger.warn(`Genesis assistant: ${resourceName} lists ${undescribed.join(', ')} as criteria fields but ` +
204
- 'describes neither type, so they are not offered as filters. Publish them in the ' +
205
- "resource's reply fields to make them filterable.");
206
- }
207
- // Whether the reply DESCRIBED any fields at all, so the caller can tell "this resource has
208
- // nothing to filter on" from "we asked in the wrong place, or the platform sent nothing".
209
- // Presence of the keys, not their length: a resource that answers with empty lists HAS
210
- // described itself — it has nothing to filter on — while a reply that mentions none of them
211
- // has described nothing, which is a different thing to tell the host.
212
- const published = ['CRITERIA_FIELDS', 'REPLY_FIELD', 'REPLY'].some((key) => key in metadata);
213
- return { status: 'ok', fields, published, described };
270
+ return { status: 'ok', metadata };
214
271
  });
215
272
  }
273
+ /** The fields left out of a read tool's filters, and why, for the console. */
274
+ function warnLeftOut(resourceName, { unfilterable, unreadableValues, undescribed }, kind) {
275
+ if (unfilterable.length) {
276
+ logger.warn(`Genesis assistant: ${resourceName} describes ${unfilterable.join(', ')} with a type this ` +
277
+ 'assistant cannot filter on, so they are not offered as filters.');
278
+ }
279
+ if (unreadableValues.length) {
280
+ // Worded so one grep finds it: whether a Create-generated request server publishes an ENUM's
281
+ // values has not been observed (the live capture is the showcase's hand-written one), and
282
+ // if it does not, this is the line that says so.
283
+ logger.warn(`Genesis assistant: ${resourceName} describes ${unreadableValues.join(', ')} with ` +
284
+ 'allowed values this assistant cannot read (an ENUM with no readable values, or ' +
285
+ 'VALID_VALUES in a shape it does not recognise), so they are not offered as filters.');
286
+ }
287
+ if (undescribed.length && kind === 'query') {
288
+ logger.warn(`Genesis assistant: ${resourceName} lists ${undescribed.join(', ')} with no type, so they ` +
289
+ 'are not offered as filters.');
290
+ }
291
+ else if (undescribed.length) {
292
+ logger.warn(`Genesis assistant: ${resourceName} lists ${undescribed.join(', ')} as criteria fields but ` +
293
+ 'describes neither type, so they are not offered as filters. Publish them in the ' +
294
+ "resource's reply fields to make them filterable.");
295
+ }
296
+ }
@@ -13,6 +13,7 @@
13
13
  export { GENESIS_AGENT_NAME, registerGenesisAssistant } from './register-genesis-assistant';
14
14
  export { customCodeOf } from './config';
15
15
  export { GENESIS_AI_CONSUMES } from './consumes';
16
+ export { validateGenesisAiConfig } from './config';
16
17
  export { createGenesisResourceTools, GENESIS_DATA_SOURCE } from './resource-tools';
17
18
  export { createGenesisWriteTools } from './write-tools';
18
19
  export { GENESIS_WRITE_REVIEW, GenesisWriteReview } from './write-review/write-review';
@@ -0,0 +1,132 @@
1
+ import { __awaiter } from "tslib";
2
+ import { fieldKindOf } from './criteria';
3
+ import { createRequestRowSource, } from './row-source';
4
+ import { plainServerText } from './server-text';
5
+ /** The table a `REQ_<T>` reads. */
6
+ export const tableOf = (resource) => resource.replace(/^REQ_/, '');
7
+ /**
8
+ * Decides, per declared reference, whether it can be checked. A reference is checkable only when
9
+ * every one of its fields is.
10
+ *
11
+ * @internal
12
+ */
13
+ export function gateReferences(references, fields, deps) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ return Promise.all(references.map((reference) => __awaiter(this, void 0, void 0, function* () {
16
+ const unchecked = (reason) => ({
17
+ status: 'unchecked',
18
+ reference,
19
+ reason,
20
+ });
21
+ if (!deps.requestNames.has(reference.resource)) {
22
+ return unchecked(`${reference.resource} is not a read this assistant has`);
23
+ }
24
+ const source = deps.sourceFor(reference.resource);
25
+ const loaded = yield source.metadata();
26
+ if (loaded.status !== 'ok') {
27
+ if (loaded.transient)
28
+ return { status: 'transient', reference, reason: loaded.reason };
29
+ // The loader's reason can carry the app's raw ERROR, class names and hosts included, and it
30
+ // reaches the model and the review: only prose is kept.
31
+ const why = plainServerText(loaded.reason, `${reference.resource} metadata`, '');
32
+ return unchecked(`${reference.resource} could not be described${why ? ` (${why})` : ''}`);
33
+ }
34
+ for (const { field, targetField } of reference.fields) {
35
+ const target = loaded.fields.get(targetField);
36
+ if (!target)
37
+ return unchecked(`${reference.resource} cannot be searched by ${targetField}`);
38
+ const kind = fieldKindOf(target.type);
39
+ // No equals exists for a timestamp, and a date's time zone has not been confirmed. One
40
+ // reason for both: a DATE key can be described as a DATETIME.
41
+ if (kind === 'datetime' || kind === 'date') {
42
+ return unchecked(`${targetField} is a date or a date and time, which this version does not check`);
43
+ }
44
+ const own = fields.find((candidate) => candidate.name === field);
45
+ if (!(own === null || own === void 0 ? void 0 : own.type))
46
+ return unchecked(`${field} is not a field this write declares`);
47
+ if (fieldKindOf(own.type) !== kind) {
48
+ return unchecked(`${field} and ${targetField} hold different kinds of value`);
49
+ }
50
+ }
51
+ return {
52
+ status: 'checkable',
53
+ reference,
54
+ source,
55
+ targetFields: new Map(reference.fields.map(({ targetField }) => [
56
+ targetField,
57
+ loaded.fields.get(targetField),
58
+ ])),
59
+ };
60
+ })));
61
+ });
62
+ }
63
+ /**
64
+ * Turns the gates into what the tool does.
65
+ *
66
+ * @internal
67
+ */
68
+ export function referenceOutcome(op, fields, gates) {
69
+ const unchecked = new Map();
70
+ const checkable = [];
71
+ let noTool;
72
+ let transient;
73
+ for (const gate of gates) {
74
+ if (gate.status === 'checkable') {
75
+ checkable.push(gate);
76
+ continue;
77
+ }
78
+ const { resource } = gate.reference;
79
+ if (gate.status === 'transient') {
80
+ transient !== null && transient !== void 0 ? transient : (transient = `${resource} could not be described (${gate.reason})`);
81
+ continue;
82
+ }
83
+ const required = gate.reference.fields.find(({ field }) => { var _a; return ((_a = fields.find((candidate) => candidate.name === field)) === null || _a === void 0 ? void 0 : _a.optional) === false; });
84
+ if (op === 'insert' && required) {
85
+ noTool !== null && noTool !== void 0 ? noTool : (noTool = `${required.field} must match a ${tableOf(resource)} row through ${resource}, and that ` +
86
+ `cannot be checked here (${gate.reason})`);
87
+ continue;
88
+ }
89
+ for (const { field } of gate.reference.fields)
90
+ unchecked.set(field, { resource, reason: gate.reason });
91
+ }
92
+ return { noTool, transient, unchecked, checkable };
93
+ }
94
+ /** What a write with no declared references does: nothing is checked, and everything is offered. */
95
+ const NO_REFERENCES = Object.freeze({
96
+ unchecked: new Map(),
97
+ checkable: [],
98
+ });
99
+ /**
100
+ * The reference gate for one set of write tools: whether each of a write's declared references can
101
+ * be checked, and what that means for its tool. A target read is described once, however many
102
+ * events reference it.
103
+ *
104
+ * @internal
105
+ */
106
+ export function createReferenceGate(requestNames, timeouts) {
107
+ const targetSources = new Map();
108
+ const sourceFor = (connect, name) => {
109
+ let source = targetSources.get(name);
110
+ if (!source) {
111
+ source = createRequestRowSource({ connect, resource: name, timeouts });
112
+ targetSources.set(name, source);
113
+ }
114
+ return source;
115
+ };
116
+ return (resource, op, fields, connect) => __awaiter(this, void 0, void 0, function* () {
117
+ var _a;
118
+ if ((op !== 'insert' && op !== 'modify') || !((_a = resource.references) === null || _a === void 0 ? void 0 : _a.length))
119
+ return NO_REFERENCES;
120
+ const gates = yield gateReferences(resource.references, fields, {
121
+ requestNames,
122
+ sourceFor: (name) => sourceFor(connect, name),
123
+ });
124
+ return referenceOutcome(op, fields, gates);
125
+ });
126
+ }
127
+ /** What an insert says about a value it cannot check. */
128
+ export const notAcceptedHere = (field, { resource, reason }) => `${field} is not accepted here: it must match a ${tableOf(resource)} row through ${resource}, ` +
129
+ `which cannot be checked in this app (${reason}). Leave it out.`;
130
+ /** What a modify says about a new value it cannot check. */
131
+ export const cannotBeChanged = (field, { resource, reason }) => `${field} cannot be changed through this tool: it must match a ${tableOf(resource)} row ` +
132
+ `through ${resource}, which cannot be checked here (${reason}).`;