@genesislcap/ai-assistant 15.37.0 → 15.38.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 +638 -0
- package/dist/dts/genesis/calendar.d.ts +25 -0
- package/dist/dts/genesis/calendar.d.ts.map +1 -0
- package/dist/dts/genesis/config.d.ts +16 -0
- package/dist/dts/genesis/config.d.ts.map +1 -1
- package/dist/dts/genesis/criteria.d.ts +24 -2
- package/dist/dts/genesis/criteria.d.ts.map +1 -1
- package/dist/dts/genesis/event-fields.d.ts +84 -0
- package/dist/dts/genesis/event-fields.d.ts.map +1 -0
- package/dist/dts/genesis/filter-fields.d.ts +69 -5
- package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
- package/dist/dts/genesis/index.d.ts +3 -0
- package/dist/dts/genesis/index.d.ts.map +1 -1
- package/dist/dts/genesis/register-genesis-assistant.d.ts +13 -0
- package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
- package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
- package/dist/dts/genesis/review-model.d.ts +202 -0
- package/dist/dts/genesis/review-model.d.ts.map +1 -0
- package/dist/dts/genesis/row-source.d.ts +102 -0
- package/dist/dts/genesis/row-source.d.ts.map +1 -0
- package/dist/dts/genesis/serialisable.d.ts +25 -0
- package/dist/dts/genesis/serialisable.d.ts.map +1 -0
- package/dist/dts/genesis/server-text.d.ts +63 -0
- package/dist/dts/genesis/server-text.d.ts.map +1 -0
- package/dist/dts/genesis/type-name.d.ts +18 -0
- package/dist/dts/genesis/type-name.d.ts.map +1 -0
- package/dist/dts/genesis/types.d.ts +7 -0
- package/dist/dts/genesis/types.d.ts.map +1 -1
- package/dist/dts/genesis/value-compare.d.ts +19 -0
- package/dist/dts/genesis/value-compare.d.ts.map +1 -0
- package/dist/dts/genesis/write-commit.d.ts +53 -0
- package/dist/dts/genesis/write-commit.d.ts.map +1 -0
- package/dist/dts/genesis/write-outcome.d.ts +133 -0
- package/dist/dts/genesis/write-outcome.d.ts.map +1 -0
- package/dist/dts/genesis/write-payload.d.ts +129 -0
- package/dist/dts/genesis/write-payload.d.ts.map +1 -0
- package/dist/dts/genesis/write-plan.d.ts +109 -0
- package/dist/dts/genesis/write-plan.d.ts.map +1 -0
- package/dist/dts/genesis/write-review/write-review.d.ts +127 -0
- package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -0
- package/dist/dts/genesis/write-review/write-review.styles.d.ts +2 -0
- package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -0
- package/dist/dts/genesis/write-review/write-review.template.d.ts +4 -0
- package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -0
- package/dist/dts/genesis/write-tools.d.ts +99 -0
- package/dist/dts/genesis/write-tools.d.ts.map +1 -0
- package/dist/dts/react.d.ts +10 -0
- package/dist/esm/genesis/calendar.js +38 -0
- package/dist/esm/genesis/config.js +36 -1
- package/dist/esm/genesis/criteria.js +59 -55
- package/dist/esm/genesis/event-fields.js +158 -0
- package/dist/esm/genesis/filter-fields.js +111 -20
- package/dist/esm/genesis/index.js +2 -0
- package/dist/esm/genesis/register-genesis-assistant.js +76 -4
- package/dist/esm/genesis/resource-tools.js +21 -103
- package/dist/esm/genesis/review-model.js +248 -0
- package/dist/esm/genesis/row-source.js +127 -0
- package/dist/esm/genesis/serialisable.js +38 -0
- package/dist/esm/genesis/server-text.js +186 -0
- package/dist/esm/genesis/type-name.js +20 -0
- package/dist/esm/genesis/value-compare.js +87 -0
- package/dist/esm/genesis/write-commit.js +78 -0
- package/dist/esm/genesis/write-outcome.js +299 -0
- package/dist/esm/genesis/write-payload.js +632 -0
- package/dist/esm/genesis/write-plan.js +275 -0
- package/dist/esm/genesis/write-review/write-review.js +252 -0
- package/dist/esm/genesis/write-review/write-review.styles.js +214 -0
- package/dist/esm/genesis/write-review/write-review.template.js +182 -0
- package/dist/esm/genesis/write-tools.js +660 -0
- package/dist/react.cjs +7 -0
- package/dist/react.mjs +6 -0
- package/docs/genesis.md +152 -10
- package/package.json +18 -18
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Connect } from '@genesislcap/foundation-comms';
|
|
2
|
+
import { type GenesisFilterField } from './criteria';
|
|
3
|
+
/**
|
|
4
|
+
* Reading the row a write is based on.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A modify or a delete needs the row as it stands now, twice over and for different reasons:
|
|
8
|
+
*
|
|
9
|
+
* - **Before the review**, because a generated CRUD modify REPLACES the record. A payload
|
|
10
|
+
* carrying only the fields the model named would write null over every field it did not, and
|
|
11
|
+
* nobody would see it happen (see `buildEventPayload`).
|
|
12
|
+
* - **After the user approves**, to check that the row still looks the way the review showed it.
|
|
13
|
+
* A review the user reads for a minute is a minute in which somebody else can change the same
|
|
14
|
+
* row, and writing the payload built from the old one would silently undo their change.
|
|
15
|
+
*
|
|
16
|
+
* **The row is read through a resource the assistant can already read.** That is the rule, not
|
|
17
|
+
* a convenience: the read tools are the assistant's whole view of the app's data, and sourcing
|
|
18
|
+
* a pre-image anywhere else would let the write path see — and show a user, and hand a model —
|
|
19
|
+
* fields that no read tool was allowed to return. A write may therefore only be built on a row
|
|
20
|
+
* the same assistant could have read itself.
|
|
21
|
+
*/
|
|
22
|
+
export type GenesisRowRead = {
|
|
23
|
+
status: 'ok';
|
|
24
|
+
row: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Nothing matches the key. Before the review it cannot be built; after it, the row is gone. */
|
|
27
|
+
| {
|
|
28
|
+
status: 'missing';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* More than one row matches, so the values given are not a key. Never written on: a modify
|
|
32
|
+
* would be applied to whichever row the server picked, which is not a thing to ask a user to
|
|
33
|
+
* approve.
|
|
34
|
+
*
|
|
35
|
+
* No count: the read asks for at most two rows (KEY_MAX_ROWS), so any number it gave would say
|
|
36
|
+
* two whether two rows matched or four hundred, and a model told "matches 2 rows" reads the key
|
|
37
|
+
* as nearly unique and adds one condition.
|
|
38
|
+
*/
|
|
39
|
+
| {
|
|
40
|
+
status: 'ambiguous';
|
|
41
|
+
} | {
|
|
42
|
+
status: 'failed';
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Where a write's rows are read from. One per event resource, held for the life of the tools.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export interface GenesisRowSource {
|
|
51
|
+
/** The resource rows are read through, named in a refusal so the link is visible. */
|
|
52
|
+
readonly resource: string;
|
|
53
|
+
read(key: Record<string, unknown>): Promise<GenesisRowRead>;
|
|
54
|
+
/**
|
|
55
|
+
* Every column this resource describes and the type it describes it as, or `undefined` when
|
|
56
|
+
* its metadata could not be read.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Two callers, which is why it carries the type rather than just the name. The coverage check
|
|
60
|
+
* asks whether a row read here can carry a WHOLE event payload — a generated modify replaces
|
|
61
|
+
* the record, so a column the resource does not return is a column written null, and no
|
|
62
|
+
* row-by-row check can catch it. The REVIEW asks something else: a delete renders the whole
|
|
63
|
+
* row, including columns the event never declares, and without a type for those a date is
|
|
64
|
+
* shown to the approver as raw epoch millis.
|
|
65
|
+
*/
|
|
66
|
+
describes(): Promise<ReadonlyMap<string, string> | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* The fields a key can be matched on here, with the types the read composes its criteria
|
|
69
|
+
* with, or `undefined` when its metadata could not be read.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Not the event's fields. The read finds a row by composing a criteria against THIS map, which
|
|
73
|
+
* is narrower: only `CRITERIA_FIELDS` when the resource publishes one, and never a field it
|
|
74
|
+
* leaves untyped or whose allowed values cannot be read. A key schema built from the event's
|
|
75
|
+
* own fields offered keys the read then refused by name, and put a review in front of the user
|
|
76
|
+
* with every row red.
|
|
77
|
+
*/
|
|
78
|
+
filterableBy(): Promise<ReadonlyMap<string, GenesisFilterField> | undefined>;
|
|
79
|
+
}
|
|
80
|
+
/** @internal */
|
|
81
|
+
export interface RequestRowSourceOptions {
|
|
82
|
+
connect: Connect;
|
|
83
|
+
/** The `REQ_*` resource to read through — one of the assistant's own read resources. */
|
|
84
|
+
resource: string;
|
|
85
|
+
timeouts?: {
|
|
86
|
+
metadataMs?: number;
|
|
87
|
+
readMs?: number;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reads single rows from a request resource, by an exact match on the key fields.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* The criteria is composed by {@link composeCriteria} against the resource's own filter fields,
|
|
95
|
+
* so the expression, the escaping and the types are the ones the read tools already use — the
|
|
96
|
+
* key travels as a value, never as text spliced into an expression, and a field the resource
|
|
97
|
+
* does not publish is refused here rather than by the server.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export declare function createRequestRowSource({ connect, resource, timeouts, }: RequestRowSourceOptions): GenesisRowSource;
|
|
102
|
+
//# sourceMappingURL=row-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row-source.d.ts","sourceRoot":"","sources":["../../../src/genesis/row-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE;AAChD,gGAAgG;GAC9F;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE;AACvB;;;;;;;;GAQG;GACD;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GACvB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5D;;;;;;;;;;;OAWG;IACH,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IAC9D;;;;;;;;;;OAUG;IACH,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,SAAS,CAAC,CAAC;CAC9E;AAKD,gBAAgB;AAChB,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,wFAAwF;IACxF,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,QAAQ,EACR,QAAQ,GACT,EAAE,uBAAuB,GAAG,gBAAgB,CAwH5C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row values as they can be serialised.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Comms' own deserializer turns any integer outside the safe range into a `BigInt`
|
|
6
|
+
* (`foundation-utils` `customNumberParser`), so a Genesis LONG or BIGINT column arrives as one.
|
|
7
|
+
* A BigInt cannot be `JSON.stringify`'d, and both paths that carry a row hit that:
|
|
8
|
+
*
|
|
9
|
+
* - a READ tool's result, which the chat driver stringifies — one such column anywhere in a row
|
|
10
|
+
* killed the turn with "TypeError: Do not know how to serialize a BigInt";
|
|
11
|
+
* - a WRITE's pre-image, which travels into the review interaction's `data` and from there into
|
|
12
|
+
* the driver's history, where it is persisted.
|
|
13
|
+
*
|
|
14
|
+
* A value that fits a JS number exactly becomes one; anything larger becomes its decimal string,
|
|
15
|
+
* because the alternative is telling the model — or showing a user — a number that is quietly
|
|
16
|
+
* wrong. Nested values are walked: the BigInt can sit inside an object or an array in the row.
|
|
17
|
+
*
|
|
18
|
+
* `foundation-utils`' own serializer is not the fix here: it solves stringifying (and is the
|
|
19
|
+
* right fix for the driver, separately), but routing rows through it and back would lose the
|
|
20
|
+
* very precision this preserves.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function serialisable(value: unknown): unknown;
|
|
25
|
+
//# sourceMappingURL=serialisable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialisable.d.ts","sourceRoot":"","sources":["../../../src/genesis/serialisable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAepD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export declare const readsLikeProse: (text: string) => boolean;
|
|
3
|
+
/** Whether text is a Genesis identifier, the {@link FIELD_NAME} shape. @internal */
|
|
4
|
+
export declare const readsLikeFieldName: (text: string) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a value the server produced may be shown as a KEY value — an id like
|
|
7
|
+
* `000000000000001TRLO1`, a code, a decimal.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Restricted characters, then the same shape tests the prose rule uses, for the same reason: a
|
|
11
|
+
* class name, an address and a path all arrive looking like an ordinary value. The characters
|
|
12
|
+
* alone were not enough — `global.genesis.db.DbRecord` and `TradeDao.java` are letters and dots
|
|
13
|
+
* — while a decimal like `1.25` has a digit before its dot and is a perfectly ordinary key.
|
|
14
|
+
*
|
|
15
|
+
* One rule for the index value in a duplicate-key `FIELD` and for a key a write GENERATED, so the
|
|
16
|
+
* two cannot drift.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare const readsLikeKeyValue: (text: string) => boolean;
|
|
21
|
+
/** @internal */
|
|
22
|
+
export declare function plainFieldName(field: string | undefined, context: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The server's text if it can be shown, and a plain fallback if it cannot.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Anything replaced is logged with its context: an unfamiliar refusal is exactly the one whoever
|
|
28
|
+
* is debugging the bridge needs to see, and it is the one the model was told nothing about.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function plainServerText(text: string | undefined, context: string, fallback: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Whatever a rejection turns out to be, as a sentence.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Comms rejects with a plain object rather than an `Error` on the socket path, so `String(error)`
|
|
38
|
+
* handed the model `The read failed: [object Object]` — which tells it nothing and, worse, reads
|
|
39
|
+
* like the bridge having no idea what happened. An `Error` still answers with its message.
|
|
40
|
+
*/
|
|
41
|
+
export declare function describeFailure(error: unknown): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* A rejection as one sentence a model and a user may both see.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* Three shapes reach here and all three used to be printed raw with `String(error)`:
|
|
47
|
+
*
|
|
48
|
+
* - an `Error` from the server, whose message can carry a SQL code, a class name or a host;
|
|
49
|
+
* - a plain object, which comms rejects with on the socket path — `[object Object]`, which
|
|
50
|
+
* tells the model nothing and reads like the bridge not knowing what happened;
|
|
51
|
+
* - {@link withTimeout}'s own rejection, which is OUR message and names an internal helper.
|
|
52
|
+
*
|
|
53
|
+
* The timeout is said in words, because it is not the server's text and "it took too long" is
|
|
54
|
+
* something the model can act on. Everything else goes through the same allow-list a refusal
|
|
55
|
+
* does. The full detail is always logged.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function plainFailure(error: unknown, context: string, wording: {
|
|
60
|
+
timeout: string;
|
|
61
|
+
failed: string;
|
|
62
|
+
}): string;
|
|
63
|
+
//# sourceMappingURL=server-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-text.d.ts","sourceRoot":"","sources":["../../../src/genesis/server-text.ts"],"names":[],"mappings":"AA2DA,gBAAgB;AAChB,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAQrB,CAAC;AAyB1B,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OAAgC,CAAC;AAEnF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,OAC8C,CAAC;AAEhG,gBAAgB;AAChB,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAY7F;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR;AAKD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUlE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3C,MAAM,CAKR"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Genesis field type, as the platform writes it, reduced to the name a lookup can match.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Metadata and schemas carry parameters — `STRING(256)`, `BIGDECIMAL(20,4)` — and every place
|
|
6
|
+
* that reasons about a type has to strip them first. Shared because forgetting it fails
|
|
7
|
+
* SILENTLY, differently each time: a parameterised decimal falls outside the numeric set and is
|
|
8
|
+
* compared as text (a change marked that is not one), or misses the JSON-type map and goes to
|
|
9
|
+
* the wire in the wrong shape. Four call sites each learned that separately; the fifth would
|
|
10
|
+
* have learned it too.
|
|
11
|
+
*
|
|
12
|
+
* Only the PARSING is shared. Each caller keeps its own set of types, because what counts as a
|
|
13
|
+
* date to a formatter is not what counts as a number to a comparator.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const genesisTypeName: (type: string | undefined) => string;
|
|
18
|
+
//# sourceMappingURL=type-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-name.d.ts","sourceRoot":"","sources":["../../../src/genesis/type-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,MAIhD,CAAC"}
|
|
@@ -90,6 +90,13 @@ export interface RegisterGenesisAssistantOptions {
|
|
|
90
90
|
*/
|
|
91
91
|
connect?: Connect;
|
|
92
92
|
extensions?: GenesisAssistantExtensions;
|
|
93
|
+
/**
|
|
94
|
+
* Which request resource a modify or delete reads its rows from, by event name. Defaults to
|
|
95
|
+
* the `REQ_` resource for the same table — `EVENT_TRADE_MODIFY` reads `REQ_TRADE` — when the
|
|
96
|
+
* app exposes one. An event with no source gets no tool: a modify that cannot read its row
|
|
97
|
+
* cannot be built, because the fields nobody named would be written as null.
|
|
98
|
+
*/
|
|
99
|
+
rowSources?: Record<string, string>;
|
|
93
100
|
/**
|
|
94
101
|
* Vendors the user may switch between. Defaults to the configured vendor alone: an app whose
|
|
95
102
|
* proxy holds one key would otherwise offer a switch to a vendor that cannot answer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/genesis/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAErF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,OAAO,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,mDAAoD,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,mBAAmB,CAAC;IAC1B,mBAAmB;IACnB,EAAE,CAAC,EAAE,cAAc,CAAC;IACpB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,iBAAiB,EAAE,C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EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6EAA6E;IAC7E,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One canonical text for a value, whatever shape it arrived in.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Numbers are canonicalised as TEXT rather than through `Number`: a Genesis LONG beyond 2^53
|
|
6
|
+
* arrives from a read as a decimal string, and parsing it to compare would round exactly the
|
|
7
|
+
* values — ids, sequence numbers — where a wrong answer is worst. So `100.50` and `100.5` are
|
|
8
|
+
* the same value, and `9007199254740993` is not `9007199254740992`.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function normaliseValue(value: unknown, type?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether two values are the same value, whichever side each came from.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const sameValue: (left: unknown, right: unknown, type?: string) => boolean;
|
|
19
|
+
//# sourceMappingURL=value-compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-compare.d.ts","sourceRoot":"","sources":["../../../src/genesis/value-compare.ts"],"names":[],"mappings":"AAmDA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAoBpE;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,OACb,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Connect } from '@genesislcap/foundation-comms';
|
|
2
|
+
import type { GenesisEventOp } from './types';
|
|
3
|
+
import { type GenesisWriteOutcome } from './write-outcome';
|
|
4
|
+
/**
|
|
5
|
+
* Commits the rows a user selected in the review — and only those, exactly as they were shown.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* **The payload committed is the object the review rendered**, carried through by reference
|
|
9
|
+
* rather than rebuilt from the model's original arguments after approval. Rebuilding would
|
|
10
|
+
* reopen the gap the review exists to close: the user approves what they read, and anything
|
|
11
|
+
* re-derived afterwards is something they did not.
|
|
12
|
+
*
|
|
13
|
+
* There is **no pre-write validation pass**. `VALIDATE: true` is accepted and ignored by a
|
|
14
|
+
* Create-generated handler — it declares `onCommit` only, so the platform runs it as a plain
|
|
15
|
+
* event handler and the row is COMMITTED. Asking for a dry run there would write every row the
|
|
16
|
+
* user was still deciding about, then report it as merely checked. What the dry run was buying
|
|
17
|
+
* is already done client-side, before anything is sent: required fields, types, enums, dates
|
|
18
|
+
* and read-only fields are all checked against the same metadata the server's schema validation
|
|
19
|
+
* reads.
|
|
20
|
+
*/
|
|
21
|
+
export interface GenesisWriteRow {
|
|
22
|
+
/** Position in the model's original list, so an outcome can be matched back to its row. */
|
|
23
|
+
index: number;
|
|
24
|
+
/** Exactly what will be sent as `DETAILS` — the object the review showed. */
|
|
25
|
+
details: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/** @internal */
|
|
28
|
+
export interface CommitOptions {
|
|
29
|
+
connect: Connect;
|
|
30
|
+
eventName: string;
|
|
31
|
+
/** The event's op: what a refusal means depends on it (see mapWriteReply's options). */
|
|
32
|
+
op: GenesisEventOp;
|
|
33
|
+
/** Why the user approved it, composed by the bridge and sent as the event's `REASON`. */
|
|
34
|
+
reason?: string;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
export interface GenesisRowResult extends GenesisWriteOutcome {
|
|
39
|
+
index: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Commits rows one at a time, in order, and never throws.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Sequential on purpose: a batch sent in parallel gives the user no way to reason about what
|
|
46
|
+
* happened when the connection drops halfway, and the per-row outcome is what both the user and
|
|
47
|
+
* the model are told. A row that fails does not stop the ones after it — each row is its own
|
|
48
|
+
* decision and its own answer — but every result says whether it reached the database.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export declare function commitRows(rows: readonly GenesisWriteRow[], { connect, eventName, op, reason, timeoutMs }: CommitOptions): Promise<GenesisRowResult[]>;
|
|
53
|
+
//# sourceMappingURL=write-commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-commit.d.ts","sourceRoot":"","sources":["../../../src/genesis/write-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,eAAe;IAC9B,2FAA2F;IAC3F,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,EAAE,EAAE,cAAc,CAAC;IACnB,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,gBAAgB;AAChB,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAC3D,KAAK,EAAE,MAAM,CAAC;CACf;AAmBD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,SAAS,eAAe,EAAE,EAChC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,SAA6B,EAAE,EAAE,aAAa,GAC/E,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAyD7B"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { GenesisEventOp } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* What happened to one row, read from the platform's own reply.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The shapes here were captured from a live 8.15 backend rather than inferred, because the
|
|
7
|
+
* replies do not share one envelope and the differences carry meaning:
|
|
8
|
+
*
|
|
9
|
+
* - `EVENT_ACK` has `GENERATED` and no error keys at all.
|
|
10
|
+
* - `EVENT_NACK` carries `ERROR` and `WARNING`, with **three** different error `@type`s.
|
|
11
|
+
* - An unmapped event name answers `MSG_NACK` — a different envelope entirely, with a numeric
|
|
12
|
+
* `CODE` and no `@type` — so nothing here may key off `EVENT_NACK`. The router answers other
|
|
13
|
+
* failures in the same envelope, with other codes, and only its 404 says nothing ran.
|
|
14
|
+
*
|
|
15
|
+
* The `FieldError` split is the one that changes who the message is for. `PATH` set (e.g.
|
|
16
|
+
* `"$.DETAILS"`) means the PAYLOAD was malformed: the bridge or the model built it wrong, and
|
|
17
|
+
* the model can act on that. `PATH` null means the payload was fine and the APP's own rule
|
|
18
|
+
* refused it: that is a business answer for the user, not a bug to retry. They must not read
|
|
19
|
+
* the same.
|
|
20
|
+
*/
|
|
21
|
+
export type GenesisWriteStatus = 'written'
|
|
22
|
+
/**
|
|
23
|
+
* A `VALIDATE` pass came back clean. NOT a promise the commit will succeed: on a
|
|
24
|
+
* Create-generated app the handler emits `onCommit` only, so its `onValidate` accepts
|
|
25
|
+
* anything and this proves the payload is well-formed and nothing more.
|
|
26
|
+
*/
|
|
27
|
+
| 'checked'
|
|
28
|
+
/** The payload was malformed — the model or the bridge built it wrong. */
|
|
29
|
+
| 'invalid_payload'
|
|
30
|
+
/** The app's own validation refused it. Nothing to retry; the answer is no. */
|
|
31
|
+
| 'refused_by_app'
|
|
32
|
+
/** A record with that key already exists. */
|
|
33
|
+
| 'duplicate'
|
|
34
|
+
/** The row changed or was removed between the review and the write. Nothing was written. */
|
|
35
|
+
| 'gone'
|
|
36
|
+
/** The database refused it for another reason. */
|
|
37
|
+
| 'database_error'
|
|
38
|
+
/**
|
|
39
|
+
* The event is not mapped to a service: a 404 `MSG_NACK`. Not any other MSG_NACK (a 5xx from
|
|
40
|
+
* the router can follow a commit) and not a reply this cannot read: both are `unknown`,
|
|
41
|
+
* because only a reply that says no can say nothing was written.
|
|
42
|
+
*/
|
|
43
|
+
| 'unavailable'
|
|
44
|
+
/** Nothing was sent: the app was not connected, or the bridge refused the row first. */
|
|
45
|
+
| 'failed'
|
|
46
|
+
/**
|
|
47
|
+
* The row WAS sent, and no answer that settles its fate came back: none at all (a timeout, a
|
|
48
|
+
* connection that went away mid-flight), a reply in a shape this cannot read, or a MSG_NACK
|
|
49
|
+
* other than a 404. Any of those can follow a commit. Distinct from `failed` because it must
|
|
50
|
+
* not carry a retry affordance: retrying an `unknown` row is how a record gets written twice.
|
|
51
|
+
*/
|
|
52
|
+
| 'unknown';
|
|
53
|
+
/** @internal */
|
|
54
|
+
export interface GenesisWriteOutcome {
|
|
55
|
+
status: GenesisWriteStatus;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the row is KNOWN to have reached the database. False on an `unknown` outcome does
|
|
58
|
+
* NOT mean nothing was written — read `status` before counting rows as unwritten or offering
|
|
59
|
+
* to try again.
|
|
60
|
+
*/
|
|
61
|
+
committed: boolean;
|
|
62
|
+
/** One line, written for whoever it is addressed to — see the `PATH` split above. */
|
|
63
|
+
message: string;
|
|
64
|
+
/** Per-field problems, when the reply named fields. */
|
|
65
|
+
fields?: Array<{
|
|
66
|
+
field?: string;
|
|
67
|
+
text: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** Keys the server generated, e.g. `[{ TRADE_ID: '000000000000001TRLO1' }]`. */
|
|
70
|
+
generated?: Array<Record<string, unknown>>;
|
|
71
|
+
/** Server warnings. Shown, never suppressed: the bridge does not send IGNORE_WARNINGS. */
|
|
72
|
+
warnings?: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether the reply came from a real commit or from a `VALIDATE` dry run. It changes what an
|
|
76
|
+
* ACK means, and nothing else.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* Required, with no default, because neither default is safe. Defaulting to commit and
|
|
80
|
+
* forgetting it on a dry run reports a row as written when the database was never touched.
|
|
81
|
+
* Defaulting to validate and forgetting it on a commit reports a row as unwritten when it WAS
|
|
82
|
+
* written — the user retries and inserts a second one, which nothing catches on a table with no
|
|
83
|
+
* unique key. There is no safer side to err on, so the compiler asks every caller.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export type WriteReplyMode = 'commit' | 'validate';
|
|
88
|
+
/**
|
|
89
|
+
* What a reply is read against.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* `op` is required for the reason `mode` is: what a reply means depends on it, and a default
|
|
93
|
+
* would decide that silently. `RECORD_NOT_FOUND` says an existing row is gone only on a modify
|
|
94
|
+
* or a delete; on an insert there is no existing row, and it is a reference the handler looked up.
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
export interface WriteReplyOptions {
|
|
99
|
+
mode: WriteReplyMode;
|
|
100
|
+
op: GenesisEventOp;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads one commit or `VALIDATE` reply into an outcome.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* Never throws, and never guesses: a reply it does not recognise is `unknown`, naming the
|
|
107
|
+
* reply's message type, rather than an optimistic "written".
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
export declare function mapWriteReply(reply: unknown, { mode, op }: WriteReplyOptions): GenesisWriteOutcome;
|
|
112
|
+
/**
|
|
113
|
+
* The outcome for a row that never reached the server — a thrown request, a timeout, or a row
|
|
114
|
+
* the bridge itself refused before sending.
|
|
115
|
+
*
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
export declare const writeNotAttempted: (status: Extract<GenesisWriteStatus, "failed" | "invalid_payload">, message: string, fields?: Array<{
|
|
119
|
+
field?: string;
|
|
120
|
+
text: string;
|
|
121
|
+
}>) => GenesisWriteOutcome;
|
|
122
|
+
/**
|
|
123
|
+
* The outcome for a row that WAS sent and whose fate no answer settles.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* Its own status precisely because `committed: false` is not a fact here: the server may have
|
|
127
|
+
* written the row before the connection went. A consumer counting unwritten rows, or offering
|
|
128
|
+
* to try again, must be able to tell this apart from a row that never left.
|
|
129
|
+
*
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export declare const writeOutcomeUnknown: (message: string) => GenesisWriteOutcome;
|
|
133
|
+
//# sourceMappingURL=write-outcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-outcome.d.ts","sourceRoot":"","sources":["../../../src/genesis/write-outcome.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,kBAAkB,GAC1B,SAAS;AACX;;;;GAIG;GACD,SAAS;AACX,0EAA0E;GACxE,iBAAiB;AACnB,+EAA+E;GAC7E,gBAAgB;AAClB,6CAA6C;GAC3C,WAAW;AACb,4FAA4F;GAC1F,MAAM;AACR,kDAAkD;GAChD,gBAAgB;AAClB;;;;GAIG;GACD,aAAa;AACf,wFAAwF;GACtF,QAAQ;AACV;;;;;GAKG;GACD,SAAS,CAA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|
+
/**
|
|
4
|
+
* Turns one row of model-supplied values into the `DETAILS` payload an event takes.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* **Every value is written the way the platform's own metadata says it travels, never the way
|
|
8
|
+
* JavaScript would guess.** Two of those differences were found on a live 8.15 backend and both
|
|
9
|
+
* are silent when you get them wrong:
|
|
10
|
+
*
|
|
11
|
+
* - **A date is epoch millis on a write.** Sending `'2026-09-21'` is refused by schema
|
|
12
|
+
* validation with "string found, integer expected" — and, because the field is
|
|
13
|
+
* `oneOf [integer, null]`, that arrives as three errors for one mistake, which is a confusing
|
|
14
|
+
* way to learn you used the wrong formatter. Criteria READS take `yyyyMMdd` strings, so the
|
|
15
|
+
* two paths take different forms and this one must not borrow the read path's formatter.
|
|
16
|
+
* - **A BIGDECIMAL is a STRING**, with a numeric pattern (`JSON_TYPE: 'string'`), while a DOUBLE
|
|
17
|
+
* is a JSON number. Putting a decimal through `Number` is a silent rounding of someone's
|
|
18
|
+
* money — the same family as an integer beyond 2^53 arriving as a BigInt.
|
|
19
|
+
*
|
|
20
|
+
* **Why two date representations, deliberately (parked 2026-09-21).** Collapsing the criteria
|
|
21
|
+
* literal onto millis too was considered and rejected on evidence. A live 8.15.14 app showed
|
|
22
|
+
* millis, `'20260921'` and `'2026-09-21'` returning identical rows — but only for RAW
|
|
23
|
+
* comparisons (`TRADE_DATE > …`). `criteria.ts` does not emit those: it calls the platform's
|
|
24
|
+
* own helpers with a quoted string (`Expr.dateIsAfter(TRADE_DATE, '20260921')`), and the
|
|
25
|
+
* dateTime helpers take a combined `yyyyMMdd-HH:mm` bound that has no millis analogue. Whether
|
|
26
|
+
* those helpers accept millis is untested, and an argument shape a helper does not take fails
|
|
27
|
+
* the way every date mistake fails here — zero rows, no error. What would justify the collapse
|
|
28
|
+
* is one live comparison of `Expr.dateIsAfter(FIELD, 1789948800000)` against
|
|
29
|
+
* `Expr.dateIsAfter(FIELD, '20260921')` with a discriminating row count; nothing less.
|
|
30
|
+
*
|
|
31
|
+
* Anything it cannot build is refused as a whole row: a partial payload would write a record
|
|
32
|
+
* the user never reviewed.
|
|
33
|
+
*/
|
|
34
|
+
export type PayloadResult = {
|
|
35
|
+
status: 'ok';
|
|
36
|
+
details: Record<string, unknown>;
|
|
37
|
+
} | {
|
|
38
|
+
status: 'rejected';
|
|
39
|
+
problems: string[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Types a model may not SET: a value is only ever carried through, unchanged, from the row.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* `NANO_TIMESTAMP`'s unit has not been captured from a live app. It is written as an integer,
|
|
46
|
+
* and if that integer is nanoseconds, a date the model writes as millis lands in 1970, while one
|
|
47
|
+
* beyond 2^53 cannot travel as a JSON number exactly at all. It used to go through the date
|
|
48
|
+
* branch, so a modify of any OTHER field carried it from the row and wrote it back rounded —
|
|
49
|
+
* `…123` as `…000` — while the review showed nothing changing in it. Until the unit is known,
|
|
50
|
+
* the only safe write is the row's own value, exactly, and only when a number can hold it.
|
|
51
|
+
*
|
|
52
|
+
* The platform's own `TIMESTAMP` column never gets here: it is {@link PLATFORM_MAINTAINED}.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare const isCarryOnly: (field: Pick<GenesisEventField, "type">) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a field holds a whole number, by its GENESIS type — the one rule the payload builder
|
|
59
|
+
* and the tool schema both follow, so the schema never offers what the builder then refuses.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare const isWholeNumberType: (type: string | undefined) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Builds one event payload from a row the model supplied.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Columns the platform adds to every generated table and nobody models. Never sent, whatever
|
|
71
|
+
* the op: they are not a business key, and a model has no business setting either.
|
|
72
|
+
*
|
|
73
|
+
* Also left out of the approve-time staleness check: TIMESTAMP moves on every write, so
|
|
74
|
+
* comparing it would call a row stale because somebody else's unrelated write touched it.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export declare const PLATFORM_MAINTAINED: Set<string>;
|
|
79
|
+
/** @internal */
|
|
80
|
+
export interface BuildPayloadOptions {
|
|
81
|
+
/** The resource's op. Decides whether a read-only field may travel; see above. */
|
|
82
|
+
op?: GenesisEventOp;
|
|
83
|
+
/**
|
|
84
|
+
* The row as it stands now, for a modify or delete — the same pre-image the review shows and
|
|
85
|
+
* the staleness check compares against.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* **A generated CRUD modify REPLACES the record** (`entityDb.modify(entity)`), so a payload
|
|
89
|
+
* carrying only the fields the model named writes null over every field it did not. Nobody
|
|
90
|
+
* would see it: the review shows what the user asked for, the server ACKs, and the rest of
|
|
91
|
+
* the record is gone — a successful write that destroys data.
|
|
92
|
+
*
|
|
93
|
+
* So the bridge fills the rest from the row it already has and the model supplies only the
|
|
94
|
+
* key and what it wants changed. That is correct under either server semantic: if the handler
|
|
95
|
+
* replaces, the whole record is required; if it patches, the whole record is identical to the
|
|
96
|
+
* patch. It also means a delete does not need the model to restate a row's values, which
|
|
97
|
+
* would be a model inventing them.
|
|
98
|
+
*/
|
|
99
|
+
preImage?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The fields this op may put on the wire: what the event declares, minus the platform's own
|
|
103
|
+
* columns, minus anything the op may not send.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* One rule, three readers — the pre-image merge, the "not a field of this event" message, and
|
|
107
|
+
* the review's columns — because a second copy of it is a second thing to get wrong, and the
|
|
108
|
+
* three disagreeing means a user is shown a set that is not the set being written.
|
|
109
|
+
*
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export declare const sendableFields: (fields: readonly GenesisEventField[], op: GenesisEventOp | undefined) => GenesisEventField[];
|
|
113
|
+
/**
|
|
114
|
+
* Whether text shows nothing at all. One test for the payload builder and the review, so what the
|
|
115
|
+
* review calls empty is exactly what the builder treats as a blank.
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
export declare const isBlankText: (text: string) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Whether a value the model sent means "I am not setting this": an empty string, a null, or text
|
|
122
|
+
* that shows nothing (see {@link isBlankText}). On a modify the field keeps the row's value, so
|
|
123
|
+
* none of them can clear a column; on an insert the field is left out. See `sourceOf`.
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
export declare const isBlankEntry: (value: unknown) => boolean;
|
|
128
|
+
export declare function buildEventPayload(fields: readonly GenesisEventField[], row: unknown, { op, preImage }?: BuildPayloadOptions): PayloadResult;
|
|
129
|
+
//# sourceMappingURL=write-payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-payload.d.ts","sourceRoot":"","sources":["../../../src/genesis/write-payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAClD;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAa/C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,KAAG,OACnB,CAAC;AAwCnD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